10using PointMap = std::map<int, std::array<double, 3>>;
11using CellKey = std::array<int, 4>;
14 std::set<CellKey>
cells;
15 std::set<std::array<int, 3>>
skin;
19Snapshot read(
const char *file, PetscInt
order,
bool require_positive =
true) {
23 std::map<std::array<int, 3>,
int> incidence;
29 std::array<double, 3> x;
34 "Duplicate or missing vertex ID");
36 for (
auto cell :
cells) {
37 const EntityHandle *conn;
47 std::array<double, 3>
a, b,
c;
48 for (
int d = 0;
d != 3; ++
d) {
53 const double det =
a[0] * (b[1] *
c[2] - b[2] *
c[1]) -
54 a[1] * (b[0] *
c[2] - b[2] *
c[0]) +
55 a[2] * (b[0] *
c[1] - b[1] *
c[0]);
56 std::sort(ids.begin(), ids.end());
57 if ((require_positive && det <= 0) || !
result.
cells.insert(ids).second)
59 "Nonpositive or duplicate cell");
61 for (
int opposite = 0; opposite != 4; ++opposite) {
62 std::array<int, 3> face;
64 for (
int d = 0;
d != 4; ++
d)
70 for (
const auto &[face, count] : incidence)
76 "Hybrid stage summary");
79 nullptr, 1, summaries),
80 "Hybrid summary meshsets");
81 if (summaries.empty())
83 std::map<std::array<int, 3>, std::set<std::array<int, 3>>> graph;
85 std::vector<std::array<int, 3>> interior;
86 for (
int opposite = 0; opposite != 4; ++opposite) {
87 std::array<int, 3> face;
89 for (
int d = 0;
d != 4; ++
d)
92 if (incidence.at(face) == 2)
93 interior.push_back(face);
95 for (
const auto &face : interior)
96 graph[face].insert(interior.begin(), interior.
end());
98 for (
auto set : summaries) {
99 std::array<double, 5> data;
101 "Hybrid stage counts");
104 "Checkpoint hybrid order differs from requested order");
106 const double block_rows =
110 const double schur_rows = graph.size() * face_dofs;
112 for (
const auto &[face, neighbors] : graph)
113 nnz += face_dofs * face_dofs * neighbors.
size();
114 if (data[1] != block_rows + schur_rows || data[2] != block_rows ||
115 data[3] != schur_rows || data[4] != nnz)
117 "Hybrid algebra does not match checkpoint topology");
122Snapshot readStep(
const char *stage, PetscInt step, PetscInt
order,
123 bool require_positive =
true) {
124 std::ostringstream
name;
125 name << stage <<
"_" << std::setw(4) << std::setfill(
'0') << step <<
".h5m";
126 return read(
name.str().c_str(),
order, require_positive);
133 PetscInt hybrid_order = 2;
134 double twist_degrees = 60;
135 std::array<double, 3>
scale{2, 1, .75};
142 for (
int d = 0;
d != 3; ++
d) {
143 const std::string option = std::string(
"-scale_") +
"xyz"[
d];
147 const auto sphere = read(
"01_sphere.h5m", hybrid_order);
148 const auto partitioned = read(
"02_partitioned.h5m", hybrid_order);
149 auto previous = read(
"03_distributed.h5m", hybrid_order);
154 "Partitioning or deletion changed source topology/IDs");
155 int changes = 0, subsequent_changes = 0;
156 int surface_changes = 0, subsequent_surface_changes = 0;
157 for (PetscInt step = 1; step <= steps; ++step) {
160 const auto stretched = readStep(
"04_ellipsoid", step, hybrid_order,
false);
161 const auto reconstructed = readStep(
"05_reconstructed", step, hybrid_order);
162 auto synchronised = readStep(
"06_synchronised", step, hybrid_order);
163 if (
previous.cells != stretched.cells ||
164 stretched.points != reconstructed.points ||
165 stretched.points != synchronised.points ||
166 reconstructed.cells != synchronised.cells ||
167 reconstructed.skin != synchronised.skin ||
168 stretched.points.size() !=
sphere.points.size())
170 "A stretch/reconstruction step lost vertex identity or topology");
171 const double fraction =
static_cast<double>(step) / steps;
172 std::array<double, 3> axis_scale;
173 double volume_scale = 1;
174 for (
int d = 0;
d != 3; ++
d) {
175 axis_scale[
d] = 1. + fraction * (
scale[
d] - 1.);
176 volume_scale *= axis_scale[
d];
180 .5 * twist_degrees * std::acos(-1.) / 180. * fraction * original[0];
181 const std::array<double, 3> rotated{
183 std::cos(
angle) * original[1] - std::sin(
angle) * original[2],
184 std::sin(
angle) * original[1] + std::cos(
angle) * original[2]};
185 for (
int d = 0;
d != 3; ++
d) {
186 const double expected = axis_scale[
d] * rotated[
d];
187 if (std::abs(stretched.points.at(
id)[
d] - expected) >
188 1e-12 * (1. + std::abs(expected)))
190 "Incremental stretch/twist reached the wrong coordinates");
195 const double expected_volume =
sphere.volume * volume_scale;
196 if (std::abs(reconstructed.volume - expected_volume) >
197 .05 * expected_volume)
199 "Reconstructed volume is inconsistent with the ellipsoid");
200 if (stretched.skin != reconstructed.skin) {
203 ++subsequent_surface_changes;
205 if (stretched.cells != reconstructed.cells) {
208 ++subsequent_changes;
212 if (!changes || (steps > 1 && !subsequent_changes))
214 "The stretching fixture did not produce successive connectivity "
216 if (twist_degrees != 0 &&
217 (!surface_changes || (steps > 1 && !subsequent_surface_changes)))
219 "The twist fixture did not change the surface skin");
220 if (twist_degrees == 0 && subsequent_surface_changes)
222 "Affine stretching unexpectedly changed the convex-hull skin");
224 <<
"Verified " << steps <<
" checkpoint steps, " << changes
225 <<
" with connectivity changes, " << surface_changes
226 <<
" with skin changes";
231int main(
int argc,
char *argv[]) {
const std::vector< Vec > * points
bool angle
Radians between candidate face and target plane.
std::vector< int > vertices
std::vector< Cell > cells
std::map< EntityHandle, std::pair< bool, std::vector< double > > > previous
#define CATCH_ERRORS
Catch errors.
#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 ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_ATOM_TEST_INVALID
#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.
#define NBFACETRI_L2(P)
Number of base functions on triangle for L2 space.
#define NBVOLUMETET_DEMKOWICZ_HDIV(P)
#define NBFACETRI_DEMKOWICZ_HDIV(P)
#define NBVOLUMETET_L2(P)
Number of base functions on tetrahedron for L2 space.
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
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
MoFEMErrorCode run(MoFEM::Interface &m_field)
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.
Deprecated interface functions.
std::vector< std::array< int, 4 > > cells
Zero-based point indices.
std::vector< std::array< double, 3 > > points
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.