44 ep16Prep *ep16Prep::readJSON(
const std::string &ifname)
46 std::cout <<
"Reading JSON file" << std::endl;
47 std::ifstream inputStream(ifname);
50 std::cerr <<
"Error opening file " << ifname << std::endl;
55 std::cerr <<
"Input File must be in .json format" << std::endl;
59 jsoncons::json inputjson;
60 inputStream >> inputjson;
63 if (inputjson.is_array())
66 <<
"Warning: Input is an array. Only first element will be processed" 68 inputjson = inputjson[0];
71 ep16Prep *ep =
new ep16Prep(inputjson);
77 ep16Prep *ep16Prep::readJSON(
const jsoncons::json &inputjson)
79 ep16Prep *ep =
new ep16Prep(inputjson);
87 void ep16Prep::readJSON()
89 std::cout <<
"Reading Epic 2016 Input Generation JSON." << std::endl;
93 _fname = _jstrm[
"File Name"].as<std::string>();
94 if (_jstrm.contains(
"Type"))
96 type = _jstrm[
"Type"].as<std::string>();
100 if (type !=
"short form" 101 && type !=
"long form" 102 && type !=
"long form edit")
104 std::cerr <<
"Unknown type " << type
105 <<
", switching to short form." << std::endl;
109 if (type ==
"long form")
111 std::cerr <<
"Long form is not supported yet." << std::endl;
114 else if (type ==
"short form")
122 std::vector<std::string> order;
125 if (type ==
"short form")
132 "mesh.nodeset.projectile",
133 "mesh.nodeset.target",
134 "mesh.elementset.projectile",
135 "mesh.elementset.target",
140 else if (type ==
"long form edit")
144 "edit.slideline.seek",
159 void ep16Prep::process()
163 wrtCmnt(
"EPIC 2016 INPUT FILE");
165 wrtCmnt(
"Short Form Description Card for ExodusII/CUBIT Data");
168 std::string exo_fname = _jstrm[
"Mesh"][
"File"].as<std::string>();
173 jsoncons::json _matj = _jstrm[
"Material"];
174 for (
const auto &km: _matj.object_range())
176 std::string kmkey = std::string(km.key());
178 _mat[kmkey] = km.value().as<
int>();
182 jsoncons::json _bcsj = _jstrm[
"Boundary Condition"];
183 for (
const auto &km: _bcsj.object_range()) {
184 std::string kmkey = std::string(km.key());
186 _bcs[kmkey] = km.value().as<std::string>();
188 std::string bcskmkey = _bcs[kmkey];
190 if (bcskmkey ==
"fixed")
196 std::vector<std::string> ord = getOrder();
197 for (
const auto &oi : ord)
203 std::cout << tsk <<
" -- " << _tsk <<
" -- " << __tsk <<
"\n";
206 else if (tsk ==
"mesh")
208 else if (tsk ==
"misc")
209 wrtMisc(_tsk, __tsk);
210 else if (tsk ==
"edit")
216 void ep16Prep::wrtCmnt(
const std::string &cmnt)
218 std::stringstream ss;
219 ss << getCmntStr() << cmnt;
224 void ep16Prep::wrtPre(
const std::string &_tsk,
const std::string &__tsk)
226 std::stringstream _tcmnt;
227 std::stringstream _tstr;
231 _tstr.str(std::string());
233 _tcmnt.str(std::string());
234 int _ctype = _jstrm[
"Case"][
"Type"].as<
int>();
235 int _cid = _jstrm[
"Case"][
"Id"].as<
int>();
236 std::string _des =
" " + _jstrm[
"Case"][
"Description"].as<std::string>();
237 _tcmnt <<
"CASE DESCRIPTION";
238 _tstr << std::setw(5) << _ctype
239 << std::setw(5) << _cid
240 << std::setw(70) << std::left << _des;
242 else if (_tsk ==
"run")
245 _tstr.str(std::string());
247 _tcmnt.str(std::string());
248 int _rmde, _unt, _pat, _dplt, _ssld;
253 _rmde = _jstrm[
"Run"][
"Mode"].as<
int>();
254 _unt = _jstrm[
"Run"][
"Unit"].as<
int>();
255 _tmx = _jstrm[
"Run"][
"Tmax"].as<
double>();
256 _ssld = _jstrm[
"Run"].get_with_default(
"SSLD", 1);
257 _tcmnt <<
"Run Card\n";
258 _tcmnt << getCmntStr() <<
" RUN UNIT PAT DPLT TMAX CPMAX";
260 _tstr << std::setw(5) << _rmde
261 << std::setw(5) << _unt
262 << std::setw(5) << _pat
263 << std::setw(5) << _dplt
264 << std::setw(10) << std::scientific << _tmx
265 << std::setw(10) << _cpmx
266 << std::setw(1) << _ssld;
268 else if (_tsk ==
"exodus")
271 int _npns, _ntns, _npes, _ntes, _ctact, _conv, _sym, _tet;
273 std::vector<std::string> ns_names, eb_names;
274 ns_names = _mdb->getNdeSetNames();
275 eb_names = _mdb->getElmBlkNames();
280 for (
auto ni = ns_names.begin(); ni != ns_names.end(); ni++)
286 else if (pre ==
"trg")
289 for (
auto ei = eb_names.begin(); ei != eb_names.end(); ei++)
295 std::cerr <<
"Warnning: TRIANGLE element blocks will be ignored!\n";
303 else if (pre ==
"trg")
313 _tstr.str(std::string());
315 _tcmnt.str(std::string());
316 _tcmnt <<
"Exodus II Description Card\n";
317 _tcmnt << getCmntStr()
318 <<
"NPNS NTNS NPES NTES CTCT CONV SYM TET GAP";
320 _tstr << std::setw(5) << _npns
321 << std::setw(5) << _ntns
322 << std::setw(5) << _npes
323 << std::setw(5) << _ntes
324 << std::setw(5) << _ctact
325 << std::setw(5) << _conv
326 << std::setw(5) << _sym
327 << std::setw(5) << _tet
328 << std::setw(10) << std::scientific << _gap;
330 else if (_tsk ==
"arraysize")
333 int _mxn, _mxl, _mxmn, _mxsn;
334 _mxn = _mdb->getNumberOfNodes();
335 _mxl = _mdb->getNumberOfElements();
340 _tstr.str(std::string());
342 _tcmnt.str(std::string());
343 _tcmnt <<
"Array Size/Dimension Card\n";
344 _tcmnt << getCmntStr() <<
" MXN MXL MXMN MXSN";
345 _tstr << std::setw(10) << _mxn * 50
346 << std::setw(10) << _mxl * 50
347 << std::setw(10) << _mxmn * 50
348 << std::setw(10) << _mxsn * 50;
351 if (!_tcmnt.str().empty())
352 wrtCmnt(_tcmnt.str());
353 if (!_tstr.str().empty())
358 void ep16Prep::wrtMsh(
const std::string &_tsk,
const std::string &__tsk)
360 std::stringstream _tcmnt;
361 std::stringstream _tstr;
362 if (_tsk ==
"nodeset")
365 _tcmnt.str(std::string());
367 _tstr.str(std::string());
369 if (__tsk ==
"projectile")
371 _tcmnt <<
"Projectile Node Set Cards\n";
374 else if (__tsk ==
"target")
376 _tcmnt <<
"Target Node Set Cards\n";
381 std::cerr <<
"Error: Unknown node set type " << __tsk << std::endl;
384 _tcmnt << getCmntStr() <<
"NSET XYZ";
385 wrtCmnt(_tcmnt.str());
386 for (
int ns = 0; ns < _mdb->getNumberOfNodeSets(); ns++)
392 int _nset = _mdb->getNdeSetId(ns);
393 std::string nsName = _mdb->getNdeSetName(ns);
396 auto srch = _bcs.find(nsName);
397 if (srch != _bcs.end())
398 nsChar = srch->second;
401 _tstr << std::setw(5) << _nset << std::setw(8) << nsChar;
406 else if (_tsk ==
"elementset")
409 _tcmnt.str(std::string());
411 _tstr.str(std::string());
413 if (__tsk ==
"projectile")
415 _tcmnt <<
"Projectile Element/Particle Set Cards\n";
418 else if (__tsk ==
"target")
420 _tcmnt <<
"Target Element/Particle Set Cards\n";
425 std::cerr <<
"Error: Unknown node set type " << __tsk << std::endl;
428 _tcmnt << getCmntStr()
429 <<
"LSET MATL TYPE SSET THICK/AREA";
430 wrtCmnt(_tcmnt.str());
431 int _lset, _matl, _type, _sset;
434 _blnk.insert(_blnk.end(), 50,
' ');
435 for (
int es = 0; es < (_mdb->getNumberOfElementBlocks()); es++)
437 std::string es_name = _mdb->getElmBlkName(es);
442 _lset = _mdb->getElmBlkId(es);
443 _matl = _mat[es_name];
446 std::cerr <<
"WARNING: Keyword " << es_name
447 <<
" is not defined in input file." << std::endl;
454 _tstr << std::setw(5) << _lset
455 << std::setw(5) << _matl
456 << std::setw(5) << _type
457 << std::setw(5) << _sset
459 << std::setw(10) << std::scientific << _ta;
467 void ep16Prep::wrtMisc(
const std::string &_tsk,
const std::string &__tsk)
469 std::stringstream _tcmnt;
470 std::stringstream _tstr;
471 if (_tsk ==
"velocity")
474 _tcmnt.str(std::string());
475 _tcmnt <<
"Projectile and Target Velocities Card\n";
476 _tcmnt << getCmntStr()
477 <<
" PXVEL PYVEL PZVEL TXVEL TYVEL TZVEL";
478 wrtCmnt(_tcmnt.str());
481 std::vector<double> _prjv, _trgv;
482 jsoncons::json _vj = _jstrm[
"Velocity"];
483 for (
int i = 0; i < 3; i++)
485 _prjv.push_back(_vj[
"Projectile"][i].as<double>());
486 _trgv.push_back(_vj[
"Target"][i].as<double>());
490 _tstr.str(std::string());
492 _tstr << std::setw(10) << _prjv[0]
493 << std::setw(10) << _prjv[1]
494 << std::setw(10) << _prjv[2]
495 << std::setw(10) << _trgv[0]
496 << std::setw(10) << _trgv[1]
497 << std::setw(10) << _trgv[2];
500 else if (_tsk ==
"detonation")
503 _tcmnt.str(std::string());
504 _tcmnt <<
"Detonation Point Card\n";
505 _tcmnt << getCmntStr() <<
" XDET YDET ZDET";
506 wrtCmnt(_tcmnt.str());
509 std::vector<double> _det;
510 jsoncons::json _vj = _jstrm[
"Detonation"];
511 for (
int i = 0; i < 3; i++)
513 _det.push_back(_vj[
"Coordinate"][i].as<double>());
517 _tstr.str(std::string());
519 _tstr << std::setw(10) << _det[0]
520 << std::setw(10) << _det[1]
521 << std::setw(10) << _det[2];
527 void ep16Prep::edit(
const std::string &_tsk,
const std::string &__tsk)
531 else if (_tsk ==
"slideline" && __tsk ==
"seek")
534 if (!_jstrm.contains(
"Slideline"))
536 int seek = _jstrm[
"Slideline"].get_with_default(
"Seek", 6);
538 std::stringstream iss;
539 std::stringstream oss;
540 iss << _buffer.rdbuf();
541 while (iss.rdbuf()->in_avail() != 0)
545 std::string line(cl);
546 if (line.find(
"seek") != std::string::npos)
553 oss << std::setw(5) << dmy;
556 oss << std::setw(5) << seek;
559 oss << std::string(rem);
567 _buffer.str(std::string());
568 _buffer << oss.rdbuf();
570 else if (_tsk ==
"detonation")
573 if (!_jstrm.contains(
"Detonation"))
576 std::vector<double> _g;
580 if (_jstrm[
"Detonation"].contains(
"Gravity"))
582 _g[0] = _jstrm[
"Detonation"][
"Gravity"][0].as<
double>();
583 _g[1] = _jstrm[
"Detonation"][
"Gravity"][1].as<
double>();
584 _g[2] = _jstrm[
"Detonation"][
"Gravity"][2].as<
double>();
587 if (_jstrm[
"Detonation"].contains(
"Tburn"))
588 tburn = _jstrm[
"Detonation"][
"Tburn"].as<double>();
590 std::stringstream iss;
591 std::stringstream oss;
592 iss << _buffer.rdbuf();
593 while (iss.rdbuf()->in_avail() != 0)
597 std::string line(cl);
598 if (line.find(
"rdet") != std::string::npos)
606 oss << std::setw(10) << std::setprecision(3) << std::scientific << dmy;
609 oss << std::setw(10) << std::setprecision(3) << std::scientific << dmy;
612 oss << std::setw(10) << std::setprecision(3) << std::scientific << dmy;
615 oss << std::setw(10) << std::setprecision(3) << std::scientific << tburn;
618 oss << std::setw(5) << dmyi;
621 oss << std::setw(5) << dmyi;
624 oss << std::setw(10) << std::setprecision(3) << std::scientific << _g[0];
627 oss << std::setw(10) << std::setprecision(3) << std::scientific << _g[1];
630 oss << std::setw(10) << std::setprecision(3) << std::scientific << _g[2];
638 _buffer.str(std::string());
639 _buffer << oss.rdbuf();
641 else if (_tsk ==
"main")
644 if (!_jstrm.contains(
"Main"))
648 int dplt = _jstrm[
"Main"].get_with_default(
"DPLT", -666);
649 double dtdyn = _jstrm[
"Main"].get_with_default(
"DTDYN", -666.0);
651 std::stringstream iss;
652 std::stringstream oss;
653 iss << _buffer.rdbuf();
654 while (iss.rdbuf()->in_avail() != 0)
658 std::string line(cl);
659 if (line.find(
"sys") != std::string::npos)
661 char *buf =
new char[5];
669 oss << std::setw(5) << dmyi;
673 oss << std::setw(5) << dmyi;
677 oss << std::setw(5) << dmyi;
681 dmyi = std::stoi(std::string(buf));
682 oss << std::setw(5) << (dplt == -666 ? dmyi : dplt);
686 oss << std::setw(10) << std::setprecision(4) << std::scientific << dmy;
690 oss << std::setw(10) << std::setprecision(4) << std::scientific << dmy;
694 oss << std::setw(10) << std::setprecision(4) << std::scientific << dmy;
698 oss << std::setw(10) << std::setprecision(4) << std::scientific << dmy;
702 oss << std::setw(10) << std::setprecision(4) << std::scientific
703 << (dtdyn == -666 ? dmy : dtdyn);
707 oss << std::setw(10) << std::setprecision(4) << std::scientific << dmy;
717 _buffer.str(std::string());
718 _buffer << oss.rdbuf();
720 else if (_tsk ==
"close")
722 std::string ofname = _jstrm.get_with_default(
"Output File Name", _fname);
728 void ep16Prep::read(
const std::string &fname)
730 std::ifstream _ifile;
734 std::cerr <<
"Error opening file " << fname << std::endl;
738 _buffer << _ifile.rdbuf();
744 void ep16Prep::close(
const std::string &fname)
746 std::ofstream _ofile;
748 if (!_ofile.is_open())
750 std::cerr <<
"Problem opening the output file." << std::endl;
753 _ofile << _buffer.rdbuf();
A complete I/O class for EXODUS II file format.
std::string find_ext(const std::string &fname)
std::string findToStr(const std::string &str, const std::string &ptrn)
std::string findFromStr(const std::string &str, const std::string &ptrn)
void toLower(std::string &str)