2 const auto &ordering = JsonConfigManager::canonical_attributes_ordering;
3 const auto it = std::find_if(
4 ordering.begin(), ordering.end(), [&](
const std::string &name) {
5 return toLowerCopy(name) == lower_key;
7 if (it == ordering.end()) {
10 return static_cast<int>(std::distance(ordering.begin(), it));
14 const std::string &file_name,
15 const std::string &context) {
17 return value.as_bool() ? 1.0 : 0.0;
19 return requireNumber(value, file_name, context);
23 const JsonObject &props,
24 const std::string &file_name,
25 const std::string &context,
26 const std::string &blockset_name) {
28 std::map<int, double> ordered_values;
30 for (
const auto &item : props) {
31 if (item.value().is_string()) {
35 const auto key = toStdString(item.key());
36 const auto lower_key = toLowerCopy(
key);
42 item.value(), file_name, makeContext(context,
key));
45 if (ordered_values.size() > MAX_MESHSET_ATTRIBUTES) {
48 "BLOCKSET attributes exceed maximum supported direct attribute count " +
49 boost::lexical_cast<std::string>(MAX_MESHSET_ATTRIBUTES));
52 std::vector<double> values;
53 values.reserve(ordered_values.size());
54 for (
const auto &attribute : ordered_values) {
55 values.push_back(attribute.second);
58 CHKERR meshsets_manager.setAttributes(
BLOCKSET,
id, values, blockset_name);
63 const size_t meshset_index) {
64 return mesh_context +
".meshsets[" +
65 boost::lexical_cast<std::string>(meshset_index) +
"]";
83 std::map<BlocksetParamKey, BlocksetStringParams>;
86 return makeContext(entry.
context,
"attributes");
91 const auto max_name_size = NAME_TAG_SIZE - 1;
92 const auto type_id_name = entry.
typeName +
"_" + id;
94 if (type_id_name.size() > max_name_size) {
95 std::ostringstream ss;
96 ss <<
"JSON " << entry.
context <<
": generated BLOCKSET name '"
97 << type_id_name <<
"' is too long (" << type_id_name.size()
98 <<
" characters); cannot fit type and id into " << max_name_size
105 if (meshset_name.empty() || meshset_name == entry.
typeName) {
109 const auto full_name = entry.
typeName +
"_" + meshset_name +
"_" + id;
110 if (full_name.size() <= max_name_size) {
115 <<
"JSON " << entry.
context <<
": generated BLOCKSET name '"
116 << full_name <<
"' is too long (" << full_name.size()
117 <<
" characters); removed meshset_name and using '" << type_id_name
123 const std::string &meshset_name,
124 const std::string &file_name,
125 const std::string &context,
126 const CubitMeshSets **blockset_ptr) {
128 *blockset_ptr =
nullptr;
129 int number_of_meshsets = 0;
131 for (
auto it = meshsets_manager.getBegin(); it != meshsets_manager.getEnd();
133 if ((it->getBcType() & CubitBCType(
BLOCKSET)).none() ||
134 it->getName() != meshset_name) {
137 *blockset_ptr = &*it;
138 ++number_of_meshsets;
141 if (number_of_meshsets == 0) {
142 CHKERR failConfig(file_name, makeContext(context,
"meshset_name"),
143 "failed to resolve BLOCKSET meshset_name '" +
146 if (number_of_meshsets != 1) {
147 CHKERR failConfig(file_name, makeContext(context,
"meshset_name"),
148 "BLOCKSET meshset_name '" + meshset_name +
149 "' is not unique; resolve by explicit id");
156 const int meshset_id,
157 const std::string &file_name,
158 const std::string &context,
159 const CubitMeshSets **blockset_ptr) {
161 if (!meshsets_manager.checkMeshset(meshset_id,
BLOCKSET)) {
162 CHKERR failConfig(file_name, makeContext(context,
"id"),
163 "failed to resolve BLOCKSET id '" +
164 boost::lexical_cast<std::string>(meshset_id) +
"'");
172 const bool has_meshset_id,
173 const int requested_meshset_id,
174 const std::string &lookup_meshset_name,
175 const std::string &file_name,
176 const std::string &context,
178 std::string &meshset_name) {
180 const CubitMeshSets *blockset_by_id =
nullptr;
182 if (has_meshset_id) {
184 context, &blockset_by_id);
185 meshset_id = blockset_by_id->getMeshsetId();
186 meshset_name = blockset_by_id->getName();
187 if (!lookup_meshset_name.empty() && meshset_name != lookup_meshset_name) {
190 "meshset id '" + boost::lexical_cast<std::string>(meshset_id) +
191 "' does not match meshset_name '" + lookup_meshset_name +
"'");
193 }
else if (!lookup_meshset_name.empty()) {
194 const CubitMeshSets *blockset_by_name =
nullptr;
196 file_name, context, &blockset_by_name);
197 meshset_id = blockset_by_name->getMeshsetId();
198 meshset_name = blockset_by_name->getName();
205 const std::string &file_name,
206 const std::string &context,
207 MeshsetsManager *meshsets_manager_ptr,
213 bool has_meshset_id =
false;
215 for (
const auto &item : meshset_object) {
216 const auto key = toStdString(item.key());
219 requireInt(item.value(), file_name, makeContext(context,
key));
220 has_meshset_id =
true;
223 if (
key ==
"meshset_name") {
225 requireString(item.value(), file_name, makeContext(context,
key));
230 requireString(item.value(), file_name, makeContext(context,
key));
233 if (
key ==
"attributes") {
235 requireObject(item.value(), file_name, makeContext(context,
key));
238 CHKERR failConfig(file_name, makeContext(context,
key),
"unknown meshset key");
242 CHKERR failConfig(file_name, makeContext(context,
"type"),
243 "missing meshset type");
245 if (!has_meshset_id && entry.
meshsetName.empty()) {
246 CHKERR failConfig(file_name, context,
247 "meshset requires either 'id' or 'meshset_name'");
250 if (meshsets_manager_ptr) {
251 int resolved_meshset_id = -1;
252 std::string resolved_meshset_name;
254 *meshsets_manager_ptr, has_meshset_id, entry.
meshsetId,
255 entry.
meshsetName, file_name, context, resolved_meshset_id,
256 resolved_meshset_name);
265 const std::string &mesh_context,
266 const std::string &file_name,
267 MeshsetsManager *meshsets_manager_ptr,
268 std::vector<ParsedMeshsetEntry> &parsed_meshsets) {
270 parsed_meshsets.clear();
271 parsed_meshsets.reserve(meshsets.size());
273 for (
size_t meshset_index = 0; meshset_index != meshsets.size();
275 const auto current_meshset_context =
277 const auto &meshset_object =
278 requireObject(meshsets[meshset_index], file_name, current_meshset_context);
282 meshsets_manager_ptr, entry);
283 parsed_meshsets.push_back(std::move(entry));
289 const std::string &mesh_context,
290 const std::string &file_name) {
292 std::vector<ParsedMeshsetEntry> ignored_meshsets;
299 const std::string &file_name) {
302 if (item.value().is_string()) {
306 const auto key = toStdString(item.key());
314 const std::string &file_name) {
317 if (!item.value().is_string()) {
321 const auto key = toStdString(item.key());
322 params[toLowerCopy(
key)] = requireString(
329 const int meshset_id) {
330 return {toLowerCopy(entry.
typeName), meshset_id};
334 const std::vector<ParsedMeshsetEntry> &parsed_meshsets,
337 std::set<int> &used_blockset_ids) {
339 params_by_key.clear();
340 string_params_by_key.clear();
341 used_blockset_ids.clear();
343 for (
const auto &entry : parsed_meshsets) {
344 used_blockset_ids.insert(entry.meshsetId);
347 if (params_by_key.count(param_key) || string_params_by_key.count(param_key)) {
349 file_name, entry.context,
350 "duplicate JSON meshset entry for type '" + entry.typeName +
352 boost::lexical_cast<std::string>(entry.meshsetId) +
"'");
361 const std::vector<ParsedMeshsetEntry> &parsed_meshsets,
365 for (
const auto &entry : parsed_meshsets) {
366 if (entry.appliedMeshsetId != entry.meshsetId) {
378 for (
auto it = meshsets_manager.getBegin(); it != meshsets_manager.getEnd();
380 if ((it->getBcType() & CubitBCType(
BLOCKSET)).any()) {
381 next_id = std::max(next_id, it->getMeshsetId() + 1);
388 while (meshsets_manager.checkMeshset(next_id,
BLOCKSET)) {
395 const int source_id,
const int new_id,
396 const std::string &name) {
398 const CubitMeshSets *source_meshset =
nullptr;
402 Interface &m_field = meshsets_manager.cOre;
404 CHKERR m_field.get_moab().get_entities_by_handle(source_meshset->getMeshset(),
408 if (!entities.empty()) {
409 CHKERR meshsets_manager.addEntitiesToMeshset(
BLOCKSET, new_id, entities);
415 MeshsetsManager &meshsets_manager,
416 std::vector<ParsedMeshsetEntry> &parsed_meshsets,
417 const std::string &file_name) {
420 std::map<int, int> applied_entries_by_source_id;
423 for (
auto &entry : parsed_meshsets) {
424 CHKERR ensureBlocksetExists(meshsets_manager, entry.meshsetId, file_name,
427 entry.appliedMeshsetId = entry.meshsetId;
428 auto &applied_entries = applied_entries_by_source_id[entry.meshsetId];
429 const bool make_copy = applied_entries > 0;
431 entry.appliedMeshsetId =
440 entry.appliedMeshsetId, blockset_name);
445 entry.attributes, file_name,
MoFEMErrorCode validateMeshsets(const JsonArray &meshsets, const std::string &mesh_context, const std::string &file_name)
MoFEMErrorCode getUniqueBlocksetByName(MeshsetsManager &meshsets_manager, const std::string &meshset_name, const std::string &file_name, const std::string &context, const CubitMeshSets **blockset_ptr)
MoFEMErrorCode cacheAppliedBlocksetParams(const std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name, BlocksetParamsByKey ¶ms_by_key, BlocksetStringParamsByKey &string_params_by_key)
MoFEMErrorCode applyParsedMeshsets(MeshsetsManager &meshsets_manager, std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name)
std::map< std::string, double > BlocksetParams
std::map< std::string, std::string > BlocksetStringParams
std::string meshsetAttributesContext(const ParsedMeshsetEntry &entry)
int canonicalAttributeOrder(const std::string &lower_key)
MoFEMErrorCode parseMeshsetEntry(const JsonObject &meshset_object, const std::string &file_name, const std::string &context, MeshsetsManager *meshsets_manager_ptr, ParsedMeshsetEntry &entry)
BlocksetParams getBlocksetParams(const ParsedMeshsetEntry &entry, const std::string &file_name)
std::pair< std::string, int > BlocksetParamKey
std::string appliedBlocksetName(const ParsedMeshsetEntry &entry)
MoFEMErrorCode getBlocksetById(MeshsetsManager &meshsets_manager, const int meshset_id, const std::string &file_name, const std::string &context, const CubitMeshSets **blockset_ptr)
double requireBlockAttributeValue(const JsonValue &value, const std::string &file_name, const std::string &context)
int firstGeneratedBlocksetId(MeshsetsManager &meshsets_manager)
MoFEMErrorCode cacheResolvedBlocksetParams(const std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name, BlocksetParamsByKey ¶ms_by_key, BlocksetStringParamsByKey &string_params_by_key, std::set< int > &used_blockset_ids)
std::string meshsetContext(const std::string &mesh_context, const size_t meshset_index)
BlocksetStringParams getBlocksetStringParams(const ParsedMeshsetEntry &entry, const std::string &file_name)
MoFEMErrorCode createBlocksetCopy(MeshsetsManager &meshsets_manager, const int source_id, const int new_id, const std::string &name)
int takeNextFreeBlocksetId(MeshsetsManager &meshsets_manager, int &next_id)
MoFEMErrorCode parseMeshsets(const JsonArray &meshsets, const std::string &mesh_context, const std::string &file_name, MeshsetsManager *meshsets_manager_ptr, std::vector< ParsedMeshsetEntry > &parsed_meshsets)
BlocksetParamKey getBlocksetParamKey(const ParsedMeshsetEntry &entry, const int meshset_id)
MoFEMErrorCode resolveMeshsetIdAndName(MeshsetsManager &meshsets_manager, const bool has_meshset_id, const int requested_meshset_id, const std::string &lookup_meshset_name, const std::string &file_name, const std::string &context, int &meshset_id, std::string &meshset_name)
MoFEMErrorCode applyBlockAttributes(MeshsetsManager &meshsets_manager, int id, const JsonObject &props, const std::string &file_name, const std::string &context, const std::string &blockset_name)
std::map< BlocksetParamKey, BlocksetParams > BlocksetParamsByKey
std::map< BlocksetParamKey, BlocksetStringParams > BlocksetStringParamsByKey
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
std::string sourceMeshsetName