#include <iomanip>
}
<<
"Completed " <<
stretchSteps <<
" stretch/reconstruction steps";
}
private:
struct Mesh {
};
std::array<double, 3>
scale{2, 1, .75};
int error;
CHKERR MPI_Allreduce(&local_error, &error, 1, MPI_INT, MPI_MAX,
if (error)
"Mesh stage failed on an MPI rank");
}
char file[PETSC_MAX_PATH_LEN] = "sphere.py";
sizeof(file), nullptr);
nullptr);
"hybrid_order must be positive");
"twist_degrees must be finite");
nullptr);
"stretch_steps must be positive");
for (
int d = 0;
d != 3; ++
d) {
const std::string option = std::string(
"-scale_") +
"xyz"[
d];
nullptr);
"Scaling must be positive");
}
}
auto *pc =
}
const int initial_owner = 0;
&initial_owner);
nullptr,
nullptr,
QUIET,
false,
true);
}
}
const double before =
static_cast<double>(step - 1) /
stretchSteps;
const double after =
static_cast<double>(step) /
stretchSteps;
std::array<double, 3> old_scale, new_scale;
for (
int d = 0;
d != 3; ++
d) {
old_scale[
d] = 1. + before * (
scale[
d] - 1.);
new_scale[
d] = 1. + after * (
scale[
d] - 1.);
}
const double angle_increment =
for (
auto vertex :
currentPtr->entities.subset_by_type(MBVERTEX)) {
std::array<double, 3> x;
CHKERR mb.get_coords(&vertex, 1, x.data());
for (
int d = 0;
d != 3; ++
d)
const double angle = angle_increment * x[0];
const std::array<double, 3> rotated{x[0],
c * x[1] -
s * x[2],
for (
int d = 0;
d != 3; ++
d)
x[
d] = new_scale[
d] * rotated[
d];
CHKERR mb.set_coords(&vertex, 1, x.data());
}
}
std::set<std::array<int, 4>> keys;
for (
const auto &cell :
mesh.cells) {
std::array<int, 4> ids;
for (
int d = 0;
d != 4; ++
d)
ids[
d] =
mesh.vertexIds[cell[
d]];
std::sort(ids.begin(), ids.end());
keys.insert(ids);
}
return keys;
}
std::map<std::array<int, 3>, int> incidence;
for (
const auto &cell :
mesh.cells)
for (int opposite = 0; opposite != 4; ++opposite) {
std::array<int, 3> face;
for (
int d = 0;
d != 4; ++
d)
face[
n++] =
mesh.vertexIds[cell[
d]];
std::sort(face.begin(), face.end());
++incidence[face];
}
std::set<std::array<int, 3>>
skin;
for (const auto &[face, count] : incidence)
if (count == 1)
}
->getTools()
auto changes = [](const auto &before, const auto &after) {
const auto retained =
std::count_if(before.begin(), before.end(),
[&](
const auto &
key) { return after.count(key); });
return std::make_pair(before.size() - retained,
after.size() - retained);
};
<<
"Step " << step <<
"/" <<
stretchSteps <<
": tetrahedra removed "
<<
"; skin triangles removed " <<
skin.first <<
", added "
}
}
}
CHKERR mb.get_entities_by_handle(0, geometry);
geometry = subtract(geometry, geometry.subset_by_type(MBENTITYSET));
CHKERR mb.tag_clear_data(
field.get_basic_entity_data_ptr()->th_RefBitLevel,
geometry, &no_bits);
const EntityHandle no_parent = 0;
&no_parent);
const unsigned char unshared = 0;
CHKERR mb.tag_clear_data(pc->pstatus_tag(), geometry, &unshared);
for (
auto tag : {pc->sharedp_tag(), pc->sharedps_tag(), pc->sharedh_tag(),
pc->sharedhs_tag()}) {
const auto error =
mb.tag_delete_data(
tag, geometry);
if (error != MB_SUCCESS && error != MB_TAG_NOT_FOUND)
}
Range sets = pc->interface_sets();
sets.merge(pc->partition_sets());
delete pc;
int id = -1;
pc =
new ParallelComm(&
mb,
field.get_comm(), &
id);
"Unexpected ParallelComm index after resetting sharing");
}
if (remove.empty())
CHKERR mb.get_entities_by_type(0, MBENTITYSET, sets);
for (auto set : sets)
for (int dim = 3; dim >= 0; --dim) {
const auto batch = remove.subset_by_dimension(dim);
if (!batch.empty())
}
}
auto trim_lineage = [&]() {
const auto parent_tag =
}
for (int dim = 2; dim >= 0; --dim) {
CHKERR mb.get_adjacencies(needed.subset_by_dimension(dim + 1), dim,
false,
closure, moab::Interface::UNION);
}
if (remove.empty())
};
}
if (!
mesh.sharingReady) {
auto retain = [&]() {
if (!
field.get_comm_rank())
const auto cells =
mesh.entities.subset_by_type(MBTET);
for (
auto cell :
cells) {
owned.insert(cell);
}
moab::Interface::UNION);
Range owned_faces, face_cells;
for (
auto face :
mesh.entities.subset_by_type(MBTRI)) {
owned_faces.insert(face);
}
CHKERR mb.get_adjacencies(owned_faces, 3,
false, face_cells,
moab::Interface::UNION);
halo.merge(face_cells);
halo = intersect(halo,
cells);
for (int dim : {0, 1, 2}) {
CHKERR mb.get_adjacencies(halo.subset_by_type(MBTET), dim,
false,
}
Range protected_entities = preserve;
protected_entities.merge(halo);
mesh.entities,
mesh.activeBit, protected_entities);
};
mesh.sharingReady =
true;
}
int owned = 0, invalid = 0;
for (
auto cell :
mesh.entities.subset_by_type(MBTET)) {
}
int global_owned, root_cells =
mesh.entities.num_of_type(MBTET);
CHKERR MPI_Allreduce(&owned, &global_owned, 1, MPI_INT, MPI_SUM,
CHKERR MPI_Bcast(&root_cells, 1, MPI_INT, 0,
field.get_comm());
CHKERR testing_ptr->checkValue<TestType::SCALAR>(
"root retains every owned cell", root_cells, global_owned, zero);
CHKERR testing_ptr->checkValue<TestType::SCALAR>(
"off-partition residents are ghost cells", invalid, 0, zero);
CHKERR pc->check_all_shared_handles();
}
std::vector<std::array<int, 3>> keys;
auto find_interior = [&]() {
if (
field.get_comm_rank())
const auto tets =
mesh.entities.subset_by_type(MBTET);
CHKERR mb.get_adjacencies(tets, 2,
true,
faces, moab::Interface::UNION);
const EntityHandle *conn;
std::array<int, 3> ids;
CHKERR mb.get_connectivity(face, conn,
n,
true);
CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 3, ids.data());
std::sort(ids.begin(), ids.end());
keys.push_back(ids);
}
if (keys.size() > static_cast<size_t>(INT_MAX) / 3)
"Skeleton exceeds MPI count range");
};
int count = keys.size();
CHKERR MPI_Bcast(&count, 1, MPI_INT, 0,
field.get_comm());
keys.resize(count);
CHKERR MPI_Bcast(keys.data(), 3 * count, MPI_INT, 0,
field.get_comm());
const std::set<std::array<int, 3>> interior(keys.begin(), keys.end());
auto select_skeleton = [&]() {
for (
auto face :
mesh.entities.subset_by_type(MBTRI)) {
const EntityHandle *conn;
std::array<int, 3> ids;
CHKERR mb.get_connectivity(face, conn,
n,
true);
CHKERR mb.tag_get_data(
mb.globalId_tag(), conn, 3, ids.data());
std::sort(ids.begin(), ids.end());
if (interior.count(ids))
skeleton.insert(face);
}
};
mesh.registrationChanged =
false;
}
PetscInt step = 0) {
auto &m_field =
mesh.field;
const auto &entities =
mesh.entities;
if (step)
name <<
"_" << std::setw(4) << std::setfill(
'0') << step;
const auto file =
name.str();
auto write = [&]() {
if (!distributed && m_field.get_comm_rank())
auto &
mb = m_field.get_moab();
EntityHandle selection;
CHKERR mb.create_meshset(MESHSET_SET, selection);
CHKERR mb.add_entities(selection, entities);
CHKERR mb.tag_get_handle(
"FUN3_HYBRID_COUNTS", 5, MB_TYPE_DOUBLE,
summary_tag, MB_TAG_SPARSE | MB_TAG_CREAT);
CHKERR mb.tag_set_data(summary_tag, &selection, 1,
mesh.hybrid.summary.data());
auto tag = pc->part_tag();
CHKERR mb.get_entities_by_type_and_tag(0, MBENTITYSET, &
tag,
nullptr, 1,
parts);
CHKERR mb.add_entities(selection, parts);
CHKERR mb.write_file(file.c_str(),
"MOAB",
distributed ? "PARALLEL=WRITE_PART" : "", &selection,
1);
CHKERR mb.delete_entities(&selection, 1);
};
MOFEM_LOG(
"WORLD", Sev::inform) <<
"Saved " << file;
}
};
int main(
int argc,
char *argv[]) {
&argc, &argv, nullptr,
"Sphere, partition, stretch, twist and reconstruct a mesh\n");
try {
CHKERR SDFPython::initialise();
{
CHKERR DMRegister_MoFEM(
"DMMOFEM");
}
}
return 0;
}
CGALInterfaceImpl & owner
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
bool angle
Radians between candidate face and target plane.
std::vector< int > vertices
std::vector< int > parent
bool closure
The face (f0, f1, w) closes a corner at f0 or f1.
std::vector< Cell > cells
Reusable hybrid algebra and graph validation for FUN-3.
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#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.
const double c
speed of light (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
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)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Fun3::HybridProblem hybrid
std::unique_ptr< Mesh > currentPtr
TetMeshData reconstructed
MoFEMErrorCode rebuildHybrid(Mesh &mesh, const std::string &tag)
MoFEMErrorCode deleteGeometry(const Range &remove)
MoFEMErrorCode generateSphere()
CGALTools::ImplicitMeshSettings settings
MoFEMErrorCode distributeSphere()
MoFEMErrorCode reconstructOnRoot(PetscInt step)
static auto skinKeys(const TetMeshData &mesh)
MoFEMErrorCode reconstructMesh(PetscInt step)
MoFEMErrorCode saveStage(Mesh &mesh, const char *stage, bool distributed, PetscInt step=0)
static auto cellKeys(const TetMeshData &mesh)
MoFEMErrorCode readOptions()
MoFEMErrorCode synchroniseMesh()
MoFEMErrorCode resetMeshForImport()
MoFEMErrorCode deformMesh(PetscInt step)
MoFEMErrorCode partitionSphere()
MoFEMErrorCode agree(MoFEMErrorCode local_error)
MoFEMErrorCode prepareDistributed(Mesh &mesh, const Range &preserve={})
std::array< double, 3 > scale
Retain the parent/sub-DMs, field DOFs and block storage across mesh edits.
Tag get_th_RefParentHandle() const
virtual CGALTools & getTools()=0
virtual MoFEMErrorCode importMesh(const TetMeshData &data, BitRefLevel bit, Range &entities, EntityHandle &volume, EntityHandle &surface)=0
virtual MoFEMErrorCode reconstructDelaunay(const Range &source_entities, BitRefLevel output_bit, Range &entities, CGALTools::ReconstructionMethod method=CGALTools::ReconstructionMethod::PointDelaunay)=0
MoFEMErrorCode inheritPartitions(const Range &source_entities, const Range &child_entities)
MoFEMErrorCode gatherMesh(const Range &cells, TetMeshData &data, int root=0)
MoFEMErrorCode broadcastMesh(TetMeshData &data, int root=0)
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.
Mesh refinement interface.
MoFEMErrorCode setTopologicalParents(const Range &source_entities, const Range &child_entities, const BitRefLevel &output_bit, int verb=QUIET, const std::map< EntityHandle, EntityHandle > &moved_vertices={})
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.