00001 #ifndef PART_H
00002 #define PART_H
00003
00004 #include <vector>
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007
00008 #include "Point.h"
00009 #include "Connection.h"
00010 #include "Operations.h"
00011
00012 #define verbose 1
00013
00018 template <class DataType, int dim>
00019 class PartBase {
00020 public:
00021 typedef Connection ConBase;
00022 typedef Segment<DataType,dim> SegType;
00023 typedef Facet<DataType> FacetType;
00024
00025 PartBase() {
00026 deformable = 0;
00027 mobile = 1;
00028 }
00029 ~PartBase() {}
00030
00034 enum IOType { pointList ,
00035 VTK_curve ,
00036 Brep2D ,
00037 VTK_PL ,
00038 Brep3D ,
00039 STL ,
00040 loft ,
00041 VelDat };
00042
00043 virtual void read(const int type, std::string file) = 0;
00044 virtual void output(int type, DataType time, std::string file) = 0;
00045 virtual void output(int type, DataType time, FILE* fout) = 0;
00046
00047 virtual std::string Name() const { return name; }
00048 virtual void setName(std::string val) { name = val; }
00049
00050 virtual std::vector<int>& IdTag() { return idTag; }
00051 virtual void setIdTag(std::vector<int> val) { idTag = val; }
00052
00053 virtual void setDHMat( MType val ) { DHMat = val; }
00054 virtual MType GetDHMat() { return DHMat; }
00055
00056 virtual void setDHMat_old( MType val ) { DHMat_old = val; }
00057 virtual MType GetDHMat_old() { return DHMat_old; }
00058
00059 virtual void measure() = 0;
00060 virtual DataType Length() const = 0;
00061 virtual DataType Area() const = 0;
00062 virtual DataType Volume() const = 0;
00063 virtual bool closure() const = 0;
00064 virtual void setClosure(bool val) = 0;
00065 virtual PType Centroid() const = 0;
00066 virtual void setCentroid(PType val) = 0;
00067
00068 virtual void AddPoint( PType v) = 0;
00069 virtual int GetNumPoints() const = 0;
00070 virtual PType GetNthPoint(int n) const = 0;
00071 virtual PType * GetNthPointAddress(int n) = 0;
00072 virtual PType * GetNthVelocityAddress(int n) = 0;
00073
00074 virtual int GetNumConnections() const = 0;
00075 virtual ConBase * GetNthConnection(int n) const = 0;
00076 virtual int getNthCon(int i) const = 0;
00077
00078
00079 virtual std::vector<PType>& GetCPoints() = 0;
00080 virtual std::vector<PType>& GetCPoints_org() = 0;
00081 virtual std::vector<PType>& GetVelocities() = 0;
00082
00083 virtual void updatePart(DataType dt,DataType time) = 0;
00084 virtual void resetPart() = 0;
00085
00086 virtual void setDeformation(bool val) = 0;
00087 virtual bool GetDeformation() const = 0;
00088 virtual void deformPart(DataType dt,DataType time) = 0;
00089 virtual void setMobility(bool val) { mobile = val; }
00090 virtual bool GetMobility() const { return mobile; }
00091
00092 virtual void print() {
00093 ( mklog() << Name() << "\n\tDHMat_old = " << DHMat_old << std::endl
00094 << "\n\tDHMat = " << DHMat << std::endl ).flush();
00095 }
00096
00097 virtual void Restart(std::ifstream& ifs, int& pos, double& t, double& dt) = 0;
00098 virtual void Checkpointing(std::ofstream& ofs) = 0;
00099
00100 virtual void RestartPart(std::ifstream& ifs, int& pos, double& t, double& dt) {
00101 #ifdef CHECKRESTART_DEBUG_ON
00102 ( mklog() << "\nRESTARTING Part " << Name() << t << " dt = " << dt << " pos = "
00103 << pos << std::endl ).flush();
00104 #endif
00105 ifs.seekg(pos);
00106
00107 ifs.read((char*)&DHMat(0,0),sizeof(DataType));
00108 ifs.read((char*)&DHMat(0,1),sizeof(DataType));
00109 ifs.read((char*)&DHMat(0,2),sizeof(DataType));
00110 ifs.read((char*)&DHMat(0,3),sizeof(DataType));
00111 ifs.read((char*)&DHMat(1,0),sizeof(DataType));
00112 ifs.read((char*)&DHMat(1,1),sizeof(DataType));
00113 ifs.read((char*)&DHMat(1,2),sizeof(DataType));
00114 ifs.read((char*)&DHMat(1,3),sizeof(DataType));
00115 ifs.read((char*)&DHMat(2,0),sizeof(DataType));
00116 ifs.read((char*)&DHMat(2,1),sizeof(DataType));
00117 ifs.read((char*)&DHMat(2,2),sizeof(DataType));
00118 ifs.read((char*)&DHMat(2,3),sizeof(DataType));
00119 ifs.read((char*)&DHMat(3,0),sizeof(DataType));
00120 ifs.read((char*)&DHMat(3,1),sizeof(DataType));
00121 ifs.read((char*)&DHMat(3,2),sizeof(DataType));
00122 ifs.read((char*)&DHMat(3,3),sizeof(DataType));
00123
00124 ifs.read((char*)&DHMat_old(0,0),sizeof(DataType));
00125 ifs.read((char*)&DHMat_old(0,1),sizeof(DataType));
00126 ifs.read((char*)&DHMat_old(0,2),sizeof(DataType));
00127 ifs.read((char*)&DHMat_old(0,3),sizeof(DataType));
00128 ifs.read((char*)&DHMat_old(1,0),sizeof(DataType));
00129 ifs.read((char*)&DHMat_old(1,1),sizeof(DataType));
00130 ifs.read((char*)&DHMat_old(1,2),sizeof(DataType));
00131 ifs.read((char*)&DHMat_old(1,3),sizeof(DataType));
00132 ifs.read((char*)&DHMat_old(2,0),sizeof(DataType));
00133 ifs.read((char*)&DHMat_old(2,1),sizeof(DataType));
00134 ifs.read((char*)&DHMat_old(2,2),sizeof(DataType));
00135 ifs.read((char*)&DHMat_old(2,3),sizeof(DataType));
00136 ifs.read((char*)&DHMat_old(3,0),sizeof(DataType));
00137 ifs.read((char*)&DHMat_old(3,1),sizeof(DataType));
00138 ifs.read((char*)&DHMat_old(3,2),sizeof(DataType));
00139 ifs.read((char*)&DHMat_old(3,3),sizeof(DataType));
00140
00141 pos = ifs.tellg();
00142
00143 }
00144
00145 virtual void CheckpointPart(std::ofstream& ofs) {
00146 #ifdef CHECKRESTART_DEBUG_ON
00147 ( mklog() << "\nCHECKPOINTING Part " << Name() << std::endl ).flush();
00148 #endif
00149 ofs.write((char*)&DHMat(0,0),sizeof(DataType));
00150 ofs.write((char*)&DHMat(0,1),sizeof(DataType));
00151 ofs.write((char*)&DHMat(0,2),sizeof(DataType));
00152 ofs.write((char*)&DHMat(0,3),sizeof(DataType));
00153 ofs.write((char*)&DHMat(1,0),sizeof(DataType));
00154 ofs.write((char*)&DHMat(1,1),sizeof(DataType));
00155 ofs.write((char*)&DHMat(1,2),sizeof(DataType));
00156 ofs.write((char*)&DHMat(1,3),sizeof(DataType));
00157 ofs.write((char*)&DHMat(2,0),sizeof(DataType));
00158 ofs.write((char*)&DHMat(2,1),sizeof(DataType));
00159 ofs.write((char*)&DHMat(2,2),sizeof(DataType));
00160 ofs.write((char*)&DHMat(2,3),sizeof(DataType));
00161 ofs.write((char*)&DHMat(3,0),sizeof(DataType));
00162 ofs.write((char*)&DHMat(3,1),sizeof(DataType));
00163 ofs.write((char*)&DHMat(3,2),sizeof(DataType));
00164 ofs.write((char*)&DHMat(3,3),sizeof(DataType));
00165
00166 ofs.write((char*)&DHMat_old(0,0),sizeof(DataType));
00167 ofs.write((char*)&DHMat_old(0,1),sizeof(DataType));
00168 ofs.write((char*)&DHMat_old(0,2),sizeof(DataType));
00169 ofs.write((char*)&DHMat_old(0,3),sizeof(DataType));
00170 ofs.write((char*)&DHMat_old(1,0),sizeof(DataType));
00171 ofs.write((char*)&DHMat_old(1,1),sizeof(DataType));
00172 ofs.write((char*)&DHMat_old(1,2),sizeof(DataType));
00173 ofs.write((char*)&DHMat_old(1,3),sizeof(DataType));
00174 ofs.write((char*)&DHMat_old(2,0),sizeof(DataType));
00175 ofs.write((char*)&DHMat_old(2,1),sizeof(DataType));
00176 ofs.write((char*)&DHMat_old(2,2),sizeof(DataType));
00177 ofs.write((char*)&DHMat_old(2,3),sizeof(DataType));
00178 ofs.write((char*)&DHMat_old(3,0),sizeof(DataType));
00179 ofs.write((char*)&DHMat_old(3,1),sizeof(DataType));
00180 ofs.write((char*)&DHMat_old(3,2),sizeof(DataType));
00181 ofs.write((char*)&DHMat_old(3,3),sizeof(DataType));
00182
00183 }
00184
00185 std::string name;
00186 std::vector<int> idTag;
00193 virtual void setCGS(int val) { cgs = val; }
00194 virtual int GetCGS() const { return cgs; }
00195
00196 virtual void pressureForce( multi_index_type* cons, DataType* press, DataType scale ) = 0;
00197 virtual void logLoad( std::ofstream& ofs, DataType time_, int step ) = 0;
00198
00199 protected:
00200 bool deformable;
00201 bool mobile;
00202 MType AssemblyTmatrix;
00203 MType MotionTmatrix;
00204
00205 MType DHMat;
00206 MType DHMat_old;
00207
00208 int cgs;
00209 };
00210
00211 template <class DataType, int dim>
00212 class Part : public PartBase<DataType,dim> {
00213 public:
00214 typedef PartBase<DataType,dim> base;
00215 Part() {
00216 base();
00217 base::DHMat.resize(dim+1,dim+1);
00218 base::DHMat.assign(imatrix(dim+1));
00219 base::DHMat_old.resize(dim+1,dim+1);
00220 base::DHMat_old.assign(imatrix(dim+1));
00221 }
00222 ~Part() {}
00223 };
00224
00225 template <class DataType>
00226 class Part<DataType,2> : public PartBase<DataType,2> {
00227 public:
00228 typedef Connection ConBase;
00229 typedef Segment<DataType,2> SegType;
00230 typedef Facet<DataType> FacetType;
00231
00232 virtual void AddConnection( SegType v) = 0;
00233 virtual const SegType * GetNthSegment(int n) const = 0;
00234 virtual SegType * EditNthSegment(int n) = 0;
00235
00236 protected:
00237
00238 };
00239
00240 template <class DataType>
00241 class Part<DataType,3> : public PartBase<DataType,3> {
00242 public:
00243 typedef Connection ConBase;
00244 typedef Segment<DataType,3> SegType;
00245 typedef Facet<DataType> FacetType;
00246
00247 virtual void AddConnection( SegType v) = 0;
00248 virtual void AddConnection( FacetType v) = 0;
00249 virtual const SegType * GetNthSegment(int n) const = 0;
00250 virtual const FacetType * GetNthFacet(int n) const = 0;
00251 virtual FacetType * EditNthFacet(int n) = 0;
00252 virtual SegType * EditNthSegment(int n) = 0;
00253 virtual PType Normal() const = 0;
00254 virtual void setNormal(PType val) = 0;
00255
00256 protected:
00257
00258 };
00259
00260 #endif // PART_H