29 #define _USE_MATH_DEFINES 48 : templateName(
std::move(templateName)) {}
52 std::cout <<
"TemplateMeshDriver created" << std::endl;
59 std::cout <<
"TemplateMeshDriver destroyed" << std::endl;
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";
106 std::string params) {
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");
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;
208 std::string params_name) {
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;
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;
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));
const Files & getFiles() const
static void executeTemplate(std::string tplName, std::string outName, std::string params)
Executes the template file.
~TemplateMeshDriver() override
const Opts & getOpts() const
jsoncons::string_view getProgramType() const override
static std::string spiralTapePipe(jsoncons::json inputjson)
Reads the parameters for Spiral Tape geometry/mesh from the input JSON file and generates the appropr...
void execute() const override
Run the workflow represented by the driver.
jsoncons::json templateParams
Driver class to generate meshes according to a template.
static void insertParams(std::string file, std::string params_name)
Inserts the parameters file name into the template file at the appropriate line.
void setFiles(Files file)
static std::string decrypt(std::string filename)
Decrypts the template file.
static void encrypt(std::string inFile, std::string outFile)
Encrypts the template file.
static constexpr const char * programType