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.
nemAux Namespace Reference

Classes

class  Timer
 

Functions

template<typename T >
std::vector< T > flatten (const std::vector< std::vector< T >> &v)
 
template<typename T >
std::vector< std::vector< T > > fold (const std::vector< T > &v, int dim)
 
template<typename T >
std::vector< T > operator+ (const std::vector< T > &x, const std::vector< T > &y)
 
template<typename T >
std::vector< T > operator- (const std::vector< T > &x, const std::vector< T > &y)
 
template<typename T >
std::vector< T > operator* (T a, const std::vector< T > &x)
 
template<typename T >
std::vector< T > hadamard (const std::vector< T > &x, const std::vector< T > &y)
 
template<typename T >
l2_Norm (const std::vector< T > &x)
 
template<typename T >
reciprocal (T x)
 
template<typename T >
void reciprocal_vec (std::vector< T > &x)
 
template<typename T >
bool hasZero (const std::vector< T > &x)
 
template<typename T >
std::vector< T > getMinMax (const std::vector< T > &x)
 
template<typename T >
scale_to_range (T x, const std::vector< T > &xminmax, const std::vector< T > &yminmax)
 
template<typename T >
void scale_vec_to_range (std::vector< T > &x, const std::vector< T > &xminmax, const std::vector< T > &yminmax)
 
template<typename T >
std::vector< T > getMeanStdev (const std::vector< T > &x)
 
template<typename T >
std::vector< bool > cellsToRefine (const std::vector< T > &values, T tol)
 
template<typename T >
std::vector< bool > cellsToRefineStdev (const std::vector< T > &values, T mean, T dev)
 
template<typename T >
std::vector< bool > cellsToRefineMaxdev (const std::vector< T > &values, T dev)
 
std::string trim_fname (const std::string &name, const std::string &ext)
 
std::string find_ext (const std::string &fname)
 
void toLower (std::string &str)
 
void toUpper (std::string &str)
 
std::string findToStr (const std::string &str, const std::string &ptrn)
 
std::string findFromStr (const std::string &str, const std::string &ptrn)
 
std::string getTimeStr ()
 
std::string find_name (const std::string &fname)
 
template<typename T >
void printVec (const std::vector< T > &v)
 
template<typename T >
bool valInVec (const std::vector< T > &v, T val)
 
template<typename A , typename B >
std::pair< B, A > flip_pair (const std::pair< A, B > &p)
 
template<typename A , typename B >
std::multimap< B, A > flip_map (const std::map< A, B > &src)
 
template<typename T >
bool isInBBox (const std::vector< T > &crd, const std::vector< T > &bb)
 
template<typename A , typename B >
std::vector< A > getSortedKeys (const std::map< A, B > &mapObj)
 
std::string getRandomString (int length)
 
std::shared_ptr< char > strToChar (const std::string &strng)
 
std::vector< std::string > Tokenize (const std::string &lineIn, const char &delim)
 
std::vector< std::string > Tokenize (const std::string &lineIn, const std::string &delim)
 
template<typename A , typename B >
leastUnusedKey (const std::map< A, B > &map, A min=1)
 

Function Documentation

◆ cellsToRefine()

template<typename T >
std::vector< bool > nemAux::cellsToRefine ( const std::vector< T > &  values,
tol 
)

Definition at line 402 of file AuxiliaryFunctions.H.

Referenced by Foam::AMRFoam::update(), Foam::AMRFoam::updateAMR(), and Foam::AMRFoam::updateAMRML().

402  {
403  std::vector<bool> result(values.size(), false);
404  for (std::size_t i = 0; i < values.size(); ++i)
405  if (values[i] > tol) result[i] = true;
406  return result;
407 }

◆ cellsToRefineMaxdev()

template<typename T >
std::vector< bool > nemAux::cellsToRefineMaxdev ( const std::vector< T > &  values,
dev 
)

Definition at line 426 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

426  {
427  dev = std::abs(dev);
428  if (dev > 1) dev = 1;
429 
430  T max = *std::max_element(values.begin(), values.end());
431  T hl = (1 - dev) * max;
432 
433  std::vector<bool> result(values.size(), false);
434  for (std::size_t i = 0; i < values.size(); ++i)
435  if (values[i] > hl) result[i] = true;
436  return result;
437 }

◆ cellsToRefineStdev()

template<typename T >
std::vector< bool > nemAux::cellsToRefineStdev ( const std::vector< T > &  values,
mean,
dev 
)

Definition at line 411 of file AuxiliaryFunctions.H.

412  {
413  if (std::abs(dev / mean) >= 1.0) dev = 0.99 * mean;
414 
415  T th = mean + dev;
416  T tl = mean - dev;
417 
418  std::vector<bool> result(values.size(), false);
419  for (std::size_t i = 0; i < values.size(); ++i)
420  if (values[i] > th || values[i] < tl) result[i] = true;
421  return result;
422 }

◆ find_ext()

std::string nemAux::find_ext ( const std::string &  fname)
inline

Definition at line 451 of file AuxiliaryFunctions.H.

Referenced by NEM::GEN::gmshGen::createMeshFromSTEP(), NEM::DRV::GmshMeshGenDriver::execute(), NEM::DRV::GmshToExoConversionDriver::execute(), NEM::DRV::MeshGenDriver::MeshGenDriver(), NEM::MSH::MeshTypeFromFilename(), NEM::MSH::vtkStandardNewMacro(), NEM::MSH::vtkGeoMesh::write(), NEM::MSH::exoGeoMesh::write(), NEM::MSH::oshGeoMesh::write(), and vtkMesh::write().

451  {
452  std::string::size_type last = fname.find_last_of('.');
453  if (last != std::string::npos) {
454  return fname.substr(last);
455  } else {
456  std::cerr << "Error finding file extension for " << fname << std::endl;
457  exit(1);
458  }
459 }

◆ find_name()

std::string nemAux::find_name ( const std::string &  fname)
inline

Definition at line 497 of file AuxiliaryFunctions.H.

497  {
498  std::string::size_type first = fname.find_last_of('/');
499  std::string::size_type last = fname.find_last_of('.');
500  if (first != std::string::npos && last != std::string::npos) {
501  return fname.substr(first + 1, last);
502  } else {
503  std::cerr << "error finding file extension for " << fname << std::endl;
504  exit(1);
505  }
506 }

◆ findFromStr()

std::string nemAux::findFromStr ( const std::string &  str,
const std::string &  ptrn 
)
inline

Definition at line 477 of file AuxiliaryFunctions.H.

Referenced by NEM::MSH::gmshGeoMesh::getVTKTypeFromGmshType().

477  {
478  return str.substr(str.find_first_of(ptrn) + 1, std::string::npos);
479 }

◆ findToStr()

std::string nemAux::findToStr ( const std::string &  str,
const std::string &  ptrn 
)
inline

Definition at line 472 of file AuxiliaryFunctions.H.

Referenced by NEM::MSH::gmshGeoMesh::getVTKTypeFromGmshType().

472  {
473  return str.substr(0, str.find_first_of(ptrn));
474 }

◆ flatten()

template<typename T >
std::vector< T > nemAux::flatten ( const std::vector< std::vector< T >> &  v)

Definition at line 211 of file AuxiliaryFunctions.H.

Referenced by OrderOfAccuracy::computeMeshWithResolution().

211  {
212  std::size_t size = 0;
213  for (const auto &sub : v) size += sub.size();
214 
215  std::vector<T> result;
216  result.reserve(size);
217  for (const auto &sub : v) result.insert(result.end(), sub.begin(), sub.end());
218  return result;
219 }

◆ flip_map()

template<typename A , typename B >
std::multimap< B, A > nemAux::flip_map ( const std::map< A, B > &  src)

Definition at line 529 of file AuxiliaryFunctions.H.

Referenced by ReadDegenerateVTKFile().

529  {
530  std::multimap<B, A> dst;
531  std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()),
532  flip_pair<A, B>);
533  return dst;
534 }

◆ flip_pair()

template<typename A , typename B >
std::pair< B, A > nemAux::flip_pair ( const std::pair< A, B > &  p)

Definition at line 524 of file AuxiliaryFunctions.H.

524  {
525  return std::pair<B, A>(p.second, p.first);
526 }

◆ fold()

template<typename T >
std::vector< std::vector< T > > nemAux::fold ( const std::vector< T > &  v,
int  dim 
)

Definition at line 223 of file AuxiliaryFunctions.H.

223  {
224  if (v.size() % dim != 0) {
225  std::cerr << "Size must be divisible by dim for folding" << std::endl;
226  exit(1);
227  }
228 
229  std::vector<std::vector<T>> result(v.size() / dim);
230  for (std::size_t i = 0; i < result.size(); ++i) {
231  result[i].resize(dim);
232  for (std::size_t j = 0; j < dim; ++j) result[i][j] = v[i * dim + j];
233  }
234  return result;
235 }

◆ getMeanStdev()

template<typename T >
std::vector< T > nemAux::getMeanStdev ( const std::vector< T > &  x)

Definition at line 388 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

388  {
389  T ave = 0;
390  for (const auto &i : x) ave += i;
391  ave /= x.size();
392 
393  T stdev = 0;
394  for (const auto &i : x) stdev += (i - ave) * (i - ave);
395  stdev = std::sqrt(stdev / x.size());
396 
397  return {ave, stdev};
398 }

◆ getMinMax()

template<typename T >
std::vector< T > nemAux::getMinMax ( const std::vector< T > &  x)

Definition at line 358 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

358  {
359  std::vector<T> tmp;
360  for (std::size_t i = 0; i < x.size(); ++i)
361  if (!std::isinf(x[i])) // exclude inf
362  tmp.push_back(x[i]);
363 
364  auto minmax = std::minmax_element(tmp.begin(), tmp.end());
365 
366  return {*minmax.first, *minmax.second};
367 }

◆ getRandomString()

std::string nemAux::getRandomString ( int  length)
inline

Definition at line 556 of file AuxiliaryFunctions.H.

Referenced by NEM::MSH::foamGeoMesh::foam2GM(), NEM::MSH::inpGeoMesh::inp2GM(), NEM::MSH::geoMeshBase::reconstructGeo(), NEM::MSH::gmshGeoMesh::resetNative(), and NEM::MSH::vtkGeoMesh::vtk2GM().

556  {
557  const char *alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
558  std::random_device rd;
559  std::default_random_engine dre(rd());
560  std::uniform_int_distribution<int> uid(0, strlen(alp) - 1);
561 
562  std::string out;
563  for (int i = 0; i < length; ++i) out += alp[uid(dre)];
564 
565  return out;
566 }

◆ getSortedKeys()

template<typename A , typename B >
std::vector< A > nemAux::getSortedKeys ( const std::map< A, B > &  mapObj)

Definition at line 544 of file AuxiliaryFunctions.H.

544  {
545  if (!mapObj.empty()) {
546  std::vector<A> sortedKeys(mapObj.size());
547  for (const auto &i : mapObj) sortedKeys.emplace_back(i.first);
548  return sortedKeys;
549  } else {
550  std::cerr << "Map is empty! No sorted keys to return." << std::endl;
551  exit(1);
552  }
553 }

◆ getTimeStr()

std::string nemAux::getTimeStr ( )
inline

Definition at line 482 of file AuxiliaryFunctions.H.

482  {
483  time_t rawTime;
484  struct tm *timeInfo;
485  char buffer[80];
486 
487  time(&rawTime);
488  timeInfo = localtime(&rawTime);
489 
490  strftime(buffer, sizeof(buffer), "%d-%m-%Y %I:%M:%S %p", timeInfo);
491  std::string str(buffer);
492 
493  return str;
494 }

◆ hadamard()

template<typename T >
std::vector< T > nemAux::hadamard ( const std::vector< T > &  x,
const std::vector< T > &  y 
)

Definition at line 281 of file AuxiliaryFunctions.H.

281  {
282  if (x.size() != y.size()) {
283  std::cerr << "Vectors must be same length for Hadamard product"
284  << std::endl;
285  exit(1);
286  }
287 
288  std::vector<T> result(x.size());
289  for (std::size_t i = 0; i < x.size(); ++i) result[i] = x[i] * y[i];
290  return result;
291 }

◆ hasZero()

template<typename T >
bool nemAux::hasZero ( const std::vector< T > &  x)

Definition at line 350 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

350  {
351  for (const auto &i : x)
352  if (i == 0) return true;
353  return false;
354 }

◆ isInBBox()

template<typename T >
bool nemAux::isInBBox ( const std::vector< T > &  crd,
const std::vector< T > &  bb 
)

Definition at line 537 of file AuxiliaryFunctions.H.

Referenced by meshSrch::FindCellsWithinBounds().

537  {
538  for (std::size_t i = 0; i < crd.size(); ++i)
539  if (crd[i] < bb[2 * i] || crd[i] > bb[2 * i + 1]) return false;
540  return true;
541 }

◆ l2_Norm()

template<typename T >
T nemAux::l2_Norm ( const std::vector< T > &  x)

Definition at line 239 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::GradSizeField::computeL2GradAtAllCells(), NEM::ADP::ValSizeField::computeL2ValAtAllCells(), FETransfer::transferCellData(), COBALT::cobalt::write(), and PATRAN::patran::write6().

239  {
240  T result = 0.0;
241  for (const auto &i : x) result += i * i;
242 
243  return std::sqrt(result);
244 }

◆ leastUnusedKey()

template<typename A , typename B >
A nemAux::leastUnusedKey ( const std::map< A, B > &  map,
min = 1 
)

Definition at line 569 of file AuxiliaryFunctions.H.

Referenced by NEM::MSH::exoGeoMesh::addElemBlock(), NEM::MSH::exoGeoMesh::addNodeSet(), NEM::MSH::exoGeoMesh::addSideSet(), NEM::MSH::exoGeoMesh::reassignCells(), NEM::MSH::exoGeoMesh::resetElemBlocks(), and NEM::MSH::exoGeoMesh::stitch().

569  {
570  A i = min;
571  auto it = map.begin();
572  if (min > 1) {
573  auto ub = map.upper_bound(min);
574  if (ub != it) {
575  it = --ub;
576  }
577  }
578  for (; it != map.end(); ++it) {
579  if (it->first == i) {
580  ++i;
581  } else {
582  return i;
583  }
584  }
585  return i;
586 }

◆ operator*()

template<typename T >
std::vector< T > nemAux::operator* ( a,
const std::vector< T > &  x 
)

Definition at line 274 of file AuxiliaryFunctions.H.

274  {
275  std::vector<T> result(x.size());
276  for (std::size_t i = 0; i < x.size(); ++i) result[i] = a * x[i];
277  return result;
278 }

◆ operator+()

template<typename T >
std::vector< T > nemAux::operator+ ( const std::vector< T > &  x,
const std::vector< T > &  y 
)

Definition at line 248 of file AuxiliaryFunctions.H.

248  {
249  if (x.size() != y.size()) {
250  std::cerr << "Vectors must be same length for addition" << std::endl;
251  exit(1);
252  }
253 
254  std::vector<T> result(x.size());
255  for (std::size_t i = 0; i < x.size(); ++i) result[i] = x[i] + y[i];
256  return result;
257 }

◆ operator-()

template<typename T >
std::vector< T > nemAux::operator- ( const std::vector< T > &  x,
const std::vector< T > &  y 
)

Definition at line 261 of file AuxiliaryFunctions.H.

261  {
262  if (x.size() != y.size()) {
263  std::cerr << "Vectors must be same length for subtraction" << std::endl;
264  exit(1);
265  }
266 
267  std::vector<T> result(x.size());
268  for (std::size_t i = 0; i < x.size(); ++i) result[i] = x[i] - y[i];
269  return result;
270 }

◆ printVec()

template<typename T >
void nemAux::printVec ( const std::vector< T > &  v)

Definition at line 510 of file AuxiliaryFunctions.H.

Referenced by orthoPoly3D::computeA(), and orthoPoly3D::orthoPoly3D().

510  {
511  for (const auto &i : v) std::cout << std::setprecision(15) << i << " ";
512  std::cout << std::endl;
513 }

◆ reciprocal()

template<typename T >
T nemAux::reciprocal ( x)

Definition at line 295 of file AuxiliaryFunctions.H.

295  {
296  return 1 / x;
297 }

◆ reciprocal_vec()

template<typename T >
void nemAux::reciprocal_vec ( std::vector< T > &  x)

Definition at line 345 of file AuxiliaryFunctions.H.

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

345  {
346  std::transform(x.begin(), x.end(), x.begin(), reciprocal<T>);
347 }

◆ scale_to_range()

template<typename T >
T nemAux::scale_to_range ( x,
const std::vector< T > &  xminmax,
const std::vector< T > &  yminmax 
)

Definition at line 372 of file AuxiliaryFunctions.H.

Referenced by scale_vec_to_range().

373  {
374  if (std::isinf(x)) return yminmax[1];
375  return yminmax[0] + (yminmax[1] - yminmax[0]) * (x - xminmax[0]) /
376  (xminmax[1] - xminmax[0]);
377 }

◆ scale_vec_to_range()

template<typename T >
void nemAux::scale_vec_to_range ( std::vector< T > &  x,
const std::vector< T > &  xminmax,
const std::vector< T > &  yminmax 
)

Definition at line 381 of file AuxiliaryFunctions.H.

References scale_to_range().

Referenced by NEM::ADP::SizeFieldBase::mutateValues().

382  {
383  for (auto &&i : x) i = scale_to_range(i, xminmax, yminmax);
384 }
T scale_to_range(T x, const std::vector< T > &xminmax, const std::vector< T > &yminmax)

◆ strToChar()

std::shared_ptr< char > nemAux::strToChar ( const std::string &  strng)
inline

Definition at line 300 of file AuxiliaryFunctions.H.

Referenced by Foam::AMRFoam::readIncomingCellField(), Foam::AMRFoam::readIncomingPtField(), and NEM::GEO::rocPack::rocParser().

300  {
301  std::shared_ptr<char> tab(new char[strng.length() + 1],
302  std::default_delete<char[]>());
303  std::strcpy(tab.get(), strng.c_str());
304  return tab;
305 }

◆ Tokenize() [1/2]

std::vector< std::string > nemAux::Tokenize ( const std::string &  lineIn,
const char &  delim 
)
inline

Definition at line 308 of file AuxiliaryFunctions.H.

Referenced by NEM::GEO::rocPack::getShapeData(), and NEM::GEO::rocPack::rocParser().

309  {
310  std::vector<std::string> rtrnTokens;
311 
312  std::string intermediate;
313  std::stringstream checkStr(lineIn);
314 
315  // Tokenizing
316  while (std::getline(checkStr, intermediate, delim)) {
317  rtrnTokens.push_back(intermediate);
318  }
319  return rtrnTokens;
320 }

◆ Tokenize() [2/2]

std::vector< std::string > nemAux::Tokenize ( const std::string &  lineIn,
const std::string &  delim 
)
inline

Definition at line 323 of file AuxiliaryFunctions.H.

324  {
325  std::vector<std::string> rtrnTokens;
326  std::vector<char> delimStr;
327  delimStr.reserve(delim.size());
328 
329  for (int i = 0; i < delim.size(); i++) delimStr.push_back(delim[i]);
330 
331  std::string intermediate;
332  std::stringstream checkStr(lineIn);
333 
334  // Tokenizing
335  int iter = 0;
336  while (std::getline(checkStr, intermediate, delimStr[iter])) {
337  rtrnTokens.push_back(intermediate);
338  iter++;
339  }
340  return rtrnTokens;
341 }

◆ toLower()

void nemAux::toLower ( std::string &  str)
inline

◆ toUpper()

void nemAux::toUpper ( std::string &  str)
inline

Definition at line 467 of file AuxiliaryFunctions.H.

467  {
468  std::transform(str.begin(), str.end(), str.begin(), ::toupper);
469 }

◆ trim_fname()

std::string nemAux::trim_fname ( const std::string &  name,
const std::string &  ext 
)
inline

Definition at line 440 of file AuxiliaryFunctions.H.

Referenced by MeshQuality::checkMesh(), NEM::GEN::gmshGen::createMeshFromSTEP(), netgenGen::createMeshFromSTL(), NEM::DRV::CFMeshMeshGenDriver::execute(), NEM::DRV::GmshMeshGenDriver::execute(), NEM::DRV::SnappyMeshMeshGenDriver::execute(), NEM::DRV::NetgenMeshGenDriver::execute(), meshBase::exportPntToVtk(), meshBase::exportVolToVtk(), meshStitcher::initSurfCgObj(), meshStitcher::initVolCgObj(), NEM::DRV::MeshGenDriver::MeshGenDriver(), meshBase::partition(), and vtkMesh::write().

440  {
441  std::string::size_type end = fname.find_last_of('.');
442  if (end != std::string::npos) {
443  return fname.substr(0, end).append(ext);
444  } else {
445  std::cerr << "Error finding file extension for " << fname << std::endl;
446  exit(1);
447  }
448 }

◆ valInVec()

template<typename T >
bool nemAux::valInVec ( const std::vector< T > &  v,
val 
)

Definition at line 517 of file AuxiliaryFunctions.H.

517  {
518  for (const auto &i : v)
519  if (i == val) return true;
520  return false;
521 }