rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
parameters.cpp
1 #include "parameters.hpp"
2 
3 #include <cassert>
4 #include <cmath>
5 #include <cstdlib>
6 #include <ctime>
7 #include <fstream>
8 #include <iomanip>
9 #include <iostream>
10 #include <sstream>
11 #include <string>
12 
13 #include "rsvsjson.hpp"
14 #include "warning.hpp"
15 
16 //===========================================
17 // Bounds template class method definitions
18 //===========================================
19 using namespace std;
20 using json = rsvsjson::json;
21 
22 template <class T> void param::to_json(json &j, const filltype<T> &p)
23 {
24  j = json{
25  {"active", p.active},
26  {"fill", p.fill},
27  };
28 }
29 template <class T> void param::from_json(const json &j, filltype<T> &p)
30 {
31  j.at("active").get_to(p.active);
32  j.at("fill").get_to(p.fill);
33 }
34 
35 //===========================================
36 // outputtemplate json interface
37 //===========================================
38 
39 param::outputtemplate::outputtemplate()
40 {
41  this->directory = "../TESTOUT/layouts";
42  this->templateregex = "RSVS_";
43  this->filenameregex = "VarSet |LFDSFN1| =";
44  this->loglvlspecialisation = {{0, ""}};
45 }
46 
47 void param::to_json(json &j, const outputtemplate &p)
48 {
49  j = json{
50  {"directory", p.directory},
51  {"templateregex", p.templateregex},
52  {"filenameregex", p.filenameregex},
53  {"loglvlspecialisation", p.loglvlspecialisation},
54  };
55 }
56 void param::from_json(const json &j, outputtemplate &p)
57 {
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>();
62 }
63 
64 std::string param::tecplottemplate::TemplateLogging(int lvl, bool withPath, std::string pattern) const
65 {
66  std::string fileBaseName = this->templateregex + "loglvl" + std::to_string(lvl) + pattern + ".lay";
67 
68  for (auto spec : this->loglvlspecialisation)
69  {
70  if (spec.first == lvl)
71  {
72  fileBaseName = spec.second + pattern + ".lay";
73  }
74  }
75 
76  if (withPath)
77  {
78  return this->directory + "/" + fileBaseName;
79  }
80  else
81  {
82  return fileBaseName;
83  }
84 }
85 
86 //===========================================
87 // voxel class method definitions
88 //===========================================
89 
90 param::voxel::voxel()
91 {
92  this->gridsizebackground = {1, 1, 1};
93  this->gridsizesnake = {6, 6, 6};
94 }
95 
96 param::voxel::~voxel()
97 {
98 }
99 void param::voxel::PrepareForUse()
100 {
101 }
102 void param::to_json(json &j, const voxel &p)
103 {
104  j = json{
105  {"gridsizebackground", p.gridsizebackground},
106  {"gridsizesnake", p.gridsizesnake},
107  };
108 }
109 void param::from_json(const json &j, voxel &p)
110 {
111  j.at("gridsizebackground").get_to(p.gridsizebackground);
112  j.at("gridsizesnake").get_to(p.gridsizesnake);
113 }
114 
115 //===========================================
116 // Voronoi class method definitions
117 //===========================================
118 
119 param::voronoi::voronoi()
120 {
121  this->inputpoints = {0.0};
122  this->pointfile = "";
123  this->distancebox = 0.51;
124  this->snakecoarseness = 0.0;
125  this->vorosnakelayers = 2;
126 }
127 
128 param::voronoi::~voronoi()
129 {
130 }
131 void param::voronoi::PrepareForUse()
132 {
133 }
134 void param::to_json(json &j, const voronoi &p)
135 {
136  j = json{
137  {"inputpoints", p.inputpoints}, {"distancebox", p.distancebox}, {"pointfile", p.pointfile},
138  {"snakecoarseness", p.snakecoarseness}, {"vorosnakelayers", p.vorosnakelayers},
139  };
140 }
141 void param::from_json(const json &j, voronoi &p)
142 {
143  p.inputpoints = j.at("inputpoints").get<std::vector<double>>();
144  // j.at("inputpoints").get_to(p.inputpoints);
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);
149 }
150 void param::voronoi::ReadPoints()
151 {
152  std::ifstream pointstream;
153 
154  pointstream.open(this->pointfile, std::ios::in);
155  CheckFStream(pointstream, __PRETTY_FUNCTION__, this->pointfile);
156 
157  this->inputpoints.clear();
158 
159  double temp;
160  while (pointstream >> temp)
161  {
162  this->inputpoints.push_back(temp);
163  std::cout << temp << " ";
164  }
165  pointstream.close();
166  std::cout << std::endl;
167 }
168 
169 //===========================================
170 // snaking class method definitions
171 //===========================================
172 
173 param::snaking::snaking()
174 {
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;
181  this->maxsteps = 50;
182  this->spawnposition = 1e-5;
183 }
184 
185 param::snaking::~snaking()
186 {
187 }
188 void param::to_json(json &j, const snaking &p)
189 {
190  j = json{
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},
195  };
196 }
197 void param::from_json(const json &j, snaking &p)
198 {
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);
207 }
208 void param::snaking::PrepareForUse()
209 {
210 }
211 
212 //===========================================
213 // RSVS class method definitions
214 //===========================================
215 
216 param::rsvs::rsvs()
217 {
218  this->solveralgorithm = 0;
219 
220  this->cstfill.active = false;
221  this->cstfill.fill = 0.5;
222 
223  this->filefill.active = false;
224  this->filefill.fill = "";
225 
226  this->makefill.active = false;
227  this->makefill.fill = "";
228 }
229 
230 param::rsvs::~rsvs()
231 {
232 }
233 void param::to_json(json &j, const rsvs &p)
234 {
235  j = json{
236  {"solveralgorithm", p.solveralgorithm},
237  {"cstfill", p.cstfill},
238  {"filefill", p.filefill},
239  {"makefill", p.makefill},
240  };
241 }
242 void param::from_json(const json &j, rsvs &p)
243 {
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);
248 }
249 void param::rsvs::PrepareForUse()
250 {
251 }
252 
253 //===========================================
254 // grid class method definitions
255 //===========================================
256 
257 param::grid::grid()
258 {
259  for (int i = 0; i < 3; ++i)
260  {
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;
265  }
266 
267  this->activegrid = "voxel";
268 }
269 void param::to_json(json &j, const grid &p)
270 {
271  j = json{
272  {"domain", p.domain}, {"voxel", p.voxel}, {"voronoi", p.voronoi},
273  {"physdomain", p.physdomain}, {"activegrid", p.activegrid},
274  };
275 }
276 void param::from_json(const json &j, grid &p)
277 {
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);
283 }
284 void param::grid::PrepareForUse()
285 {
286  if (this->activegrid.compare("voronoi") == 0)
287  {
288  // Load data into this->voronoi
289  if (this->voronoi.inputpoints.size() <= 1)
290  {
291  this->voronoi.ReadPoints();
292  }
293  }
294  this->voxel.PrepareForUse();
295  this->voronoi.PrepareForUse();
296 }
297 
298 //===========================================
299 // File and io classes method definitions
300 //===========================================
301 
302 param::ioin::ioin()
303 {
304  this->snakemeshname = "";
305  this->volumeshname = "";
306  this->snakefile = "";
307  this->casename = "";
308 }
309 
310 void param::to_json(json &j, const ioin &p)
311 {
312  j = json{
313  {"snakemeshname", p.snakemeshname},
314  {"volumeshname", p.volumeshname},
315  {"snakefile", p.snakefile},
316  {"casename", p.casename},
317  };
318 }
319 void param::from_json(const json &j, ioin &p)
320 {
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);
325 }
326 void param::ioin::PrepareForUse()
327 {
328  if (!this->snakefile.empty() && (this->volumeshname.empty() || this->snakemeshname.empty()))
329  {
330  RSVS3D_ERROR_ARGUMENT("Incompatible ioin parameters: mesh files must "
331  "be defined to load a 'snakefile'.");
332  }
333 }
334 
335 param::ioout::ioout()
336 {
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_";
341  this->outdir = "";
342  this->pattern = "";
343 
344  this->redirectcout = false;
345  this->redirectcerr = false;
346 
347  this->logginglvl = 2;
348  this->outputlvl = 2;
349 }
350 
351 void param::ioout::PrepareForUse()
352 {
353  std::time_t t_ptr;
354  auto t = std::time(&t_ptr);
355  auto tm = *std::localtime(&t);
356  std::ostringstream oss;
357  if (this->pathoutdir.size() == 0)
358  {
359  this->pathoutdir += ".";
360  }
361  if (this->pathpattern.size() > 0)
362  {
363  oss << std::put_time(&tm, this->pathpattern.c_str());
364  this->pathoutdir += "/";
365  this->pathoutdir += oss.str();
366  oss.str(std::string());
367  }
368  if (this->basenamepattern.size() > 0)
369  {
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();
374  }
375  if (this->outdir.size() == 0)
376  {
377  this->outdir = this->pathoutdir + "/" + this->basenameoutdir;
378  }
379 }
380 void param::to_json(json &j, const ioout &p)
381 {
382  j = json{
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},
394  };
395 }
396 void param::from_json(const json &j, ioout &p)
397 {
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);
409 }
410 
411 param::files::files()
412 {
413  this->appcasename2outdir = true;
414  this->exportconfig = {{"", ""}};
415 }
416 void param::files::PrepareForUse()
417 {
418  this->ioout.PrepareForUse();
419  this->ioin.PrepareForUse();
420 
421  if (this->appcasename2outdir)
422  {
423  this->ioout.outdir += this->ioin.casename;
424  this->ioout.pattern += this->ioin.casename;
425  this->appcasename2outdir = false;
426  }
427  std::cout << "Output folder: " << this->ioout.outdir << std::endl;
428 }
429 void param::to_json(json &j, const files &p)
430 {
431  j = json{
432  {"ioin", p.ioin},
433  {"ioout", p.ioout},
434  {"appcasename2outdir", p.appcasename2outdir},
435  {"exportconfig", p.exportconfig},
436  };
437 }
438 void param::from_json(const json &j, files &p)
439 {
440  j.at("ioin").get_to(p.ioin);
441  j.at("ioout").get_to(p.ioout);
442  j.at("appcasename2outdir").get_to(p.appcasename2outdir);
443  p.exportconfig = j.at("exportconfig").get<param::exports>();
444 }
445 
446 //===========================================
447 // parameters class method definitions
448 //===========================================
449 void param::parameters::PrepareForUse()
450 {
451  this->rsvs.PrepareForUse();
452  this->snak.PrepareForUse();
453  this->grid.PrepareForUse();
454  this->files.PrepareForUse();
455 }
456 void param::to_json(json &j, const parameters &p)
457 {
458  j = json{{"rsvs", p.rsvs},
459  {"snak", p.snak},
460  {"grid", p.grid},
461  {"files", p.files}
462 #ifdef RSVS_ACCESS_DEVELOPMENT_PARAMETERS
463  ,
464  {"dev", p.dev}
465 #endif
466  };
467 }
468 void param::from_json(const json &j, parameters &p)
469 {
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);
476 #endif
477 }
478 
479 //===========================================
480 // DEV namespace class method definitions
481 //===========================================
482 
483 param::dev::rsvseps::rsvseps()
484 {
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;
490 }
491 
492 void param::dev::to_json(json &j, const rsvseps &p)
493 {
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}};
500 }
501 void param::dev::from_json(const json &j, rsvseps &p)
502 {
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);
509 }
510 
511 param::dev::devparam::devparam()
512 {
513  this->limitlagrangian = 1e+308; // Close to infinity but parsable by JSON
514  this->mindesvarsparse = 200;
515  this->surfcentrejacobian = true;
516  this->surfcentrehessian = false;
517  this->snaxDistanceLimit_conserveShape = false;
518  this->smoothstepmethod = "none";
519 }
520 
521 void param::dev::to_json(json &j, const devparam &p)
522 {
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}};
530 }
531 void param::dev::from_json(const json &j, devparam &p)
532 {
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);
540 }
541 
542 //================================
543 // io
544 //================================
545 
546 void param::io::read(const std::string &fileName, parameters &p)
547 {
548  std::ifstream file;
549  json j, j_fin;
550 
551  file.open(fileName);
552  CheckFStream(file, __PRETTY_FUNCTION__, fileName);
553 
554  j_fin = p;
555  file >> j;
556  file.close();
557 
558  try
559  {
560  j = j.unflatten();
561  }
562  catch (std::exception const &ex)
563  {
564  // if j is already not flat catch the exception and move on
565  // TODO check the correct exception is being thrown (one day)
566  }
567 
568  // Insert values read into the parameter structure
569  rsvsjson::flatupdate(j_fin, j, false, false);
570 
571  param::from_json(j_fin, p);
572 }
573 
574 void param::io::write(const std::string &fileName, const parameters &p)
575 {
576  std::ofstream file;
577  json j;
578 
579  file.open(fileName);
580 
581  CheckFStream(file, __PRETTY_FUNCTION__, fileName);
582  j = p;
583  file << j.dump(2);
584  file.flush();
585  file.close();
586 }
587 
588 void param::io::readflat(const std::string &fileName, parameters &p)
589 {
590  std::ifstream file;
591  json jnew, jfin;
592 
593  file.open(fileName);
594  CheckFStream(file, __PRETTY_FUNCTION__, fileName);
595 
596  jfin = p;
597  // std::cout << "jfin assigned " << std::endl;
598  file >> jnew;
599  file.close();
600  rsvsjson::flatupdate(jfin, jnew, false, true);
601  // p=jfin;
602  param::from_json(jfin, p);
603 
604  // std::cout << "p assigned " << std::endl;
605 }
606 void param::io::writeflat(const std::string &fileName, const parameters &p)
607 {
608  std::ofstream file;
609  json j;
610 
611  file.open(fileName);
612  CheckFStream(file, __PRETTY_FUNCTION__, fileName);
613 
614  j = p;
615  file << j.flatten().dump(2);
616  file.flush();
617  file.close();
618 }
619 void param::io::defaultconf()
620 {
621  param::parameters params;
622  std::string fileName("config/defaultconf.json");
623  std::string fileNameFlat("config/defaultconfflat.json");
624 
625  param::io::write(fileName, params);
626  param::io::writeflat(fileNameFlat, params);
627 
628  json j;
629  j = params;
630  std::cout << j.flatten().dump(2);
631 }
632 
633 int param::io::updatefromstring(const std::vector<std::string> &flatjsonKeyVal, parameters &p, const std::string &&sep)
634 {
635  /*Parses json key value pairs returning the number of failures.*/
636  int numFail = 0;
637  json j = p;
638  std::size_t pos;
639  std::string key, val;
640  j = j.flatten();
641 
642  for (auto keyVal : flatjsonKeyVal)
643  {
644  pos = keyVal.find(sep);
645  if (pos == std::string::npos)
646  { // if separator was found
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
649  << std::endl;
650  ++numFail;
651  continue;
652  }
653  // split the string and parse it
654  key = keyVal.substr(0, pos);
655  val = keyVal.substr(pos + 1);
656  if (j[key] == nullptr)
657  {
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
661  << std::endl;
662  ++numFail;
663  continue;
664  }
665 
666  if (!j[key].is_number() && !j[key].is_string() && !j[key].is_boolean())
667  {
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
671  << std::endl;
672  ++numFail;
673  continue;
674  }
675 
676  if (j[key].is_string())
677  {
678  j[key] = val;
679  }
680  else if (j[key].is_number_integer())
681  {
682  j[key] = std::stoi(val);
683  }
684  else if (j[key].is_number_float())
685  {
686  j[key] = std::stod(val);
687  }
688  else if (j[key].is_boolean())
689  {
690  std::istringstream is(val);
691  is >> std::boolalpha >> j[key];
692  }
693  }
694  j = j.unflatten();
695  param::from_json(j, p);
696  return (numFail);
697 }
698 
699 //================================
700 // Tests
701 //================================
702 int param::test::base()
703 {
704  /*
705 
706  */
707  param::parameters params, params2;
708  json j, j2;
709 
710  j = params;
711 
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;
716 
717  param::from_json(j, params2);
718 
719  j2 = params2;
720  std::cout << "j " << j.flatten().dump(2);
721  std::cout << "j2 " << j2.flatten().dump(2);
722 
723  if (j != j2)
724  {
725  std::cerr << "Error: Parameter conversion to JSON "
726  << " is not symmetrical" << std::endl;
727  std::cerr << "In: " << __PRETTY_FUNCTION__ << std::endl;
728  return (1);
729  };
730  param::io::defaultconf();
731  return (0);
732 }
733 
734 int param::test::io()
735 {
736  param::parameters params, params2;
737  std::string fileName = "../TESTOUT/testioparam.json";
738  json j1, j2;
739 
740  params.snak.arrivaltolerance = 1;
741  param::io::write(fileName, params);
742 
743  param::io::read(fileName, params2);
744 
745  j1 = params;
746  j2 = params2;
747 
748  if (j1 != j2)
749  {
750  std::cerr << "Error: Parameter read/write "
751  << " is not symmetrical" << std::endl;
752  std::cerr << "In: " << __PRETTY_FUNCTION__ << std::endl;
753  return (1);
754  };
755 
756  return (0);
757 }
758 
759 int param::test::ioflat()
760 {
761  param::parameters params, params2;
762  std::string fileName = "../TESTOUT/testioflatparam.json";
763  json j1, j2;
764 
765  params.snak.arrivaltolerance = 1;
766  param::io::writeflat(fileName, params);
767 
768  param::io::readflat(fileName, params2);
769 
770  j1 = params;
771  j2 = params2;
772 
773  if (j1 != j2)
774  {
775  std::cerr << "Error: Parameter read/write "
776  << " is not symmetrical" << std::endl;
777  std::cerr << "In: " << __PRETTY_FUNCTION__ << std::endl;
778  return (1);
779  };
780 
781  return (0);
782 }
783 
784 int param::test::ipartialread()
785 {
786  param::parameters params, params2;
787  std::string fileName = "config/partialconfflat.json";
788  std::string fileName2 = "config/partialconfflat_out.json";
789  json j1, j2;
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;
795 
796  j1 = params;
797  j2 = params2;
798  std::cout << j1.flatten().dump(2);
799  std::cout << j2.flatten().dump(2);
800  if (j1 == j2)
801  {
802  std::cerr << "Error: Parameter read/write "
803  << " is not symmetrical" << std::endl;
804  std::cerr << "In: " << __PRETTY_FUNCTION__ << std::endl;
805  return (1);
806  }
807  else
808  {
809  std::cout << "Partial read succesful, outputs are different" << std::endl;
810  }
811 
812  return (0);
813 }
814 
815 int param::test::prepareforuse()
816 {
817  param::parameters params, params2;
818  std::string fileName = "config/confprepared.json";
819  std::string fileName2 = "config/confprepared2.json";
820  json j1, j2;
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;
826 
827  j1 = params;
828  j2 = params2;
829 
830  if (j1 == j2)
831  {
832  std::cerr << "Error: Parameter read/write "
833  << " is not symmetrical" << std::endl;
834  std::cerr << "In: " << __PRETTY_FUNCTION__ << std::endl;
835  return (1);
836  }
837  else
838  {
839  std::cout << "Partial read succesful, outputs are different" << std::endl;
840  }
841 
842  return (0);
843 }
844 
845 int param::test::autoflat()
846 {
847  param::parameters params, params2;
848 
849  json j1, j2;
850 
851  j1 = params;
852  j2 = params2;
853 
854  j1 = j1.flatten();
855  std::cout << "Dump j1 flattened" << std::endl << j1.dump(1);
856  j1 = j1.flatten();
857  std::cout << "Dump j1 flattened twice" << std::endl << j1.dump(1);
858 
859  try
860  {
861  j2 = j2.unflatten();
862  std::cout << "Dump j2 unflattened" << std::endl << j2.dump(1);
863  }
864  catch (std::exception const &ex)
865  {
866  std::cout << "Cannot be unflattened and throws exception" << std::endl;
867  std::cout << ex.what() << std::endl;
868 
869  std::cout << "Dump j2 unflattened" << std::endl << j2.dump(1);
870  }
871 
872  return (0);
873 }
874 
875 int param::test::symmetry()
876 {
877  json j1, j2;
879  // std::vector<double> v1, v2;
880 
881  // v2 = v1;
882  v1.grid.voronoi.inputpoints.push_back(1.0);
883  j1 = v1;
884  // v2 = j1
885  j1.get_to(v1);
886  j2 = v1;
887 
888  std::cout << j1 << endl;
889  std::cout << j2 << endl;
890 
891  if (j1 != j2)
892  {
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;
898  return (1);
899  };
900 
901  return (0);
902 }
903 
904 int param::test::symmetry_makefillactive()
905 {
906  json j1, j2;
908  // std::vector<double> v1, v2;
909  if (v1.rsvs.makefill.active)
910  {
911  RSVS3D_ERROR_NOTHROW("makefile has been turned active at "
912  "construction.");
913  return (3);
914  }
915 
916  j1 = v1;
917  // v2 = j1
918  j1.get_to(v1);
919  if (v1.rsvs.makefill.active)
920  {
921  RSVS3D_ERROR_NOTHROW("makefile has been turned active when returned "
922  "from json.");
923  return (2);
924  }
925  j2 = v1;
926 
927  std::cout << j1 << endl;
928  std::cout << j2 << endl;
929 
930  if (j1 != j2)
931  {
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;
937  return (1);
938  };
939 
940  return (0);
941 }
Root class for all the parameters.
Definition: parameters.hpp:288
filltype< std::string > makefill
Fill the VOS values from a run time function accessible from makefill.fill.
Definition: parameters.hpp:89
double arrivaltolerance
Distance along edge at which a vertex is considered arrived regardless of "d" and "v".
Definition: parameters.hpp:106
std::vector< double > inputpoints
Vector of input points, 4 datums per point.
Definition: parameters.hpp:147
std::vector< std::pair< std::string, std::string > > exports
Collects the export settings which is a vector of pairs of strings.
Definition: parameters.hpp:37
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.
Definition: warning.hpp:120
void CheckFStream(const T &file, const char *callerID, const std::string &fileName)
Checks a file stream.
Definition: warning.hpp:187
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.
Definition: warning.hpp:148