NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
inputGen.H
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #ifndef NEMOSYS_INPUTGEN_H_
30 #define NEMOSYS_INPUTGEN_H_
31 
32 // headers
33 #include "nemosys_export.h"
34 
35 #include <jsoncons/json.hpp>
36 
37 #include <map>
38 
39 class meshBase;
40 
42 
43 // class declarations
44 // inputGen is an abstract class that provides a general-purpose,
45 // template structure for generating input needed for the
46 // high fidelity physics codes.
47 class NEMOSYS_EXPORT inputGen {
48  // constructors and destructors
49  public:
50  explicit inputGen(jsoncons::json jsnStrm)
51  : _jstrm(std::move(jsnStrm)), _key("generic") {};
52 
53  virtual ~inputGen() {
54  for (auto &&inp : _inp)
55  delete inp.second;
56  }
57 
58  // basic methods
59  public:
60  // setting keyword for each input file
61  void _set_key(const std::string &key) { _key = key; }
62 
63  virtual void setNameType(const std::string &fname, inpFileType ftyp,
64  const std::string &key = std::string());
65  // order of writing lines into the file
66  virtual void setOrder(const std::vector<std::string> &ord,
67  const std::string &key = std::string());
68  virtual std::vector<std::string>
69  getOrder(const std::string &key = std::string());
70  virtual void pushOrder(const std::string &ord,
71  const std::string &key = std::string());
72  // setting mesh database
73  virtual void setMsh(meshBase *mb,
74  const std::string &key = std::string());
75  // string used for commenting for each input file
76  virtual void setCmntStr(const std::string &cmstr,
77  const std::string &key = std::string());
78  virtual std::string getCmntStr(const std::string &key = std::string());
79  // analyzing input and prepare for writing to the file
80  virtual void process() = 0;
81  // wrting into the file, implementation can be different
82  virtual void write(const std::string &key = std::string()) const;
83  // reading input file, implementation can be different
84  virtual void read(const std::string &fname) = 0;
85  // closing input file opened by read, implementation can be different
86  virtual void close(const std::string &fname) = 0;
87 
88  // commonly used feature specifications
89  public:
90  // adding element sets and node sets
91  virtual void addNdeSet() = 0;
92  virtual void addElmSet() = 0;
93 
94  // attribute assignment
95  public:
96  virtual void addMat() = 0;
97  virtual void addBC() = 0;
98  virtual void addIC() = 0;
99  virtual bool addMisc() = 0;
100 
101  // internal processing
102  public:
103  virtual void wrtPre(const std::string &_tsk, const std::string &__tsk) = 0;
104  virtual void wrtCmnt(const std::string &cmnt) = 0;
105  virtual void wrtMsh(const std::string &_tsk, const std::string &__tsk) = 0;
106  virtual void wrtNdeCrds() = 0;
107  virtual void wrtElmCon() = 0;
108  virtual void wrtPost() = 0;
109  virtual void wrtNdeSet() = 0;
110  virtual void wrtElmSet() = 0;
111  virtual void wrtMisc(const std::string &_tsk, const std::string &__tsk) = 0;
112  virtual void edit(const std::string &_tsk, const std::string &__tsk) = 0;
113 
114  // raw methods
115  protected:
116  virtual void _write(std::stringstream &ss)
117  {
118  auto key_it = _inp.find(_key);
119  if (key_it == _inp.end())
120  _inp.insert(
121  std::pair<std::string, std::stringstream *>(
122  _key,
123  new std::stringstream()
124  )
125  );
126 
127  *(_inp.at(_key)) << ss.str() << std::endl;
128  ss.clear();
129  ss.str(std::string());
130  };
131 
132  protected:
133  jsoncons::json _jstrm;
134  std::string _key;
135  std::map<std::string, std::stringstream *> _inp;
136  std::map<std::string, std::vector<meshBase *>> _mb;
137  std::map<std::string, std::vector<std::string>> _ord;
138  std::map<std::string, std::string> _fn;
139  std::map<std::string, inpFileType> _tpe;
140  std::map<std::string, std::string> _cmnt;
141 };
142 
143 #endif // NEMOSYS_INPUTGEN_H_
virtual ~inputGen()
Definition: inputGen.H:53
void _set_key(const std::string &key)
Definition: inputGen.H:61
virtual void _write(std::stringstream &ss)
Definition: inputGen.H:116
inputGen(jsoncons::json jsnStrm)
Definition: inputGen.H:50
A brief description of meshBase.
Definition: meshBase.H:64
STL namespace.
std::map< std::string, std::string > _cmnt
Definition: inputGen.H:140
inpFileType
Definition: inputGen.H:41
std::map< std::string, std::vector< std::string > > _ord
Definition: inputGen.H:137
jsoncons::json _jstrm
Definition: inputGen.H:130
std::map< std::string, inpFileType > _tpe
Definition: inputGen.H:139
std::map< std::string, std::string > _fn
Definition: inputGen.H:138
std::map< std::string, std::vector< meshBase * > > _mb
Definition: inputGen.H:136
std::string _key
Definition: inputGen.H:134
std::map< std::string, std::stringstream * > _inp
Definition: inputGen.H:135