12constexpr int source_components = 5;
14std::vector<std::array<double, 3>> sourceCoordinates(
int rank) {
15 std::vector<std::array<double, 3>> x{{0, 0, 0}, {1, 0, 0}, {0, 1, 0},
16 {0, 0, 1}, {0, 0, 0}, {.4, .3, .2}};
26 for (
bool source : {
true,
false}) {
28 auto pc = std::make_unique<ParallelComm>(&
mb,
comm);
30 CHKERR pc->create_part(part);
32 CHKERR mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid,
33 MB_TAG_DENSE | MB_TAG_CREAT);
34 auto x = sourceCoordinates(rank);
38 v[0] = 2 * rank + .1 + .1 * (
v[0] - 2 * rank);
39 v[1] = .1 + .1 *
v[1];
40 v[2] = .1 + .1 *
v[2];
44 for (
size_t i = 0;
i != x.size(); ++
i) {
48 const int id = (
source ? 1 : 501) + 20 * rank +
i;
53 const int cell_id = (
source ? 100 : 600) + rank;
54 CHKERR mb.tag_set_data(gid, &cell, 1, &cell_id);
56 CHKERR mb.add_entities(part, &cell, 1);
59 CHKERR mb.tag_get_handle(
"INDEX_TEST", source_components, MB_TYPE_DOUBLE,
60 tag, MB_TAG_SPARSE | MB_TAG_CREAT);
65 for (
auto e : tagged) {
67 CHKERR mb.tag_get_data(gid, &e, 1, &
id);
68 std::array<double, source_components>
row;
69 for (
int c = 0;
c != source_components; ++
c)
70 row[
c] = 10. *
id +
c;
75 :
"mesh_data_transfer_target.h5m",
76 nullptr,
"PARALLEL=WRITE_PART", pc->partition_sets());
82 const char *
name,
int component) {
89 CHKERR testing.checkValue<TestType::SCALAR>(
"copied vertices",
94 CHKERR mb.tag_get_handle(GLOBAL_ID_TAG_NAME, gid);
100 "copied tag length",
n, component < 0 ? source_components : 1, {0., 0.});
102 const auto compare = [&](
double actual,
double expected) {
103 error = std::isfinite(actual) ? std::max(error, std::abs(actual - expected))
104 :
std::numeric_limits<
double>::infinity();
107 entities.merge(
cells);
108 for (
auto e : entities) {
110 CHKERR mb.tag_get_data(gid, &e, 1, &
id);
111 if (
mb.type_from_handle(e) == MBVERTEX) {
114 const auto expected = sourceCoordinates(
id / 20).at(
id % 20 - 1);
115 for (
int d = 0;
d != 3; ++
d)
116 compare(x[
d], expected[
d]);
118 std::array<double, source_components> value;
120 "untagged entity remains untagged",
121 mb.tag_get_data(
tag, &e, 1, value.data()), MB_TAG_NOT_FOUND,
126 std::vector<double> value(
n);
128 for (
int c = 0;
c !=
n; ++
c)
129 compare(value[
c], 10. *
id + (component < 0 ?
c : component));
130 std::array<double, source_components> original;
132 for (
int c = 0;
c != source_components; ++
c)
133 compare(original[
c], 10. *
id +
c);
136 "exact tag copy and preserved source", error, 0., {0., 0.});
143 CHKERR mb.load_file(nodal ?
"mesh_data_transfer_component.h5m"
144 :
"mesh_data_transfer_cell_component.h5m");
147 CHKERR mb.tag_get_handle(GLOBAL_ID_TAG_NAME, gid);
150 CHKERR testing.checkValue<TestType::SCALAR>(
"transferred scalar length",
n,
153 CHKERR mb.get_entities_by_type(0, nodal ? MBVERTEX : MBTET, entities);
155 "transferred entities", entities.size(), nodal ? 8. : 2., {0., 0.});
157 for (
auto e : entities) {
158 double value, expected;
163 const int rank =
static_cast<int>(x[0] / 2.);
165 200. * rank + 10. * (1. + x[0] - 2 * rank + 2 * x[1] + 3 * x[2]) + 4.;
168 CHKERR mb.tag_get_data(gid, &e, 1, &
id);
169 expected = 10. * (100 +
id - 600);
171 error = std::isfinite(value) ? std::max(error, std::abs(value - expected))
172 :
std::numeric_limits<
double>::infinity();
175 "selected-component interpolation", error, 1., {1.e-11, 0.});
180int main(
int argc,
char **argv) {
182 "Mesh tag transfer file fixtures\n");
186 std::unique_ptr<TestingInterface> owned_testing(
188 CHKERR owned_testing->addTestCommandLine(
189 "", 1,
"prepare", [&]() {
return prepare(PETSC_COMM_WORLD); });
190 CHKERR owned_testing->addTestCommandLine(
"", 2,
"copy", [&]() {
191 return checkCopy(*owned_testing,
"mesh_data_transfer_copy.h5m",
194 CHKERR owned_testing->addTestCommandLine(
"", 3,
"extract", [&]() {
195 return checkCopy(*owned_testing,
"mesh_data_transfer_extract.h5m",
198 CHKERR owned_testing->addTestCommandLine(
"", 4,
"alias", [&]() {
199 return checkCopy(*owned_testing,
"mesh_data_transfer_alias.h5m",
202 CHKERR owned_testing->addTestCommandLine(
203 "", 5,
"nodal", [&]() {
return checkTransfer(*owned_testing,
true); });
204 CHKERR owned_testing->addTestCommandLine(
205 "", 6,
"cell", [&]() {
return checkTransfer(*owned_testing,
false); });
206 CHKERR owned_testing->addTestCommandLine(
"", 7,
"parallel_copy", [&]() {
207 return checkCopy(*owned_testing,
"mesh_data_transfer_parallel.h5m",
210 CHKERR owned_testing->runTests();
std::vector< int > source
std::vector< int > vertices
std::vector< Cell > cells
std::vector< FieldBitNumber > row
#define CATCH_ERRORS
Catch errors.
#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
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
TestingInterface * createInterface< TestingInterface >(const Core &core)
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.