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.
inputGen.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 // Nemosys headers
31 
32 // other headers
33 #include <iostream>
34 #include <fstream>
35 
36 #include "AuxiliaryFunctions.H"
37 
38 
39 void inputGen::setNameType(const std::string &fname,
40  inpFileType ftyp,
41  const std::string &key)
42 {
43  if (!key.empty())
44  _key = key;
45  _fn[_key] = fname;
46  _tpe[_key] = ftyp;
47 }
48 
49 
50 void inputGen::setOrder(const std::vector<std::string> &__ord,
51  const std::string &key)
52 {
53  if (!key.empty())
54  _key = key;
55  std::vector<std::string> ord = __ord;
56  for (auto &&it : ord)
57  nemAux::toLower(it);
58  _ord[_key].insert(_ord[_key].end(), ord.begin(), ord.end());
59 }
60 
61 
62 std::vector<std::string> inputGen::getOrder(const std::string &key)
63 {
64  if (!key.empty())
65  _key = key;
66  return _ord[_key];
67 }
68 
69 
70 void inputGen::pushOrder(const std::string &__ord, const std::string &key)
71 {
72  if (!key.empty())
73  _key = key;
74  std::string ord = __ord;
75  nemAux::toLower(ord);
76  _ord[_key].push_back(ord);
77 }
78 
79 
80 void inputGen::setMsh(meshBase *mb, const std::string &key)
81 {
82  if (!key.empty())
83  _key = key;
84  _mb[_key].push_back(mb);
85 }
86 
87 
88 void inputGen::setCmntStr(const std::string &cmstr, const std::string &key)
89 {
90  if (!key.empty())
91  _key = key;
92  _cmnt[_key] = cmstr;
93 }
94 
95 
96 std::string inputGen::getCmntStr(const std::string &key)
97 {
98  if (!key.empty())
99  _key = key;
100  return _cmnt[_key];
101 }
102 
103 void inputGen::write(const std::string &key) const
104 {
105  bool onlyKey = false;
106  if (!key.empty())
107  onlyKey = true;
108  for (const auto &it : _inp)
109  {
110  if (onlyKey && it.first != key)
111  continue;
112 
113  std::string fname = _fn.at(it.first);
114  std::ofstream ofile;
115  ofile.open(fname);
116  if (!ofile.good())
117  {
118  std::cerr << "Error opening file " << fname << std::endl;
119  throw;
120  }
121  ofile << (it.second)->str();
122  ofile.close();
123  }
124 }
125 
virtual std::string getCmntStr(const std::string &key=std::string())
Definition: inputGen.C:96
A brief description of meshBase.
Definition: meshBase.H:64
virtual void setCmntStr(const std::string &cmstr, const std::string &key=std::string())
Definition: inputGen.C:88
std::map< std::string, std::string > _cmnt
Definition: inputGen.H:140
inpFileType
Definition: inputGen.H:41
std::map< std::string, std::vector< std::string > > _ord
Definition: inputGen.H:137
virtual void pushOrder(const std::string &ord, const std::string &key=std::string())
Definition: inputGen.C:70
virtual void setOrder(const std::vector< std::string > &ord, const std::string &key=std::string())
Definition: inputGen.C:50
void toLower(std::string &str)
virtual void setMsh(meshBase *mb, const std::string &key=std::string())
Definition: inputGen.C:80
std::map< std::string, inpFileType > _tpe
Definition: inputGen.H:139
std::map< std::string, std::string > _fn
Definition: inputGen.H:138
std::map< std::string, std::vector< meshBase * > > _mb
Definition: inputGen.H:136
std::string _key
Definition: inputGen.H:134
std::map< std::string, std::stringstream * > _inp
Definition: inputGen.H:135
virtual void write(const std::string &key=std::string()) const
Definition: inputGen.C:103
virtual std::vector< std::string > getOrder(const std::string &key=std::string())
Definition: inputGen.C:62
virtual void setNameType(const std::string &fname, inpFileType ftyp, const std::string &key=std::string())
Definition: inputGen.C:39