NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
NEM::MSH::foamGeoMesh Class Reference

A concrete implementation of geoMeshBase representing a mesh in a fvMesh. More...

Detailed Description

Definition at line 52 of file foamGeoMesh.H.

Public Member Functions

 foamGeoMesh ()
 Create a foamMesh from mesh in current directory. More...
 
 foamGeoMesh (Foam::fvMesh *foamMesh, const std::string &phyGrpArrayName=std::string())
 Construct a foamGeoMesh from an existing fvMesh. More...
 
 ~foamGeoMesh () override
 foamGeoMesh destructor More...
 
void write (const std::string &fileName) override
 Writes foam mesh into current directory. More...
 
void report (std::ostream &out) const override
 Reports data about mesh. More...
 
const Foam::fvMesh & getFoamMesh () const
 Copy the mesh. More...
 
void setFoamMesh (std::unique_ptr< Foam::fvMesh > foamMesh)
 Set the foamGeoMesh's mesh to foamMesh. More...
 
void resetNative () override
 Resets the class members and initiates an empty foam mesh. More...
 
virtual void takeGeoMesh (geoMeshBase *otherGeoMesh)
 Take the GeoMesh of another geoMeshBase. More...
 
virtual void reconstructGeo ()
 Construct the geometry from the mesh alone. More...
 
virtual void mergeGeoMesh (geoMeshBase *otherGeoMesh)
 Merge mesh data from a new geoMesh to an existing geoMesh. More...
 
const std::string & getGeoEntArrayName () const
 Get the name of the geometric entities array. More...
 
void setGeoEntArrayName (const std::string &geoEntArrayName)
 Set the name of the geometric entities array. More...
 
double getAngleThreshold () const
 Get the angle threshold used for surface classification. More...
 
void setAngleThreshold (double angleThreshold)
 Set the angle threshold used for surface classification. More...
 
nemId_t getNumberOfPoints () const
 Get the number of points in mesh. More...
 
nemId_t getNumberOfCells () const
 Get the number of cells in mesh. More...
 
void getPoint (nemId_t id, std::array< double, 3 > *x) const
 Get the coordinate of a point. More...
 
std::array< double, 3 > getPoint (nemId_t id) const
 Get the coordinate of a point. More...
 
void getCell (nemId_t cellId, vtkGenericCell *cell) const
 Get cell. More...
 
vtkCell * getCell (nemId_t cellId) const
 Get cell. More...
 
void getCellBounds (nemId_t cellId, std::array< double, 6 > *bounds) const
 Get cell bounds. More...
 
std::array< double, 6 > getCellBounds (nemId_t cellId) const
 Get cell bounds. More...
 
VTKCellType getCellType (nemId_t cellId) const
 Get VTK cell type. More...
 
void getCellPoints (nemId_t cellId, vtkIdList *ptIds) const
 Get list of point ids defining specified cell. More...
 
void getPointCells (nemId_t ptId, vtkIdList *cellIds) const
 Get list of cell ids using specified point. More...
 
void getCellNeighbors (nemId_t cellId, vtkIdList *ptIds, vtkIdList *cellIds) const
 Get list of cells sharing points ptIds excluding cellId. More...
 
int getNumberOfPointDataArrays () const
 Get number of arrays in the point data. More...
 
void getPointDataArrayCopy (const std::string &arrayName, vtkAbstractArray *array, int *arrayIdx=nullptr) const
 Get copy of point data array by name. More...
 
vtkSmartPointer< vtkAbstractArray > getPointDataArrayCopy (const std::string &arrayName, int *arrayIdx=nullptr) const
 Create and return a copy of point data array by name. More...
 
void getPointDataArrayCopy (int arrayIdx, vtkAbstractArray *array) const
 Get copy of point data array by index. More...
 
vtkSmartPointer< vtkAbstractArray > getPointDataArrayCopy (int arrayIdx) const
 Create and return a copy of point data array by index. More...
 
int getNumberOfCellDataArrays () const
 Get number of arrays in the cell data. More...
 
void getCellDataArrayCopy (const std::string &arrayName, vtkAbstractArray *array, int *arrayIdx=nullptr) const
 Get copy of cell data array by name. More...
 
vtkSmartPointer< vtkAbstractArray > getCellDataArrayCopy (const std::string &arrayName, int *arrayIdx=nullptr) const
 Create and return a copy of cell data array by name. More...
 
void getCellDataArrayCopy (int arrayIdx, vtkAbstractArray *array) const
 Get copy of cell data array by index. More...
 
vtkSmartPointer< vtkAbstractArray > getCellDataArrayCopy (int arrayIdx) const
 Create and return a copy of cell data array by index. More...
 
int getNumberOfFieldDataArrays () const
 Get number of arrays in the field data. More...
 
void getFieldDataArrayCopy (const std::string &arrayName, vtkAbstractArray *array, int *arrayIdx=nullptr) const
 Get copy of field data array by name. More...
 
vtkSmartPointer< vtkAbstractArray > getFieldDataArrayCopy (const std::string &arrayName, int *arrayIdx=nullptr) const
 Create and return a copy of field data array by name. More...
 
void getFieldDataArrayCopy (int arrayIdx, vtkAbstractArray *array) const
 Get copy of field data array by index. More...
 
vtkSmartPointer< vtkAbstractArray > getFieldDataArrayCopy (int arrayIdx) const
 Create and return a copy of field data array by index. More...
 

Static Public Member Functions

static foamGeoMeshNew ()
 

Protected Member Functions

int setPointDataArray (vtkAbstractArray *array)
 Set point data. More...
 
int setCellDataArray (vtkAbstractArray *array)
 Set cell data. More...
 
int setFieldDataArray (vtkAbstractArray *array)
 Set field data. More...
 
void unsetPointDataArray (int arrayIdx)
 Remove point data array by index. More...
 
void unsetPointDataArray (const std::string &arrayName)
 Remove point data array by name. More...
 
void unsetCellDataArray (int arrayIdx)
 Remove cell data array by index. More...
 
void unsetCellDataArray (const std::string &arrayName)
 Remove cell data array by name. More...
 
void unsetFieldDataArray (int arrayIdx)
 Remove field data array by index. More...
 
void unsetFieldDataArray (const std::string &arrayName)
 Remove field data array by name. More...
 
const GeoMeshgetGeoMesh () const
 Get the underlying geometry object. More...
 
void setGeoMesh (const geoMeshBase::GeoMesh &geoMesh)
 Set the underlying geometry object. More...
 

Static Protected Attributes

static constexpr auto GEO_ENT_DEFAULT_NAME = "GeoEnt"
 

Private Member Functions

void InitializeFoam ()
 Initializes arguments and runtime objects. More...
 

Static Private Member Functions

static GeoMesh foam2GM (Foam::fvMesh *foamMesh, const std::string &phyGrpArrayName=std::string())
 Create a GeoMesh from a fvMesh. More...
 
static std::unique_ptr< Foam::fvMesh > GM2foam (const GeoMesh &geoMesh, Foam::Time *runTime, const std::string &phyGrpArrayName=std::string())
 Create a fvMesh from geoMeshBase. More...
 

Private Attributes

std::unique_ptr< Foam::dictionary > controlDict_
 
std::unique_ptr< Foam::dictionary > fvSchemes_
 
std::unique_ptr< Foam::dictionary > fvSolution_
 
std::unique_ptr< Foam::Time > runTime_
 
std::unique_ptr< Foam::fvMesh > fmesh_
 

Inherits NEM::MSH::geoMeshBase.

Constructor & Destructor Documentation

◆ foamGeoMesh() [1/2]

NEM::MSH::foamGeoMesh::foamGeoMesh ( )
Parameters
fileNamename of file
phyGrpArrayNamename of a volScalarField defining the physical group of each cell
Returns
new foamGeoMesh from mesh Construct a foamGeoMesh with an empty mesh

Definition at line 95 of file foamGeoMesh.C.

References InitializeFoam().

Referenced by NEM::MSH::vtkStandardNewMacro().

95 : foamGeoMesh(nullptr) { InitializeFoam(); }
foamGeoMesh()
Create a foamMesh from mesh in current directory.
Definition: foamGeoMesh.C:95
void InitializeFoam()
Initializes arguments and runtime objects.
Definition: foamGeoMesh.C:667

◆ foamGeoMesh() [2/2]

NEM::MSH::foamGeoMesh::foamGeoMesh ( Foam::fvMesh *  foamMesh,
const std::string &  phyGrpArrayName = std::string() 
)
explicit
Parameters
foamMeshexisting foamMesh
phyGrpArrayNamename of a volScalarField defining the physical group of each cell

Definition at line 97 of file foamGeoMesh.C.

99  : geoMeshBase(foam2GM(foamMesh, phyGrpArrayName)), fmesh_(foamMesh) {
100  std::cout << "foamGeoMesh Constructed" << std::endl;
101 }
static GeoMesh foam2GM(Foam::fvMesh *foamMesh, const std::string &phyGrpArrayName=std::string())
Create a GeoMesh from a fvMesh.
Definition: foamGeoMesh.C:107
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162
geoMeshBase()
Query for conversion from vtk to gmsh.
Definition: geoMeshBase.C:77

◆ ~foamGeoMesh()

NEM::MSH::foamGeoMesh::~foamGeoMesh ( )
override

Definition at line 103 of file foamGeoMesh.C.

103  {
104  std::cout << "foamGeoMesh destructed" << std::endl;
105 }

Member Function Documentation

◆ foam2GM()

geoMeshBase::GeoMesh NEM::MSH::foamGeoMesh::foam2GM ( Foam::fvMesh *  foamMesh,
const std::string &  phyGrpArrayName = std::string() 
)
staticprivate

Assumes gmsh has already been initialized.

Parameters
foamMeshfv mesh
phyGrpArrayNamename of cell data array describing physical group of each cell
Returns
GeoMesh

Definition at line 107 of file foamGeoMesh.C.

References nemAux::getRandomString(), NEM::MSH::GmshInterface::Initialize(), and NEM::MSH::New().

Referenced by setFoamMesh(), and NEM::MSH::vtkStandardNewMacro().

108  {
109  // create vtk database
110  vtkSmartPointer<vtkUnstructuredGrid> vtkdataSet =
112 
113  // Check for cellsets and cellzones
114  if (!foamMesh) {
115  return {vtkdataSet, "", "", {}};
116  } else {
117  const Foam::cellZoneMesh &cellZones =
118  foamMesh->cellZones(); // get cellZoneMesh
119  Foam::label zoneI = cellZones.size();
120 
121  // creating equivalent vtk topology from fvMesh
122  // by default polyhedral cells will be decomposed to
123  // tets and pyramids. Additional points will be added
124  // to underlying fvMesh.
125  std::cout << "Performing topological decomposition.\n";
126  auto objVfoam = Foam::vtk::vtuAdaptor();
127  vtkdataSet = objVfoam.internal(*foamMesh);
128 
129  // Check for cellZones and extract physical groups
130  Foam::List<Foam::scalar> physGrps(foamMesh->nCells(), 0.0);
131  if (zoneI > 0) {
132  for (int i = 0; i < zoneI; i++) {
133  const Foam::cellZone &cz = cellZones[i];
134  forAll (cz, j)
135  physGrps[cz[j]] = i;
136  }
137 
138  vtkSmartPointer<vtkDoubleArray> pg =
140  pg->SetName(phyGrpArrayName.c_str());
141  pg->SetNumberOfComponents(1);
142  for (int i = 0; i < foamMesh->nCells(); i++)
143  pg->InsertNextTuple1(physGrps[i]);
144  vtkdataSet->GetCellData()->AddArray(pg);
145  }
146 
147  // Create boundary patches arrays and add to VTK
148  const Foam::polyBoundaryMesh &patches = foamMesh->boundaryMesh();
149  Foam::wordList patchNames = patches.names();
150  Foam::wordList patchTypes = patches.types();
151  // const Foam::labelList &patchIds = patches.patchID();
152  Foam::label patchSize = patches.size();
153  std::vector<int> face_patch_map; // Which patch the current face is in
154  Foam::label nFaces = foamMesh->nFaces();
155  for (int i = 0; i < nFaces; i++)
156  face_patch_map.push_back(int(patches.whichPatch(i)));
157 
158  // Create sideSets
159  vtkSmartPointer<vtkPolyData> sideSet = vtkSmartPointer<vtkPolyData>::New();
160  Foam::faceList allFaces = foamMesh->faces();
161  Foam::labelList faceOwners = foamMesh->faceOwner();
162  Foam::pointField allPoints = foamMesh->points();
163 
164  // Filter internal faces out
165  int nonInternalFaces = 0;
166  for (int i = 0; i < patchSize; i++) nonInternalFaces += patches[i].size();
167  Foam::faceList sideSetOnlyFaces(nonInternalFaces);
168  Foam::labelList sideSetOnlyFaceLabels(nonInternalFaces);
169  Foam::labelList sideSetOnlyOwners(nonInternalFaces);
170  int indx = 0;
171  for (int i = 0; i < static_cast<int>(face_patch_map.size()); i++) {
172  if (face_patch_map[i] != -1) {
173  sideSetOnlyFaces[indx] = allFaces[i];
174  sideSetOnlyOwners[indx] = faceOwners[i];
175  sideSetOnlyFaceLabels[indx] = i;
176  indx++;
177  }
178  }
179 
180  sideSet->SetPoints(vtkdataSet->GetPoints());
181  sideSet->Allocate();
182 
183  // Start adding cells (2D faces)
184  std::vector<int> facePntIds;
185  for (int i = 0; i < sideSetOnlyFaces.size(); i++) {
186  if (sideSetOnlyFaces[i].size() == 3) {
187  // add triangle face (#5)
188  vtkSmartPointer<vtkIdList> vtkCellIds =
190  vtkCellIds->SetNumberOfIds(sideSetOnlyFaces[i].size());
191  for (int j = 0; j < sideSetOnlyFaces[i].size(); j++)
192  vtkCellIds->SetId(j, sideSetOnlyFaces[i][j]);
193  sideSet->InsertNextCell(5, vtkCellIds);
194  } else if (sideSetOnlyFaces[i].size() == 4) {
195  // add quad face (#9)
196  vtkSmartPointer<vtkIdList> vtkCellIds =
198  vtkCellIds->SetNumberOfIds(sideSetOnlyFaces[i].size());
199  for (int j = 0; j < sideSetOnlyFaces[i].size(); j++)
200  vtkCellIds->SetId(j, sideSetOnlyFaces[i][j]);
201  sideSet->InsertNextCell(9, vtkCellIds);
202  } else if (sideSetOnlyFaces[i].size() > 4) {
203  // add polygon face (#7)
204  vtkSmartPointer<vtkIdList> vtkCellIds =
206  vtkCellIds->SetNumberOfIds(sideSetOnlyFaces[i].size());
207  for (int j = 0; j < sideSetOnlyFaces[i].size(); j++)
208  vtkCellIds->SetId(j, sideSetOnlyFaces[i][j]);
209  sideSet->InsertNextCell(7, vtkCellIds);
210  } else {
211  Foam::Info << "Face type not supported yet!" << Foam::nl;
212  }
213  }
214 
215  auto sideSetEntities = vtkSmartPointer<vtkIntArray>::New();
216  sideSetEntities->SetName("GeoEnt");
217 
218  auto sideSetOrigCellId = vtkSmartPointer<vtkIdTypeArray>::New();
219  sideSetOrigCellId->SetName("OrigCellIds");
220  sideSetOrigCellId->SetNumberOfComponents(2);
221 
222  auto sideSetCellFaceId = vtkSmartPointer<vtkIntArray>::New();
223  sideSetCellFaceId->SetName("CellFaceIds");
224  sideSetCellFaceId->SetNumberOfComponents(2);
225 
226  auto sideSetPatchId = vtkSmartPointer<vtkIntArray>::New();
227  sideSetPatchId->SetName("PatchIds");
228 
229  auto sideSetPatchName = vtkSmartPointer<vtkStringArray>::New();
230  sideSetPatchName->SetName("PatchNames");
231 
232  for (int i = 0; i < sideSetOnlyFaces.size(); i++) {
233  sideSetEntities->InsertNextValue(
234  static_cast<int>(physGrps[sideSetOnlyOwners[i]]));
235  sideSetOrigCellId->InsertNextTuple2(sideSetOnlyOwners[i],-1);
236  }
237 
238  for (int i = 0; i < sideSetOnlyOwners.size(); i++) {
239  const Foam::cell& facesCell = foamMesh->cells()[sideSetOnlyOwners[i]];
240  for (int j = 0; j < facesCell.size(); j++) {
241  if (foamMesh->faces()[facesCell[j]] == sideSetOnlyFaces[i]) {
242  sideSetCellFaceId->InsertNextTuple2(j,-1);
243  }
244  }
245  }
246 
247  for (int i = 0; i < sideSetOnlyFaces.size(); i++) {
248  sideSetPatchId->InsertNextValue(face_patch_map[sideSetOnlyFaceLabels[i]]);
249  sideSetPatchName->InsertNextValue(
250  patchNames[face_patch_map[sideSetOnlyFaceLabels[i]]]);
251  }
252 
253  // Add arrays to sideSet
254  sideSet->GetCellData()->AddArray(sideSetPatchId);
255  sideSet->GetFieldData()->AddArray(sideSetPatchName);
256 
257  // Create sideSet struct
258  auto sideSetStruct =
259  SideSet(sideSet, sideSetEntities, sideSetOrigCellId, sideSetCellFaceId);
260 
261  std::string gmshMesh = "foamGeoMesh_" + nemAux::getRandomString(6);
262 #ifdef HAVE_GMSH
264  gmsh::model::add(gmshMesh);
265  gmsh::model::setCurrent(gmshMesh);
266 
267  { // Add geometric entities and physical groups
268  std::set<std::pair<int, int>> dim_phyGrp;
269  int idx = 0;
270  auto phyGrpArray = vtkArrayDownCast<vtkDataArray>(
271  vtkdataSet->GetCellData()->GetArray(phyGrpArrayName.c_str(), idx));
272  vtkSmartPointer<vtkGenericCell> vtkGC =
274 
275  if (idx != -1) {
276  // First sort
277  for (vtkIdType i = 0; i < vtkdataSet->GetNumberOfCells(); ++i) {
278  vtkGC->SetCellType(vtkdataSet->GetCellType(i));
279  int dim = vtkGC->GetCellDimension();
280  int phyGrp = static_cast<int>(phyGrpArray->GetComponent(i, 0));
281 
282  dim_phyGrp.insert({dim, phyGrp});
283  }
284 
285  // then add. Each phyGrp gets its own geoEnt
286  for (const auto &dp : dim_phyGrp) {
287  gmsh::model::addDiscreteEntity(dp.first, dp.second);
288  gmsh::model::addPhysicalGroup(dp.first, {dp.second}, dp.second);
289  }
290  }
291  }
292 #endif
293  return {vtkdataSet, gmshMesh, phyGrpArrayName, sideSetStruct};
294  }
295 }
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
static void Initialize()
Initialize Gmsh.
Definition: geoMeshBase.C:67
std::string getRandomString(int length)

◆ getAngleThreshold()

double NEM::MSH::geoMeshBase::getAngleThreshold ( ) const
inlineinherited
Returns
angle threshold (in radians)

Definition at line 171 of file geoMeshBase.H.

171 { return _angleThreshold; }
double _angleThreshold
Dihedral angle threshold (in radians) to classify surfaces (Default: 30 degrees)
Definition: geoMeshBase.H:554

◆ getCell() [1/2]

void NEM::MSH::geoMeshBase::getCell ( nemId_t  cellId,
vtkGenericCell *  cell 
) const
inlineinherited
Parameters
cellIdcell id
cellcell

Definition at line 214 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

214  {
215  _geoMesh.mesh->GetCell(cellId, cell);
216  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCell() [2/2]

vtkCell* NEM::MSH::geoMeshBase::getCell ( nemId_t  cellId) const
inlineinherited
Parameters
cellIdcell id
Returns
cell

Definition at line 222 of file geoMeshBase.H.

222  {
223  return _geoMesh.mesh->GetCell(cellId);
224  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellBounds() [1/2]

void NEM::MSH::geoMeshBase::getCellBounds ( nemId_t  cellId,
std::array< double, 6 > *  bounds 
) const
inlineinherited
Parameters
cellIdcell id
boundsarray of bounds as (x_min,x_max, y_min,y_max, z_min,z_max)

Definition at line 230 of file geoMeshBase.H.

230  {
231  _geoMesh.mesh->GetCellBounds(cellId, bounds->data());
232  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellBounds() [2/2]

std::array<double, 6> NEM::MSH::geoMeshBase::getCellBounds ( nemId_t  cellId) const
inlineinherited
Parameters
cellIdcell id
Returns
array of bounds as (x_min,x_max, y_min,y_max, z_min,z_max)

Definition at line 238 of file geoMeshBase.H.

238  {
239  std::array<double, 6> bounds{};
240  getCellBounds(cellId, &bounds);
241  return bounds;
242  }
void getCellBounds(nemId_t cellId, std::array< double, 6 > *bounds) const
Get cell bounds.
Definition: geoMeshBase.H:230

◆ getCellDataArrayCopy() [1/4]

void NEM::MSH::geoMeshBase::getCellDataArrayCopy ( const std::string &  arrayName,
vtkAbstractArray *  array,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arraycell data array
arrayIdxarray index

Definition at line 180 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

Referenced by NEM::MSH::diffMesh().

182  {
183  getArrCopy(_geoMesh.mesh->GetCellData(), arrayName, arrayIdx, array);
184 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellDataArrayCopy() [2/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getCellDataArrayCopy ( const std::string &  arrayName,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 186 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

187  {
188  return getArrCopy(_geoMesh.mesh->GetCellData(), arrayName, arrayIdx);
189 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellDataArrayCopy() [3/4]

void NEM::MSH::geoMeshBase::getCellDataArrayCopy ( int  arrayIdx,
vtkAbstractArray *  array 
) const
inherited
Parameters
arrayIdxarray index
arraycell data array

Definition at line 191 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

192  {
193  getArrCopy(_geoMesh.mesh->GetCellData(), arrayIdx, array);
194 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellDataArrayCopy() [4/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getCellDataArrayCopy ( int  arrayIdx) const
inherited
Parameters
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 196 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

197  {
198  return getArrCopy(_geoMesh.mesh->GetCellData(), arrayIdx);
199 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellNeighbors()

void NEM::MSH::geoMeshBase::getCellNeighbors ( nemId_t  cellId,
vtkIdList *  ptIds,
vtkIdList *  cellIds 
) const
inlineinherited
Parameters
cellIdid of cell to exclude
ptIdspoint id
cellIdslist of cell ids

Definition at line 273 of file geoMeshBase.H.

274  {
275  _geoMesh.mesh->GetCellNeighbors(cellId, ptIds, cellIds);
276  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellPoints()

void NEM::MSH::geoMeshBase::getCellPoints ( nemId_t  cellId,
vtkIdList *  ptIds 
) const
inlineinherited
Parameters
cellIdcell id
ptIdslist of point ids

Definition at line 256 of file geoMeshBase.H.

256  {
257  _geoMesh.mesh->GetCellPoints(cellId, ptIds);
258  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getCellType()

VTKCellType NEM::MSH::geoMeshBase::getCellType ( nemId_t  cellId) const
inlineinherited
Parameters
cellIdcell id
Returns
VTK cell type (see vtk documentation for specifics)

Definition at line 248 of file geoMeshBase.H.

248  {
249  return static_cast<VTKCellType>(_geoMesh.mesh->GetCellType(cellId));
250  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getFieldDataArrayCopy() [1/4]

void NEM::MSH::geoMeshBase::getFieldDataArrayCopy ( const std::string &  arrayName,
vtkAbstractArray *  array,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arrayfield data array
arrayIdxarray index

Definition at line 201 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

203  {
204  getArrCopy(_geoMesh.mesh->GetFieldData(), arrayName, arrayIdx, array);
205 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getFieldDataArrayCopy() [2/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getFieldDataArrayCopy ( const std::string &  arrayName,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 207 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

208  {
209  return getArrCopy(_geoMesh.mesh->GetFieldData(), arrayName, arrayIdx);
210 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getFieldDataArrayCopy() [3/4]

void NEM::MSH::geoMeshBase::getFieldDataArrayCopy ( int  arrayIdx,
vtkAbstractArray *  array 
) const
inherited
Parameters
arrayIdxarray index
arrayfield data array

Definition at line 212 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

213  {
214  getArrCopy(_geoMesh.mesh->GetFieldData(), arrayIdx, array);
215 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getFieldDataArrayCopy() [4/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getFieldDataArrayCopy ( int  arrayIdx) const
inherited
Parameters
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 217 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

218  {
219  return getArrCopy(_geoMesh.mesh->GetFieldData(), arrayIdx);
220 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getFoamMesh()

const Foam::fvMesh& NEM::MSH::foamGeoMesh::getFoamMesh ( ) const
inline
Returns
fvMesh

Definition at line 105 of file foamGeoMesh.H.

Referenced by MeshManipulationFoam::addArtificialThicknessElements(), and MeshManipulationFoam::addCohesiveElements().

105 { return *fmesh_; }
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162

◆ getGeoEntArrayName()

const std::string& NEM::MSH::geoMeshBase::getGeoEntArrayName ( ) const
inlineinherited
Returns
name of geometric entities array

Definition at line 157 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

157 { return _geoMesh.link; }

◆ getGeoMesh()

◆ getNumberOfCellDataArrays()

int NEM::MSH::geoMeshBase::getNumberOfCellDataArrays ( ) const
inlineinherited
Returns
number of arrays in the cell data

Definition at line 318 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

318  {
319  return _geoMesh.mesh->GetCellData()->GetNumberOfArrays();
320  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getNumberOfCells()

nemId_t NEM::MSH::geoMeshBase::getNumberOfCells ( ) const
inlineinherited
Returns
number of cells in mesh

Definition at line 190 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

190 { return _geoMesh.mesh->GetNumberOfCells(); }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getNumberOfFieldDataArrays()

int NEM::MSH::geoMeshBase::getNumberOfFieldDataArrays ( ) const
inlineinherited
Returns
number of arrays in the field data

Definition at line 355 of file geoMeshBase.H.

355  {
356  return _geoMesh.mesh->GetFieldData()->GetNumberOfArrays();
357  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getNumberOfPointDataArrays()

int NEM::MSH::geoMeshBase::getNumberOfPointDataArrays ( ) const
inlineinherited
Returns
number of arrays in the point data

Definition at line 281 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

281  {
282  return _geoMesh.mesh->GetPointData()->GetNumberOfArrays();
283  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getNumberOfPoints()

nemId_t NEM::MSH::geoMeshBase::getNumberOfPoints ( ) const
inlineinherited
Returns
number of points in mesh

Definition at line 183 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

183  {
184  return _geoMesh.mesh->GetNumberOfPoints();
185  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPoint() [1/2]

void NEM::MSH::geoMeshBase::getPoint ( nemId_t  id,
std::array< double, 3 > *  x 
) const
inlineinherited
Parameters
idpoint id
xarray of coordinates as (x,y,z)

Definition at line 196 of file geoMeshBase.H.

Referenced by NEM::MSH::diffMesh().

196  {
197  _geoMesh.mesh->GetPoint(id, x->data());
198  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPoint() [2/2]

std::array<double, 3> NEM::MSH::geoMeshBase::getPoint ( nemId_t  id) const
inlineinherited
Parameters
idpoint id
Returns
array of coordinates as (x,y,z)

Definition at line 204 of file geoMeshBase.H.

204  {
205  std::array<double, 3> x{};
206  getPoint(id, &x);
207  return x;
208  }
void getPoint(nemId_t id, std::array< double, 3 > *x) const
Get the coordinate of a point.
Definition: geoMeshBase.H:196

◆ getPointCells()

void NEM::MSH::geoMeshBase::getPointCells ( nemId_t  ptId,
vtkIdList *  cellIds 
) const
inlineinherited
Parameters
ptIdpoint id
cellIdslist of cell ids

Definition at line 264 of file geoMeshBase.H.

264  {
265  _geoMesh.mesh->GetPointCells(ptId, cellIds);
266  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPointDataArrayCopy() [1/4]

void NEM::MSH::geoMeshBase::getPointDataArrayCopy ( const std::string &  arrayName,
vtkAbstractArray *  array,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arraypoint data array
arrayIdxarray index

Definition at line 159 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

Referenced by NEM::MSH::diffMesh().

161  {
162  getArrCopy(_geoMesh.mesh->GetPointData(), arrayName, arrayIdx, array);
163 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPointDataArrayCopy() [2/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getPointDataArrayCopy ( const std::string &  arrayName,
int *  arrayIdx = nullptr 
) const
inherited

Optionally, get array index.

Parameters
arrayNamearray name
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 165 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

166  {
167  return getArrCopy(_geoMesh.mesh->GetPointData(), arrayName, arrayIdx);
168 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPointDataArrayCopy() [3/4]

void NEM::MSH::geoMeshBase::getPointDataArrayCopy ( int  arrayIdx,
vtkAbstractArray *  array 
) const
inherited
Parameters
arrayIdxarray index
arraypoint data array

Definition at line 170 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

171  {
172  getArrCopy(_geoMesh.mesh->GetPointData(), arrayIdx, array);
173 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ getPointDataArrayCopy() [4/4]

vtkSmartPointer< vtkAbstractArray > NEM::MSH::geoMeshBase::getPointDataArrayCopy ( int  arrayIdx) const
inherited
Parameters
arrayIdxarray index
Returns
pointer to copy of array

Definition at line 175 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, and NEM::MSH::geoMeshBase::GeoMesh::mesh.

176  {
177  return getArrCopy(_geoMesh.mesh->GetPointData(), arrayIdx);
178 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ GM2foam()

std::unique_ptr< Foam::fvMesh > NEM::MSH::foamGeoMesh::GM2foam ( const GeoMesh geoMesh,
Foam::Time *  runTime,
const std::string &  phyGrpArrayName = std::string() 
)
staticprivate
Parameters
geoMeshGeoMesh
runTimeTODO
phyGrpArrayNamename of cell data array describing physical group of each cell
Returns
fvMesh

Definition at line 297 of file foamGeoMesh.C.

References NEM::MSH::geoMeshBase::GeoMesh::mesh, NEM::MSH::New(), NEM::MSH::geoMeshBase::SideSet::sides, and NEM::MSH::geoMeshBase::GeoMesh::sideSet.

Referenced by resetNative().

299  {
300  int numPoints = static_cast<int>(geoMesh.mesh->GetNumberOfPoints());
301  int numCells = static_cast<int>(geoMesh.mesh->GetNumberOfCells());
302 
303  Foam::pointField pointData(numPoints);
304  Foam::pointField pointData2(numPoints);
305  Foam::cellShapeList cellShapeData(numCells);
306  Foam::cellShapeList cellShapeData2(numCells);
307 
308  if (numPoints > 0) {
309  // Fetch all points and coordinates
310  std::vector<std::vector<double>> verts;
311  verts.resize(numPoints);
312  for (int ipt = 0; ipt < numPoints; ipt++) {
313  std::vector<double> getPt = std::vector<double>(3);
314  geoMesh.mesh->GetPoint(ipt, &getPt[0]);
315  verts[ipt].resize(3);
316  verts[ipt][0] = getPt[0];
317  verts[ipt][1] = getPt[1];
318  verts[ipt][2] = getPt[2];
319  }
320 
321  // Gets Ids for cells
322  std::vector<std::vector<int>> cellIds;
323  cellIds.resize(numCells);
324 
325  // Gets celltypes for all cells in mesh
326  std::vector<int> typeCell;
327  typeCell.resize(numCells);
328 
329  for (int i = 0; i < numPoints; i++) {
330  pointData[i] = Foam::vector(verts[i][0], verts[i][1], verts[i][2]);
331  pointData2[i] = Foam::vector(verts[i][0], verts[i][1], verts[i][2]);
332  }
333 
334  for (int i = 0; i < numCells; i++) {
335  vtkIdList *ptIds = vtkIdList::New();
336  geoMesh.mesh->GetCellPoints(i, ptIds);
337  int numIds = static_cast<int>(ptIds->GetNumberOfIds());
338  cellIds[i].resize(numIds);
339  for (int j = 0; j < numIds; j++) cellIds[i][j] = static_cast<int>(ptIds->GetId(j));
340  Foam::labelList meshPoints(numIds);
341  for (int k = 0; k < numIds; k++) meshPoints[k] = cellIds[i][k];
342  typeCell[i] = geoMesh.mesh->GetCellType(i);
343  if (typeCell[i] == 12) {
344  cellShapeData[i] = Foam::cellShape("hex", meshPoints, true);
345  cellShapeData2[i] = Foam::cellShape("hex", meshPoints, true);
346  } else if (typeCell[i] == 14) {
347  cellShapeData[i] = Foam::cellShape("pyr", meshPoints, true);
348  cellShapeData2[i] = Foam::cellShape("pyr", meshPoints, true);
349  } else if (typeCell[i] == 10) {
350  cellShapeData[i] = Foam::cellShape("tet", meshPoints, true);
351  cellShapeData2[i] = Foam::cellShape("tet", meshPoints, true);
352  } else {
353  std::cerr << "Only Hexahedral, Tetrahedral,"
354  << " and Pyramid cells are supported in foamGeoMesh!"
355  << std::endl;
356  throw;
357  }
358  }
359  } else {
360  return nullptr;
361  }
362 
363  // Foam::word regName = Foam::polyMesh::defaultRegion;
364  Foam::word regName = "";
365 
366  // Get patch names from mesh
367  int idx1 = 0;
368  int idx2 = 0;
369  std::map<int, std::string> ptchNameIDMap;
370  Foam::faceListList bndryFaces(0);
371  Foam::wordList BndryPatchNames(0);
372  Foam::wordList BndryPatchTypes(0);
373  Foam::wordList boundaryPatchPhysicalTypes(0);
374  int totalPatches;
375  std::vector<int> startIds;
376  std::vector<int> nFacesInPatch;
377  Foam::PtrList<Foam::polyPatch> patchPtrList(0);
378  Foam::cellList cellLst2(0);
379  Foam::faceList faceLst2(0);
380 
381  if (geoMesh.sideSet.sides) {
382  auto ptchIds = vtkIntArray::FastDownCast(
383  geoMesh.sideSet.sides->GetCellData()->GetArray("PatchIds", idx1));
384  auto ptchNms = vtkStringArray::SafeDownCast(
385  geoMesh.sideSet.sides->GetFieldData()->GetAbstractArray("PatchNames",
386  idx2));
387 
388  if (idx1 != -1 && idx2 != -1) {
389  // Patches exist
390  for (int i = 0; i < ptchIds->GetNumberOfTuples(); ++i) {
391  // Get patch Id
392  auto cc = ptchIds->GetTypedComponent(i, 0);
393  int id_p = cc;
394 
395  // Get patch name
396  std::string nm = ptchNms->GetValue(i);
397 
398  // Create maps
399  ptchNameIDMap[id_p] = nm;
400  }
401 
402  totalPatches = static_cast<int>(ptchNameIDMap.size());
403  std::vector<int> faceCounts(totalPatches,
404  0); // Counts faces for each patch
405  std::vector<std::vector<int>> facePatchIds;
406  facePatchIds.resize(totalPatches);
407  for (int i = 0; i < ptchIds->GetNumberOfTuples(); ++i) {
408  // Get patch Id
409  auto cc = ptchIds->GetTypedComponent(i, 0);
410  int id_p = cc;
411  faceCounts[id_p] += 1;
412  facePatchIds[id_p].push_back(i);
413  }
414 
415  BndryPatchNames.setSize(totalPatches);
416  BndryPatchTypes.setSize(totalPatches);
417 
418  auto iter = ptchNameIDMap.begin();
419  int r_indx = 0;
420  while (iter != ptchNameIDMap.end()) {
421  BndryPatchNames[r_indx] = iter->second;
422  BndryPatchTypes[r_indx] = "patch";
423  iter++;
424  r_indx++;
425  }
426 
427  // Start pulling out cell (2D faces) point order from sideSets and create
428  // faceList. Append those into faceListList at the end of every patch.
429  bndryFaces.clear();
430  for (int i = 0; i < totalPatches; i++) {
431  Foam::faceList thisPatch(0);
432  thisPatch.clear();
433  for (int j : facePatchIds[i]) {
434  vtkIdList *ptIds = vtkIdList::New();
435  geoMesh.sideSet.sides->GetCellPoints(j, ptIds);
436  int numIds = static_cast<int>(ptIds->GetNumberOfIds());
437  Foam::labelList lstLbl(0);
438  lstLbl.clear();
439  for (int k = 0; k < numIds; k++) {
440  lstLbl.append(static_cast<int>(ptIds->GetId(k)));
441  }
442  if (!lstLbl.empty()) thisPatch.append(Foam::face(lstLbl));
443  }
444  bndryFaces.append(thisPatch);
445  nFacesInPatch.push_back(thisPatch.size());
446  }
447  boundaryPatchPhysicalTypes.resize(totalPatches,
448  Foam::polyPatch::typeName);
449  }
450  }
451 
452  {
453  Foam::polyMesh tmpfm(
454  Foam::IOobject(regName, runTime->timeName(), *runTime,
455  Foam::IOobject::NO_READ, Foam::IOobject::AUTO_WRITE),
456  std::move(pointData), // Vertices
457  cellShapeData, // Cell shape and points
458  bndryFaces, // Boundary faces
459  BndryPatchNames, // Boundary Patch Names
460  BndryPatchTypes, // Boundary Patch Types
461  "defaultPatch", // Default Patch Name
462  Foam::polyPatch::typeName, // Default Patch Type
463  Foam::wordList());
464 
465  const Foam::polyBoundaryMesh &patches2 = tmpfm.boundaryMesh();
466 
467  for (int i = 0; i < patches2.size(); i++) {
468  auto *tmpPtch = new Foam::polyPatch(patches2[i]);
469  patchPtrList.append(tmpPtch);
470  }
471 
472  // Get pointField (points), faceList (faces), and cellList (cells).
473  const Foam::cellList &cellLst = tmpfm.cells();
474  cellLst2 = cellLst;
475  const Foam::faceList &faceLst = tmpfm.faces();
476  faceLst2 = faceLst;
477  }
478 
479  auto fm = std::unique_ptr<Foam::fvMesh>(new Foam::fvMesh(
480  Foam::IOobject(regName, runTime->timeName(), *runTime,
481  Foam::IOobject::NO_READ, Foam::IOobject::AUTO_WRITE),
482  std::move(pointData2), std::move(faceLst2), std::move(cellLst2)));
483 
484  // Add boundary patches to fvMesh using patchPtrList
485  fm->addFvPatches(patchPtrList, true);
486 
487  // Get Physical Groups Vector from GeoMesh
488  std::vector<double> allGroups;
489  int idx;
490  vtkSmartPointer<vtkDataArray> cd =
491  geoMesh.mesh->GetCellData()->GetArray(phyGrpArrayName.c_str(), idx);
492  if (idx != -1) {
493  // allGroups.resize(cd->GetNumberOfTuples());
494  double x[1];
495  for (nemId_t i = 0; i < cd->GetNumberOfTuples(); ++i) {
496  cd->GetTuple(i, x);
497  allGroups.push_back(x[0]);
498  }
499 
500  // Figure out number of physical groups
501  std::vector<double> scratchVec = allGroups;
502  std::sort(scratchVec.begin(), scratchVec.end());
503  scratchVec.erase(unique(scratchVec.begin(), scratchVec.end()),
504  scratchVec.end());
505  int totalGroups = static_cast<int>(scratchVec.size());
506 
507  // Create cellZones
508  Foam::label zoneI;
509  for (int i = 0; i < totalGroups; i++) {
510  Foam::labelList currentGroupList;
511  //for (int j : allGroups) {
512  for (int j = 0; j < static_cast<int>(allGroups.size()); j++) {
513  if (static_cast<int>(allGroups[j]) == i) currentGroupList.append(j);
514  }
515 
516  const Foam::cellZoneMesh &cellZones = fm->cellZones();
517  zoneI = cellZones.size();
518  fm->cellZones().setSize(zoneI + 1);
519  Foam::word nameSet = "pg_" + std::to_string(i);
520  auto clzn =
521  new Foam::cellZone(nameSet, currentGroupList, zoneI, cellZones);
522  fm->cellZones().set(zoneI, clzn);
523  }
524  fm->cellZones().writeOpt() = Foam::IOobject::AUTO_WRITE;
525  }
526  return fm;
527 }
std::size_t nemId_t
Definition: meshBase.H:51
geoMeshBase * New(MeshType meshType)
Create a new mesh object.

◆ InitializeFoam()

void NEM::MSH::foamGeoMesh::InitializeFoam ( )
private

Definition at line 667 of file foamGeoMesh.C.

References controlDict_, fvSchemes_, fvSolution_, and runTime_.

Referenced by foamGeoMesh(), and resetNative().

667  {
668  bool writeDicts = false;
669  std::unique_ptr<getDicts> initFoam;
670  initFoam = std::unique_ptr<getDicts>(new getDicts());
671  controlDict_ = initFoam->createControlDict(writeDicts);
672  fvSchemes_ = initFoam->createFvSchemes(writeDicts);
673  fvSolution_ = initFoam->createFvSolution(writeDicts);
674 
675  // Create time class without reading controlDict
676  runTime_ =
677  std::unique_ptr<Foam::Time>(new Foam::Time(controlDict_.get(), ".", "."));
678  Foam::argList::noParallel();
679 }
std::unique_ptr< Foam::dictionary > controlDict_
Definition: foamGeoMesh.H:150
std::unique_ptr< Foam::dictionary > fvSolution_
Definition: foamGeoMesh.H:156
std::unique_ptr< Foam::dictionary > fvSchemes_
Definition: foamGeoMesh.H:153
std::unique_ptr< Foam::Time > runTime_
Definition: foamGeoMesh.H:159

◆ mergeGeoMesh()

void NEM::MSH::geoMeshBase::mergeGeoMesh ( geoMeshBase otherGeoMesh)
virtualinherited

Deletes the data from the new geoMesh pointer

Parameters
otherGeoMeshA new geoMesh data to merge

Definition at line 113 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, NEM::MSH::geoMeshBase::GeoMesh::mesh, NEM::MSH::New(), and NEM::MSH::geoMeshBase::resetNative().

113  {
114  vtkSmartPointer<vtkAppendFilter> appendFilter =
116  appendFilter->AddInputData(_geoMesh.mesh);
117  appendFilter->AddInputData(otherGeoMesh->_geoMesh.mesh);
118  appendFilter->MergePointsOn();
119  appendFilter->Update();
120  _geoMesh.mesh = appendFilter->GetOutput();
121  otherGeoMesh->_geoMesh = {
123  otherGeoMesh->resetNative();
124 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
virtual void resetNative()=0

◆ New()

static foamGeoMesh* NEM::MSH::foamGeoMesh::New ( )
static

◆ reconstructGeo()

void NEM::MSH::geoMeshBase::reconstructGeo ( )
virtualinherited

Sets geometry, link, and side set. Does not alter the mesh.

Reimplemented in NEM::MSH::exoGeoMesh, NEM::MSH::oshGeoMesh, and NEM::MSH::inpGeoMesh.

Definition at line 466 of file geoMeshBaseReconstructGeo.C.

References NEM::MSH::geoMeshBase::_angleThreshold, NEM::MSH::geoMeshBase::_geoMesh, NEM::MSH::geoMeshBase::GeoMesh::geo, NEM::MSH::geoMeshBase::GEO_ENT_DEFAULT_NAME, nemAux::getRandomString(), NEM::MSH::geoMeshBase::GeoMesh::link, NEM::MSH::geoMeshBase::GeoMesh::mesh, NEM::MSH::geoMeshBase::SideSet::sides, and NEM::MSH::geoMeshBase::GeoMesh::sideSet.

Referenced by NEM::MSH::inpGeoMesh::reconstructGeo(), NEM::MSH::oshGeoMesh::reconstructGeo(), and NEM::MSH::exoGeoMesh::reconstructGeo().

466  {
467 #ifdef HAVE_GMSH
468  if (_geoMesh.geo.empty()) {
469  _geoMesh.geo = "geoMesh_" + nemAux::getRandomString(6);
470  } else {
471  gmsh::model::setCurrent(_geoMesh.geo);
472  gmsh::model::remove();
473  }
474  gmsh::model::add(_geoMesh.geo);
475  gmsh::model::setCurrent(_geoMesh.geo);
476 #endif
477  if (_geoMesh.link.empty()) {
479  }
480  _geoMesh.sideSet = SideSet{
481  computeDiscreteGeoFromMsh(_geoMesh.mesh, _geoMesh.link, _angleThreshold)};
482  assert(_geoMesh.mesh->GetPoints() == _geoMesh.sideSet.sides->GetPoints());
483 }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419
static constexpr auto GEO_ENT_DEFAULT_NAME
Definition: geoMeshBase.H:446
std::string getRandomString(int length)
vtkSmartPointer< vtkPolyData > sides
Cells represent edges/faces of some GeoMesh.
Definition: geoMeshBase.H:399
double _angleThreshold
Dihedral angle threshold (in radians) to classify surfaces (Default: 30 degrees)
Definition: geoMeshBase.H:554

◆ report()

void NEM::MSH::foamGeoMesh::report ( std::ostream &  out) const
overridevirtual

Implements NEM::MSH::geoMeshBase.

Definition at line 642 of file foamGeoMesh.C.

References NEM::MSH::geoMeshBase::report().

642 { geoMeshBase::report(out); }
virtual void report(std::ostream &out) const =0
Print a report about the mesh.
Definition: geoMeshBase.C:97

◆ resetNative()

void NEM::MSH::foamGeoMesh::resetNative ( )
overridevirtual

Implements NEM::MSH::geoMeshBase.

Definition at line 652 of file foamGeoMesh.C.

References controlDict_, fmesh_, fvSchemes_, fvSolution_, NEM::MSH::geoMeshBase::getGeoMesh(), GM2foam(), InitializeFoam(), and runTime_.

652  {
653  // Clear
654  controlDict_.reset();
655  fvSchemes_.reset();
656  fvSolution_.reset();
657  runTime_.reset();
658  fmesh_.reset();
659 
660  // Initialize required variables
661  InitializeFoam();
662 
663  // Reset fvMesh
664  fmesh_ = GM2foam(getGeoMesh(), runTime_.get());
665 }
static std::unique_ptr< Foam::fvMesh > GM2foam(const GeoMesh &geoMesh, Foam::Time *runTime, const std::string &phyGrpArrayName=std::string())
Create a fvMesh from geoMeshBase.
Definition: foamGeoMesh.C:297
std::unique_ptr< Foam::dictionary > controlDict_
Definition: foamGeoMesh.H:150
std::unique_ptr< Foam::dictionary > fvSolution_
Definition: foamGeoMesh.H:156
void InitializeFoam()
Initializes arguments and runtime objects.
Definition: foamGeoMesh.C:667
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162
std::unique_ptr< Foam::dictionary > fvSchemes_
Definition: foamGeoMesh.H:153
std::unique_ptr< Foam::Time > runTime_
Definition: foamGeoMesh.H:159
const GeoMesh & getGeoMesh() const
Get the underlying geometry object.
Definition: geoMeshBase.H:533

◆ setAngleThreshold()

void NEM::MSH::geoMeshBase::setAngleThreshold ( double  angleThreshold)
inlineinherited
Parameters
angleThreshold(in radians)

Definition at line 176 of file geoMeshBase.H.

176  {
177  _angleThreshold = angleThreshold;
178  }
double _angleThreshold
Dihedral angle threshold (in radians) to classify surfaces (Default: 30 degrees)
Definition: geoMeshBase.H:554

◆ setCellDataArray()

int NEM::MSH::geoMeshBase::setCellDataArray ( vtkAbstractArray *  array)
inlineprotectedinherited
Parameters
arrayarray pointer
Returns
array index

Definition at line 473 of file geoMeshBase.H.

473  {
474  return _geoMesh.mesh->GetCellData()->AddArray(array);
475  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ setFieldDataArray()

int NEM::MSH::geoMeshBase::setFieldDataArray ( vtkAbstractArray *  array)
inlineprotectedinherited
Parameters
arrayarray pointer
Returns
array index

Definition at line 481 of file geoMeshBase.H.

481  {
482  return _geoMesh.mesh->GetFieldData()->AddArray(array);
483  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ setFoamMesh()

void NEM::MSH::foamGeoMesh::setFoamMesh ( std::unique_ptr< Foam::fvMesh >  foamMesh)
Parameters
foamMeshexisting fvMesh;

Definition at line 644 of file foamGeoMesh.C.

References fmesh_, foam2GM(), and NEM::MSH::geoMeshBase::setGeoMesh().

644  {
645  // Setting class parameters
646  fmesh_ = std::unique_ptr<Foam::fvMesh>(foamMesh.get());
647 
648  // Parent
649  setGeoMesh(foam2GM(foamMesh.get()));
650 }
static GeoMesh foam2GM(Foam::fvMesh *foamMesh, const std::string &phyGrpArrayName=std::string())
Create a GeoMesh from a fvMesh.
Definition: foamGeoMesh.C:107
void setGeoMesh(const geoMeshBase::GeoMesh &geoMesh)
Set the underlying geometry object.
Definition: geoMeshBase.H:538
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162

◆ setGeoEntArrayName()

void NEM::MSH::geoMeshBase::setGeoEntArrayName ( const std::string &  geoEntArrayName)
inlineinherited
Parameters
geoEntArrayNamename of geometric entities array

Definition at line 162 of file geoMeshBase.H.

162  {
163  auto a = _geoMesh.mesh->GetCellData()->GetArray(_geoMesh.link.c_str());
164  if (a) a->SetName(geoEntArrayName.c_str());
165  _geoMesh.link = geoEntArrayName;
166  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ setGeoMesh()

void NEM::MSH::geoMeshBase::setGeoMesh ( const geoMeshBase::GeoMesh geoMesh)
inlineprotectedinherited

◆ setPointDataArray()

int NEM::MSH::geoMeshBase::setPointDataArray ( vtkAbstractArray *  array)
inlineprotectedinherited
Parameters
arrayarray pointer
Returns
array index

Definition at line 465 of file geoMeshBase.H.

465  {
466  return _geoMesh.mesh->GetPointData()->AddArray(array);
467  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ takeGeoMesh()

void NEM::MSH::geoMeshBase::takeGeoMesh ( geoMeshBase otherGeoMesh)
virtualinherited

Note that otherGeoMesh will be left with an empty mesh.

Parameters
otherGeoMeshother geoMeshBase object; mesh will be left empty

Reimplemented in NEM::MSH::exoGeoMesh, and NEM::MSH::oshGeoMesh.

Definition at line 104 of file geoMeshBase.C.

References NEM::MSH::geoMeshBase::_geoMesh, NEM::MSH::New(), and NEM::MSH::geoMeshBase::resetNative().

Referenced by NEM::MSH::oshGeoMesh::takeGeoMesh(), and NEM::MSH::exoGeoMesh::takeGeoMesh().

104  {
105  _geoMesh = std::move(otherGeoMesh->_geoMesh);
106  otherGeoMesh->_geoMesh = {
108  otherGeoMesh->resetNative();
109  resetNative();
110 }
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
virtual void resetNative()=0

◆ unsetCellDataArray() [1/2]

void NEM::MSH::geoMeshBase::unsetCellDataArray ( int  arrayIdx)
inlineprotectedinherited
Parameters
arrayIdxarray index

Definition at line 503 of file geoMeshBase.H.

503  {
504  _geoMesh.mesh->GetCellData()->RemoveArray(arrayIdx);
505  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ unsetCellDataArray() [2/2]

void NEM::MSH::geoMeshBase::unsetCellDataArray ( const std::string &  arrayName)
inlineprotectedinherited
Parameters
arrayNamearray name

Definition at line 510 of file geoMeshBase.H.

510  {
511  _geoMesh.mesh->GetCellData()->RemoveArray(arrayName.c_str());
512  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ unsetFieldDataArray() [1/2]

void NEM::MSH::geoMeshBase::unsetFieldDataArray ( int  arrayIdx)
inlineprotectedinherited
Parameters
arrayIdxarray index

Definition at line 517 of file geoMeshBase.H.

517  {
518  _geoMesh.mesh->GetFieldData()->RemoveArray(arrayIdx);
519  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ unsetFieldDataArray() [2/2]

void NEM::MSH::geoMeshBase::unsetFieldDataArray ( const std::string &  arrayName)
inlineprotectedinherited
Parameters
arrayNamearray name

Definition at line 524 of file geoMeshBase.H.

524  {
525  _geoMesh.mesh->GetFieldData()->RemoveArray(arrayName.c_str());
526  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ unsetPointDataArray() [1/2]

void NEM::MSH::geoMeshBase::unsetPointDataArray ( int  arrayIdx)
inlineprotectedinherited
Parameters
arrayIdxarray index

Definition at line 489 of file geoMeshBase.H.

489  {
490  _geoMesh.mesh->GetPointData()->RemoveArray(arrayIdx);
491  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ unsetPointDataArray() [2/2]

void NEM::MSH::geoMeshBase::unsetPointDataArray ( const std::string &  arrayName)
inlineprotectedinherited
Parameters
arrayNamearray name

Definition at line 496 of file geoMeshBase.H.

496  {
497  _geoMesh.mesh->GetPointData()->RemoveArray(arrayName.c_str());
498  }
vtkSmartPointer< vtkUnstructuredGrid > mesh
Definition: geoMeshBase.H:419

◆ write()

void NEM::MSH::foamGeoMesh::write ( const std::string &  fileName)
overridevirtual
Parameters
fileNameDirectory path where foam mesh should be written

Implements NEM::MSH::geoMeshBase.

Definition at line 529 of file foamGeoMesh.C.

References controlDict_, fmesh_, fvSchemes_, and fvSolution_.

529  {
530  // Create system directory
531  Foam::word w = "system";
532  if (!Foam::isDir(w)) Foam::mkDir(w);
533 
534  // Write ControlDict
535  Foam::fileName fcontrolDict = "system/controlDict";
536  if (!Foam::exists(fcontrolDict)) {
537  Foam::OFstream outcontrolDict(fcontrolDict);
538  Foam::IOobject::writeBanner(outcontrolDict);
539  controlDict_->write(outcontrolDict, false);
540  }
541 
542  // Write fvSchemes
543  Foam::fileName ffvSchemes = "system/fvSchemes";
544  if (!Foam::exists(ffvSchemes)) {
545  Foam::OFstream outfvSchemes(ffvSchemes);
546  Foam::IOobject::writeBanner(outfvSchemes);
547  fvSchemes_->write(outfvSchemes, false);
548  }
549 
550  // Write fvSolution
551  Foam::fileName ffvSolution = "system/fvSolution";
552  if (!Foam::exists(ffvSolution)) {
553  Foam::OFstream outfvSolution(ffvSolution);
554  Foam::IOobject::writeBanner(outfvSolution);
555  fvSolution_->write(outfvSolution, false);
556  }
557 
558  // Region to write in
559  Foam::fileName newReg = "";
560  if (fileName.empty())
561  newReg = "";
562  else
563  newReg = fileName;
564 
565  // Write dictionaries to the specific region too
566  if (!Foam::isDir("system/" + newReg)) Foam::mkDir("system/" + newReg);
567 
568  Foam::fileName fcontrolDict_2 = "system/" + newReg + "/controlDict";
569  if (!Foam::exists(fcontrolDict_2)) { Foam::cp(fcontrolDict, fcontrolDict_2); }
570 
571  // Write fvSchemes
572  Foam::fileName ffvSchemes_2 = "system/" + newReg + "/fvSchemes";
573  if (!Foam::exists(ffvSchemes_2)) { Foam::cp(ffvSchemes, ffvSchemes_2); }
574 
575  // Write fvSolution
576  Foam::fileName ffvSolution_2 = "system/" + newReg + "/fvSolution";
577  if (!Foam::exists(ffvSolution_2)) { Foam::cp(ffvSolution, ffvSolution_2); }
578 
579  // Write mesh in fileName
580  if (!Foam::isDir("0")) Foam::mkDir("0");
581 
582  // Write cellZones and cellSets
583  const Foam::cellZoneMesh &czMesh = fmesh_->cellZones();
584  Foam::label numZones = czMesh.size();
585 
586  fmesh_->setInstance("0");
587  fmesh_->write();
588 
589  if (numZones > 0) {
590  for (int i = 0; i < numZones; i++) {
591  const Foam::cellZone &cz = czMesh[i];
592  Foam::cellSet(*fmesh_, cz.name(), cz).write();
593  }
594  }
595 
596  Foam::fileName currentDir = "0";
597  Foam::fileName currentReg = fmesh_->dbDir();
598  Foam::fileName newDir = "constant";
599  Foam::fileName finalMesh = "";
600 
601  if (currentReg.empty()) {
602  if (!Foam::isDir(currentDir + "/" + newReg))
603  Foam::mkDir(currentDir + "/" + newReg);
604  if (!newReg.empty()) {
605  Foam::mv(currentDir + "/polyMesh",
606  currentDir + "/" + newReg + "/polyMesh");
607  finalMesh = currentDir + "/" + newReg;
608  } else {
609  finalMesh = currentDir + "/polyMesh";
610  }
611  } else {
612  if (!newReg.empty()) {
613  Foam::mv(currentDir + "/" + currentReg, currentDir + "/" + newReg);
614  finalMesh = currentDir + "/" + newReg;
615  } else {
616  Foam::mv(currentDir + "/" + currentReg, currentDir + "/");
617  finalMesh = currentDir + "/polyMesh";
618  }
619  }
620 
621  if (!Foam::isDir(newDir + "/" + newReg)) {
622  if (!newReg.empty()) {
623  Foam::mkDir(newDir + "/" + newReg);
624  Foam::mv(finalMesh, newDir + "/" + newReg);
625  } else {
626  Foam::mkDir(newDir + "/polyMesh");
627  Foam::mv(finalMesh, newDir + "/polyMesh");
628  }
629  }
630 
631  if (!newReg.empty()) {
632  if (!Foam::isDir(newDir + "/" + newReg)) {
633  Foam::mkDir(newDir + "/" + newReg);
634  Foam::mv(finalMesh, newDir + "/" + newReg);
635  }
636  } else {
637  if (!Foam::isDir(newDir + "/polyMesh")) Foam::mkDir(newDir + "/polyMesh");
638  Foam::mv(finalMesh, newDir + "/polyMesh");
639  }
640 }
void write(const std::string &fileName) override
Writes foam mesh into current directory.
Definition: foamGeoMesh.C:529
std::unique_ptr< Foam::dictionary > controlDict_
Definition: foamGeoMesh.H:150
std::unique_ptr< Foam::dictionary > fvSolution_
Definition: foamGeoMesh.H:156
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162
std::unique_ptr< Foam::dictionary > fvSchemes_
Definition: foamGeoMesh.H:153

Member Data Documentation

◆ controlDict_

std::unique_ptr<Foam::dictionary> NEM::MSH::foamGeoMesh::controlDict_
private

Definition at line 150 of file foamGeoMesh.H.

Referenced by InitializeFoam(), resetNative(), and write().

◆ fmesh_

std::unique_ptr<Foam::fvMesh> NEM::MSH::foamGeoMesh::fmesh_
private

Definition at line 162 of file foamGeoMesh.H.

Referenced by resetNative(), setFoamMesh(), and write().

◆ fvSchemes_

std::unique_ptr<Foam::dictionary> NEM::MSH::foamGeoMesh::fvSchemes_
private

Definition at line 153 of file foamGeoMesh.H.

Referenced by InitializeFoam(), resetNative(), and write().

◆ fvSolution_

std::unique_ptr<Foam::dictionary> NEM::MSH::foamGeoMesh::fvSolution_
private

Definition at line 156 of file foamGeoMesh.H.

Referenced by InitializeFoam(), resetNative(), and write().

◆ GEO_ENT_DEFAULT_NAME

constexpr auto NEM::MSH::geoMeshBase::GEO_ENT_DEFAULT_NAME = "GeoEnt"
staticprotectedinherited

◆ runTime_

std::unique_ptr<Foam::Time> NEM::MSH::foamGeoMesh::runTime_
private

Definition at line 159 of file foamGeoMesh.H.

Referenced by InitializeFoam(), and resetNative().


The documentation for this class was generated from the following files: