12 return "root." + std::string(section_key) +
"[" +
13 boost::lexical_cast<std::string>(mesh_index) +
"]";
17 const std::string &file_name) {
18 const auto meshes_it = root_object.find(
MESHES_KEY);
20 if (meshes_it != root_object.end() && input_files_it != root_object.end()) {
21 CHKERRABORT(PETSC_COMM_SELF,
22 failConfig(file_name,
"root.input_files",
23 "cannot be used together with root.meshes"));
26 if (meshes_it != root_object.end())
28 if (input_files_it != root_object.end())
34 const std::string &file_name,
35 const char **section_key =
nullptr) {
38 *section_key = selected_key;
42 const auto section_it = root_object.find(selected_key);
43 return &requireArray(section_it->value(), file_name,
44 makeContext(
"root", selected_key));
48 const std::string &file_name,
49 const size_t mesh_index) {
50 const char *section_key =
nullptr;
51 const auto *meshes_array =
56 if (mesh_index >= meshes_array->size()) {
57 CHKERRABORT(PETSC_COMM_SELF,
58 failConfig(file_name,
meshContext(mesh_index, section_key),
59 "mesh index out of range"));
62 const auto context =
meshContext(mesh_index, section_key);
63 const auto &mesh_object =
64 requireObject((*meshes_array)[mesh_index], file_name, context);
65 if (
const auto meshsets_it = mesh_object.find(
"meshsets");
66 meshsets_it != mesh_object.end()) {
67 return &requireArray(meshsets_it->value(), file_name,
68 makeContext(context,
"meshsets"));
75 const JsonValue &value,
76 const std::string &file_name,
77 const std::string &context,
78 ParsedMeshEntry &entry,
79 bool &has_non_empty_meshsets) {
82 entry.key = requireString(value, file_name, makeContext(context,
field_name));
84 entry.type = requireString(value, file_name, makeContext(context,
field_name));
87 requireString(value, file_name, makeContext(context,
field_name));
89 const auto &meshsets =
90 requireArray(value, file_name, makeContext(context,
field_name));
91 has_non_empty_meshsets = !meshsets.empty();
94 "unknown input file field");
100 const std::string &file_name,
101 const std::string &context,
102 const size_t mesh_index) {
104 if (entry.type.empty()) {
105 CHKERR failConfig(file_name, makeContext(context,
"type"),
106 "missing required mesh type");
108 if (entry.fileName.empty()) {
109 CHKERR failConfig(file_name, makeContext(context,
"file_name"),
110 "missing required file_name");
114 CHKERR failConfig(file_name, makeContext(context,
"type"),
115 "unsupported mesh type '" + entry.type +
"'");
119 CHKERR failConfig(file_name, makeContext(context,
"type"),
120 "primary runtime mesh must be " +
125 CHKERR failConfig(file_name, makeContext(context,
"key"),
127 " requires a unique key");
134 const std::string &file_name,
135 std::vector<ParsedMeshEntry> &meshes,
136 bool *has_meshsets) {
140 *has_meshsets =
false;
142 const char *section_key =
nullptr;
143 if (
const auto *meshes_array =
146 meshes.reserve(meshes_array->size());
147 for (
size_t i = 0;
i != meshes_array->size(); ++
i) {
149 const auto &mesh_object =
150 requireObject((*meshes_array)[
i], file_name, context);
152 ParsedMeshEntry entry;
153 bool has_non_empty_meshsets =
false;
154 for (
const auto &item : mesh_object) {
156 file_name, context, entry,
157 has_non_empty_meshsets);
161 if (has_meshsets && has_non_empty_meshsets) {
162 *has_meshsets =
true;
164 meshes.push_back(std::move(entry));
168 std::set<std::string> moab_mesh_keys;
169 std::set<std::string> python_script_keys;
170 for (
const auto &entry : meshes) {
172 if (entry.key.empty()) {
175 const auto inserted = moab_mesh_keys.insert(entry.key);
176 if (!inserted.second) {
177 CHKERR failConfig(file_name, makeContext(
"root", section_key),
179 " key '" + entry.key +
"'");
184 const auto inserted = python_script_keys.insert(entry.key);
185 if (!inserted.second) {
186 CHKERR failConfig(file_name, makeContext(
"root", section_key),
188 " key '" + entry.key +
"'");
std::string meshContext(const size_t mesh_index, const char *section_key=MESHES_KEY)
const JsonArray * getMeshsetsArray(const JsonObject &root_object, const std::string &file_name, const size_t mesh_index)
constexpr auto MESHES_KEY
MoFEMErrorCode validateMeshEntry(const ParsedMeshEntry &entry, const std::string &file_name, const std::string &context, const size_t mesh_index)
MoFEMErrorCode collectMeshes(const JsonObject &root_object, const std::string &file_name, std::vector< ParsedMeshEntry > &meshes, bool *has_meshsets)
constexpr auto INPUT_FILES_KEY
bool isPythonScriptMeshType(const std::string &type)
const char * getMeshSectionKey(const JsonObject &root_object, const std::string &file_name)
MoFEMErrorCode parseMeshEntryField(const std::string &field_name, const JsonValue &value, const std::string &file_name, const std::string &context, ParsedMeshEntry &entry, bool &has_non_empty_meshsets)
const JsonArray * getMeshesArray(const JsonObject &root_object, const std::string &file_name, const char **section_key=nullptr)
constexpr auto MOAB_MESH_TYPE
constexpr auto PYTHON_SCRIPT_TYPE
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
FTensor::Index< 'i', SPACE_DIM > i
constexpr auto field_name