2 if (lower_key ==
"center_x" || lower_key ==
"x0")
4 if (lower_key ==
"center_y" || lower_key ==
"y0")
6 if (lower_key ==
"center_z" || lower_key ==
"z0")
12 const std::string &lower_key) {
13 if (lower_type ==
"fix_x" && lower_key ==
"x")
15 if (lower_type ==
"fix_y" && lower_key ==
"y")
17 if (lower_type ==
"fix_z" && lower_key ==
"z")
19 if (lower_type ==
"fix_all") {
28 if (lower_type ==
"rotate_x") {
29 if (lower_key ==
"rx")
33 if (lower_type ==
"rotate_y") {
34 if (lower_key ==
"ry")
38 if (lower_type ==
"rotate_z") {
39 if (lower_key ==
"rz")
43 if (lower_type ==
"rotate_all") {
44 if (lower_key ==
"rx")
46 if (lower_key ==
"ry")
48 if (lower_key ==
"rz")
53 if (lower_type.rfind(
"boundary_condition", 0) == 0 &&
54 (lower_key ==
"value" || lower_key ==
"potential"))
56 if (lower_type ==
"hencky" || lower_type.rfind(
"mat_elastic", 0) == 0) {
57 if (lower_key ==
"young" || lower_key ==
"young_modulus")
59 if (lower_key ==
"poisson" || lower_key ==
"poisson_ratio")
67 if (lower_key.size() < 5 || lower_key.compare(0, 4,
"user") != 0) {
72 return boost::lexical_cast<int>(lower_key.substr(4));
79 const std::string &file_name,
80 const std::string &context) {
82 return value.as_bool() ? 1.0 : 0.0;
84 return requireNumber(value, file_name, context);
88 const JsonObject &props,
89 const std::string &file_name,
90 const std::string &context,
91 const std::string &type_name,
92 const std::string &blockset_name) {
94 std::vector<double> values(MAX_MESHSET_ATTRIBUTES, 0);
96 const auto lower_type = toLowerCopy(type_name);
97 std::array<bool, MAX_MESHSET_ATTRIBUTES> used_indices{};
98 std::vector<const JsonObject::value_type *> fallback_items;
100 auto set_value = [&](
const JsonObject::value_type &item,
const int index) {
101 const auto key = toStdString(item.key());
102 if (index < 1 || index > MAX_MESHSET_ATTRIBUTES) {
104 file_name, makeContext(context,
key),
105 "User index must be between 1 and " +
106 boost::lexical_cast<std::string>(MAX_MESHSET_ATTRIBUTES));
109 item.value(), file_name, makeContext(context,
key));
110 used_indices[index - 1] =
true;
111 max_index = std::max(max_index, index);
115 for (
const auto &item : props) {
116 const auto key = toStdString(item.key());
117 const auto lower_key = toLowerCopy(
key);
123 fallback_items.push_back(&item);
126 CHKERR set_value(item, index);
129 for (
const auto *item_ptr : fallback_items) {
130 int fallback_index = 0;
131 for (
int index = 1; index <= MAX_MESHSET_ATTRIBUTES; ++index) {
132 if (!used_indices[index - 1]) {
133 fallback_index = index;
137 if (!fallback_index) {
140 "generic BLOCKSET custom attributes exhausted available User slots");
142 CHKERR set_value(*item_ptr, fallback_index);
145 values.resize(max_index);
146 CHKERR meshsets_manager.setAttributes(
BLOCKSET,
id, values, blockset_name);
151 const size_t meshset_index) {
152 return mesh_context +
".meshsets[" +
153 boost::lexical_cast<std::string>(meshset_index) +
"]";
171 return makeContext(entry.
context,
"attributes");
182 return entry.
typeName +
"_" + name +
"_" +
187 const std::string &meshset_name,
188 const std::string &file_name,
189 const std::string &context,
190 const CubitMeshSets **blockset_ptr) {
192 *blockset_ptr =
nullptr;
193 int number_of_meshsets = 0;
195 for (
auto it = meshsets_manager.getBegin(); it != meshsets_manager.getEnd();
197 if ((it->getBcType() & CubitBCType(
BLOCKSET)).none() ||
198 it->getName() != meshset_name) {
201 *blockset_ptr = &*it;
202 ++number_of_meshsets;
205 if (number_of_meshsets == 0) {
206 CHKERR failConfig(file_name, makeContext(context,
"meshset_name"),
207 "failed to resolve BLOCKSET meshset_name '" +
210 if (number_of_meshsets != 1) {
211 CHKERR failConfig(file_name, makeContext(context,
"meshset_name"),
212 "BLOCKSET meshset_name '" + meshset_name +
213 "' is not unique; resolve by explicit id");
220 const int meshset_id,
221 const std::string &file_name,
222 const std::string &context,
223 const CubitMeshSets **blockset_ptr) {
225 if (!meshsets_manager.checkMeshset(meshset_id,
BLOCKSET)) {
226 CHKERR failConfig(file_name, makeContext(context,
"id"),
227 "failed to resolve BLOCKSET id '" +
228 boost::lexical_cast<std::string>(meshset_id) +
"'");
236 const bool has_meshset_id,
237 const int requested_meshset_id,
238 const std::string &lookup_meshset_name,
239 const std::string &file_name,
240 const std::string &context,
242 std::string &meshset_name) {
244 const CubitMeshSets *blockset_by_id =
nullptr;
246 if (has_meshset_id) {
248 context, &blockset_by_id);
249 meshset_id = blockset_by_id->getMeshsetId();
250 meshset_name = blockset_by_id->getName();
251 if (!lookup_meshset_name.empty() && meshset_name != lookup_meshset_name) {
254 "meshset id '" + boost::lexical_cast<std::string>(meshset_id) +
255 "' does not match meshset_name '" + lookup_meshset_name +
"'");
257 }
else if (!lookup_meshset_name.empty()) {
258 const CubitMeshSets *blockset_by_name =
nullptr;
260 file_name, context, &blockset_by_name);
261 meshset_id = blockset_by_name->getMeshsetId();
262 meshset_name = blockset_by_name->getName();
269 const std::string &file_name,
270 const std::string &context,
271 MeshsetsManager *meshsets_manager_ptr,
277 bool has_meshset_id =
false;
279 for (
const auto &item : meshset_object) {
280 const auto key = toStdString(item.key());
283 requireInt(item.value(), file_name, makeContext(context,
key));
284 has_meshset_id =
true;
287 if (
key ==
"meshset_name") {
289 requireString(item.value(), file_name, makeContext(context,
key));
294 requireString(item.value(), file_name, makeContext(context,
key));
297 if (
key ==
"attributes") {
299 requireObject(item.value(), file_name, makeContext(context,
key));
302 CHKERR failConfig(file_name, makeContext(context,
key),
"unknown meshset key");
306 CHKERR failConfig(file_name, makeContext(context,
"type"),
307 "missing meshset type");
309 if (!has_meshset_id && entry.
meshsetName.empty()) {
310 CHKERR failConfig(file_name, context,
311 "meshset requires either 'id' or 'meshset_name'");
314 if (meshsets_manager_ptr) {
315 int resolved_meshset_id = -1;
316 std::string resolved_meshset_name;
318 *meshsets_manager_ptr, has_meshset_id, entry.
meshsetId,
319 entry.
meshsetName, file_name, context, resolved_meshset_id,
320 resolved_meshset_name);
329 const std::string &mesh_context,
330 const std::string &file_name,
331 MeshsetsManager *meshsets_manager_ptr,
332 std::vector<ParsedMeshsetEntry> &parsed_meshsets) {
334 parsed_meshsets.clear();
335 parsed_meshsets.reserve(meshsets.size());
337 for (
size_t meshset_index = 0; meshset_index != meshsets.size();
339 const auto current_meshset_context =
341 const auto &meshset_object =
342 requireObject(meshsets[meshset_index], file_name, current_meshset_context);
346 meshsets_manager_ptr, entry);
347 parsed_meshsets.push_back(std::move(entry));
353 const std::string &mesh_context,
354 const std::string &file_name) {
356 std::vector<ParsedMeshsetEntry> ignored_meshsets;
363 const std::string &file_name) {
366 const auto key = toStdString(item.key());
374 const int meshset_id) {
375 return {toLowerCopy(entry.
typeName), meshset_id};
379 const std::vector<ParsedMeshsetEntry> &parsed_meshsets,
381 std::set<int> &used_blockset_ids) {
383 params_by_key.clear();
384 used_blockset_ids.clear();
386 for (
const auto &entry : parsed_meshsets) {
387 used_blockset_ids.insert(entry.meshsetId);
394 file_name, entry.context,
395 "duplicate JSON meshset entry for type '" + entry.typeName +
397 boost::lexical_cast<std::string>(entry.meshsetId) +
"'");
404 const std::vector<ParsedMeshsetEntry> &parsed_meshsets,
407 for (
const auto &entry : parsed_meshsets) {
408 if (entry.appliedMeshsetId != entry.meshsetId) {
418 for (
auto it = meshsets_manager.getBegin(); it != meshsets_manager.getEnd();
420 if ((it->getBcType() & CubitBCType(
BLOCKSET)).any()) {
421 next_id = std::max(next_id, it->getMeshsetId() + 1);
428 while (meshsets_manager.checkMeshset(next_id,
BLOCKSET)) {
435 const int source_id,
const int new_id,
436 const std::string &name) {
438 const CubitMeshSets *source_meshset =
nullptr;
442 Interface &m_field = meshsets_manager.cOre;
444 CHKERR m_field.get_moab().get_entities_by_handle(source_meshset->getMeshset(),
448 if (!entities.empty()) {
449 CHKERR meshsets_manager.addEntitiesToMeshset(
BLOCKSET, new_id, entities);
455 MeshsetsManager &meshsets_manager,
456 std::vector<ParsedMeshsetEntry> &parsed_meshsets,
457 const std::string &file_name) {
460 std::map<int, int> applied_entries_by_source_id;
463 for (
auto &entry : parsed_meshsets) {
464 CHKERR ensureBlocksetExists(meshsets_manager, entry.meshsetId, file_name,
467 entry.appliedMeshsetId = entry.meshsetId;
468 auto &applied_entries = applied_entries_by_source_id[entry.meshsetId];
469 if (applied_entries > 0) {
471 entry.appliedMeshsetId =
474 entry.appliedMeshsetId,
480 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 applyParsedMeshsets(MeshsetsManager &meshsets_manager, std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name)
std::map< std::string, double > BlocksetParams
std::string meshsetAttributesContext(const ParsedMeshsetEntry &entry)
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)
MoFEMErrorCode cacheResolvedBlocksetParams(const std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name, BlocksetParamsByKey ¶ms_by_key, std::set< int > &used_blockset_ids)
int firstGeneratedBlocksetId(MeshsetsManager &meshsets_manager)
MoFEMErrorCode applyBlockAttributes(MeshsetsManager &meshsets_manager, int id, const JsonObject &props, const std::string &file_name, const std::string &context, const std::string &type_name, const std::string &blockset_name)
std::string meshsetContext(const std::string &mesh_context, const size_t meshset_index)
MoFEMErrorCode createBlocksetCopy(MeshsetsManager &meshsets_manager, const int source_id, const int new_id, const std::string &name)
int centerAttributeSlot(const std::string &lower_key, const int first_slot)
int takeNextFreeBlocksetId(MeshsetsManager &meshsets_manager, int &next_id)
int parseGenericBlockUserIndex(const std::string &lower_key)
MoFEMErrorCode parseMeshsets(const JsonArray &meshsets, const std::string &mesh_context, const std::string &file_name, MeshsetsManager *meshsets_manager_ptr, std::vector< ParsedMeshsetEntry > &parsed_meshsets)
MoFEMErrorCode cacheAppliedBlocksetParams(const std::vector< ParsedMeshsetEntry > &parsed_meshsets, const std::string &file_name, BlocksetParamsByKey ¶ms_by_key)
int positionalBlockAttributeSlot(const std::string &lower_type, const std::string &lower_key)
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)
std::map< BlocksetParamKey, BlocksetParams > BlocksetParamsByKey
#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.
std::string sourceMeshsetName