32CVoxelMesh::CVoxelMesh(
string Type)
34 if ( Type ==
"CShearedPeriodicBoundaries" )
36 else if ( Type ==
"CStaggeredPeriodicBoundaries" )
38 else if ( Type ==
"CRotatedPeriodicBoundaries" )
40 else if ( Type ==
"CBendingPeriodicBoundaries" )
52 bool bOutputMatrix,
bool bOutputYarns,
int iBoundaryConditions,
int iElementType,
int FileType)
60 TGERROR(
"Unable to create ABAQUS input file: No domain specified");
67 TGLOG(
"Calculating voxel sizes");
70 TGERROR(
"Unable to create ABAQUS input file: Error calculating voxel sizes");
73 TGLOG(
"Replacing spaces in filename with underscore for ABAQUS compatibility");
79 timer.
start(
"Timing SaveToAbaqus");
80 SaveToAbaqus(OutputFilename, Textile, bOutputMatrix, bOutputYarns, iBoundaryConditions, iElementType);
81 timer.
check(
"End of SaveToAbaqus");
249 ofstream Output(Filename.c_str());
262 vector<POINT_INFO>::iterator itElementInfo;
266 YarnIndex.
m_Data.push_back(itElementInfo->iYarnIndex);
267 YarnTangent.
m_Data.push_back(itElementInfo->YarnTangent);
268 Location.
m_Data.push_back(itElementInfo->Location);
269 VolumeFraction.
m_Data.push_back(itElementInfo->dVolumeFraction);
270 SurfaceDistance.
m_Data.push_back(itElementInfo->dSurfaceDistance);
271 Orientation.
m_Data.push_back(itElementInfo->Orientation);
275 vector<CMeshDataBase*> MeshData;
277 MeshData.push_back(&YarnIndex);
278 MeshData.push_back(&YarnTangent);
279 MeshData.push_back(&Location);
280 MeshData.push_back(&VolumeFraction);
281 MeshData.push_back(&SurfaceDistance);
282 MeshData.push_back(&Orientation);
292 ofstream Output(Filename.c_str());
296 TGERROR(
"Unable to output voxel mesh to ABAQUS file format, could not open file: " << Filename);
300 TGLOG(
"Saving voxel mesh data to " << Filename);
302 Output <<
"*Heading" <<
"\n";
303 Output <<
"File generated by TexGen v" <<
TEXGEN.GetVersion() <<
"\n";
305 Output <<
"************" <<
"\n";
306 Output <<
"*** MESH ***" <<
"\n";
307 Output <<
"************" <<
"\n";
308 Output <<
"*Node" <<
"\n";
312 TGLOG(
"Outputting hex elements");
314 int iNumHexElements = 0;
317 Output <<
"*Element, Type=C3D8R" <<
"\n";
321 Output <<
"*Element, Type=C3D8" <<
"\n";
326 bool bMatrixOnly =
false;
327 if ( bOutputMatrix && !bOutputYarn )
332 TGLOG(
"Outputting orientations & element sets");
337 else if ( bMatrixOnly )
355 TGLOG(
"Finished saving to Abaqus");
361 Filename +=
".hx.pts";
363 ofstream NodesFile(Filename.c_str());
367 TGERROR(
"Unable to output voxel mesh to SCIRun file format, could not open file: " << Filename);
371 TGLOG(
"Saving voxel mesh data points to " << Filename);
378 ofstream OutputElements(Filename.c_str());
382 TGERROR(
"Unable to output voxel mesh to SCIRun file format, could not open file: " << Filename);
386 TGLOG(
"Outputting hex elements");
388 int iNumHexElements = 0;
392 TGLOG(
"Finished saving to SCIRun format");
404 vector<POINT_INFO>::iterator itElementInfo =
m_ElementsInfo.begin();
405 int iElementNumber = 1;
407 vector<POINT_INFO> NewElementInfo;
418 if ( (itElementInfo->iYarnIndex == -1 && bOutputMatrix)
419 || (itElementInfo->iYarnIndex >=0 && bOutputYarn) )
423 Output << iElementNumber <<
", ";
424 Output << (x+1) +y*numx + z*numx*numy + 1 <<
", " << (x+1) + (y+1)*numx + z*numx*numy + 1 <<
", ";
425 Output << x + (y+1)*numx + z*numx*numy + 1 <<
", " << x + y*numx + z*numx*numy + 1 <<
", ";
426 Output << (x+1) +y*numx + (z+1)*numx*numy + 1 <<
", " << (x+1) +(y+1)*numx + (z+1)*numx*numy + 1 <<
", ";
427 Output << x +(y+1)*numx + (z+1)*numx*numy + 1 <<
", " << x +y*numx + (z+1)*numx*numy + 1 <<
"\n";
431 Output << x +y*numx + z*numx*numy + 1 <<
", " << (x+1) + y*numx + z*numx*numy + 1 <<
", ";
432 Output << x + y*numx + (z+1)*numx*numy + 1 <<
", " << (x+1) + y*numx + (z+1)*numx*numy + 1 <<
", ";
433 Output << x + (y+1)*numx + z*numx*numy + 1 <<
", " << (x+1) +(y+1)*numx + z*numx*numy + 1 <<
", ";
434 Output << x +(y+1)*numx + (z+1)*numx*numy + 1 <<
", " << (x+1) + (y+1)*numx + (z+1)*numx*numy + 1 <<
"\n";
439 Indices.push_back(x + y*numx + z*numx*numy);
440 Indices.push_back((x + 1) + y*numx + z*numx*numy);
441 Indices.push_back((x + 1) + y*numx + (z + 1)*numx*numy);
442 Indices.push_back(x + y*numx + (z + 1)*numx*numy);
443 Indices.push_back(x + (y + 1)*numx + z*numx*numy);
444 Indices.push_back((x + 1) + (y + 1)*numx + z*numx*numy);
445 Indices.push_back((x + 1) + (y + 1)*numx + (z + 1)*numx*numy);
446 Indices.push_back(x + (y + 1)*numx + (z + 1)*numx*numy);
450 if ( bOutputYarn && !bOutputMatrix )
452 NewElementInfo.push_back( *itElementInfo );
462 if ( bOutputYarn && !bOutputMatrix )
467 return ( iElementNumber-1 );
474 ofstream Output(Filename.c_str(), ofstream::app);
480 string OrientationsFilename = Filename;
481 OrientationsFilename.replace(OrientationsFilename.end()-4, OrientationsFilename.end(),
".ori");
482 ofstream OriOutput(OrientationsFilename.c_str());
483 string ElementDataFilename = Filename;
484 ElementDataFilename.replace(ElementDataFilename.end()-4, ElementDataFilename.end(),
".eld");
485 ofstream DataOutput(ElementDataFilename.c_str());
489 TGERROR(
"Unable to output orientations, could not open file: " << OrientationsFilename);
494 TGERROR(
"Unable to output additional element data, could not open file: " << ElementDataFilename);
498 TGLOG(
"Saving element orientations data to " << OrientationsFilename);
499 TGLOG(
"Saving additional element data to " << ElementDataFilename);
502 Output <<
"*Distribution Table, Name=TexGenOrientationVectors" <<
"\n";
503 Output <<
"COORD3D,COORD3D" <<
"\n";
504 Output <<
"*Distribution, Location=Element, Table=TexGenOrientationVectors, Name=TexGenOrientationVectors, Input=" <<
StripPath(OrientationsFilename) <<
"\n";
505 Output <<
"*Orientation, Name=TexGenOrientations, Definition=coordinates" <<
"\n";
506 Output <<
"TexGenOrientationVectors" <<
"\n";
507 Output <<
"1, 0" <<
"\n";
511 OriOutput <<
", 1.0, 0.0, 0.0, 0.0, 1.0, 0.0" <<
"\n";
517 map<int, vector<int> > ElementSets;
518 vector<POINT_INFO>::iterator itData;
521 if (itData->iYarnIndex != -1)
524 XYZ Dir = itData->Orientation;
528 OriOutput << i <<
", " << Dir <<
", " << Perp <<
"\n";
533 OriOutput << i <<
", 1.0, 0.0, 0.0, 0.0, 1.0, 0.0" <<
"\n";
536 DataOutput <<
", " << itData->iYarnIndex;
537 DataOutput <<
", " << itData->Location;
538 DataOutput <<
", " << itData->dVolumeFraction;
539 DataOutput <<
", " << itData->dSurfaceDistance;
541 ElementSets[itData->iYarnIndex].push_back(i);
545 Output <<
"********************" <<
"\n";
546 Output <<
"*** ELEMENT SETS ***" <<
"\n";
547 Output <<
"********************" <<
"\n";
548 Output <<
"** TexGen generates a number of element sets:" <<
"\n";
549 Output <<
"** All - Contains all elements" <<
"\n";
550 Output <<
"** Matrix - Contains all elements belonging to the matrix" <<
"\n";
551 Output <<
"** YarnX - Where X represents the yarn index" <<
"\n";
552 Output <<
"*ElSet, ElSet=AllElements, Generate" <<
"\n";
554 vector<int>::iterator itIndices;
555 map<int, vector<int> >::iterator itElementSet;
556 for (itElementSet = ElementSets.begin(); itElementSet != ElementSets.end(); ++itElementSet)
558 if (itElementSet->first == -1)
559 Output <<
"*ElSet, ElSet=Matrix" <<
"\n";
561 Output <<
"*ElSet, ElSet=Yarn" << itElementSet->first <<
"\n";
573 Output <<
"********************" <<
"\n";
574 Output <<
"*** ELEMENT SETS ***" <<
"\n";
575 Output <<
"********************" <<
"\n";
576 Output <<
"** TexGen generates a number of element sets:" <<
"\n";
577 Output <<
"** All - Contains all elements" <<
"\n";
578 Output <<
"** Matrix - Contains all elements belonging to the matrix" <<
"\n";
579 Output <<
"** YarnX - Where X represents the yarn index" <<
"\n";
580 Output <<
"*ElSet, ElSet=Matrix, Generate" <<
"\n";
581 Output <<
"1, " << iNumHexElements <<
", 1" <<
"\n";
586 Output <<
"*****************" <<
"\n";
587 Output <<
"*** NODE SETS ***" <<
"\n";
588 Output <<
"*****************" <<
"\n";
589 Output <<
"** AllNodes - Node set containing all elements" <<
"\n";
590 Output <<
"*NSet, NSet=AllNodes, Generate" <<
"\n";
600 pair< vector<int>, vector<int> > Faces;
608 for (
int z = 1; z < numz-1; ++z )
610 for (
int y = 1; y < numy-1; ++y )
612 GroupA.push_back( numx-1 + y*numx + z*numx*numy +1 );
613 GroupB.push_back( y*numx + z*numx*numy + 1);
621 for (
int z = 1; z < numz-1; ++z )
623 for (
int x = 1; x < numx-1; ++x )
625 GroupA.push_back( x + (numy-1)*numx + z*numx*numy +1 );
626 GroupB.push_back( x + z*numx*numy + 1);
634 for (
int y = 1; y < numy-1; ++y )
636 for (
int x = 1; x < numx-1; ++x )
638 GroupA.push_back( x + y*numx + (numz-1)*numx*numy + 1);
639 GroupB.push_back( x + y*numx + 1 );
646 vector<int> Edges[4];
648 for (
int z = 1; z < numz-1; ++z )
650 Edges[0].push_back( z*numx*numy + 1 );
651 Edges[3].push_back( numx*(numy-1) + z*numx*numy +1 );
652 Edges[2].push_back( (z+1)*numx*numy );
653 Edges[1].push_back( numx + z*numx*numy );
656 for (
int i = 0; i < 4; ++i )
662 for (
int y = 1; y < numy-1; ++y )
664 Edges[3].push_back( y*numx + (numz-1)*numx*numy + 1 );
665 Edges[2].push_back( (y+1)*numx +(numz-1)*numx*numy );
666 Edges[1].push_back( (y+1)*numx );
667 Edges[0].push_back( y*numx + 1 );
670 for (
int i = 0; i < 4; ++i )
676 for (
int x = 1; x < numx-1; ++x )
678 Edges[3].push_back( x + (numz-1)*numx*numy + 1 );
679 Edges[2].push_back( x + numx*(numy-1) + (numz-1)*numx*numy +1 );
680 Edges[1].push_back( x + numx*(numy-1) + 1 );
681 Edges[0].push_back( x + 1 );
684 for (
int i = 0; i < 4; ++i )
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
#define TEXGEN
Helper macro to get the texgen instance.
Class used to generate Abaqus input file for periodic boundary conditions for a unit cell in tension ...
Abstract base class representing the domain in which a textile cell may lie.
const CMesh & GetMesh() const
Get the mesh representing the domain as a surface mesh.
bool AddElement(ELEMENT_TYPE Type, const vector< int > &Indices)
Add an element to the mesh of given type with node number checking.
bool SaveToVTK(string Filename, const vector< CMeshDataBase * > *pMeshData=NULL) const
Save the mesh to VTK unstructured grid file format (.vtu)
Class used to generate Abaqus output for periodic boundary conditions.
void SetFaceB(vector< int > &B1, vector< int > &B2)
void CreatePeriodicBoundaries(ostream &Output, int iDummyNodeNum, CTextile &Textile, int iBoundarConditions, bool bMatrixOnly)
void SetEdges(vector< int > &Edge)
virtual void SetDomainSize(const CMesh &Mesh)
void SetVertex(int Vertex)
void SetFaceA(vector< int > &A1, vector< int > &A2)
void SetFaceC(vector< int > &C1, vector< int > &C2)
Class used to generate Abaqus input file for periodic boundary conditions for a textile with rotated ...
Class used to generate Abaqus input file for periodic boundary conditions for a textile with sheared ...
Class used to generate Abaqus input file for periodic boundary conditions for a textile with staggere...
Represents a textile cell containing yarns.
const CDomain * GetDomain() const
void OutputMaterials(ostream &Output, int iNumYarns, bool bMatrixOnly)
Output materials and assign to yarn element sets.
void SetupMaterials(CTextile &Textile)
Set up a material for each unique set of material constants.
Class used to meaure the amount of time it takes to perform a certain task.
void stop(const char *msg=0)
Stop the timer and print an optional message.
void check(const char *msg=0)
void start(const char *msg=0)
int m_XVoxels
Number of voxels along x,y and z axes.
void SaveToSCIRun(string Filename, CTextile &Textile)
Save voxel mesh in SCIRun .pts and .hex format without boundary conditions.
virtual void OutputNodes(ostream &Output, CTextile &Textile, int Filetype=INP_EXPORT)=0
Outputs nodes to .inp file and gets element information.
CTextileMaterials m_Materials
virtual void OutputPeriodicBoundaries(ostream &Output, CTextile &Textile, int iBoundaryConditions, bool bMatrixOnly)
Output periodic boundary conditions to .inp file.
virtual bool CalculateVoxelSizes(CTextile &Textile)=0
Calculate voxel size based on number of voxels on each axis and domain size.
virtual int OutputHexElements(ostream &Output, bool bOutputMatrix, bool bOutputYarn, int Filetype=INP_EXPORT)
Output hex elements to .inp file.
CPeriodicBoundaries * m_PeriodicBoundaries
void SaveToAbaqus(string Filename, CTextile &Textile, bool bOutputMatrix, bool bOutputYarn, int iBoundaryConditions, int iElementType)
void OutputMatrixElementSet(string Filename, ostream &Output, int iNumHexElements, bool bMatrixOnly)
Outputs all elements when only outputting matrix.
void OutputOrientationsAndElementSets(string Filename)
Outputs yarn orientations and element sets to .ori and .eld files.
void SaveVoxelMeshToVTK(string Filename, CTextile &Textile)
Add nodes for whole domain.
vector< POINT_INFO > m_ElementsInfo
Element information as calculated by GetPointInformation.
void AddElementInfo(vector< POINT_INFO > &RowInfo)
Add a row of element information.
void OutputAllNodesSet(string Filename, ostream &Output)
Output node set containing all nodes.
CMesh m_Mesh
Find intersections of yarn surfaces with grid of lines from node points in each axis.
virtual void SaveVoxelMesh(CTextile &Textile, string OutputFilename, int XVoxNum, int YVoxNum, int ZVoxNum, bool bOutputMatrix, bool bOutputYarns, int iBoundaryConditions, int iElementType=0, int FileType=INP_EXPORT)
virtual ~CVoxelMesh(void)
Namespace containing a series of customised math operations not found in the standard c++ library.
std::string RemoveExtension(std::string &Filename, std::string Extension)
Strip the extension from the filename.
std::string StripPath(std::string Filename)
Strip the path from the filename (e.g. "c:\folder\file.ext -> file.ext")
std::string ReplaceFilenameSpaces(std::string Filename)
Replaces spaces in filename with underscore.
void WriteElementsHeader(std::ostream &Output)
Write elements header for ABAQUS .eld files.
void WriteOrientationsHeader(std::ostream &Output)
Write orientations header for ABAQUS .ori files.
void WriteValues(std::ostream &Output, T &Values, int iMaxPerLine)
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
void AddExtensionIfMissing(std::string &Filename, std::string Extension)
Adds an extension to the filename if it is missing otherwise do nothing (e.g. picture -> picture....
XYZ CrossProduct(const XYZ &left, const XYZ &right)
Get the cross product of two vectors.
Struct for representing points in 3D space.