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.
meshStitcher Class Reference

Detailed Description

Definition at line 48 of file meshStitcher.H.

Public Member Functions

 meshStitcher (std::vector< std::string > cgFileNames, bool surf)
 
 ~meshStitcher ()=default
 
 meshStitcher (const meshStitcher &that)=delete
 
meshStitcheroperator= (const meshStitcher &that)=delete
 
std::shared_ptr< cgnsAnalyzergetStitchedCGNS () const
 
std::shared_ptr< meshBasegetStitchedMB () const
 

Private Member Functions

void initSurfCgObj ()
 
void initVolCgObj ()
 

Private Attributes

const std::vector< std::string > cgFileNames
 
std::vector< std::shared_ptr< cgnsAnalyzer > > partitions
 
std::shared_ptr< meshBasestitchedMesh
 
std::shared_ptr< rocstarCgnscgObj
 

Constructor & Destructor Documentation

◆ meshStitcher() [1/2]

meshStitcher::meshStitcher ( std::vector< std::string >  cgFileNames,
bool  surf 
)

Definition at line 36 of file meshStitcher.C.

References cgFileNames, initSurfCgObj(), and initVolCgObj().

37  : cgFileNames(std::move(_cgFileNames)),
38  stitchedMesh(nullptr),
39  cgObj(nullptr) {
40  if (!cgFileNames.empty()) {
41  if (surf)
42  initSurfCgObj();
43  else
44  initVolCgObj();
45  }
46 }
const std::vector< std::string > cgFileNames
Definition: meshStitcher.H:65
void initVolCgObj()
Definition: meshStitcher.C:48
void initSurfCgObj()
Definition: meshStitcher.C:122
std::shared_ptr< rocstarCgns > cgObj
Definition: meshStitcher.H:71
std::shared_ptr< meshBase > stitchedMesh
Definition: meshStitcher.H:69

◆ ~meshStitcher()

meshStitcher::~meshStitcher ( )
default

◆ meshStitcher() [2/2]

meshStitcher::meshStitcher ( const meshStitcher that)
delete

Member Function Documentation

◆ getStitchedCGNS()

std::shared_ptr< cgnsAnalyzer > meshStitcher::getStitchedCGNS ( ) const

Definition at line 176 of file meshStitcher.C.

References cgObj, and partitions.

176  {
177  if (!partitions.empty())
178  return partitions[0];
179  else if (cgObj)
180  return cgObj;
181  else {
182  std::cerr << "No stitched mesh to return!" << std::endl;
183  exit(1);
184  }
185 }
std::shared_ptr< rocstarCgns > cgObj
Definition: meshStitcher.H:71
std::vector< std::shared_ptr< cgnsAnalyzer > > partitions
Definition: meshStitcher.H:67

◆ getStitchedMB()

std::shared_ptr< meshBase > meshStitcher::getStitchedMB ( ) const

Definition at line 167 of file meshStitcher.C.

References stitchedMesh.

167  {
168  if (stitchedMesh)
169  return stitchedMesh;
170  else {
171  std::cerr << "No stitched mesh to return!" << std::endl;
172  exit(1);
173  }
174 }
std::shared_ptr< meshBase > stitchedMesh
Definition: meshStitcher.H:69

◆ initSurfCgObj()

void meshStitcher::initSurfCgObj ( )
private

Definition at line 122 of file meshStitcher.C.

References cgFileNames, cgObj, meshBase::CreateShared(), NODAL, stitchedMesh, and nemAux::trim_fname().

Referenced by meshStitcher().

122  {
123  cgObj = std::make_shared<rocstarCgns>(cgFileNames);
124  // different read for burn files
125  if (cgFileNames[0].find("burn") != std::string::npos)
126  cgObj->setBurnBool(true);
127  cgObj->loadCgSeries();
128  cgObj->stitchGroup();
129  // cgObj->closeCG();
130  std::cout << "Surface mesh stitched successfully." << std::endl;
131  std::cout << "Exporting stitched mesh to VTK format." << std::endl;
132  std::string newname(cgFileNames[0]);
133  std::size_t pos = newname.find_last_of('/');
134  newname = newname.substr(pos + 1);
135  newname = nemAux::trim_fname(newname, "stitched.vtu");
136  stitchedMesh = meshBase::CreateShared(cgObj->getVTKMesh(), newname);
137  std::cout << "Transferring physical quantities to vtk mesh." << std::endl;
138  // figure out what exists on the stitched grid
139  int outNData, outNDim;
140  std::vector<std::string> slnNameList;
141  std::vector<std::string> appSlnNameList;
142  cgObj->getSolutionDataNames(slnNameList);
143  cgObj->getAppendedSolutionDataName(appSlnNameList);
144  slnNameList.insert(slnNameList.end(), appSlnNameList.begin(),
145  appSlnNameList.end());
146  // write all data into vtk file
147  for (auto is = slnNameList.begin(); is < slnNameList.end(); is++) {
148  std::vector<double> physData;
149  cgObj->getSolutionDataStitched(*is, physData, outNData, outNDim);
150  solution_type_t dt = cgObj->getSolutionDataObj(*is)->getDataType();
151  if (dt == solution_type_t::NODAL) {
152  std::cout << "Embedding nodal " << *is << std::endl;
153  stitchedMesh->setPointDataArray((*is).c_str(), physData);
154  } else {
155  // gs field is 'weird' in irocstar files- we don't write it back
156  // if (!(*is).compare("gs"))
157  if (*is == "mdot_old") { continue; }
158  std::cout << "Embedding cell-based " << *is << std::endl;
159  stitchedMesh->setCellDataArray((*is).c_str(), physData);
160  }
161  }
162  stitchedMesh->report();
163  // TODO: expensive IO, need to be refactored
164  stitchedMesh->write();
165 }
const std::vector< std::string > cgFileNames
Definition: meshStitcher.H:65
std::string trim_fname(const std::string &name, const std::string &ext)
solution_type_t
Definition: cgnsAnalyzer.H:58
std::shared_ptr< rocstarCgns > cgObj
Definition: meshStitcher.H:71
std::shared_ptr< meshBase > stitchedMesh
Definition: meshStitcher.H:69
static std::shared_ptr< meshBase > CreateShared(const std::string &fname)
Create shared ptr from fname.
Definition: meshBase.C:171

◆ initVolCgObj()

void meshStitcher::initVolCgObj ( )
private

Definition at line 48 of file meshStitcher.C.

References cgFileNames, meshBase::CreateShared(), ELEMENTAL, NODAL, partitions, stitchedMesh, and nemAux::trim_fname().

Referenced by meshStitcher().

48  {
49  partitions.resize(cgFileNames.size(), nullptr);
50  for (int iCg = 0; iCg < cgFileNames.size(); ++iCg) {
51  partitions[iCg] = std::make_shared<cgnsAnalyzer>(cgFileNames[iCg]);
52  partitions[iCg]->loadGrid(1);
53  // defining partition flags
54  std::vector<double> slnData(partitions[iCg]->getNElement(), iCg);
55  // append partition number data if not already existing
56  bool exists = false;
57  std::vector<std::string> slnNamelist;
58  partitions[iCg]->getSolutionDataNames(slnNamelist);
59  for (const auto &in : slnNamelist)
60  if (in == "partitionOld") {
61  exists = true;
62  break;
63  }
64  if (!exists)
65  partitions[iCg]->appendSolutionData("partitionOld", slnData,
67  partitions[iCg]->getNElement(), 1);
68  // stitching new partitions to partition 0
69  // close partition CGNS file to avoid clutter
70  // MS: writing ghost mesh before closing
71  // std::vector<std::string> secNames;
72  // partitions[iCg]->getSectionNames(secNames);
73  // auto its = std::find(secNames.begin(), secNames.end(), ":T4:virtual");
74  // if (its != secNames.end())
75  // meshBase::Create(partitions[iCg]->getSectionMesh(*its),
76  // "_virtual_" + nemAux::find_name(cgFileNames[iCg]) +
77  // ".vtu")->write();
78  // End of ghost mesh
79  if (iCg) {
80  partitions[0]->stitchMesh(partitions[iCg].get(), true);
81  partitions[iCg]->closeCG();
82  }
83  }
84  std::cout << "Meshes stitched successfully." << std::endl;
85  std::cout << "Exporting stitched mesh to VTK format." << std::endl;
86  std::string newname(cgFileNames[0]);
87  std::size_t pos = newname.find_last_of('/');
88  newname = newname.substr(pos + 1);
89  newname = nemAux::trim_fname(newname, "stitched.vtu");
90  stitchedMesh = meshBase::CreateShared(partitions[0]->getVTKMesh(), newname);
91  std::cout << "Transferring physical quantities to vtk mesh." << std::endl;
92  // figure out what is existing on the stitched grid
93  int outNData, outNDim;
94  std::vector<std::string> slnNameList;
95  std::vector<std::string> appSlnNameList;
96  partitions[0]->getSolutionDataNames(slnNameList);
97  partitions[0]->getAppendedSolutionDataName(appSlnNameList);
98  slnNameList.insert(slnNameList.end(), appSlnNameList.begin(),
99  appSlnNameList.end());
100 
101  // write all data into vtk file
102  for (auto is = slnNameList.begin(); is < slnNameList.end(); is++) {
103  std::vector<double> physData;
104  partitions[0]->getSolutionDataStitched(*is, physData, outNData, outNDim);
105  solution_type_t dt = partitions[0]->getSolutionDataObj(*is)->getDataType();
106  if (dt == solution_type_t::NODAL) {
107  std::cout << "Embedding nodal " << *is << std::endl;
108  stitchedMesh->setPointDataArray((*is).c_str(), physData);
109  } else {
110  // gs field is 'weird' in irocstar files- we don't write it back
111  // if (!(*is).compare("gs"))
112  // continue;
113  std::cout << "Embedding cell-based " << *is << std::endl;
114  stitchedMesh->setCellDataArray((*is).c_str(), physData);
115  }
116  }
117  stitchedMesh->report();
118  // TODO: Expensive IO, refactoring needed
119  stitchedMesh->write();
120 }
const std::vector< std::string > cgFileNames
Definition: meshStitcher.H:65
std::string trim_fname(const std::string &name, const std::string &ext)
solution_type_t
Definition: cgnsAnalyzer.H:58
std::shared_ptr< meshBase > stitchedMesh
Definition: meshStitcher.H:69
std::vector< std::shared_ptr< cgnsAnalyzer > > partitions
Definition: meshStitcher.H:67
static std::shared_ptr< meshBase > CreateShared(const std::string &fname)
Create shared ptr from fname.
Definition: meshBase.C:171

◆ operator=()

meshStitcher& meshStitcher::operator= ( const meshStitcher that)
delete

Member Data Documentation

◆ cgFileNames

const std::vector<std::string> meshStitcher::cgFileNames
private

Definition at line 65 of file meshStitcher.H.

Referenced by initSurfCgObj(), initVolCgObj(), and meshStitcher().

◆ cgObj

std::shared_ptr<rocstarCgns> meshStitcher::cgObj
private

Definition at line 71 of file meshStitcher.H.

Referenced by getStitchedCGNS(), and initSurfCgObj().

◆ partitions

std::vector<std::shared_ptr<cgnsAnalyzer> > meshStitcher::partitions
private

Definition at line 67 of file meshStitcher.H.

Referenced by getStitchedCGNS(), and initVolCgObj().

◆ stitchedMesh

std::shared_ptr<meshBase> meshStitcher::stitchedMesh
private

Definition at line 69 of file meshStitcher.H.

Referenced by getStitchedMB(), initSurfCgObj(), and initVolCgObj().


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