GEOS
InternalMeshGenerator.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_MESH_GENERATORS_INTERNALMESHGENERATOR_HPP
21 #define GEOS_MESH_GENERATORS_INTERNALMESHGENERATOR_HPP
22 
26 #include "mesh/mpiCommunications/SpatialPartition.hpp"
27 
28 namespace geos
29 {
30 
31 
37 {
38 public:
39 
45  InternalMeshGenerator( const string & name, Group * const parent );
46 
47  virtual ~InternalMeshGenerator() override = default;
48 
53  static string catalogName() { return "InternalMesh"; }
54 
55 
57  string const & blockName,
58  string const & meshFieldName,
59  bool isMaterialField,
60  dataRepository::WrapperBase & wrapper ) const override
61  {
62  GEOS_UNUSED_VAR( block );
63  GEOS_UNUSED_VAR( blockName );
64  GEOS_UNUSED_VAR( meshFieldName );
65  GEOS_UNUSED_VAR( isMaterialField );
66  GEOS_UNUSED_VAR( wrapper );
67  }
68 
72  virtual inline bool isCartesian() const
73  {
74  return true;
75  }
76 
82  virtual void reduceNumNodesForPeriodicBoundary( SpatialPartition & partition,
83  integer (& numNodes) [3] )
84  {
85  GEOS_UNUSED_VAR( partition, numNodes );
86  };
87 
96  virtual void
97  setNodeGlobalIndicesOnPeriodicBoundary( SpatialPartition & partition,
98  int (& index)[3] )
99  {
100  GEOS_UNUSED_VAR( partition, index );
101  }
102 
110  virtual void setConnectivityForPeriodicBoundaries( int ( & globalIJK )[3],
111  integer const ( &numNodesInDir )[3],
112  int const ( &firstElemIndexInPartition )[3],
113  localIndex ( & nodeOfBox )[8] )
114  {
115  GEOS_UNUSED_VAR( globalIJK, numNodesInDir, firstElemIndexInPartition, nodeOfBox );
116  }
117 
126  void setConnectivityForPeriodicBoundary( int const component,
127  int const (&globalIJK)[3],
128  integer const (&numNodesInDir)[3],
129  int const (&firstElemIndexInPartition)[3],
130  localIndex ( &nodeOfBox )[8] );
131 
138  {
139  GEOS_UNUSED_VAR( X );
140  GEOS_UNUSED_VAR( nodeSets );
141  }
142 
143 
144 protected:
145 
147  struct viewKeyStruct
148  {
149  constexpr static char const * xCoordsString() { return "xCoords"; }
150  constexpr static char const * yCoordsString() { return "yCoords"; }
151  constexpr static char const * zCoordsString() { return "zCoords"; }
152  constexpr static char const * xElemsString() { return "nx"; }
153  constexpr static char const * yElemsString() { return "ny"; }
154  constexpr static char const * zElemsString() { return "nz"; }
155  constexpr static char const * xBiasString() { return "xBias"; }
156  constexpr static char const * yBiasString() { return "yBias"; }
157  constexpr static char const * zBiasString() { return "zBias"; }
158  constexpr static char const * cellBlockNamesString() { return "cellBlockNames"; }
159  constexpr static char const * elementTypesString() { return "elementTypes"; }
160  constexpr static char const * trianglePatternString() { return "trianglePattern"; }
161  constexpr static char const * meshTypeString() { return "meshType"; }
162  constexpr static char const * positionToleranceString() { return "positionTolerance"; }
163  };
165 
166  void postInputInitialization() override;
167 
169  int m_dim;
170 
173 
176 
179 
182 
185 
188 
193 
194 private:
195 
197  array1d< string > m_regionNames;
198 
200  array1d< integer > m_firstElemIndexForBlock[3];
201 
203  array1d< integer > m_lastElemIndexForBlock[3];
204 
206  globalIndex m_numElemsTotal[3];
207 
209  array1d< string > m_elementType;
210 
212  array1d< integer > m_numElePerBox;
213 
251  int m_trianglePattern;
252 
254  real64 m_fPerturb = 0.0;
255 
257  int m_randSeed = 0;
258 
260  real64 m_skewAngle = 0;
261 
263  real64 m_skewCenter[3] = { 0, 0, 0 };
264 
265 
266 
267  virtual void fillCellBlockManager( CellBlockManager & cellBlockManager, SpatialPartition & partition ) override;
268 
273  inline globalIndex nodeGlobalIndex( int const index[3] )
274  {
275  return index[0] + index[1]*(m_numElemsTotal[0]+1) + index[2]*(m_numElemsTotal[0]+1)*(m_numElemsTotal[1]+1);
276  }
277 
282  inline globalIndex elemGlobalIndex( int const index[3] )
283  {
284  return index[0] + index[1]*m_numElemsTotal[0] + index[2]*m_numElemsTotal[0]*m_numElemsTotal[1];
285  }
286 
296  template< typename OUT_VECTOR >
297  inline void getNodePosition( int const (&a)[3], int trianglePattern, OUT_VECTOR && X )
298  {
299  real64 xInterval( 0 );
300 
301  int xPosIndex = 0;
302  if( trianglePattern == 1 )
303  {
304  int startingIndex = 0;
305  int endingIndex = 0;
306  int block = 0;
307  for( block=0; block<m_nElems[0].size(); ++block )
308  {
309  startingIndex = endingIndex;
310  endingIndex = startingIndex + m_nElems[0][block];
311  }
312  xPosIndex = endingIndex;
313  }
314 
315  for( int i=0; i<3; ++i )
316  {
317  if( m_setCoords[i].size()>0 )
318  {
319  X[i] = m_setCoords[i][a[i]];
320  }
321  else
322  {
323 
324  int startingIndex = 0;
325  int endingIndex = 0;
326  int block = 0;
327  for( block=0; block<m_nElems[i].size(); ++block )
328  {
329  startingIndex = endingIndex;
330  endingIndex = startingIndex + m_nElems[i][block];
331  if( a[i]>=startingIndex && a[i]<=endingIndex )
332  {
333  break;
334  }
335  }
336  real64 min = m_vertices[i][block];
337  real64 max = m_vertices[i][block+1];
338 
339 
340  X[i] = min + (max-min) * ( double( a[i] - startingIndex ) / m_nElems[i][block] );
341 
342  // First check if m_nElemBias contains values
343  // Otherwise the next test will cause a segfault when looking for "block"
344  if( m_nElemBias[i].size()>0 )
345  {
346  // Verify that the bias is non-zero and applied to more than one block:
347  if( ( !isZero( m_nElemBias[i][block] ) ) && (m_nElems[i][block]>1))
348  {
349  GEOS_ERROR_IF( fabs( m_nElemBias[i][block] ) >= 1,
350  getWrapperDataContext( i == 0 ? viewKeyStruct::xBiasString() :
351  i == 1 ? viewKeyStruct::yBiasString() :
352  viewKeyStruct::zBiasString() ) <<
353  ", block index = " << block << " : Mesh bias must between -1 and 1!" );
354 
355  real64 len = max - min;
356  real64 xmean = len / m_nElems[i][block];
357  real64 x0 = xmean * double( a[i] - startingIndex );
358  real64 chi = m_nElemBias[i][block]/(xmean/len - 1.0);
359  real64 dx = -x0*chi + x0*x0*chi/len;
360  X[i] += dx;
361  }
362  }
363 
364  // This is for creating regular triangle pattern
365  if( i==0 ) xInterval = (max-min) / m_nElems[i][block];
366  if( trianglePattern == 1 && i == 1 && a[1] % 2 == 1 && a[0] != 0 && a[0] != xPosIndex )
367  X[0] -= xInterval * 0.5;
368  }
369  }
370  }
371 
378  template< typename OUT_VECTOR >
379  inline void getElemCenterPosition( int const k[3], OUT_VECTOR && X )
380  {
381  for( int i=0; i<3; ++i )
382  {
383  X[i] = m_min[i] + (m_max[i]-m_min[i]) * ( ( k[i] + 0.5 ) / m_numElemsTotal[i] );
384  }
385  }
386 
387 public:
388 
389 
390 };
391 
392 } /* namespace geos */
393 
394 #endif /* GEOS_MESH_GENERATORS_INTERNALMESHGENERATOR_HPP */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:142
The CellBlockManager class provides an interface to ObjectManagerBase in order to manage CellBlock da...
The InternalMeshGenerator class is a class handling GEOSX generated meshes.
real64 m_max[3]
Maximum extent of mesh dimensions.
void postInputInitialization() override
array1d< integer > m_nElems[3]
Ndim x nElem spatialized for element indexes.
int m_dim
Mesh number of dimension.
static string catalogName()
Return the name of the InternalMeshGenerator in object Catalog.
virtual void coordinateTransformation(arrayView2d< real64, nodes::REFERENCE_POSITION_USD > X, std::map< string, SortedArray< localIndex > > &nodeSets)
Performs a coordinate transformation of all nodes.
void setConnectivityForPeriodicBoundary(int const component, int const (&globalIJK)[3], integer const (&numNodesInDir)[3], int const (&firstElemIndexInPartition)[3], localIndex(&nodeOfBox)[8])
Alter connectivity to adhere to a periodic type boundary.
real64 m_min[3]
Minimum extent of mesh dimensions.
InternalMeshGenerator(const string &name, Group *const parent)
Main constructor for InternalMeshGenerator.
virtual void setConnectivityForPeriodicBoundaries(int(&globalIJK)[3], integer const (&numNodesInDir)[3], int const (&firstElemIndexInPartition)[3], localIndex(&nodeOfBox)[8])
Alter connectivity to adhere to a specific periodic type boundary.
array1d< real64 > m_nElemBias[3]
Ndim x nElem spatialized array of element bias.
void importFieldOnArray(Block block, string const &blockName, string const &meshFieldName, bool isMaterialField, dataRepository::WrapperBase &wrapper) const override
import field from the mesh on the array accessible via the given wrapper.
virtual void reduceNumNodesForPeriodicBoundary(SpatialPartition &partition, integer(&numNodes)[3])
Reduce the number of nodes in a block coordinate direction for.
real64 m_coordinatePrecision
Position tolerance for adding nodes to nodesets.
virtual void setNodeGlobalIndicesOnPeriodicBoundary(SpatialPartition &partition, int(&index)[3])
Alter the directional indices for when the ending index should be set to the beginning of the index a...
array1d< real64 > m_vertices[3]
Array of vertex coordinates.
The MeshGeneratorBase class provides an abstract base class implementation for different mesh types....
Block
Describe which kind of block must be considered.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1315
DataContext const & getWrapperDataContext(KEY key) const
Definition: Group.hpp:1354
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:56
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:369
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Definition: DataTypes.hpp:267
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176