TexGen
Mesher.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21
22#include <iterator>
23#include "Mesh.h"
24#include "BasicVolumes.h"
25#include "Materials.h"
26
27namespace TexGen
28{
29 using namespace std;
30
31// class CYarn;
32 class CTextile;
33 class CGeometrySolver;
34 class CPeriodicBoundaries;
35 class CMaterials;
36
37 enum FACE
38 {
44 FACE_F
45 };
46
48 {
49 public:
50 virtual ~CMesherBase(void) {}
51
52 virtual bool CreateMesh(CTextile &Textile) = 0;
53 virtual bool CreateMesh(string TextileName);
54
55 protected:
56 };
57
60 {
61 friend class CGeometrySolver;
62 public:
63 CMesher(int iBoundaryConditions = NO_BOUNDARY_CONDITIONS );
64 ~CMesher(void);
65
66 bool CreateMesh(CTextile &Textile);
67 // Necessary in order for SWIG to wrap it properly
68 bool CreateMesh(string TextileName) { return CMesherBase::CreateMesh(TextileName); }
69
70 void SetMergeTolerance(double dMergeTolerance) { m_dLayerMergeTolerance = dMergeTolerance; }
71 double GetMergeTolerance() { return m_dLayerMergeTolerance; }
72
73 void SetHybrid(bool bHybrid) { m_bHybrid = bHybrid; }
74 bool GetHybrid() { return m_bHybrid; }
75
76 void SetQuadratic(bool bQuadratic) { m_bQuadratic = bQuadratic; }
77 bool GetQuadratic() { return m_bQuadratic; }
78
79 void SetProjectMidSideNodes(bool bProjectMidSideNodes) { m_bProjectMidSideNodes = bProjectMidSideNodes; }
80 bool GetProjectMidSideNodes() { return m_bProjectMidSideNodes; }
81
82 void SaveVolumeMeshToVTK(string Filename);
83 void SaveVolumeMeshToABAQUS(string Filename, string TextileName);
84 void SaveVolumeMeshToABAQUS(string Filename, CTextile& Textile );
85
86 const CMesh &GetMesh() { return m_VolumeMesh; }
87 const list<MESHER_ELEMENT_DATA> *GetElementData(CMesh::ELEMENT_TYPE ElementType);
88
89 protected:
91 {
92 int iIndex; // Mesh index
93 double dZ;
95 bool bMerged;
96 bool operator < (const RAISED_NODE &right) const
97 {
98 return dZ < right.dZ;
99 }
100 RAISED_NODE() : iIndex(0), dZ(0), bMerged(false) {}
101 };
102
104 {
105 vector<RAISED_NODE> RaisedNodes;
107 };
108
109 struct TRIANGLE
110 {
111 int i[3];
112 };
113
114 typedef pair<int, int> NODE_PAIR;
115 typedef vector<NODE_PAIR> NODE_PAIR_SET;
116 typedef vector<NODE_PAIR_SET> NODE_PAIR_SETS;
117
118 void CreateVolumeMesh(CTextile &Textile);
119 void RaiseNodes(int iIndex);
120 void SubdivideNodes(int iIndex);
121 double GetBestSeed(int iIndex);
122 bool ShouldConnect(vector<RAISED_NODE> &Column1, vector<RAISED_NODE> &Column2, int h1, int h2);
123 bool ViolatesEdgeConstraint(const set<pair<int, int> > &EdgeConstraints1, const set<pair<int, int> > &EdgeConstraints2, int h, int h1, int h2);
124 void MeshColumn(TRIANGLE Triangle, int iRegion);
125 bool SplitColumn(PROJECTED_NODE &Node, vector<int> &YarnIndices, vector<vector<RAISED_NODE> > &Column);
126// int MixedMeshColumn(vector<RAISED_NODE> Columns[3], set<pair<int, int> > EdgeConstraints[3]);
127 int TetMeshColumn(vector<RAISED_NODE> Columns[3], set<pair<int, int> > EdgeConstraints[3]);
128 int MeshDifficultRegion(vector<RAISED_NODE> Columns[3], int Limits[6], set<pair<int, int> > EdgeConstraints[3]);
129 void FillYarnTangentsData();
130 void BuildEdgeConstraints(vector<RAISED_NODE> Columns[3], set<pair<int, int> > EdgeConstraints[3]);
131 void AddElement(CMesh::ELEMENT_TYPE Type, const vector<int> &Indices);
132 void AddEdgeConstraint(int i1, int i2);
133 void BuildMidSideNodes(vector<RAISED_NODE> Columns[3], int iYarnIndex);
134 void BuildMidSideNode(int iNodeIndex1, int iNodeIndex2, int iYarnIndex, bool bTop);
135 XYZ GetMidSideNode(int iNodeIndex1, int iNodeIndex2);
136 void ConvertMeshToQuadratic();
137
138 // Given a pair of indices, find the matching pair on the opposite boundary
139 bool GetPairIndices(int iIndex1, int iIndex2, NODE_PAIR &MatchPair);
140 // Find matching nodes on opposite side of domain (for top surface edges). If corner will return all four nodes in Match
141 void GetEdgePairIndices(const NODE_PAIR_SETS &NodePairSets, int iIndex, set<int> &Match);
142 // If bSwapY is true sort by y value, otherwise sort by x
143 void SortPairs( NODE_PAIR_SET &NodePairs, bool bSwapY );
144 // Create Face, Edge and Corner node sets for periodic boundary conditions
145 void CreateNodeSets( NODE_PAIR_SETS &EdgeNodePairSets, set<int> &CornerIndex, const vector<XYZ> &Repeats );
146 // Save node sets to CPeriodicBoundaries class
147 bool SaveNodeSets();
148 // Add extra edge nodes for quadratic elements to node sets
149 void AddQuadraticNodesToSets();
150 // Create node sets for each face containing all nodes on face, including edges and corners
151 void SetupFaceSets( vector< set<int> >& FaceSets );
152 // Find all face sets which contain iIndex
153 vector<int> FindFaceSets( vector< set<int> >& FaceSets, int iIndex );
154 // Add quad node to appropriate face,edge or corner set
155 void AddQuadNodeToSet( int i, int j, vector<int>& FaceSeti, vector<int>& FaceSetj, vector<int> &Indices );
156 // Add quad node to correct face set
157 void AddQuadNodeToFace( int i, int j, int iFace, vector<int> &Indices );
158 // Returns index for quad edge node between i and j
159 int GetQuadNodeToAdd( int i, int j );
160 // Add quad node to correct edge set
161 void AddQuadNodeToEdge( int i, int j, int iEdge, vector<int> &Indices );
162 // Finds the edge between face1 and face2
163 int GetEdge( int iFace1, int iFace2 );
164 // Remove duplicate nodes from node sets
165 void RemoveDuplicateNodes();
166 void RemoveDuplicateFaceNodes( vector<int>& FaceSet );
167
168 // Each node in the volume mesh is assigned an integer z order
169 // the z order provides a consistant method of determining if one
170 // node is higher than the other. This method is consistant in that
171 // it will always give the same results even if two heights are equal.
172// vector<int> m_TriangleNeighbors;
174
175 // This set represents the edges that have already been created by adding elements
176 // when adding new elements it is necessary to avoid creating edges which cross
177 // over existing edges so that a conforming mesh can be acheived. The pair of ints
178 // represents the two node indices, where the first in the pair is always the lowest.
179 set<pair<int, int> > m_EdgeConstraints;
180
181 // This map represents the mid-side node locations when mid-side nodes are activated.
182 // Similarly to the edge constraints, the two ints represent the indices of the nodes.
183 // and the XYZ represents the location of the mid-side node.
184 map<pair<int, int>, XYZ> m_MidSideNodeLocations;
185
186 // Sets of nodes on opposite faces of the domain
188
189 vector<PROJECTED_NODE> m_ProjectedNodes;
194 // Contains data about each element of the elements in m_VolumeMesh
195 list<MESHER_ELEMENT_DATA> m_ElementData[CMesh::NUM_ELEMENT_TYPES];
196
199
200 // Node sets for periodic boundary conditions
201 vector<int> m_FaceA;
202 vector<int> m_FaceB;
203 vector<int> m_FaceC;
204 vector<int> m_FaceD;
205 vector<int> m_FaceE;
206 vector<int> m_FaceF;
207 vector< vector<int> > m_Edges;
208 vector<int> m_Vertices;
209
210 // Class for export of material properties
212 };
213
214}; // namespace TexGen
215
216
217
218
219
220
221
222
223
224
225
226
227
#define CLASS_DECLSPEC
Definition: Misc.h:35
Class for meshing fabric unit cells.
Definition: BasicVolumes.h:33
Class for creating realistic fabric geometry using FE.
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
ELEMENT_TYPE
Each element type is represented by a unique integer value.
Definition: Mesh.h:66
@ NUM_ELEMENT_TYPES
Definition: Mesh.h:77
virtual bool CreateMesh(CTextile &Textile)=0
virtual ~CMesherBase(void)
Definition: Mesher.h:50
Class for meshing fabric unit cells.
Definition: Mesher.h:60
vector< int > m_FaceD
Definition: Mesher.h:204
vector< PROJECTED_NODE > m_ProjectedNodes
Definition: Mesher.h:189
vector< int > m_FaceF
Definition: Mesher.h:206
bool m_bProjectMidSideNodes
Definition: Mesher.h:192
pair< int, int > NODE_PAIR
Definition: Mesher.h:114
void SetQuadratic(bool bQuadratic)
Definition: Mesher.h:76
double GetMergeTolerance()
Definition: Mesher.h:71
double m_dLayerMergeTolerance
Definition: Mesher.h:193
set< pair< int, int > > m_EdgeConstraints
Definition: Mesher.h:179
bool GetQuadratic()
Definition: Mesher.h:77
vector< int > m_FaceE
Definition: Mesher.h:205
CPeriodicBoundaries * m_PeriodicBoundaries
Definition: Mesher.h:197
vector< int > m_FaceC
Definition: Mesher.h:203
vector< NODE_PAIR_SET > NODE_PAIR_SETS
Definition: Mesher.h:116
void SetHybrid(bool bHybrid)
Definition: Mesher.h:73
NODE_PAIR_SETS m_NodePairSets
Definition: Mesher.h:187
CTextileMaterials * m_Materials
Definition: Mesher.h:211
bool CreateMesh(string TextileName)
Definition: Mesher.h:68
void SetProjectMidSideNodes(bool bProjectMidSideNodes)
Definition: Mesher.h:79
vector< int > m_Vertices
Definition: Mesher.h:208
void SetMergeTolerance(double dMergeTolerance)
Definition: Mesher.h:70
vector< int > m_FaceB
Definition: Mesher.h:202
bool GetProjectMidSideNodes()
Definition: Mesher.h:80
vector< vector< int > > m_Edges
Definition: Mesher.h:207
CMesh m_VolumeMesh
Definition: Mesher.h:173
map< pair< int, int >, XYZ > m_MidSideNodeLocations
Definition: Mesher.h:184
bool GetHybrid()
Definition: Mesher.h:74
vector< NODE_PAIR > NODE_PAIR_SET
Definition: Mesher.h:115
vector< int > m_FaceA
Definition: Mesher.h:201
const CMesh & GetMesh()
Definition: Mesher.h:86
bool m_bHybrid
Definition: Mesher.h:190
int m_iBoundaryConditions
Definition: Mesher.h:198
bool m_bQuadratic
Definition: Mesher.h:191
Class used to generate Abaqus output for periodic boundary conditions.
Represents a textile cell containing yarns.
Definition: Textile.h:39
Namespace containing a series of customised math operations not found in the standard c++ library.
FACE
Definition: Mesher.h:38
@ FACE_D
Definition: Mesher.h:42
@ FACE_F
Definition: Mesher.h:44
@ FACE_A
Definition: Mesher.h:39
@ FACE_C
Definition: Mesher.h:41
@ FACE_E
Definition: Mesher.h:43
@ FACE_B
Definition: Mesher.h:40
bool operator<(const PROP_YARN_INFO &left, const PROP_YARN_INFO &right)
Used for sorting algorithms.
@ NO_BOUNDARY_CONDITIONS
Definition: Misc.h:270
vector< RAISED_NODE > RaisedNodes
Definition: Mesher.h:105
vector< int > YarnBoundaryIndices
Definition: Mesher.h:94
Struct for representing points in 3D space.
Definition: mymath.h:56