Interpolate every MED environmental snapshot onto target corner nodes.
10 {
12 if (source_file.empty())
14 "Environmental tag transfer requires a source mesh file");
15
18 source.parallelCommId = -1;
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 = [&]() {
30
31
32 {
33 moab::Core metadata;
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))
43 continue;
50 "Environmental tag %s must contain one double per node",
52 maps.push_back(
54 }
55 }
56 if (maps.empty())
58 "No Amentum environmental snapshot tags in %s",
59 source_file.c_str());
60 std::sort(maps.begin(), maps.end(), [](
const auto &
a,
const auto &b) {
61 return a.sourceTag < b.sourceTag;
62 });
63 EntityHandle root;
64 CHKERR mb.create_meshset(MESHSET_SET, root);
65
66 const EntityHandle root_set = 0;
68 int build_state;
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);
78 };
79 const int local_error = load();
80 int global_error;
81 CHKERR MPI_Allreduce(&local_error, &global_error, 1, MPI_INT, MPI_MAX,
83 if (global_error)
85 "Could not load environmental tag source %s",
86 source_file.c_str());
87
88 CouplerInterface::Options options;
92 options.absoluteTolerance = 5.e-10;
95 CouplerInterface::Report
report;
99 << "Transferred " << maps.size() << " environmental snapshot tags from "
100 << source_file <<
" to " <<
report.globalLocated <<
" mesh vertices";
102 };
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));
111
112
113 for (int dim = 3; dim >= 0; --dim)
114 CHKERR mb.delete_entities(imported.subset_by_dimension(dim));
116 };
117 const auto cleanup_error = cleanup();
122}
std::vector< int > source
MoFEMErrorCode transfer(const std::string &source_file, const Range &target_elements)
#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.
#define MOFEM_LOG(channel, severity)
Log.
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual boost::shared_ptr< BasicEntityData > & get_basic_entity_data_ptr()=0
Get pointer to basic entity data.
boost::shared_ptr< const Locations > LocationsPtr
boost::shared_ptr< Transfer > TransferPtr
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.