GEOSX
InternalMeshGenerator.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_MESHUTILITIES_INTERNALMESHGENERATOR_HPP
20 #define GEOSX_MESHUTILITIES_INTERNALMESHGENERATOR_HPP
21 
22 #include <stdlib.h> /* srand, rand */
23 #include <time.h> /* time */
24 
25 #include "dataRepository/Group.hpp"
26 #include "codingUtilities/Utilities.hpp"
27 #include "MeshGeneratorBase.hpp"
28 
29 namespace geosx
30 {
31 
32 namespace dataRepository
33 {
34 
35 /*
36  * @name keys for InternalMesh object
37  */
39 namespace keys
40 {
42 string const xCoords = "xCoords";
44 string const yCoords = "yCoords";
46 string const zCoords = "zCoords";
48 string const xElems = "nx";
50 string const yElems = "ny";
52 string const zElems = "nz";
54 string const xBias = "xBias";
56 string const yBias = "yBias";
58 string const zBias = "zBias";
60 string const cellBlockNames = "cellBlockNames";
62 string const elementTypes = "elementTypes";
64 string const trianglePattern = "trianglePattern";
65 }
67 
68 }
69 
70 class NodeManager;
71 class DomainPartition;
77 {
78 public:
79 
85  InternalMeshGenerator( const std::string & name,
86  Group * const parent );
87 
88  virtual ~InternalMeshGenerator() override;
89 
94  static string CatalogName() { return "InternalMesh"; }
95 
96 // void ProcessInputFile( xmlWrapper::xmlNode const & targetNode ) override;
97 //
98 //
99 
100  virtual void GenerateElementRegions( DomainPartition & domain ) override;
101 
108  virtual Group * CreateChild( string const & childKey, string const & childName ) override;
109 
110  virtual void GenerateMesh( DomainPartition * const domain ) override;
111 
112  // virtual void GenerateNodesets( xmlWrapper::xmlNode const & targetNode,
113  // NodeManager * nodeManager ) override;
114 
115  virtual void GetElemToNodesRelationInBox ( const std::string & elementType,
116  const int index[],
117  const int & iEle,
118  int nodeIDInBox[],
119  const int size ) override;
120 
121  virtual void RemapMesh ( dataRepository::Group * const domain ) override;
122 
123 // int m_delayMeshDeformation;
124 
125 protected:
126 
127  void PostProcessInput() override final;
128 
129 private:
130 
132  int m_dim;
134  array1d< real64 > m_vertices[3];
136  integer_array m_nElems[3];
138  array1d< real64 > m_nElemScaling[3];
139 
140  //bool m_useBias = false;
142  array1d< real64 > m_nElemBias[3];
143 
145  string_array m_regionNames;
146 
148  real64 m_min[3];
150  real64 m_max[3];
151 
152  //int m_numElems[3];
154  integer_array m_firstElemIndexForBlock[3];
156  integer_array m_lastElemIndexForBlock[3];
157 
158 
159 
160 // real64 m_wExtensionMin[3];
161 // real64 m_wExtensionMax[3];
162 // int m_nExtensionLayersMin[3];
163 // int m_nExtensionLayersMax[3];
164 // real64 m_extendedMin[3];
165 // real64 m_extendedMax[3]; // This is the domain size after we apply n layers
166 // of elements which are of the same size as the core elements. We will move
167 // these nodes to where they should be later when we finish the meshing.
168 
170  int m_numElemsTotal[3];
171 
172 // real64 m_commonRatioMin[3];
173 // real64 m_commonRatioMax[3];
174 
175  // String array listing the element type present
176  string_array m_elementType;
177 
179  array1d< integer > m_numElePerBox;
180 
185  int m_trianglePattern;
186 
188  real64 m_fPerturb=0.0;
190  int m_randSeed;
191 
196  int m_mapToRadial = 0;
199  // internal temp var
200  int m_meshAxis;
201  real64 m_meshTheta;
202  real64 m_meshPhi;
203  real64 m_meshRout;
204  real64 m_meshRact;
206 
208  real64 m_skewAngle = 0;
210  real64 m_skewCenter[3] = { 0, 0, 0 };
211 
212 
214  //unused
215  std::string m_meshDx, m_meshDy, m_meshDz;
217 
222  inline globalIndex NodeGlobalIndex( const int index[3] )
223  {
224  globalIndex rval = 0;
225 
226  rval = index[0]*(m_numElemsTotal[1]+1)*(m_numElemsTotal[2]+1) + index[1]*(m_numElemsTotal[2]+1) + index[2];
227  return rval;
228  }
229 
234  inline globalIndex ElemGlobalIndex( const int index[3] )
235  {
236  globalIndex rval = 0;
237 
238  rval = index[0]*m_numElemsTotal[1]*m_numElemsTotal[2] + index[1]*m_numElemsTotal[2] + index[2];
239  return rval;
240  }
241 
251  template< typename OUT_VECTOR >
252  inline void getNodePosition( int const * a, int trianglePattern, OUT_VECTOR && X )
253  {
254  real64 xInterval( 0 );
255 
256  int xPosIndex = 0;
257  if( trianglePattern == 1 )
258  {
259  int startingIndex = 0;
260  int endingIndex = 0;
261  int block = 0;
262  for( block=0; block<m_nElems[0].size(); ++block )
263  {
264  startingIndex = endingIndex;
265  endingIndex = startingIndex + m_nElems[0][block];
266  }
267  xPosIndex = endingIndex;
268  }
269 
270  for( int i=0; i<3; ++i )
271  {
272 
273  int startingIndex = 0;
274  int endingIndex = 0;
275  int block = 0;
276  for( block=0; block<m_nElems[i].size(); ++block )
277  {
278  startingIndex = endingIndex;
279  endingIndex = startingIndex + m_nElems[i][block];
280  if( a[i]>=startingIndex && a[i]<=endingIndex )
281  {
282  break;
283  }
284  }
285  real64 min = m_vertices[i][block];
286  real64 max = m_vertices[i][block+1];
287 
288 
289  X[i] = min + (max-min) * ( double( a[i] - startingIndex ) / m_nElems[i][block] );
290 
291  // First check if m_nElemBias contains values
292  // Otherwise the next test will cause a segfault when looking for "block"
293  if( m_nElemBias[i].size()>0 )
294  {
295  // Verify that the bias is non-zero and applied to more than one block:
296  if( ( !isZero( m_nElemBias[i][block] ) ) && (m_nElems[i][block]>1))
297  {
298  GEOSX_ERROR_IF( fabs( m_nElemBias[i][block] ) >= 1, "Mesh bias must between -1 and 1!" );
299 
300  real64 len = max - min;
301  real64 xmean = len / m_nElems[i][block];
302  real64 x0 = xmean * double( a[i] - startingIndex );
303  real64 chi = m_nElemBias[i][block]/(xmean/len - 1.0);
304  real64 dx = -x0*chi + x0*x0*chi/len;
305  X[i] += dx;
306  }
307  }
308 
309  // This is for creating regular triangle pattern
310  if( i==0 ) xInterval = (max-min) / m_nElems[i][block];
311  if( trianglePattern == 1 && i == 1 && a[1] % 2 == 1 && a[0] != 0 && a[0] != xPosIndex )
312  X[0] -= xInterval * 0.5;
313  }
314  }
315 
322  template< typename OUT_VECTOR >
323  inline void getElemCenterPosition( const int k[3], OUT_VECTOR && X )
324  {
325  for( int i=0; i<3; ++i )
326  {
327  X[i] = m_min[i] + (m_max[i]-m_min[i]) * ( ( k[i] + 0.5 ) / m_numElemsTotal[i] );
328  }
329  }
330 
331 public:
336  inline bool isRadial()
337  {
338  bool rval = (m_mapToRadial > 0);
339  return rval;
340  }
341 
342 };
343 }
344 
345 #endif /* GEOSX_MESHUTILITIES_INTERNALMESHGENERATOR_HPP */
string const elementTypes
key for element type
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
string const yCoords
key for y coordinates
INDEX_TYPE size() const noexcept
Definition: ArrayView.hpp:361
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data...
Definition: NodeManager.hpp:47
string const zBias
key for z bias
string const yElems
key for number of element in y-direction
The InternalMeshGenerator class is a class handling GEOSX generated meshes.
string const xBias
key for x bias
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
string const cellBlockNames
key for cellBlock names
The MeshGeneratorBase class provides an abstract base class implementation for different mesh types...
string const zElems
key for number of elemnt in z-direction
string const zCoords
key for z coordinates
string const trianglePattern
key for triangle pattern identifier
static string CatalogName()
Return the name of the InternalMeshGenerator in object Catalog.
string const xElems
key for number of element in x-direction
bool isRadial()
Check if the mesh is a radial mesh.
std::string string
String type.
Definition: DataTypes.hpp:131
string const yBias
key for y bias
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:103
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > min(T const a, T const b)
Definition: math.hpp:65
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
Definition: math.hpp:46
string const xCoords
key for x coordinates
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...