Driver class to generate meshes according to a template.
More...
Definition at line 44 of file TemplateMeshDriver.H.
|
static void | executeTemplate (std::string tplName, std::string outName, std::string params) |
| Executes the template file. More...
|
|
static std::string | spiralTapePipe (jsoncons::json inputjson) |
| Reads the parameters for Spiral Tape geometry/mesh from the input JSON file and generates the appropriate parameters file. More...
|
|
static void | insertParams (std::string file, std::string params_name) |
| Inserts the parameters file name into the template file at the appropriate line. More...
|
|
static void | encrypt (std::string inFile, std::string outFile) |
| Encrypts the template file. More...
|
|
static std::string | decrypt (std::string filename) |
| Decrypts the template file. More...
|
|
|
static constexpr const char * | programType = "Template Mesh Generation" |
|
Inherits NEM::DRV::NemDriver.
◆ Files
◆ TemplateMeshDriver() [1/2]
NEM::DRV::TemplateMeshDriver::TemplateMeshDriver |
( |
Files |
file, |
|
|
Opts |
opts |
|
) |
| |
|
explicit |
Definition at line 50 of file TemplateMeshDriver.C.
51 :
file_(std::move(file)),
opts_(std::move(opts)) {
52 std::cout <<
"TemplateMeshDriver created" << std::endl;
◆ ~TemplateMeshDriver()
NEM::DRV::TemplateMeshDriver::~TemplateMeshDriver |
( |
| ) |
|
|
override |
Definition at line 58 of file TemplateMeshDriver.C.
59 std::cout <<
"TemplateMeshDriver destroyed" << std::endl;
◆ TemplateMeshDriver() [2/2]
NEM::DRV::TemplateMeshDriver::TemplateMeshDriver |
( |
| ) |
|
|
private |
◆ decrypt()
std::string NEM::DRV::TemplateMeshDriver::decrypt |
( |
std::string |
filename | ) |
|
|
staticprivate |
- Parameters
-
- Returns
- Returns the decrypted file name
Definition at line 232 of file TemplateMeshDriver.C.
Referenced by executeTemplate().
233 std::ifstream in(filename, std::ios_base::binary);
235 std::cerr <<
"Error: Template file " << filename <<
" is not open!" 240 in.read(reinterpret_cast<char *>(&vsize),
sizeof(
unsigned));
241 std::vector<double> stuff(vsize);
242 in.read(reinterpret_cast<char *>(&stuff[0]), vsize *
sizeof(
double));
245 for (
double &d : stuff) {
246 int inv_d = (int)std::sqrt(d);
250 size_t lastindex = filename.find_last_of(
".");
251 std::string rawname = filename.substr(0, lastindex);
252 std::string name = rawname +
".geo";
253 std::ofstream ascii(name);
254 ascii << result << std::endl;
◆ encrypt()
void NEM::DRV::TemplateMeshDriver::encrypt |
( |
std::string |
inFile, |
|
|
std::string |
outFile |
|
) |
| |
|
staticprivate |
- Parameters
-
inFile | Input file name |
outFile | Output file name |
Definition at line 262 of file TemplateMeshDriver.C.
263 std::ifstream file(inFile);
265 file.seekg(0, std::ios::end);
266 str.reserve(file.tellg());
267 file.seekg(0, std::ios::beg);
268 str.assign((std::istreambuf_iterator<char>(file)),
269 std::istreambuf_iterator<char>());
273 std::vector<double> line;
274 for (
char const &c : str) {
279 unsigned linesize = line.size();
280 std::ofstream o(outFile, std::ios_base::binary);
281 o.write(reinterpret_cast<char *>(&linesize),
sizeof(
unsigned));
282 o.write(reinterpret_cast<char *>(&line[0]), line.size() *
sizeof(double));
◆ execute()
void NEM::DRV::TemplateMeshDriver::execute |
( |
| ) |
const |
|
overridevirtual |
Implements NEM::DRV::NemDriver.
Definition at line 78 of file TemplateMeshDriver.C.
References nemAux::Timer::elapsed(), executeTemplate(), file_, opts_, NEM::DRV::DriverOutFile::outputFile, spiralTapePipe(), nemAux::Timer::start(), nemAux::Timer::stop(), NEM::DRV::TemplateMeshDriver::Opts::templateName, and NEM::DRV::TemplateMeshDriver::Opts::templateParams.
79 static const std::map<std::string, std::string> tpl_map = {
80 {
"Spiral Tape Pipe",
"spiral_tape_pipe.tpl"}};
82 std::string params_name{};
87 std::cerr <<
"Error: Template name not found" << std::endl;
92 gmsh::option::setNumber(
"General.Terminal", 1);
94 std::cout <<
"Generating mesh from template" << std::endl;
101 std::cout <<
"Meshing time = " << (T.
elapsed() / 1000.0) <<
" seconds\n";
static void executeTemplate(std::string tplName, std::string outName, std::string params)
Executes the template file.
static std::string spiralTapePipe(jsoncons::json inputjson)
Reads the parameters for Spiral Tape geometry/mesh from the input JSON file and generates the appropr...
jsoncons::json templateParams
◆ executeTemplate()
void NEM::DRV::TemplateMeshDriver::executeTemplate |
( |
std::string |
tplName, |
|
|
std::string |
outName, |
|
|
std::string |
params |
|
) |
| |
|
staticprivate |
- Parameters
-
tplName | Template file to be executed |
outName | Output mesh file name |
params | Parameters file name |
Definition at line 104 of file TemplateMeshDriver.C.
References decrypt(), and insertParams().
Referenced by execute().
108 std::string name =
decrypt(tplName);
114 std::remove(name.c_str());
116 gmsh::model::mesh::generate(2);
117 gmsh::model::mesh::generate(3);
118 gmsh::model::mesh::removeDuplicateNodes();
119 gmsh::write(outName +
".msh");
static void insertParams(std::string file, std::string params_name)
Inserts the parameters file name into the template file at the appropriate line.
static std::string decrypt(std::string filename)
Decrypts the template file.
◆ getFiles()
◆ getOpts()
◆ getProgramType()
jsoncons::string_view NEM::DRV::TemplateMeshDriver::getProgramType |
( |
| ) |
const |
|
overrideprivatevirtual |
◆ insertParams()
void NEM::DRV::TemplateMeshDriver::insertParams |
( |
std::string |
file, |
|
|
std::string |
params_name |
|
) |
| |
|
staticprivate |
- Parameters
-
file | Template file to be executed |
params_name | Parameters file name |
Definition at line 207 of file TemplateMeshDriver.C.
Referenced by executeTemplate().
209 std::ifstream in(file);
211 std::vector<std::string> text;
213 std::getline(in, str,
'\n');
216 std::string a =
"SetFactory(\"built-in\");";
217 std::string b =
"SetFactory(\"OpenCASCADE\");";
218 if (a.compare(str) == 0 || b.compare(str) == 0) {
219 text.push_back(
"Include \"" + params_name +
"\";");
224 std::ofstream out(file);
225 for (
int i = 0; i < text.size(); ++i) {
226 out << text[i] << std::endl;
◆ readJSON()
std::unique_ptr< NemDriver > NEM::DRV::NemDriver::readJSON |
( |
const jsoncons::json & |
inputjson | ) |
|
|
staticinherited |
◆ setFiles()
void NEM::DRV::TemplateMeshDriver::setFiles |
( |
Files |
file | ) |
|
◆ setOpts()
void NEM::DRV::TemplateMeshDriver::setOpts |
( |
Opts |
opts | ) |
|
◆ spiralTapePipe()
std::string NEM::DRV::TemplateMeshDriver::spiralTapePipe |
( |
jsoncons::json |
inputjson | ) |
|
|
staticprivate |
- Parameters
-
inputjson | Input JSON object |
- Returns
- The date and time stamped parameters file name
Definition at line 123 of file TemplateMeshDriver.C.
Referenced by execute().
124 std::cout <<
"Reading Template Parameters" << std::endl;
128 double thickness = 0.05;
129 double extrude_len = 3;
130 double n_turns = 0.5;
131 double width_percent = 0.85;
132 double mSize_min = 0.048;
133 double mSize_max = 0.1;
134 double dist_min = 0.05;
135 double dist_max = 0.2;
136 double bl_wall_n = 0.0038;
137 double bl_far = 0.08;
138 double bl_thickness = 0.02;
140 double extrude_layers = 20;
142 int element_order = 1;
145 if (inputjson.contains(
"rx")) rx = inputjson[
"rx"].as_double();
146 if (inputjson.contains(
"ry")) ry = inputjson[
"ry"].as_double();
147 if (inputjson.contains(
"thickness"))
148 thickness = inputjson[
"thickness"].as_double();
149 if (inputjson.contains(
"extrude_len"))
150 extrude_len = inputjson[
"extrude_len"].as_double();
151 if (inputjson.contains(
"n_turns")) n_turns = inputjson[
"n_turns"].as_double();
152 if (inputjson.contains(
"width_percent"))
153 width_percent = inputjson[
"width_percent"].as_double();
155 if (inputjson.contains(
"dist_min"))
156 dist_min = inputjson[
"dist_min"].as_double();
157 if (inputjson.contains(
"dist_max"))
158 dist_max = inputjson[
"dist_max"].as_double();
159 if (inputjson.contains(
"mSize_min"))
160 mSize_min = inputjson[
"mSize_min"].as_double();
161 if (inputjson.contains(
"mSize_max"))
162 mSize_max = inputjson[
"mSize_max"].as_double();
163 if (inputjson.contains(
"bl_wall_n"))
164 bl_wall_n = inputjson[
"bl_wall_n"].as_double();
165 if (inputjson.contains(
"bl_far")) bl_far = inputjson[
"bl_far"].as_double();
166 if (inputjson.contains(
"bl_thickness"))
167 bl_thickness = inputjson[
"bl_thickness"].as_double();
168 if (inputjson.contains(
"ratio")) ratio = inputjson[
"ratio"].as_double();
169 if (inputjson.contains(
"fan_points"))
170 fan_points = inputjson[
"fan_points"].as<int>();
171 if (inputjson.contains(
"extrude_layers"))
172 extrude_layers = inputjson[
"extrude_layers"].as_double();
173 if (inputjson.contains(
"element_order"))
174 element_order = inputjson[
"element_order"].as<int>();
179 struct tm *now = localtime(&t);
181 strftime(paramsName, 80,
"params_%Y-%m-%d-%H:%M:%S.txt", now);
183 out.open(paramsName);
184 out <<
"rx = " << rx <<
";" << std::endl;
185 out <<
"ry = " << ry <<
";" << std::endl;
186 out <<
"thickness = " << thickness <<
";" << std::endl;
187 out <<
"extrude_len = " << extrude_len <<
";" << std::endl;
188 out <<
"n_turns = " << n_turns <<
";" << std::endl;
189 out <<
"width_percent = " << width_percent <<
";" << std::endl;
191 out <<
"dist_min = " << dist_min <<
";" << std::endl;
192 out <<
"dist_max = " << dist_max <<
";" << std::endl;
193 out <<
"mSize_min = " << mSize_min <<
";" << std::endl;
194 out <<
"mSize_max = " << mSize_max <<
";" << std::endl;
195 out <<
"bl_wall_n = " << bl_wall_n <<
";" << std::endl;
196 out <<
"bl_far = " << bl_far <<
";" << std::endl;
197 out <<
"bl_thickness = " << bl_thickness <<
";" << std::endl;
198 out <<
"ratio = " << ratio <<
";" << std::endl;
199 out <<
"fan_points = " << fan_points <<
";" << std::endl;
200 out <<
"extrude_layers = " << extrude_layers <<
";" << std::endl;
201 out <<
"element_order = " << element_order <<
";" << std::endl;
◆ file_
Files NEM::DRV::TemplateMeshDriver::file_ |
|
private |
◆ opts_
Opts NEM::DRV::TemplateMeshDriver::opts_ |
|
private |
◆ programType
constexpr const char* NEM::DRV::TemplateMeshDriver::programType = "Template Mesh Generation" |
|
staticprivate |
The documentation for this class was generated from the following files: