v0.16.0
Loading...
Searching...
No Matches
Functions | Variables
JsonConfigManagerMeshes.cpp File Reference

Go to the source code of this file.

Functions

bool isPythonScriptMeshType (const std::string &type)
 
std::string meshContext (const size_t mesh_index, const char *section_key=MESHES_KEY)
 
const char * getMeshSectionKey (const JsonObject &root_object, const std::string &file_name)
 
const JsonArray * getMeshesArray (const JsonObject &root_object, const std::string &file_name, const char **section_key=nullptr)
 
const JsonArray * getMeshsetsArray (const JsonObject &root_object, const std::string &file_name, const size_t mesh_index)
 
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)
 
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)
 

Variables

constexpr auto MOAB_MESH_TYPE = "MOAB_MESH"
 
constexpr auto PYTHON_SCRIPT_TYPE = "PYTHON_SCRIPT"
 
constexpr auto MESHES_KEY = "meshes"
 
constexpr auto INPUT_FILES_KEY = "input_files"
 

Function Documentation

◆ collectMeshes()

MoFEMErrorCode collectMeshes ( const JsonObject &  root_object,
const std::string &  file_name,
std::vector< ParsedMeshEntry > &  meshes,
bool has_meshsets 
)

Definition at line 133 of file JsonConfigManagerMeshes.cpp.

136 {
138 meshes.clear();
139 if (has_meshsets)
140 *has_meshsets = false;
141
142 const char *section_key = nullptr;
143 if (const auto *meshes_array =
144 getMeshesArray(root_object, file_name, &section_key);
145 meshes_array) {
146 meshes.reserve(meshes_array->size());
147 for (size_t i = 0; i != meshes_array->size(); ++i) {
148 const auto context = meshContext(i, section_key);
149 const auto &mesh_object =
150 requireObject((*meshes_array)[i], file_name, context);
151
152 ParsedMeshEntry entry;
153 bool has_non_empty_meshsets = false;
154 for (const auto &item : mesh_object) {
155 CHKERR parseMeshEntryField(toStdString(item.key()), item.value(),
156 file_name, context, entry,
157 has_non_empty_meshsets);
158 }
159
160 CHKERR validateMeshEntry(entry, file_name, context, i);
161 if (has_meshsets && has_non_empty_meshsets) {
162 *has_meshsets = true;
163 }
164 meshes.push_back(std::move(entry));
165 }
166 }
167
168 std::set<std::string> moab_mesh_keys;
169 std::set<std::string> python_script_keys;
170 for (const auto &entry : meshes) {
171 if (entry.type == MOAB_MESH_TYPE) {
172 if (entry.key.empty()) {
173 continue;
174 }
175 const auto inserted = moab_mesh_keys.insert(entry.key);
176 if (!inserted.second) {
177 CHKERR failConfig(file_name, makeContext("root", section_key),
178 "duplicate " + std::string(MOAB_MESH_TYPE) +
179 " key '" + entry.key + "'");
180 }
181 continue;
182 }
183 if (isPythonScriptMeshType(entry.type)) {
184 const auto inserted = python_script_keys.insert(entry.key);
185 if (!inserted.second) {
186 CHKERR failConfig(file_name, makeContext("root", section_key),
187 "duplicate " + std::string(PYTHON_SCRIPT_TYPE) +
188 " key '" + entry.key + "'");
189 }
190 }
191 }
192
194}
std::string meshContext(const size_t mesh_index, const char *section_key=MESHES_KEY)
MoFEMErrorCode validateMeshEntry(const ParsedMeshEntry &entry, const std::string &file_name, const std::string &context, const size_t mesh_index)
bool isPythonScriptMeshType(const std::string &type)
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

◆ getMeshesArray()

const JsonArray * getMeshesArray ( const JsonObject &  root_object,
const std::string &  file_name,
const char **  section_key = nullptr 
)

Definition at line 33 of file JsonConfigManagerMeshes.cpp.

35 {
36 const auto *selected_key = getMeshSectionKey(root_object, file_name);
37 if (section_key)
38 *section_key = selected_key;
39 if (!selected_key)
40 return nullptr;
41
42 const auto section_it = root_object.find(selected_key);
43 return &requireArray(section_it->value(), file_name,
44 makeContext("root", selected_key));
45}
const char * getMeshSectionKey(const JsonObject &root_object, const std::string &file_name)

◆ getMeshSectionKey()

const char * getMeshSectionKey ( const JsonObject &  root_object,
const std::string &  file_name 
)

Definition at line 16 of file JsonConfigManagerMeshes.cpp.

17 {
18 const auto meshes_it = root_object.find(MESHES_KEY);
19 const auto input_files_it = root_object.find(INPUT_FILES_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"));
24 }
25
26 if (meshes_it != root_object.end())
27 return MESHES_KEY;
28 if (input_files_it != root_object.end())
29 return INPUT_FILES_KEY;
30 return nullptr;
31}
constexpr auto MESHES_KEY
constexpr auto INPUT_FILES_KEY

◆ getMeshsetsArray()

const JsonArray * getMeshsetsArray ( const JsonObject &  root_object,
const std::string &  file_name,
const size_t  mesh_index 
)

Definition at line 47 of file JsonConfigManagerMeshes.cpp.

49 {
50 const char *section_key = nullptr;
51 const auto *meshes_array =
52 getMeshesArray(root_object, file_name, &section_key);
53 if (!meshes_array)
54 return nullptr;
55
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"));
60 }
61
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"));
69 }
70
71 return nullptr;
72}

◆ isPythonScriptMeshType()

bool isPythonScriptMeshType ( const std::string &  type)

Definition at line 6 of file JsonConfigManagerMeshes.cpp.

6 {
7 return type == PYTHON_SCRIPT_TYPE;
8}
std::string type

◆ meshContext()

std::string meshContext ( const size_t  mesh_index,
const char *  section_key = MESHES_KEY 
)

Definition at line 10 of file JsonConfigManagerMeshes.cpp.

11 {
12 return "root." + std::string(section_key) + "[" +
13 boost::lexical_cast<std::string>(mesh_index) + "]";
14}

◆ parseMeshEntryField()

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 
)

Definition at line 74 of file JsonConfigManagerMeshes.cpp.

79 {
81 if (field_name == "key") {
82 entry.key = requireString(value, file_name, makeContext(context, field_name));
83 } else if (field_name == "type") {
84 entry.type = requireString(value, file_name, makeContext(context, field_name));
85 } else if (field_name == "file_name") {
86 entry.fileName =
87 requireString(value, file_name, makeContext(context, field_name));
88 } else if (field_name == "meshsets") {
89 const auto &meshsets =
90 requireArray(value, file_name, makeContext(context, field_name));
91 has_non_empty_meshsets = !meshsets.empty();
92 } else {
93 CHKERR failConfig(file_name, makeContext(context, field_name),
94 "unknown input file field");
95 }
97}
constexpr auto field_name

◆ validateMeshEntry()

MoFEMErrorCode validateMeshEntry ( const ParsedMeshEntry &  entry,
const std::string &  file_name,
const std::string &  context,
const size_t  mesh_index 
)

Definition at line 99 of file JsonConfigManagerMeshes.cpp.

102 {
104 if (entry.type.empty()) {
105 CHKERR failConfig(file_name, makeContext(context, "type"),
106 "missing required mesh type");
107 }
108 if (entry.fileName.empty()) {
109 CHKERR failConfig(file_name, makeContext(context, "file_name"),
110 "missing required file_name");
111 }
112
113 if (entry.type != MOAB_MESH_TYPE && !isPythonScriptMeshType(entry.type)) {
114 CHKERR failConfig(file_name, makeContext(context, "type"),
115 "unsupported mesh type '" + entry.type + "'");
116 }
117
118 if (mesh_index == 0 && entry.type != MOAB_MESH_TYPE) {
119 CHKERR failConfig(file_name, makeContext(context, "type"),
120 "primary runtime mesh must be " +
121 std::string(MOAB_MESH_TYPE));
122 }
123
124 if (isPythonScriptMeshType(entry.type) && entry.key.empty()) {
125 CHKERR failConfig(file_name, makeContext(context, "key"),
126 std::string(PYTHON_SCRIPT_TYPE) +
127 " requires a unique key");
128 }
129
131}

Variable Documentation

◆ INPUT_FILES_KEY

constexpr auto INPUT_FILES_KEY = "input_files"
constexpr

Definition at line 4 of file JsonConfigManagerMeshes.cpp.

◆ MESHES_KEY

constexpr auto MESHES_KEY = "meshes"
constexpr

Definition at line 3 of file JsonConfigManagerMeshes.cpp.

◆ MOAB_MESH_TYPE

constexpr auto MOAB_MESH_TYPE = "MOAB_MESH"
constexpr

Definition at line 1 of file JsonConfigManagerMeshes.cpp.

◆ PYTHON_SCRIPT_TYPE

constexpr auto PYTHON_SCRIPT_TYPE = "PYTHON_SCRIPT"
constexpr

Definition at line 2 of file JsonConfigManagerMeshes.cpp.