v0.16.3
Loading...
Searching...
No Matches
JsonConfigManager.hpp
Go to the documentation of this file.
1/** \file JsonConfigManager.hpp
2 * \brief JSON configuration loader for PETSc options and meshsets
3 */
4
5#ifndef __JSONCONFIGMANAGER_HPP__
6#define __JSONCONFIGMANAGER_HPP__
7
9
10namespace MoFEM {
11
13
14 inline static std::vector<std::string> canonical_attributes_ordering =
16
17 static const std::string &supportedVersion();
18 /**
19 * Register additional numeric JSON attribute names.
20 */
21 static MoFEMErrorCode
22 addCanonicalAttributeNames(const std::vector<std::string> &names);
23
24 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
25 UnknownInterface **iface) const;
26
27 JsonConfigManager(const MoFEM::Core &core);
28 virtual ~JsonConfigManager() = default;
29
30 /**
31 * @brief Set -file_name from JSON before Core is available.
32 *
33 * Use only in programs that must read the mesh before MoFEM::Core and the
34 * JsonConfigManager interface are initialised.
35 */
37
38 /**
39 * @brief Read a boolean of the JSON "mofem" section before Core is available.
40 *
41 * Use only in programs that must branch before MoFEM::Core and the
42 * JsonConfigManager interface are initialised, as the choice of mesh loader
43 * does. The command line is not consulted; callers that honour it read the
44 * option themselves and fall back to this.
45 *
46 * @param key name of the entry in the "mofem" section, without the leading -
47 * @param value set only when the entry is present
48 * @param found whether the entry was present
49 */
50 static MoFEMErrorCode getMofemBoolFromJson(const std::string &key,
51 PetscBool &value,
52 PetscBool &found);
53
55
56 MoFEMErrorCode loadFromFile(const std::string &file_name);
58 std::string getPythonScriptByKey(const std::string &key) const;
59 std::string getMoabMeshByKey(const std::string &key) const;
60 std::map<std::string, double>
61 getParamsFromBlockset(const std::string &type_name, int meshset_id) const;
62 /**
63 * @brief Numeric attributes of the entry with this id whose type starts with
64 * type_prefix.
65 *
66 * Generated BLOCKSET names embed the type, so a consumer finding blocks by a
67 * regex such as CRACK(.*) knows the prefix and the id, but not whether the
68 * JSON type was CRACK, CRACK_1 or CRACK_2. Returns an empty map when nothing
69 * matches.
70 */
71 std::map<std::string, double>
72 getParamsFromBlocksetByTypePrefix(const std::string &type_prefix,
73 int meshset_id) const;
74 std::map<std::string, std::string>
75 getStringParamsFromBlockset(const std::string &type_name,
76 int meshset_id) const;
77
78 inline bool hasMeshsetsSection() const { return hasMeshsets; }
79
80private:
81 using MeshsetKey = std::pair<std::string, int>;
82 using MeshsetParams = std::map<std::string, double>;
83 using MeshsetStringParams = std::map<std::string, std::string>;
84
86 boost::json::value configRoot;
87 std::string configFileName;
88 bool configLoaded = false;
89 bool hasMeshsets = false;
90 bool meshsetsApplied = false;
91 std::map<std::string, std::string> moabMeshesByKey;
92 std::map<std::string, std::string> pythonScriptsByKey;
93 std::map<MeshsetKey, MeshsetParams> primaryMeshsetParamsByKey;
94 std::map<MeshsetKey, MeshsetStringParams> primaryMeshsetStringParamsByKey;
95
98};
99
100} // namespace MoFEM
101
102#endif // __JSONCONFIGMANAGER_HPP__
ParentChildKey key
Default canonical JSON block attribute names.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
std::vector< std::string > getDefaultJsonCanonicalAttributeNames()
Core (interface) class.
Definition Core.hpp:83
static const std::string & supportedVersion()
static MoFEMErrorCode setMeshFileFromJson()
Set -file_name from JSON before Core is available.
std::string getPythonScriptByKey(const std::string &key) const
std::map< std::string, std::string > moabMeshesByKey
std::map< std::string, double > MeshsetParams
virtual ~JsonConfigManager()=default
std::map< std::string, double > getParamsFromBlocksetByTypePrefix(const std::string &type_prefix, int meshset_id) const
Numeric attributes of the entry with this id whose type starts with type_prefix.
std::string getMoabMeshByKey(const std::string &key) const
std::map< std::string, double > getParamsFromBlockset(const std::string &type_name, int meshset_id) const
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
static MoFEMErrorCode addCanonicalAttributeNames(const std::vector< std::string > &names)
static std::vector< std::string > canonical_attributes_ordering
std::map< std::string, std::string > pythonScriptsByKey
MoFEMErrorCode loadFromFile(const std::string &file_name)
MoFEMErrorCode getSubInterfaceOptions()
std::map< MeshsetKey, MeshsetParams > primaryMeshsetParamsByKey
static MoFEMErrorCode getMofemBoolFromJson(const std::string &key, PetscBool &value, PetscBool &found)
Read a boolean of the JSON "mofem" section before Core is available.
std::map< std::string, std::string > MeshsetStringParams
std::map< MeshsetKey, MeshsetStringParams > primaryMeshsetStringParamsByKey
boost::json::value configRoot
std::pair< std::string, int > MeshsetKey
MoFEMErrorCode loadFromCommandLine()
std::map< std::string, std::string > getStringParamsFromBlockset(const std::string &type_name, int meshset_id) const
base class for all interface classes