TexGen
OctreeVoxelMesh.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2017 Mikhail Matveev
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#pragma once
20
21
22
23#include <iostream>
24#include <vector>
25#include <algorithm>
26#include <utility>
27#include <fstream>
28#include <math.h>
29#include <stdio.h>
30#ifdef WIN32
31# include <BaseTsd.h>
32 typedef SSIZE_T ssize_t;
33#else
34# include <inttypes.h>
35#endif
36
37extern "C" {
38#include <p4est_to_p8est.h>
39#ifndef P4_TO_P8
40#include <p4est_bits.h>
41#include <p4est_ghost.h>
42#include <p4est_lnodes.h>
43#else
44#include <p8est_bits.h>
45#include <p8est_ghost.h>
46#include <p8est_lnodes.h>
47#include <p8est_connectivity.h>
48#endif
49}
50
51#include "VoxelMesh.h"
52
53namespace TexGen
54{
55 using namespace std;
56
57 class CTextile;
58
61 {
62 public:
66 COctreeVoxelMesh(string Type= "CPeriodicBoundaries");
67 virtual ~COctreeVoxelMesh(void);
68
69 static int max_level;
70
71 static vector<XYZ> cornerPoints;
72 static vector<XYZ> CentrePoints;
73
74 static vector< vector<int> > FaceX_min;
75 static vector< vector<int> > FaceX_max;
76 static vector< vector<int> > FaceY_min;
77 static vector< vector<int> > FaceY_max;
78 static vector< vector<int> > FaceZ_min;
79 static vector< vector<int> > FaceZ_max;
80
82 static pair<XYZ, XYZ> g_DomainAABB;
83 static vector<char> materialInfo;
84
93 void SaveVoxelMesh(CTextile &Textile, string OutputFilename, int XVoxNum, int YVoxNum, int ZVoxNum, int min_level, int refine_level, bool smoothing, int smoothIter, double smooth1, double smooth2, bool surfaceOuput);
94
95
96 protected:
97 // The operator for comparison can be incorporated into XYZ structure and the all the "Point" can be replaced with "XYZ"
98 struct Point {
100 double x;
101 double y;
102 double z;
103
104 Point() {}
105 Point(int nodeNum, double x, double y, double z) : nodeNum(nodeNum), x(x), y(y), z(z) {}
106
107 bool operator<(const Point &o) const {
108 if (x != o.x) {
109 return x < o.x;
110 }
111 if (y != o.y) {
112 return y < o.y;
113 }
114 return z < o.z;
115 }
116 };
118 int CreateP4ESTRefinement(int min_level, int refine_level);
119
121 bool CalculateVoxelSizes(CTextile &Textile);
122
124 void OutputNodes(ostream &Output, CTextile &Textile, int Filetype = INP_EXPORT );
126 int OutputHexElements(ostream &Output, bool bOutputMatrix, bool bOutputYarn, int Filetype = INP_EXPORT );
128 void OutputPeriodicBoundaries(ostream &Output, CTextile& Textile, int iBoundaryConditions, bool bMatrixOnly);
130 void ConvertOctreeToNodes();
131 // Convert Hex to Tets
132 void ConvertHexToTets();
134 int storeHangingNode(int *all_lni, int *hanging_corner, int node_i, int hanging_count, double v[3]);
136 void smoothing(const std::map< int, vector<int> > &NodeSurf, const vector<int> &AllSurf);
137 void fillMaterialInfo();
138 int isBoundary(double p[3]);
139
140 int checkIndex(int currentElement, vector<int> nodes);
141 pair<int, vector<int> > GetFaceIndices2(CMesh::ELEMENT_TYPE ElemType, const set<int> &NodeIndices, int currentElement);
142
143 void storePointInfo(int refineLevel);
144 static int getPointsInfo(vector<XYZ> myPoints, int refineLevel);
145
146 //int refine_fn_uni(p4est_t * p4est, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant);
147 static int refine_fn_uni(p4est_t * p4est, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant);
148 static int refine_fn_periodic(p4est_t * p4est, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant);
149 static int refine_fn_post(p4est_t * p4est, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant);
150 static int refine_fn(p4est_t * p4est, p4est_topidx_t which_tree, p4est_quadrant_t * quadrant);
151
152 static void FindLocMinMax( int& XMin, int& XMax, int& YMin, int& YMax, XYZ& Min, XYZ& Max );
153
154 void extractSurfaceNodeSets(std::map< int, vector<int> > &NodeSurf, std::vector<int> &AllSurf);
155 void OutputSurfaces(const std::map<int, vector<int> > &NodeSurf, const std::vector<int> &AllSurf);
156 int writeTempFile(string filename, pair<XYZ, XYZ> myDomain) ;
157
158 p4est_t *p4est;
159 p4est_connectivity_t *conn;
160
161 map<int,XYZ> AllNodes;
162 vector< std::vector<int> > m_OddHexes;
163 map< int, vector<int> > m_ElementMarkup;
164 vector< std::vector<int> > m_AllElements;
165 vector< vector<int> > m_TetElements;
166 map< int, vector<int> > m_NodeConstraints;
167 map< string, int> m_NodeConstraintsReverse;
168
169 map< int, vector<int> > m_NodesEncounter;
170 map< int, vector<int> > m_NeighbourNodes;
171
172 map< int, vector<int> > m_SurfaceNodes;
173 map<int, vector< pair<int, int> > > m_SurfaceElementFaces;
174
175 //vector< vector<int> > MaterialElements;
176 vector<Point> m_boundaryPoints;
177
178
182 bool m_bTet;
183 double m_smoothCoef1, m_smoothCoef2;
185
186 /*int m_XVoxels;
187 int m_YVoxels;
188 int m_ZVoxels;*/
189 };
190}; // namespace TexGen
#define CLASS_DECLSPEC
Definition: Misc.h:35
ELEMENT_TYPE
Each element type is represented by a unique integer value.
Definition: Mesh.h:66
Class used to generate octree-refine voxel mesh for output to ABAQUS.
vector< std::vector< int > > m_AllElements
static vector< vector< int > > FaceZ_max
static vector< vector< int > > FaceX_max
map< int, vector< int > > m_NeighbourNodes
vector< vector< int > > m_TetElements
static vector< XYZ > cornerPoints
static vector< char > materialInfo
static vector< vector< int > > FaceX_min
map< int, vector< pair< int, int > > > m_SurfaceElementFaces
static vector< XYZ > CentrePoints
vector< Point > m_boundaryPoints
static vector< vector< int > > FaceY_min
map< int, vector< int > > m_SurfaceNodes
vector< std::vector< int > > m_OddHexes
map< int, vector< int > > m_NodeConstraints
static pair< XYZ, XYZ > g_DomainAABB
static CTextile gTextile
map< int, vector< int > > m_NodesEncounter
static vector< vector< int > > FaceY_max
map< string, int > m_NodeConstraintsReverse
p4est_connectivity_t * conn
static vector< vector< int > > FaceZ_min
map< int, vector< int > > m_ElementMarkup
Represents a textile cell containing yarns.
Definition: Textile.h:39
Class used to generate voxel mesh for output to ABAQUS.
Definition: VoxelMesh.h:35
Namespace containing a series of customised math operations not found in the standard c++ library.
@ INP_EXPORT
Definition: Misc.h:113
double Max(XYZ &Vector)
Get maximum element of vector and return it.
Definition: mymath.h:642
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
Definition: mymath.h:1142
Point(int nodeNum, double x, double y, double z)
bool operator<(const Point &o) const
Struct for representing points in 3D space.
Definition: mymath.h:56