v0.16.3
Loading...
Searching...
No Matches
mofem/atom_tests/rebuild_problem_hybrid.cpp

Build a hybridised broken H(div) problem on uniformly refined levels and time its problem, sub-problems and matrices.

Build a hybridised broken H(div) problem on uniformly refined levels and time its problem, sub-problems and matrices.Fields, as in test_broken_space.cpp: BROKEN (broken H(div)) and U (L2) on the interior, HYBRID (L2) on the skeleton; the domain element carries BROKEN and U, the skeleton element BROKEN and HYBRID through the skeleton adjacency. At every level, after the uniform refinement of the previous one, the test times and checks:

  1. incremental field and element registration on new tetrahedra and skeleton faces (or Simple's all-entities builders);
  2. the parent problem (adjacencies and DMSetUp through Simple::reSetUp);
  3. the SCHUR sub-problem, HYBRID only on both elements, and the BLOCK sub-problem, BROKEN and U;
  4. the block matrix of the parent (createBlockMatStructure and createBlockMat) and the nested Schur matrix on the two sub-problems;
  5. the hybridised L2 matrix of the SCHUR sub-problem (MatrixManager::createHybridL2MPIAIJ through createDMHybridisedL2Matrix), the Schur complement's pattern.

DOF counts are checked against the entity counts and the per-entity DOF numbers of the bases; every stage is a TestingInterface test. Options: -file_name, -nb_levels, -order (BROKEN order; U and HYBRID one less), -dm_is_partitioned, -incremental (default true; false uses Simple's all-entities field/element builders), -local_from <l> (from level l on, refine only the tetrahedra with an edge in the star of one vertex, which keeps the mesh conforming), -rebuild_structures (from level 1 on, update the block and nested structures of the previous level with rebuildBlockMatStructure and rebuildSchurNestedMatrixStruture, and check them against new ones made by createBlockMatStructure and createSchurNestedMatrixStruture). Hybrid preallocation is checked against the couplings of skeleton faces sharing an active tetrahedron, then filled with new allocations forbidden and checked for a diagonal.

/** \file rebuild_problem_hybrid.cpp
* \example mofem/atom_tests/rebuild_problem_hybrid.cpp
* \brief Build a hybridised broken H(div) problem on uniformly refined
* levels and time its problem, sub-problems and matrices.
*
* Fields, as in test_broken_space.cpp: BROKEN (broken H(div)) and U (L2) on
* the interior, HYBRID (L2) on the skeleton; the domain element carries
* BROKEN and U, the skeleton element BROKEN and HYBRID through the skeleton
* adjacency. At every level, after the uniform refinement of the previous
* one, the test times and checks:
*
* 1. incremental field and element registration on new tetrahedra and
* skeleton faces (or Simple's all-entities builders);
* 2. the parent problem (adjacencies and DMSetUp through Simple::reSetUp);
* 3. the SCHUR sub-problem, HYBRID only on both elements, and the BLOCK
* sub-problem, BROKEN and U;
* 4. the block matrix of the parent (createBlockMatStructure and
* createBlockMat) and the nested Schur matrix on the two sub-problems;
* 5. the hybridised L2 matrix of the SCHUR sub-problem
* (MatrixManager::createHybridL2MPIAIJ through
* createDMHybridisedL2Matrix), the Schur complement's pattern.
*
* DOF counts are checked against the entity counts and the per-entity DOF
* numbers of the bases; every stage is a TestingInterface test. Options:
* -file_name, -nb_levels, -order (BROKEN order; U and HYBRID one less),
* -dm_is_partitioned, -incremental (default true; false uses Simple's
* all-entities field/element builders), -local_from <l> (from level l on,
* refine only the tetrahedra with an edge in the star of one vertex, which
* keeps the mesh conforming), -rebuild_structures (from level 1 on, update
* the block and nested structures of the previous level with
* rebuildBlockMatStructure and rebuildSchurNestedMatrixStruture, and check
* them against new ones made by createBlockMatStructure and
* createSchurNestedMatrixStruture). Hybrid preallocation is checked
* against the couplings of skeleton faces sharing an active tetrahedron,
* then filled with new allocations forbidden and checked for a diagonal.
*/
#include <MoFEM.hpp>
#include <unordered_map>
using namespace MoFEM;
static char help[] = "Hybridised broken H(div) problem on refined levels: "
"problem, sub-problem and matrix timings.\n"
"-file_name <mesh> -nb_levels <n> -order <p> "
"[-incremental true|false] [-local_from <l>] "
"[-rebuild_structures]\n\n";
namespace {
inline BitRefLevel bit(int l) { return BitRefLevel().set(l); }
inline BitRefLevel allBits() { return BitRefLevel().set(); }
/// Timings of one level, seconds.
struct Timings {
double registration = 0, problem = 0, schurSub = 0, blockSub = 0,
blockMat = 0, nestedSchur = 0, hybridMat = 0;
};
MoFEMErrorCode time(std::function<MoFEMErrorCode()> fn, double &seconds) {
PetscLogDouble t0, t1;
CHKERR PetscTime(&t0);
CHKERR fn();
CHKERR PetscTime(&t1);
seconds = t1 - t0;
}
/// Refine the tetrahedra of level l-1 onto level l and put the children into
/// Simple's meshset. Uniformly, or locally: the edges of the star of one
/// vertex are split, and every tetrahedron with a split edge is refined, so
/// the mesh stays conforming; the other tetrahedra and their faces, edges
/// and vertices join level l unchanged.
MoFEMErrorCode refineLevel(MoFEM::Interface &m_field, Simple &simple, int l,
bool local, int &refined) {
auto bit_mng = m_field.getInterface<BitRefManager>();
auto &moab = m_field.get_moab();
Range level_tets;
CHKERR bit_mng->getEntitiesByDimAndRefLevel(bit(l - 1), allBits(), 3,
level_tets);
Range tets = level_tets, edges;
if (local) {
Range verts;
CHKERR moab.get_connectivity(level_tets, verts, true);
const EntityHandle vertex = verts.front();
Range star;
CHKERR moab.get_adjacencies(&vertex, 1, 3, false, star);
star = intersect(star, level_tets);
CHKERR moab.get_adjacencies(star, 1, true, edges, moab::Interface::UNION);
Range touched;
CHKERR moab.get_adjacencies(edges, 3, false, touched,
moab::Interface::UNION);
tets = intersect(touched, level_tets);
} else {
CHKERR moab.get_adjacencies(tets, 1, true, edges, moab::Interface::UNION);
}
refined = tets.size();
auto refine = m_field.getInterface<MeshRefinement>();
CHKERR refine->refineTets(tets, bit(l));
if (local) {
const Range unchanged = subtract(level_tets, tets);
Range adj;
CHKERR moab.get_connectivity(unchanged, adj, true);
for (auto d : {1, 2})
CHKERR moab.get_adjacencies(unchanged, d, false, adj,
moab::Interface::UNION);
CHKERR bit_mng->addBitRefLevel(unchanged, bit(l));
CHKERR bit_mng->addBitRefLevel(adj, bit(l));
}
// Simple registers fields and elements from its meshset, which is the root
// set after loadFile, so the children are already in it; a user meshset
// would need its children added.
if (simple.getMeshset() != 0)
CHKERR bit_mng->updateMeshsetByEntitiesChildren(
simple.getMeshset(), bit(l), simple.getMeshset(), MBTET, true);
}
/// Skeleton of level l: its faces without the skin of its tetrahedra.
MoFEMErrorCode setSkeleton(MoFEM::Interface &m_field, Simple &simple, int l,
int &nb_skeleton_faces) {
auto &moab = m_field.get_moab();
auto bit_mng = m_field.getInterface<BitRefManager>();
Range tets, faces;
CHKERR bit_mng->getEntitiesByDimAndRefLevel(bit(l), allBits(), 3, tets);
CHKERR moab.get_adjacencies(tets, 2, true, faces, moab::Interface::UNION);
Skinner skinner(&moab);
CHKERR skinner.find_skin(0, tets, false, skin);
const Range skeleton = subtract(faces, skin);
const EntityHandle meshset = simple.getSkeletonMeshSet();
CHKERR moab.clear_meshset(&meshset, 1);
CHKERR moab.add_entities(meshset, skeleton);
nb_skeleton_faces = skeleton.size();
}
/// Register and build only entities not already in the corresponding field.
MoFEMErrorCode registerLevel(MoFEM::Interface &m_field, Simple &simple, int l,
int order, bool incremental) {
if (!incremental) {
CHKERR simple.buildFields();
CHKERR simple.buildFiniteElements();
}
auto &moab = m_field.get_moab();
Range tets, faces, registered;
CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByDimAndRefLevel(
bit(l), allBits(), 3, tets);
CHKERR moab.get_entities_by_handle(m_field.get_field_meshset("BROKEN"),
registered);
tets = subtract(tets, registered);
CHKERR moab.get_entities_by_handle(simple.getSkeletonMeshSet(), faces);
registered.clear();
CHKERR moab.get_entities_by_handle(m_field.get_field_meshset("HYBRID"),
registered);
faces = subtract(faces, registered);
auto comm_ptr = m_field.getInterface<CommInterface>();
for (const auto &field : {"BROKEN", "U"}) {
CHKERR comm_ptr->synchroniseFieldEntities(field, 0);
tets, field, std::string(field) == "BROKEN" ? order : order - 1);
}
CHKERR m_field.add_ents_to_field_by_dim(faces, 2, "HYBRID");
CHKERR comm_ptr->synchroniseFieldEntities("HYBRID", 0);
CHKERR m_field.set_field_order(faces, "HYBRID", order - 1);
Range new_ents = tets;
new_ents.merge(faces);
CHKERR m_field.build_fields(new_ents);
simple.getDomainFEName());
simple.getSkeletonFEName());
CHKERR m_field.build_finite_elements(simple.getDomainFEName(), &tets);
CHKERR m_field.build_finite_elements(simple.getSkeletonFEName(), &faces);
}
/// Independent element-wise oracle for the hybrid matrix's preallocation.
MoFEMErrorCode checkHybridMatrix(MoFEM::Interface &m_field, DM dm, int l,
Mat matrix, TestingInterface &testing,
const std::string &tag, double &nonzeros) {
const Problem *problem_ptr;
CHKERR DMMoFEMGetProblemPtr(dm, &problem_ptr);
std::unordered_map<EntityHandle, std::vector<PetscInt>> face_dofs;
for (auto &dof : *problem_ptr->getNumeredColDofsPtr())
if (dof->getPetscGlobalDofIdx() >= 0)
face_dofs[dof->getEnt()].push_back(dof->getPetscGlobalDofIdx());
// Every active cell couples all its skeleton faces, including each face
// with itself. Deduplication accounts for a face belonging to two cells.
std::unordered_map<EntityHandle, std::vector<PetscInt>> neighbors;
Range tets;
CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByDimAndRefLevel(
bit(l), allBits(), 3, tets);
for (auto tet : tets) {
CHKERR m_field.get_moab().get_adjacencies(&tet, 1, 2, false, faces);
std::vector<PetscInt> columns;
for (auto face : faces) {
auto it = face_dofs.find(face);
if (it != face_dofs.end())
columns.insert(columns.end(), it->second.begin(), it->second.end());
}
for (auto face : faces)
if (face_dofs.count(face)) {
auto &adj = neighbors[face];
adj.insert(adj.end(), columns.begin(), columns.end());
}
}
PetscInt first_row, last_row;
CHKERR MatGetOwnershipRange(matrix, &first_row, &last_row);
MatInfo before;
CHKERR MatGetInfo(matrix, MAT_GLOBAL_SUM, &before);
CHKERR MatSetOption(matrix, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE);
double local_nnz = 0;
for (auto &entry : neighbors) {
auto &columns = entry.second;
std::sort(columns.begin(), columns.end());
columns.erase(std::unique(columns.begin(), columns.end()), columns.end());
const PetscInt nb_cols = columns.size();
const std::vector<PetscScalar> values(nb_cols, 1.);
for (auto row : face_dofs.at(entry.first))
if (row >= first_row && row < last_row) {
local_nnz += nb_cols;
CHKERR MatSetValues(matrix, 1, &row, nb_cols, columns.data(),
values.data(), INSERT_VALUES);
}
}
double expected_nnz;
CHKERR MPI_Allreduce(&local_nnz, &expected_nnz, 1, MPI_DOUBLE, MPI_SUM,
m_field.get_comm());
const auto zero = TestingInterface::Tolerance{0, 0};
CHKERR testing.checkValue<TestType::SCALAR>(
tag + " hybrid allocation equals topology non-zeros", before.nz_allocated,
expected_nnz, zero);
CHKERR MatAssemblyBegin(matrix, MAT_FINAL_ASSEMBLY);
CHKERR MatAssemblyEnd(matrix, MAT_FINAL_ASSEMBLY);
MatInfo after;
CHKERR MatGetInfo(matrix, MAT_GLOBAL_SUM, &after);
nonzeros = after.nz_used;
CHKERR testing.checkValue<TestType::SCALAR>(
tag + " hybrid filled non-zeros equal topology", nonzeros, expected_nnz,
zero);
CHKERR testing.checkValue<TestType::SCALAR>(
tag + " hybrid fill without reallocations", after.mallocs, before.mallocs,
zero);
PetscBool missing;
PetscInt missing_row;
CHKERR MatMissingDiagonal(matrix, &missing, &missing_row);
CHKERR testing.checkValue<TestType::SCALAR>(
tag + " hybrid diagonal exists in every row", missing ? 1 : 0, 0, zero);
}
const std::string &name,
const std::vector<std::string> &fields,
dm = createDM(m_field.get_comm(), "DMMOFEM");
CHKERR DMMoFEMCreateSubDM(dm, simple.getDM(), name.c_str());
CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
CHKERR DMMoFEMAddElement(dm, simple.getDomainFEName());
CHKERR DMMoFEMAddElement(dm, simple.getSkeletonFEName());
for (auto &field : fields) {
CHKERR DMMoFEMAddSubFieldRow(dm, field);
CHKERR DMMoFEMAddSubFieldCol(dm, field);
}
CHKERR DMSetUp(dm);
}
int problemRows(MoFEM::Interface &m_field, DM dm) {
const Problem *prb;
CHK_THROW_MESSAGE(DMMoFEMGetProblemPtr(dm, &prb), "problem of DM");
return prb->getNbDofsRow();
}
} // namespace
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
auto *simple = m_field.getInterface<Simple>();
CHKERR DMRegister_MoFEM("DMMOFEM");
PetscInt nb_levels = 2, order = 2;
PetscBool is_partitioned = PETSC_FALSE, incremental = PETSC_TRUE;
PetscBool rebuild_structures = PETSC_FALSE;
PetscInt local_from = -1;
CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-nb_levels", &nb_levels,
PETSC_NULLPTR);
CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-order", &order,
PETSC_NULLPTR);
CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-dm_is_partitioned",
&is_partitioned, PETSC_NULLPTR);
CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-incremental", &incremental,
PETSC_NULLPTR);
CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-rebuild_structures",
&rebuild_structures, PETSC_NULLPTR);
CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-local_from", &local_from,
PETSC_NULLPTR);
if (order < 1)
SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "-order must be >= 1");
const int u_order = order - 1;
const int hybrid_order = order - 1;
CHKERR simple->getOptions();
simple->getAddBoundaryFE() = false;
CHKERR simple->loadFile();
if (simple->getDim() != 3)
SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
"Tetrahedral meshes only");
CHKERR simple->addDomainBrokenField("BROKEN", HDIV, base, 1);
CHKERR simple->addDomainField("U", L2, base, 1);
CHKERR simple->addSkeletonField("HYBRID", L2, base, 1);
CHKERR simple->setFieldOrder("BROKEN", order);
CHKERR simple->setFieldOrder("U", u_order);
CHKERR simple->setFieldOrder("HYBRID", hybrid_order);
CHKERR simple->defineFiniteElements();
// Simple's skeleton adjacency also reaches the DOFs of the parent cells
// of the bridge cells (for hanging nodes); each level here is a complete
// mesh, so the skeleton element sees its two bridge cells only.
simple->getBitAdjParent() = BitRefLevel();
CHKERR simple->setSkeletonAdjacency(-1, simple->getSkeletonFEName());
CHKERR simple->defineProblem(is_partitioned);
MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
MOFEM_LOG("WORLD", Sev::inform)
<< "Levels " << nb_levels << ", BROKEN order " << order
<< ", U and HYBRID order " << u_order << ", "
<< (is_partitioned ? "distributed" : "replicated") << " builder, "
<< (incremental ? "incremental" : "full")
<< " field/element registration"
<< (local_from >= 0 ? ", local refinement from level " +
std::to_string(local_from)
: std::string())
<< (rebuild_structures ? ", block and nested structures rebuilt"
: "");
// DOFs per entity for the bases used.
const int dofs_broken_per_tet = 4 * NBFACETRI_DEMKOWICZ_HDIV(order) +
const int dofs_u_per_tet = NBVOLUMETET_L2(u_order);
const int dofs_hybrid_per_face = NBFACETRI_L2(hybrid_order);
auto zero = TestingInterface::Tolerance{0, 0};
auto count_tets = [&](int l) {
Range tets;
bit(l), allBits(), 3, tets),
"count tets");
return static_cast<int>(tets.size());
};
// elements and field pairs of the block matrix
const SchurFEOpsFEandFields block_ops = {
{simple->getDomainFEName(),
{{"BROKEN", "BROKEN"},
{"U", "U"},
{"BROKEN", "U"},
{"U", "BROKEN"}}},
{simple->getSkeletonFEName(),
{{"BROKEN", "HYBRID"}, {"HYBRID", "BROKEN"}}}};
// structures kept from level to level with -rebuild_structures
boost::shared_ptr<BlockStructure> kept_block;
boost::shared_ptr<NestSchurData> kept_nested;
struct Level {
SmartPetscObj<DM> schurDM, blockDM;
SmartPetscObj<Mat> blockMat, nestedMat, hybridMat;
boost::shared_ptr<BlockStructure> blockData;
boost::shared_ptr<NestSchurData> nestedData;
Timings t;
int tets = 0, skeletonFaces = 0, rows = 0, schurRows = 0, blockRows = 0;
double hybridNnz = 0;
};
std::vector<Level> levels(nb_levels + 1);
for (int l = 0; l <= nb_levels; ++l) {
const auto tag = "level " + std::to_string(l);
auto &lv = levels[l];
CHKERR testing->addTest(10 * l + 1, tag + " refine and register", [&, l,
tag]() {
const bool local = l > 0 && local_from >= 0 && l >= local_from;
int refined = 0;
if (l > 0)
CHKERR refineLevel(m_field, *simple, l, local, refined);
CHKERR setSkeleton(m_field, *simple, l, lv.skeletonFaces);
lv.tets = count_tets(l);
simple->getBitRefLevel() = bit(l);
CHKERR time(
[&]() {
return registerLevel(m_field, *simple, l, order, incremental);
},
lv.t.registration);
if (l > 0 && !local)
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " tets are eight per parent", lv.tets,
8. * levels[l - 1].tets, zero);
if (local) {
MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
MOFEM_LOG("WORLD", Sev::inform)
<< "Level " << l << " local refinement of " << refined << " of "
<< levels[l - 1].tets << " tets";
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " local refinement leaves tets unchanged",
refined < levels[l - 1].tets ? 1 : 0, 1, zero);
}
});
CHKERR testing->addTest(10 * l + 2, tag + " problem", [&, l, tag]() {
// Adjacencies on the level, the problem selector set to the level
// and DMSetUp of the parent; previous levels' sub-problems are gone.
CHKERR time([&]() { return simple->reSetUp(true); }, lv.t.problem);
lv.rows = problemRows(m_field, simple->getDM());
const double expected =
double(lv.tets) * (dofs_broken_per_tet + dofs_u_per_tet) +
double(lv.skeletonFaces) * dofs_hybrid_per_face;
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " parent dofs = BROKEN + U + HYBRID", lv.rows, expected,
zero);
});
CHKERR testing->addTest(10 * l + 3, tag + " sub-problems", [&, l,
tag]() {
CHKERR time(
[&]() {
return subProblem(m_field, *simple, "SCHUR", {"HYBRID"},
lv.schurDM);
},
lv.t.schurSub);
CHKERR time(
[&]() {
return subProblem(m_field, *simple, "BLOCK", {"BROKEN", "U"},
lv.blockDM);
},
lv.t.blockSub);
lv.schurRows = problemRows(m_field, lv.schurDM);
lv.blockRows = problemRows(m_field, lv.blockDM);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " SCHUR dofs = HYBRID", lv.schurRows,
double(lv.skeletonFaces) * dofs_hybrid_per_face, zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " BLOCK + SCHUR dofs = parent", lv.blockRows + lv.schurRows,
lv.rows, zero);
});
CHKERR testing->addTest(10 * l + 4, tag + " block and nested Schur "
"matrices",
[&, l, tag]() {
const bool rebuild = rebuild_structures && kept_block && kept_nested;
CHKERR time(
[&]() {
if (rebuild) {
CHKERR rebuildBlockMatStructure(simple->getDM(), block_ops,
kept_block);
lv.blockData = kept_block;
} else {
lv.blockData =
createBlockMatStructure(simple->getDM(), block_ops);
}
auto block = createBlockMat(simple->getDM(), lv.blockData);
lv.blockMat = block.first;
},
lv.t.blockMat);
CHKERR time(
[&]() {
if (rebuild) {
{lv.schurDM, lv.blockDM}, kept_nested);
lv.nestedData = kept_nested;
} else {
{lv.schurDM, lv.blockDM}, lv.blockData, {"BROKEN", "U"},
{nullptr, nullptr}, true);
}
auto nested = createSchurNestedMatrix(lv.nestedData);
lv.nestedMat = nested.first;
},
lv.t.nestedSchur);
if (rebuild_structures) {
kept_block = lv.blockData;
kept_nested = lv.nestedData;
}
if (rebuild) {
// Oracle: new structures for the same DMs, made from scratch.
boost::shared_ptr<BlockStructure> fresh_block;
boost::shared_ptr<NestSchurData> fresh_nested;
double fresh_block_seconds, fresh_nested_seconds;
CHKERR time(
[&]() {
fresh_block =
createBlockMatStructure(simple->getDM(), block_ops);
},
fresh_block_seconds);
CHKERR time(
[&]() {
{lv.schurDM, lv.blockDM}, fresh_block, {"BROKEN", "U"},
{nullptr, nullptr}, true);
},
fresh_nested_seconds);
MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
MOFEM_LOG("WORLD", Sev::inform)
<< "Level " << l << " structures [s]: rebuilt block "
<< lv.t.blockMat << ", rebuilt nested " << lv.t.nestedSchur
<< "; new block " << fresh_block_seconds << ", new nested "
<< fresh_nested_seconds;
auto compare = [&](const std::string &what, auto rebuilt,
auto fresh) {
const auto r = schurBlockStructureDigest(rebuilt);
const auto f = schurBlockStructureDigest(fresh);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " rebuilt " + what + " blocks", r.nbBlocks, f.nbBlocks,
zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " rebuilt " + what + " A00 elements", r.nbElems,
f.nbElems, zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " rebuilt " + what + " block index equal",
r.indexHash == f.indexHash ? 0 : 1, 0, zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " rebuilt " + what + " blocks equal",
r.blocksHash == f.blocksHash ? 0 : 1, 0, zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " rebuilt " + what + " A00 elements equal",
r.elemsHash == f.elemsHash ? 0 : 1, 0, zero);
};
CHKERR compare("block matrix", lv.blockData, fresh_block);
const auto &rebuilt_parts = std::get<1>(*lv.nestedData);
const auto &fresh_parts = std::get<1>(*fresh_nested);
for (int q = 0; q != 4; ++q)
CHKERR compare("nested quadrant " + std::to_string(q),
rebuilt_parts[q], fresh_parts[q]);
}
PetscInt m, n;
CHKERR MatGetSize(lv.blockMat, &m, &n);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " block matrix rows = parent", m, lv.rows, zero);
CHKERR MatGetSize(lv.nestedMat, &m, &n);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " nested matrix rows = parent", m, lv.rows, zero);
});
CHKERR testing->addTest(10 * l + 5, tag + " hybrid L2 matrix", [&, l,
tag]() {
CHKERR time(
[&]() {
lv.hybridMat = createDMHybridisedL2Matrix(lv.schurDM);
},
lv.t.hybridMat);
PetscInt m, n;
CHKERR MatGetSize(lv.hybridMat, &m, &n);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " hybrid matrix rows = SCHUR dofs", m, lv.schurRows, zero);
CHKERR testing->checkValue<TestType::SCALAR>(
tag + " hybrid matrix columns = SCHUR dofs", n, lv.schurRows, zero);
CHKERR checkHybridMatrix(m_field, lv.schurDM, l, lv.hybridMat, *testing,
tag, lv.hybridNnz);
MOFEM_LOG_TAG("WORLD", "RebuildHybrid");
MOFEM_LOG("WORLD", Sev::inform)
<< "Level " << l << ": tets " << lv.tets << ", skeleton faces "
<< lv.skeletonFaces << ", dofs " << lv.rows << " (SCHUR "
<< lv.schurRows << ", BLOCK " << lv.blockRows
<< "), hybrid non-zeros " << lv.hybridNnz;
MOFEM_LOG("WORLD", Sev::inform)
<< "Level " << l << " times [s]: registration "
<< lv.t.registration << ", problem " << lv.t.problem
<< ", sub SCHUR " << lv.t.schurSub << ", sub BLOCK "
<< lv.t.blockSub << ", block matrix " << lv.t.blockMat
<< ", nested Schur " << lv.t.nestedSchur << ", hybrid matrix "
<< lv.t.hybridMat;
// Release this level's algebra before the next level is built.
lv.hybridMat.reset();
lv.nestedMat.reset();
lv.nestedData.reset();
lv.blockMat.reset();
lv.blockData.reset();
// with -rebuild_structures the structures stay for the next level;
// its nested shell matrices are replaced by the rebuild
lv.blockDM.reset();
lv.schurDM.reset();
});
}
CHKERR testing->runTests();
}
return 0;
}
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
FaceSet skin
WorkMesh base
Vec t
Removal: the ring edge.
Tag tag
ProjectedField & field
std::vector< FieldBitNumber > row
Definition Schur.cpp:2488
It it
Definition Schur.cpp:2568
SmartPetscObj< Vec > values
SmartPetscObj< IS > rows
std::string name
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
static char help[]
int main()
#define CATCH_ERRORS
Catch errors.
@ DEMKOWICZ_JACOBI_BASE
Definition definitions.h:66
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ L2
field with C-1 continuity
Definition definitions.h:88
@ HDIV
field with continuous normal traction
Definition definitions.h:87
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_INVALID_DATA
Definition definitions.h:36
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
constexpr int order
MoFEMErrorCode getEntitiesByDimAndRefLevel(const BitRefLevel bit, const BitRefLevel mask, const int dim, const EntityHandle meshset, int verb=0) const
add all ents from ref level given by bit to meshset
MoFEMErrorCode addBitRefLevel(const Range &ents, const BitRefLevel bit, int verb=QUIET) const
Add bit ref level to ref entity.
virtual MoFEMErrorCode add_ents_to_finite_element_by_dim(const EntityHandle entities, const int dim, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode add_ents_to_field_by_dim(const Range &ents, const int dim, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
#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.
auto bit
set bit
PetscBool testing
constexpr int nb_levels
Definition level_set.cpp:58
FTensor::Index< 'l', 3 > l
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
SchurBlockStructureDigest schurBlockStructureDigest(boost::shared_ptr< BlockStructure > data_ptr)
Definition Schur.cpp:4821
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
Definition Schur.cpp:4859
auto createDMHybridisedL2Matrix(DM dm)
Get smart hybridised L2 matrix from DM.
Definition DMMoFEM.hpp:1249
boost::shared_ptr< BlockStructure > createBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec)
Create block matrix structure.
Definition Schur.cpp:2819
boost::shared_ptr< NestSchurData > createSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< BlockStructure > block_mat_data_ptr, std::vector< std::string > fields_names, std::vector< boost::shared_ptr< Range > > field_ents, bool add_preconditioner_block)
Create structure of nested matrix [A11 A10; A01 A00].
Definition Schur.cpp:4760
MoFEMErrorCode rebuildSchurNestedMatrixStruture(std::pair< SmartPetscObj< DM >, SmartPetscObj< DM > > dms, boost::shared_ptr< NestSchurData > nest_data_ptr)
Rebuild a nested Schur structure after rebuildBlockMatStructure.
Definition Schur.cpp:4799
MoFEMErrorCode rebuildBlockMatStructure(DM dm, SchurFEOpsFEandFields schur_fe_op_vec, boost::shared_ptr< BlockStructure > data_ptr)
Rebuild a block matrix structure after its problem changed.
Definition Schur.cpp:2833
std::vector< std::pair< std::string, std::vector< SchurFieldPair > > > SchurFEOpsFEandFields
Definition Schur.hpp:83
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
Definition Schur.cpp:3615
int r
Definition sdf.py:205
double q
FTensor::Index< 'm', 3 > m
Managing BitRefLevels.
Managing BitRefLevels.
virtual moab::Interface & get_moab()=0
virtual EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:83
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
Deprecated interface functions.
Mesh refinement interface.
MoFEMErrorCode addVerticesInTheMiddleOfEdges(const EntityHandle meshset, const BitRefLevel &bit, const bool recursive=false, int verb=QUIET, EntityHandle start_v=0)
make vertices in the middle of edges in meshset and add them to refinement levels defined by bit
keeps basic data about problem
DofIdx getNbDofsRow() const
auto & getNumeredColDofsPtr() const
get access to numeredColDofsPtr storing DOFs on cols
Simple interface for fast problem set-up.
Definition Simple.hpp:27
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.