10 const Range &target_elements) {
12 if (source_file.empty())
14 "Environmental tag transfer requires a source mesh file");
20 target.elements = target_elements;
22 CHKERR mb.get_entities_by_handle(0, before);
25 const auto apply = [&]() {
27 std::vector<CouplerInterface::TagMap> maps;
28 const auto load = [&]() {
34 CHKERR metadata.load_file(source_file.c_str());
35 std::vector<Tag> tags;
36 CHKERR metadata.tag_get_tags(tags);
37 const std::regex environmental(
38 "MED_(IRRA_ALLIRRA|TEMP_ALLNEUT|CORR_ALLNEUT)_[0-9]+");
39 for (
auto tag : tags) {
42 if (!std::regex_match(
name, environmental))
50 "Environmental tag %s must contain one double per node",
58 "No Amentum environmental snapshot tags in %s",
60 std::sort(maps.begin(), maps.end(), [](
const auto &
a,
const auto &b) {
61 return a.sourceTag < b.sourceTag;
64 CHKERR mb.create_meshset(MESHSET_SET, root);
66 const EntityHandle root_set = 0;
69 CHKERR mb.tag_get_handle(
"_MoFEMBuild", 1, MB_TYPE_INTEGER, build_tag);
70 CHKERR mb.tag_get_data(build_tag, &root_set, 1, &build_state);
71 const auto load_error =
mb.load_file(source_file.c_str(), &root);
72 const auto restore_error =
73 mb.tag_set_data(build_tag, &root_set, 1, &build_state);
76 CHKERR mb.get_entities_by_dimension(root, 3,
source.elements,
true);
79 const int local_error = load();
81 CHKERR MPI_Allreduce(&local_error, &global_error, 1, MPI_INT, MPI_MAX,
85 "Could not load environmental tag source %s",
99 <<
"Transferred " << maps.size() <<
" environmental snapshot tags from "
103 const auto error = apply();
104 const auto close_error = coupler->destroyTransfer(
transfer);
106 CHKERR mb.get_entities_by_handle(0, after);
107 const auto imported = subtract(after, before);
108 const auto cleanup = [&]() {
110 CHKERR mb.delete_entities(imported.subset_by_type(MBENTITYSET));
113 for (
int dim = 3; dim >= 0; --dim)
114 CHKERR mb.delete_entities(imported.subset_by_dimension(dim));
117 const auto cleanup_error = cleanup();