20 using json = rsvsjson::json;
22 template <
class T>
void param::to_json(json &j,
const filltype<T> &p)
29 template <
class T>
void param::from_json(
const json &j, filltype<T> &p)
31 j.at(
"active").get_to(p.active);
32 j.at(
"fill").get_to(p.fill);
39 param::outputtemplate::outputtemplate()
41 this->directory =
"../TESTOUT/layouts";
42 this->templateregex =
"RSVS_";
43 this->filenameregex =
"VarSet |LFDSFN1| =";
44 this->loglvlspecialisation = {{0,
""}};
47 void param::to_json(json &j,
const outputtemplate &p)
50 {
"directory", p.directory},
51 {
"templateregex", p.templateregex},
52 {
"filenameregex", p.filenameregex},
53 {
"loglvlspecialisation", p.loglvlspecialisation},
56 void param::from_json(
const json &j, outputtemplate &p)
58 j.at(
"directory").get_to(p.directory);
59 j.at(
"templateregex").get_to(p.templateregex);
60 j.at(
"filenameregex").get_to(p.filenameregex);
61 p.loglvlspecialisation = j.at(
"loglvlspecialisation").get<param::varconfig>();
64 std::string param::tecplottemplate::TemplateLogging(
int lvl,
bool withPath, std::string pattern)
const
66 std::string fileBaseName = this->templateregex +
"loglvl" + std::to_string(lvl) + pattern +
".lay";
68 for (
auto spec : this->loglvlspecialisation)
70 if (spec.first == lvl)
72 fileBaseName = spec.second + pattern +
".lay";
78 return this->directory +
"/" + fileBaseName;
92 this->gridsizebackground = {1, 1, 1};
93 this->gridsizesnake = {6, 6, 6};
96 param::voxel::~voxel()
99 void param::voxel::PrepareForUse()
102 void param::to_json(json &j,
const voxel &p)
105 {
"gridsizebackground", p.gridsizebackground},
106 {
"gridsizesnake", p.gridsizesnake},
109 void param::from_json(
const json &j, voxel &p)
111 j.at(
"gridsizebackground").get_to(p.gridsizebackground);
112 j.at(
"gridsizesnake").get_to(p.gridsizesnake);
119 param::voronoi::voronoi()
121 this->inputpoints = {0.0};
122 this->pointfile =
"";
123 this->distancebox = 0.51;
124 this->snakecoarseness = 0.0;
125 this->vorosnakelayers = 2;
128 param::voronoi::~voronoi()
131 void param::voronoi::PrepareForUse()
134 void param::to_json(json &j,
const voronoi &p)
137 {
"inputpoints", p.inputpoints}, {
"distancebox", p.distancebox}, {
"pointfile", p.pointfile},
138 {
"snakecoarseness", p.snakecoarseness}, {
"vorosnakelayers", p.vorosnakelayers},
141 void param::from_json(
const json &j, voronoi &p)
143 p.inputpoints = j.at(
"inputpoints").get<std::vector<double>>();
145 j.at(
"distancebox").get_to(p.distancebox);
146 j.at(
"pointfile").get_to(p.pointfile);
147 j.at(
"snakecoarseness").get_to(p.snakecoarseness);
148 j.at(
"vorosnakelayers").get_to(p.vorosnakelayers);
150 void param::voronoi::ReadPoints()
152 std::ifstream pointstream;
154 pointstream.open(this->pointfile, std::ios::in);
155 CheckFStream(pointstream, __PRETTY_FUNCTION__, this->pointfile);
157 this->inputpoints.clear();
160 while (pointstream >> temp)
162 this->inputpoints.push_back(temp);
163 std::cout << temp <<
" ";
166 std::cout << std::endl;
173 param::snaking::snaking()
175 this->engine =
"rsvs";
176 this->arrivaltolerance = 1e-7;
177 this->multiarrivaltolerance = 1e-2;
178 this->snaxtimestep = 0.9;
179 this->snaxdiststep = 0.9;
180 this->initboundary = 1;
182 this->spawnposition = 1e-5;
185 param::snaking::~snaking()
188 void param::to_json(json &j,
const snaking &p)
191 {
"arrivaltolerance", p.arrivaltolerance}, {
"multiarrivaltolerance", p.multiarrivaltolerance},
192 {
"snaxtimestep", p.snaxtimestep}, {
"snaxdiststep", p.snaxdiststep},
193 {
"initboundary", p.initboundary}, {
"maxsteps", p.maxsteps},
194 {
"spawnposition", p.spawnposition}, {
"engine", p.engine},
197 void param::from_json(
const json &j, snaking &p)
199 j.at(
"arrivaltolerance").get_to(p.arrivaltolerance);
200 j.at(
"multiarrivaltolerance").get_to(p.multiarrivaltolerance);
201 j.at(
"snaxtimestep").get_to(p.snaxtimestep);
202 j.at(
"snaxdiststep").get_to(p.snaxdiststep);
203 j.at(
"initboundary").get_to(p.initboundary);
204 j.at(
"maxsteps").get_to(p.maxsteps);
205 j.at(
"spawnposition").get_to(p.spawnposition);
206 j.at(
"engine").get_to(p.engine);
208 void param::snaking::PrepareForUse()
218 this->solveralgorithm = 0;
220 this->cstfill.active =
false;
221 this->cstfill.fill = 0.5;
223 this->filefill.active =
false;
224 this->filefill.fill =
"";
226 this->makefill.active =
false;
227 this->makefill.fill =
"";
233 void param::to_json(json &j,
const rsvs &p)
236 {
"solveralgorithm", p.solveralgorithm},
237 {
"cstfill", p.cstfill},
238 {
"filefill", p.filefill},
239 {
"makefill", p.makefill},
242 void param::from_json(
const json &j, rsvs &p)
244 j.at(
"solveralgorithm").get_to(p.solveralgorithm);
245 j.at(
"cstfill").get_to(p.cstfill);
246 j.at(
"filefill").get_to(p.filefill);
247 j.at(
"makefill").get_to(p.makefill);
249 void param::rsvs::PrepareForUse()
259 for (
int i = 0; i < 3; ++i)
261 this->domain[i][0] = 0.0;
262 this->domain[i][1] = 1.0;
263 this->physdomain[i][0] = 0.0;
264 this->physdomain[i][1] = 1.0;
267 this->activegrid =
"voxel";
269 void param::to_json(json &j,
const grid &p)
272 {
"domain", p.domain}, {
"voxel", p.voxel}, {
"voronoi", p.voronoi},
273 {
"physdomain", p.physdomain}, {
"activegrid", p.activegrid},
276 void param::from_json(
const json &j, grid &p)
278 j.at(
"domain").get_to(p.domain);
279 j.at(
"voxel").get_to(p.voxel);
280 j.at(
"voronoi").get_to(p.voronoi);
281 j.at(
"physdomain").get_to(p.physdomain);
282 j.at(
"activegrid").get_to(p.activegrid);
284 void param::grid::PrepareForUse()
286 if (this->activegrid.compare(
"voronoi") == 0)
289 if (this->voronoi.inputpoints.size() <= 1)
291 this->voronoi.ReadPoints();
294 this->voxel.PrepareForUse();
295 this->voronoi.PrepareForUse();
304 this->snakemeshname =
"";
305 this->volumeshname =
"";
306 this->snakefile =
"";
310 void param::to_json(json &j,
const ioin &p)
313 {
"snakemeshname", p.snakemeshname},
314 {
"volumeshname", p.volumeshname},
315 {
"snakefile", p.snakefile},
316 {
"casename", p.casename},
319 void param::from_json(
const json &j, ioin &p)
321 j.at(
"snakemeshname").get_to(p.snakemeshname);
322 j.at(
"volumeshname").get_to(p.volumeshname);
323 j.at(
"snakefile").get_to(p.snakefile);
324 j.at(
"casename").get_to(p.casename);
326 void param::ioin::PrepareForUse()
328 if (!this->snakefile.empty() && (this->volumeshname.empty() || this->snakemeshname.empty()))
331 "be defined to load a 'snakefile'.");
335 param::ioout::ioout()
337 this->pathoutdir =
"../out";
338 this->pathpattern =
"Archive_%Y_%m/Day_%y-%m-%d";
339 this->basenamepattern =
"%y%m%dT%H%M%S_";
340 this->basenameoutdir =
"rsvs3d_";
344 this->redirectcout =
false;
345 this->redirectcerr =
false;
347 this->logginglvl = 2;
351 void param::ioout::PrepareForUse()
354 auto t = std::time(&t_ptr);
355 auto tm = *std::localtime(&t);
356 std::ostringstream oss;
357 if (this->pathoutdir.size() == 0)
359 this->pathoutdir +=
".";
361 if (this->pathpattern.size() > 0)
363 oss << std::put_time(&tm, this->pathpattern.c_str());
364 this->pathoutdir +=
"/";
365 this->pathoutdir += oss.str();
366 oss.str(std::string());
368 if (this->basenamepattern.size() > 0)
370 oss.str(std::string());
371 oss << std::put_time(&tm, this->basenamepattern.c_str());
372 this->basenameoutdir += oss.str();
373 this->pattern = oss.str();
375 if (this->outdir.size() == 0)
377 this->outdir = this->pathoutdir +
"/" + this->basenameoutdir;
380 void param::to_json(json &j,
const ioout &p)
383 {
"pathoutdir", p.pathoutdir},
384 {
"pathpattern", p.pathpattern},
385 {
"basenamepattern", p.basenamepattern},
386 {
"basenameoutdir", p.basenameoutdir},
387 {
"outdir", p.outdir},
388 {
"pattern", p.pattern},
389 {
"redirectcout", p.redirectcout},
390 {
"redirectcerr", p.redirectcerr},
391 {
"logginglvl", p.logginglvl},
392 {
"outputlvl", p.outputlvl},
393 {
"tecplot", p.tecplot},
396 void param::from_json(
const json &j, ioout &p)
398 j.at(
"pathoutdir").get_to(p.pathoutdir);
399 j.at(
"pathpattern").get_to(p.pathpattern);
400 j.at(
"basenamepattern").get_to(p.basenamepattern);
401 j.at(
"basenameoutdir").get_to(p.basenameoutdir);
402 j.at(
"outdir").get_to(p.outdir);
403 j.at(
"pattern").get_to(p.pattern);
404 j.at(
"redirectcout").get_to(p.redirectcout);
405 j.at(
"redirectcerr").get_to(p.redirectcerr);
406 j.at(
"logginglvl").get_to(p.logginglvl);
407 j.at(
"outputlvl").get_to(p.outputlvl);
408 j.at(
"tecplot").get_to(p.tecplot);
411 param::files::files()
413 this->appcasename2outdir =
true;
414 this->exportconfig = {{
"",
""}};
416 void param::files::PrepareForUse()
418 this->ioout.PrepareForUse();
419 this->ioin.PrepareForUse();
421 if (this->appcasename2outdir)
423 this->ioout.outdir += this->ioin.casename;
424 this->ioout.pattern += this->ioin.casename;
425 this->appcasename2outdir =
false;
427 std::cout <<
"Output folder: " << this->ioout.outdir << std::endl;
429 void param::to_json(json &j,
const files &p)
434 {
"appcasename2outdir", p.appcasename2outdir},
435 {
"exportconfig", p.exportconfig},
438 void param::from_json(
const json &j, files &p)
440 j.at(
"ioin").get_to(p.ioin);
441 j.at(
"ioout").get_to(p.ioout);
442 j.at(
"appcasename2outdir").get_to(p.appcasename2outdir);
449 void param::parameters::PrepareForUse()
451 this->rsvs.PrepareForUse();
452 this->snak.PrepareForUse();
453 this->grid.PrepareForUse();
454 this->files.PrepareForUse();
456 void param::to_json(json &j,
const parameters &p)
458 j = json{{
"rsvs", p.rsvs},
462 #ifdef RSVS_ACCESS_DEVELOPMENT_PARAMETERS
468 void param::from_json(
const json &j, parameters &p)
470 j.at(
"rsvs").get_to(p.rsvs);
471 j.at(
"snak").get_to(p.snak);
472 j.at(
"grid").get_to(p.grid);
473 j.at(
"files").get_to(p.files);
474 #ifdef RSVS_ACCESS_DEVELOPMENT_PARAMETERS
475 j.at(
"dev").get_to(p.dev);
483 param::dev::rsvseps::rsvseps()
485 this->rsvsmath_automatic_eps_edge = 0.0;
486 this->rsvsmath_automatic_eps_surf = 1e-10;
487 this->rsvsmath_automatic_eps_volu = 0.0;
488 this->rsvsmath_automatic_eps_centre = 1e-10;
489 this->rsvsmath_automatic_eps_centre2 = 1e-10;
492 void param::dev::to_json(json &j,
const rsvseps &p)
494 j = json{{
"rsvsmath_automatic_eps_edge", p.rsvsmath_automatic_eps_edge},
495 {
"rsvsmath_automatic_eps_surf", p.rsvsmath_automatic_eps_surf},
496 {
"rsvsmath_automatic_eps_volu", p.rsvsmath_automatic_eps_volu},
497 {
"rsvsmath_automatic_eps_centre", p.rsvsmath_automatic_eps_centre},
498 {
"rsvsmath_automatic_eps_centre2", p.rsvsmath_automatic_eps_centre2},
499 {
"rsvsmath_automatic_eps_centre2", p.rsvsmath_automatic_eps_centre2}};
501 void param::dev::from_json(
const json &j, rsvseps &p)
503 j.at(
"rsvsmath_automatic_eps_edge").get_to(p.rsvsmath_automatic_eps_edge);
504 j.at(
"rsvsmath_automatic_eps_surf").get_to(p.rsvsmath_automatic_eps_surf);
505 j.at(
"rsvsmath_automatic_eps_volu").get_to(p.rsvsmath_automatic_eps_volu);
506 j.at(
"rsvsmath_automatic_eps_centre").get_to(p.rsvsmath_automatic_eps_centre);
507 j.at(
"rsvsmath_automatic_eps_centre2").get_to(p.rsvsmath_automatic_eps_centre2);
508 j.at(
"rsvsmath_automatic_eps_centre2").get_to(p.rsvsmath_automatic_eps_centre2);
511 param::dev::devparam::devparam()
513 this->limitlagrangian = 1e+308;
514 this->mindesvarsparse = 200;
515 this->surfcentrejacobian =
true;
516 this->surfcentrehessian =
false;
517 this->snaxDistanceLimit_conserveShape =
false;
518 this->smoothstepmethod =
"none";
521 void param::dev::to_json(json &j,
const devparam &p)
523 j = json{{
"limitlagrangian", p.limitlagrangian},
524 {
"mindesvarsparse", p.mindesvarsparse},
525 {
"surfcentrejacobian", p.surfcentrejacobian},
526 {
"surfcentrehessian", p.surfcentrehessian},
527 {
"snaxDistanceLimit_conserveShape", p.snaxDistanceLimit_conserveShape},
528 {
"smoothstepmethod", p.smoothstepmethod},
529 {
"rsvsepsilons", p.rsvsepsilons}};
531 void param::dev::from_json(
const json &j, devparam &p)
533 j.at(
"limitlagrangian").get_to(p.limitlagrangian);
534 j.at(
"mindesvarsparse").get_to(p.mindesvarsparse);
535 j.at(
"surfcentrejacobian").get_to(p.surfcentrejacobian);
536 j.at(
"surfcentrehessian").get_to(p.surfcentrehessian);
537 j.at(
"snaxDistanceLimit_conserveShape").get_to(p.snaxDistanceLimit_conserveShape);
538 j.at(
"smoothstepmethod").get_to(p.smoothstepmethod);
539 j.at(
"rsvsepsilons").get_to(p.rsvsepsilons);
546 void param::io::read(
const std::string &fileName, parameters &p)
562 catch (std::exception
const &ex)
569 rsvsjson::flatupdate(j_fin, j,
false,
false);
571 param::from_json(j_fin, p);
574 void param::io::write(
const std::string &fileName,
const parameters &p)
588 void param::io::readflat(
const std::string &fileName, parameters &p)
600 rsvsjson::flatupdate(jfin, jnew,
false,
true);
602 param::from_json(jfin, p);
606 void param::io::writeflat(
const std::string &fileName,
const parameters &p)
615 file << j.flatten().dump(2);
619 void param::io::defaultconf()
622 std::string fileName(
"config/defaultconf.json");
623 std::string fileNameFlat(
"config/defaultconfflat.json");
625 param::io::write(fileName, params);
626 param::io::writeflat(fileNameFlat, params);
630 std::cout << j.flatten().dump(2);
633 int param::io::updatefromstring(
const std::vector<std::string> &flatjsonKeyVal, parameters &p,
const std::string &&sep)
639 std::string key, val;
642 for (
auto keyVal : flatjsonKeyVal)
644 pos = keyVal.find(sep);
645 if (pos == std::string::npos)
647 std::cerr <<
"Warning in: " << std::endl <<
" " << __PRETTY_FUNCTION__ << std::endl;
648 std::cerr <<
" Separator " << sep <<
" Was not found in JSON key/val: " << keyVal << std::endl
654 key = keyVal.substr(0, pos);
655 val = keyVal.substr(pos + 1);
656 if (j[key] ==
nullptr)
658 std::cerr <<
"Warning in: " << std::endl <<
" " << __PRETTY_FUNCTION__ << std::endl;
659 std::cerr <<
" key " << key <<
" Was not found in JSON object " << std::endl
660 <<
" The following keyval will not be used: " << keyVal << std::endl
666 if (!j[key].is_number() && !j[key].is_string() && !j[key].is_boolean())
668 std::cerr <<
"Warning in: " << std::endl <<
" " << __PRETTY_FUNCTION__ << std::endl;
669 std::cerr <<
" Value of j[" << key <<
"] is neither a string or number, "
670 <<
" parsing not supported." << std::endl
676 if (j[key].is_string())
680 else if (j[key].is_number_integer())
682 j[key] = std::stoi(val);
684 else if (j[key].is_number_float())
686 j[key] = std::stod(val);
688 else if (j[key].is_boolean())
690 std::istringstream is(val);
691 is >> std::boolalpha >> j[key];
695 param::from_json(j, p);
702 int param::test::base()
712 std::cout <<
"json object" << std::endl;
713 std::cout << j.dump(2) << std::endl;
714 std::cout <<
"flattened json object" << std::endl;
715 std::cout << j.flatten().dump(2) << std::endl;
717 param::from_json(j, params2);
720 std::cout <<
"j " << j.flatten().dump(2);
721 std::cout <<
"j2 " << j2.flatten().dump(2);
725 std::cerr <<
"Error: Parameter conversion to JSON "
726 <<
" is not symmetrical" << std::endl;
727 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
730 param::io::defaultconf();
734 int param::test::io()
737 std::string fileName =
"../TESTOUT/testioparam.json";
741 param::io::write(fileName, params);
743 param::io::read(fileName, params2);
750 std::cerr <<
"Error: Parameter read/write "
751 <<
" is not symmetrical" << std::endl;
752 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
759 int param::test::ioflat()
762 std::string fileName =
"../TESTOUT/testioflatparam.json";
766 param::io::writeflat(fileName, params);
768 param::io::readflat(fileName, params2);
775 std::cerr <<
"Error: Parameter read/write "
776 <<
" is not symmetrical" << std::endl;
777 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
784 int param::test::ipartialread()
787 std::string fileName =
"config/partialconfflat.json";
788 std::string fileName2 =
"config/partialconfflat_out.json";
790 std::cout <<
"Start read" << std::endl;
791 param::io::readflat(fileName, params2);
792 std::cout <<
"succesful read" << std::endl;
793 param::io::writeflat(fileName2, params2);
794 std::cout <<
"succesful write" << std::endl;
798 std::cout << j1.flatten().dump(2);
799 std::cout << j2.flatten().dump(2);
802 std::cerr <<
"Error: Parameter read/write "
803 <<
" is not symmetrical" << std::endl;
804 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
809 std::cout <<
"Partial read succesful, outputs are different" << std::endl;
815 int param::test::prepareforuse()
818 std::string fileName =
"config/confprepared.json";
819 std::string fileName2 =
"config/confprepared2.json";
821 std::cout <<
"Start read" << std::endl;
822 param::io::readflat(fileName, params2);
823 std::cout <<
"succesful read" << std::endl;
824 param::io::writeflat(fileName2, params2);
825 std::cout <<
"succesful write" << std::endl;
832 std::cerr <<
"Error: Parameter read/write "
833 <<
" is not symmetrical" << std::endl;
834 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
839 std::cout <<
"Partial read succesful, outputs are different" << std::endl;
845 int param::test::autoflat()
855 std::cout <<
"Dump j1 flattened" << std::endl << j1.dump(1);
857 std::cout <<
"Dump j1 flattened twice" << std::endl << j1.dump(1);
862 std::cout <<
"Dump j2 unflattened" << std::endl << j2.dump(1);
864 catch (std::exception
const &ex)
866 std::cout <<
"Cannot be unflattened and throws exception" << std::endl;
867 std::cout << ex.what() << std::endl;
869 std::cout <<
"Dump j2 unflattened" << std::endl << j2.dump(1);
875 int param::test::symmetry()
888 std::cout << j1 << endl;
889 std::cout << j2 << endl;
893 std::cout << j1 << endl;
894 std::cout << j2 << endl;
895 std::cerr <<
"Error: Parameter conversion to JSON "
896 <<
" is not symmetrical" << std::endl;
897 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
904 int param::test::symmetry_makefillactive()
927 std::cout << j1 << endl;
928 std::cout << j2 << endl;
932 std::cout << j1 << endl;
933 std::cout << j2 << endl;
934 std::cerr <<
"Error: Parameter conversion to JSON "
935 <<
" is not symmetrical" << std::endl;
936 std::cerr <<
"In: " << __PRETTY_FUNCTION__ << std::endl;
Root class for all the parameters.
filltype< std::string > makefill
Fill the VOS values from a run time function accessible from makefill.fill.
double arrivaltolerance
Distance along edge at which a vertex is considered arrived regardless of "d" and "v".
std::vector< double > inputpoints
Vector of input points, 4 datums per point.
std::vector< std::pair< std::string, std::string > > exports
Collects the export settings which is a vector of pairs of strings.
Parameters for the integrated 3DRSVS.
Interface between the RSVS project and the JSON for Modern C++ library.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_NOTHROW(M)
Generic rsvs warning.
void CheckFStream(const T &file, const char *callerID, const std::string &fileName)
Checks a file stream.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.