v0.15.0
Loading...
Searching...
No Matches
ADV-6: Map solution between meshes using DG projection
Note
Prerequisites of this tutorial include FUN-0: Hello world


Note
Intended learning outcome:
  • Field evaluator
  • DG projection
  • User defined integration rules
/**
* @file between_meshes_dg_projection.cpp
* @example mofem/tutorials/adv-6/between_meshes_dg_projection.cpp
*
* @brief Testing Discontinuous Galerkin (DG) projection operators
*
*
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "DG Projection Test - validates discontinuous Galerkin "
"projection accuracy\n\n";
constexpr char FIELD_NAME_U[] = "U";
constexpr char FIELD_NAME_S[] = "S";
constexpr int BASE_DIM = 1;
constexpr int FIELD_DIM = 1;
constexpr int SPACE_DIM = 2;
constexpr int order = 2;
using DomainEleOp = DomainEle::UserDataOperator;
auto fun = [](const double x, const double y, const double z) {
return x + y + x * x + y * y;
};
struct Example {
Example(MoFEM::Interface &m_field) : mField(m_field) {}
private:
BitRefLevel refine_bit);
struct CommonData {
boost::shared_ptr<MatrixDouble> invJacPtr;
boost::shared_ptr<VectorDouble> approxVals;
boost::shared_ptr<MatrixDouble> approxGradVals;
boost::shared_ptr<MatrixDouble> approxHessianVals;
};
struct OpError;
};
auto save_range = [](moab::Interface &moab, const std::string name,
const Range r, std::vector<Tag> tags = {}) {
auto out_meshset = get_temp_meshset_ptr(moab);
CHKERR moab.add_entities(*out_meshset, r);
if (r.size()) {
CHKERR moab.write_file(name.c_str(), "VTK", "", out_meshset->get_ptr(), 1,
tags.data(), tags.size());
} else {
MOFEM_LOG("SELF", Sev::warning) << "Empty range for " << name;
}
};
struct Example::OpError : public DomainEleOp {
boost::shared_ptr<CommonData> commonDataPtr;
OpError(boost::shared_ptr<MatrixDouble> data_ptr,
: DomainEleOp(NOSPACE, OPSPACE), dataPtr(data_ptr), bitsEle(bits),
maskEle(mask) {}
MoFEMErrorCode doWork(int side, EntityType type, EntData &data) {
auto fe_ptr = getNumeredEntFiniteElementPtr();
auto fe_bit = fe_ptr->getBitRefLevel();
if ((fe_bit & bitsEle).any() && ((fe_bit & maskEle) == fe_bit)) {
const int nb_integration_pts = getGaussPts().size2();
auto t_val = getFTensor1FromMat<1>(*(dataPtr));
auto t_coords = getFTensor1CoordsAtGaussPts();
for (int gg = 0; gg != nb_integration_pts; ++gg) {
double projected_value = t_val(0);
double analytical_value = fun(t_coords(0), t_coords(1), t_coords(2));
double error = projected_value - analytical_value;
constexpr double eps = 1e-8;
if (std::abs(error) > eps) {
MOFEM_LOG("SELF", Sev::error)
<< "Projection error too large: " << error << " at point ("
<< t_coords(0) << ", " << t_coords(1) << ")"
<< " projected=" << projected_value
<< " analytical=" << analytical_value;
SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"DG projection failed accuracy test");
}
++t_val;
++t_coords;
}
MOFEM_LOG("SELF", Sev::noisy)
<< "DG projection accuracy validation passed";
}
}
private:
boost::shared_ptr<MatrixDouble> dataPtr;
};
//! [Run programme]
CHKERR outputResults("out_initial.h5m");
auto parent_bit = BitRefLevel().set(0);
auto child_bit = BitRefLevel().set(1);
auto refine_bit = BitRefLevel().set(2);
CHKERR edgeFlips(parent_bit, child_bit);
CHKERR refineSkin(child_bit, refine_bit);
CHKERR projectResults(parent_bit, child_bit, refine_bit);
CHKERR reSetupProblem(refine_bit);
CHKERR outputResults("out_projected.h5m");
}
//! [Run programme]
//! [Read mesh]
char mesh_File_Name[255];
CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, "-file_name",
mesh_File_Name, 255, PETSC_NULLPTR);
CHKERR simpleInterface->loadFile("", mesh_File_Name);
}
//! [Read mesh]
//! [Set up problem]
CHKERR simpleInterface->setUp(PETSC_FALSE);
}
//! [Set up problem]
//! [Push operators to pipeline]
auto rule = [](int, int, int p) -> int { return 2 * p; };
CHKERR pipeline_mng->setDomainLhsIntegrationRule(rule);
CHKERR pipeline_mng->setDomainRhsIntegrationRule(rule);
auto beta = [](const double, const double, const double) { return 1; };
pipeline_mng->getOpDomainLhsPipeline().push_back(
pipeline_mng->getOpDomainRhsPipeline().push_back(
pipeline_mng->getOpDomainLhsPipeline().push_back(
pipeline_mng->getOpDomainRhsPipeline().push_back(
}
//! [Push operators to pipeline]
//! [Solve]
MOFEM_LOG("WORLD", Sev::inform) << "Solving DG projection system";
auto solver = pipeline_mng->createKSP();
CHKERR KSPSetFromOptions(solver);
CHKERR KSPSetUp(solver);
auto dm = simpleInterface->getDM();
auto D = createDMVector(dm);
auto F = vectorDuplicate(D);
CHKERR KSPSolve(solver, F, D);
CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
}
//! [Solve]
//! [Project results]
BitRefLevel child_bit,
BitRefLevel refine_bit) {
auto pipeline_mng = mField.getInterface<PipelineManager>();
pipeline_mng->getDomainLhsFE().reset();
pipeline_mng->getDomainRhsFE().reset();
pipeline_mng->getOpDomainRhsPipeline().clear();
auto rule = [](int, int, int p) -> int { return 2 * p; };
CHKERR pipeline_mng->setDomainRhsIntegrationRule(rule);
// OpLoopThis, is child operator, and is use to execute
// fe_child_ptr, only on bit ref level and mask
// for child elements
auto get_child_op = [&](auto &pip) {
auto op_this_child =
new OpLoopThis<DomainEle>(mField, simple->getDomainFEName(), refine_bit,
child_bit | refine_bit, Sev::noisy);
auto fe_child_ptr = op_this_child->getThisFEPtr();
fe_child_ptr->getRuleHook = [] (int, int, int p) { return -1; };
Range child_edges;
CHKERR mField.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
refine_bit, child_bit | refine_bit, MBEDGE, child_edges);
// set integration rule, such that integration points are not on flipped edge
CHKERR setDGSetIntegrationPoints<SPACE_DIM>(
fe_child_ptr->setRuleHook, [](int, int, int p) { return 2 * p; },
boost::make_shared<Range>(child_edges));
pip.push_back(op_this_child);
return fe_child_ptr;
};
// Use field evaluator to calculate field values on parent bitref level,
// i.e. elements which were flipped.
auto get_field_eval_op = [&](auto fe_child_ptr) {
auto field_eval_ptr = mField.getInterface<FieldEvaluatorInterface>();
// Get pointer of FieldEvaluator data. Note finite element and method
// set integration points is destroyed when this pointer is releases
auto field_eval_data = field_eval_ptr->getData<DomainEle>();
// Build tree for particular element
CHKERR field_eval_ptr->buildTree<SPACE_DIM>(
field_eval_data, simpleInterface->getDomainFEName(), parent_bit,
parent_bit | child_bit);
// You can add more fields here
auto data_U_ptr = boost::make_shared<MatrixDouble>();
auto eval_data_U_ptr = boost::make_shared<MatrixDouble>();
auto data_S_ptr = boost::make_shared<MatrixDouble>();
auto eval_data_S_ptr = boost::make_shared<MatrixDouble>();
if (auto fe_eval_ptr = field_eval_data->feMethodPtr.lock()) {
fe_eval_ptr->getRuleHook = [] (int, int, int p) { return -1; };
fe_eval_ptr->getOpPtrVector().push_back(
eval_data_U_ptr));
fe_eval_ptr->getOpPtrVector().push_back(
eval_data_S_ptr));
auto op_test = new DomainEleOp(NOSPACE, DomainEleOp::OPSPACE);
op_test->doWorkRhsHook =
[](DataOperator *base_op_ptr, int side, EntityType type,
auto op_ptr = static_cast<DomainEleOp *>(base_op_ptr);
MOFEM_LOG("SELF", Sev::noisy)
<< "Field evaluator method pointer is valid";
MOFEM_LOG("SELF", Sev::noisy)
<< op_ptr->getGaussPts();
MOFEM_LOG("SELF", Sev::noisy)
<< "Loop size " << op_ptr->getPtrFE()->getLoopSize();
MOFEM_LOG("SELF", Sev::noisy)
<< "Coords at gauss pts: " << op_ptr->getCoordsAtGaussPts();
};
fe_eval_ptr->getOpPtrVector().push_back(op_test);
} else {
"Field evaluator method pointer is expired");
}
auto op_ptr = field_eval_ptr->getDataOperator<SPACE_DIM>(
{{eval_data_U_ptr, data_U_ptr}, {eval_data_S_ptr, data_S_ptr}},
simpleInterface->getDomainFEName(), field_eval_data, 0,
mField.get_comm_size(), parent_bit, parent_bit | child_bit, MF_EXIST,
fe_child_ptr->getOpPtrVector().push_back(op_ptr);
return std::make_pair(
std::vector<std::pair<std::string, boost::shared_ptr<MatrixDouble>>>{
{FIELD_NAME_U, data_U_ptr}},
std::vector<std::pair<std::string, boost::shared_ptr<MatrixDouble>>>{
{FIELD_NAME_S, data_S_ptr}}
);
};
// calculate coefficients on child (flipped) elements
auto dg_projection_base = [&](auto fe_child_ptr, auto vec_data_ptr, auto mat,
auto vec) {
constexpr int projection_order = order;
auto entity_data_l2 = boost::make_shared<EntitiesFieldData>(MBENTITYSET);
auto mass_ptr = boost::make_shared<MatrixDouble>();
auto coeffs_ptr = boost::make_shared<MatrixDouble>();
// project L2 (directly from coefficients)
for (auto &p : vec_data_ptr.first) {
auto field_name = p.first;
auto data_ptr = p.second;
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionMassMatrix(
projection_order, mass_ptr, entity_data_l2, AINSWORTH_LEGENDRE_BASE,
L2));
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
data_ptr, coeffs_ptr, mass_ptr, entity_data_l2,
// next two lines are only for testing if projection is correct, they are not
// essential
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionEvaluation(
data_ptr, coeffs_ptr, entity_data_l2, AINSWORTH_LEGENDRE_BASE, L2));
fe_child_ptr->getOpPtrVector().push_back(new OpError(data_ptr));
// set coefficients to flipped element
auto op_set_coeffs = new DomainEleOp(field_name, DomainEleOp::OPROW);
op_set_coeffs->doWorkRhsHook =
[coeffs_ptr](DataOperator *base_op_ptr, int side, EntityType type,
auto field_ents = data.getFieldEntities();
auto nb_dofs = data.getIndices().size();
if (!field_ents.size())
if (auto e_ptr = field_ents[0]) {
auto field_ent_data = e_ptr->getEntFieldData();
std::copy(coeffs_ptr->data().data(),
coeffs_ptr->data().data() + nb_dofs,
field_ent_data.begin());
}
};
fe_child_ptr->getOpPtrVector().push_back(op_set_coeffs);
}
// project H1 (via coefficients)
for (auto &p : vec_data_ptr.second) {
auto field_name = p.first;
auto data_ptr = p.second;
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionMassMatrix(
projection_order, mass_ptr, entity_data_l2, AINSWORTH_LEGENDRE_BASE,
L2));
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
data_ptr, coeffs_ptr, mass_ptr, entity_data_l2,
// next two lines are only for testing if projection is correct, they are not
// essential
fe_child_ptr->getOpPtrVector().push_back(new OpDGProjectionEvaluation(
data_ptr, coeffs_ptr, entity_data_l2, AINSWORTH_LEGENDRE_BASE, L2));
fe_child_ptr->getOpPtrVector().push_back(new OpError(data_ptr));
// assemble to global matrix, since this is H1 (you will do the shame for Hcurl of Hdiv)
auto beta = [](const double, const double, const double) { return 1; };
fe_child_ptr->getOpPtrVector().push_back(
GAUSS>::OpBaseTimesVector<1, FIELD_DIM, 1>;
fe_child_ptr->getOpPtrVector().push_back(
new OpVec(FIELD_NAME_S, data_ptr, beta));
}
};
auto dm = simple->getDM();
auto sub_dm = createDM(mField.get_comm(), "DMMOFEM");
CHKERR DMMoFEMCreateSubDM(sub_dm, dm, "SUB");
CHKERR DMMoFEMSetSquareProblem(sub_dm, PETSC_TRUE);
CHKERR DMMoFEMAddElement(sub_dm, simple->getDomainFEName());
// get only refinement bit DOFs
auto ref_entities_ptr = boost::make_shared<Range>();
CHKERR mField.getInterface<BitRefManager>()->getEntitiesByRefLevel(
refine_bit, child_bit | refine_bit, *ref_entities_ptr);
Range verts;
CHKERR mField.get_moab().get_connectivity(*ref_entities_ptr, verts, true);
ref_entities_ptr->merge(verts);
CHKERR DMMoFEMAddSubFieldRow(sub_dm, FIELD_NAME_S, ref_entities_ptr);
CHKERR DMMoFEMAddSubFieldCol(sub_dm, FIELD_NAME_S, ref_entities_ptr);
CHKERR DMSetUp(sub_dm);
auto mat = createDMMatrix(sub_dm);
auto vec = createDMVector(sub_dm);
// create child operator, and fe_child_ptr element in it
auto fe_child_ptr = get_child_op(pipeline_mng->getOpDomainRhsPipeline());
// run dg projection, note that get_field_eval_op,
// pass data_ptr values used to project and calculate coefficients
CHKERR dg_projection_base(fe_child_ptr, get_field_eval_op(fe_child_ptr), mat,
vec);
// That is to test, if projection works, and coefficients are set in correctly
// Note: FIELD_S is not tested, it is in H1, so we have to solve KSP problem first
auto test_U_data_ptr = boost::make_shared<MatrixDouble>();
pipeline_mng->getOpDomainRhsPipeline().push_back(
test_U_data_ptr));
pipeline_mng->getOpDomainRhsPipeline().push_back(
new OpError(test_U_data_ptr, refine_bit, BitRefLevel().set()));
auto fe_rhs = pipeline_mng->getCastDomainRhsFE<DomainEle>();
fe_rhs->ksp_A = mat;
fe_rhs->ksp_B = mat;
fe_rhs->ksp_f = vec;
fe_rhs->data_ctx =
PetscData::CtxSetF | PetscData::CtxSetA | PetscData::CtxSetB;
CHKERR pipeline_mng->loopFiniteElements(sub_dm);
CHKERR VecAssemblyBegin(vec);
CHKERR VecAssemblyEnd(vec);
CHKERR VecGhostUpdateBegin(vec, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(vec, ADD_VALUES, SCATTER_REVERSE);
CHKERR MatAssemblyBegin(mat, MAT_FINAL_ASSEMBLY);
CHKERR MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY);
auto ksp = createKSP(mField.get_comm());
CHKERR KSPSetOperators(ksp, mat, mat);
CHKERR KSPSetFromOptions(ksp);
auto sol = createDMVector(sub_dm);
CHKERR KSPSolve(ksp, vec, sol);
CHKERR VecGhostUpdateBegin(sol, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(sol, INSERT_VALUES, SCATTER_FORWARD);
CHKERR DMoFEMMeshToLocalVector(sub_dm, sol, INSERT_VALUES, SCATTER_REVERSE);
pipeline_mng->getOpDomainRhsPipeline().clear();
auto test_S_data_ptr = boost::make_shared<MatrixDouble>();
pipeline_mng->getOpDomainRhsPipeline().push_back(
test_S_data_ptr));
pipeline_mng->getOpDomainRhsPipeline().push_back(
new OpError(test_S_data_ptr, refine_bit, BitRefLevel().set()));
}
//! [Project results]
//! [Output results]
MoFEMErrorCode Example::outputResults(std::string file_name) {
auto pipeline_mng = mField.getInterface<PipelineManager>();
pipeline_mng->getDomainLhsFE().reset();
auto post_proc_fe = boost::make_shared<PostProcFaceEle>(mField);
post_proc_fe->getOpPtrVector(), {H1});
auto u_ptr = boost::make_shared<VectorDouble>();
post_proc_fe->getOpPtrVector().push_back(
auto s_ptr = boost::make_shared<VectorDouble>();
post_proc_fe->getOpPtrVector().push_back(
auto grad_u_ptr = boost::make_shared<MatrixDouble>();
post_proc_fe->getOpPtrVector().push_back(
auto grad_s_ptr = boost::make_shared<MatrixDouble>();
post_proc_fe->getOpPtrVector().push_back(
post_proc_fe->getOpPtrVector().push_back(
new OpPPMap(
post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
OpPPMap::DataMapVec{{FIELD_NAME_U, u_ptr}, {FIELD_NAME_S, s_ptr}},
{"GRAD_" + std::string(FIELD_NAME_U), grad_u_ptr},
{"GRAD_" + std::string(FIELD_NAME_S), grad_s_ptr}
},
)
);
pipeline_mng->getDomainRhsFE() = post_proc_fe;
CHKERR pipeline_mng->loopFiniteElements();
CHKERR post_proc_fe->writeFile(file_name);
}
//! [Output results]
//! [Edge flips]
BitRefLevel child_bit) {
moab::Interface &moab = mField.get_moab();
auto make_edge_flip = [&](auto edge, auto adj_faces, Range &new_tris) {
auto get_conn = [&](EntityHandle e, EntityHandle *conn_cpy) {
const EntityHandle *conn;
int num_nodes;
CHKERR moab.get_connectivity(e, conn, num_nodes, true);
std::copy(conn, conn + num_nodes, conn_cpy);
};
auto get_tri_normals = [&](auto &conn) {
std::array<double, 18> coords;
CHKERR moab.get_coords(conn.data(), 6, coords.data());
std::array<FTensor::Tensor1<double, 3>, 2> tri_normals;
for (int t = 0; t != 2; ++t) {
CHKERR Tools::getTriNormal(&coords[9 * t], &tri_normals[t](0));
}
return tri_normals;
};
auto test_flip = [&](auto &&t_normals) {
if (t_normals[0](i) * t_normals[1](i) <
std::numeric_limits<float>::epsilon())
return false;
return true;
};
std::array<EntityHandle, 6> adj_conn;
CHKERR get_conn(adj_faces[0], &adj_conn[0]);
CHKERR get_conn(adj_faces[1], &adj_conn[3]);
std::array<EntityHandle, 2> edge_conn;
CHKERR get_conn(edge, edge_conn.data());
std::array<EntityHandle, 2> new_edge_conn;
int j = 1;
for (int i = 0; i != 6; ++i) {
if (adj_conn[i] != edge_conn[0] && adj_conn[i] != edge_conn[1]) {
new_edge_conn[j] = adj_conn[i];
--j;
}
}
auto &new_conn = adj_conn; //< just alias this
for (int t = 0; t != 2; ++t) {
for (int i = 0; i != 3; ++i) {
if (
(adj_conn[3 * t + i % 3] == edge_conn[0] &&
adj_conn[3 * t + (i + 1) % 3] == edge_conn[1])
||
(adj_conn[3 * t + i % 3] == edge_conn[1] &&
adj_conn[3 * t + (i + 1) % 3] == edge_conn[0])
) {
new_conn[3 * t + (i + 1) % 3] = new_edge_conn[t];
break;
}
}
}
if (test_flip(get_tri_normals(new_conn))) {
for (int t = 0; t != 2; ++t) {
Range rtri;
CHKERR moab.get_adjacencies(&new_conn[3 * t], SPACE_DIM + 1, SPACE_DIM,
false, rtri);
if (!rtri.size()) {
CHKERR moab.create_element(MBTRI, &new_conn[3 * t], SPACE_DIM + 1,
tri);
new_tris.insert(tri);
} else {
#ifndef NDEBUG
if (rtri.size() != 1) {
MOFEM_LOG("SELF", Sev::error)
<< "Multiple tries created during edge flip for edge " << edge
<< " adjacent faces " << std::endl
<< rtri;
SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"Multiple tries created during edge flip");
}
#endif // NDEBUG
new_tris.merge(rtri);
}
}
Range new_edges;
CHKERR moab.get_adjacencies(new_tris, SPACE_DIM - 1, true, new_edges,
moab::Interface::UNION);
} else {
MOFEM_LOG("SELF", Sev::warning)
<< "Edge flip rejected for edge " << edge << " adjacent faces "
<< adj_faces;
}
};
Range tris;
CHKERR moab.get_entities_by_dimension(0, SPACE_DIM, tris);
CHKERR mField.getInterface<BitRefManager>()->filterEntitiesByRefLevel(
parent_bit, BitRefLevel().set(), tris);
Skinner skin(&moab);
Range skin_edges;
CHKERR skin.find_skin(0, tris, false, skin_edges);
Range edges;
CHKERR moab.get_entities_by_dimension(0, SPACE_DIM - 1, edges);
edges = subtract(edges, skin_edges);
CHKERR mField.getInterface<BitRefManager>()->filterEntitiesByRefLevel(
parent_bit, BitRefLevel().set(), edges);
Range new_tris, flipped_tris, forbidden_tris;
int flip_count = 0;
for (auto edge : edges) {
Range adjacent_tris;
CHKERR moab.get_adjacencies(&edge, 1, SPACE_DIM, true, adjacent_tris);
adjacent_tris = intersect(adjacent_tris, tris);
adjacent_tris = subtract(adjacent_tris, forbidden_tris);
if (adjacent_tris.size() == 2) {
#ifndef NDEBUG
int side_number0, sense0, offset0;
CHKERR mField.get_moab().side_number(adjacent_tris[0], edge, side_number0,
sense0, offset0);
int side_number1, sense1, offset1;
CHKERR mField.get_moab().side_number(adjacent_tris[1], edge, side_number1,
sense1, offset1);
if (sense0 * sense1 > 0)
SETERRQ(
PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"Cannot flip edge with same orientation in both adjacent faces");
#endif // NDEBUG
Range new_flipped_tris;
CHKERR make_edge_flip(edge, adjacent_tris, new_flipped_tris);
if (new_flipped_tris.size()) {
flipped_tris.merge(adjacent_tris);
forbidden_tris.merge(adjacent_tris);
new_tris.merge(new_flipped_tris);
#ifndef NDEBUG
"flipped_tris_" + std::to_string(flip_count) + ".vtk",
adjacent_tris);
moab, "new_flipped_tris_" + std::to_string(flip_count) + ".vtk",
new_flipped_tris);
#endif // NDEBUG
++flip_count;
}
}
}
Range all_tris;
CHKERR moab.get_entities_by_dimension(0, SPACE_DIM, all_tris);
Range not_flipped_tris = subtract(all_tris, flipped_tris);
MOFEM_LOG("SELF", Sev::noisy)
<< "Flipped " << flip_count << " edges with two adjacent faces.";
CHKERR mField.getInterface<BitRefManager>()->setBitRefLevel(not_flipped_tris,
child_bit);
CHKERR mField.getInterface<BitRefManager>()->setBitRefLevel(new_tris,
child_bit);
child_bit, BitRefLevel().set(), "edge_flips_before_refinement.vtk", "VTK",
"");
}
//! [Edge flips]
//! [Refine skin]
BitRefLevel child_bit) {
moab::Interface &moab = mField.get_moab();
Range tris;
CHKERR moab.get_entities_by_dimension(0, SPACE_DIM, tris);
CHKERR mField.getInterface<BitRefManager>()->filterEntitiesByRefLevel(
parent_bit, BitRefLevel().set(), tris);
Skinner skin(&moab);
Range skin_edges;
CHKERR skin.find_skin(0, tris, false, skin_edges);
CHKERR refine->addVerticesInTheMiddleOfEdges(skin_edges, child_bit);
#ifndef NDEBUG
auto debug = true;
#else
auto debug = false;
#endif
CHKERR refine->refineTris(tris, child_bit, QUIET, debug);
child_bit, BitRefLevel().set(), "edge_flips_after_refinement.vtk", "VTK",
"");
}
//! [Refine skin]
//! [Re-setup problem after mesh modification
}
//! [Re-setup problem after mesh modification]
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, NULL, help);
try {
//! [Register MoFEM discrete manager in PETSc]
DMType dm_name = "DMMOFEM";
//! [Register MoFEM discrete manager in PETSc]
//! [Create MoAB]
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
//! [Create MoAB]
//! [Create MoFEM]
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
//! [Create MoFEM]
//! [Execute DG Projection Test]
Example ex(m_field);
CHKERR ex.runProblem();
//! [Execute DG Projection Test]
}
}
#define FTENSOR_INDEX(DIM, I)
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
static char help[]
int main()
constexpr char FIELD_NAME_U[]
constexpr char FIELD_NAME_S[]
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, FIELD_DIM > OpDomainSource
constexpr int SPACE_DIM
[Define dimension]
constexpr int FIELD_DIM
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, FIELD_DIM > OpDomainMass
@ QUIET
#define CATCH_ERRORS
Catch errors.
@ MF_EXIST
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition definitions.h:60
#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
@ H1
continuous field
Definition definitions.h:85
@ NOSPACE
Definition definitions.h:83
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
auto fun
constexpr int BASE_DIM
constexpr int order
Order displacement.
PostProcBrokenMeshInMoab< FaceElementForcesAndSourcesCore > PostProcFaceEle
@ F
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:215
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:488
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:450
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:238
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
auto createDMVector(DM dm)
Get smart vector from DM.
Definition DMMoFEM.hpp:1234
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:280
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1191
boost::ptr_deque< UserDataOperator > & getOpDomainLhsPipeline()
Get the Op Domain Lhs Pipeline object.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
boost::ptr_deque< UserDataOperator > & getOpDomainRhsPipeline()
Get the Op Domain Rhs Pipeline object.
@ GAUSS
Gaussian quadrature integration.
@ PETSC
Standard PETSc assembly.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
double D
FTensor::Index< 'j', 3 > j
constexpr double eps
Definition HenckyOps.hpp:13
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
auto createKSP(MPI_Comm comm)
static const bool debug
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
int r
Definition sdf.py:8
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
constexpr double t
plate stiffness
Definition plate.cpp:58
constexpr auto field_name
boost::shared_ptr< VectorDouble > approxVals
boost::shared_ptr< MatrixDouble > invJacPtr
boost::shared_ptr< MatrixDouble > approxGradVals
boost::shared_ptr< MatrixDouble > approxHessianVals
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
boost::shared_ptr< MatrixDouble > dataPtr
boost::shared_ptr< CommonData > commonDataPtr
[Example]
Definition plastic.cpp:216
MoFEMErrorCode assembleSystem()
[Push operators to pipeline]
MoFEMErrorCode readMesh()
[Run problem]
MoFEMErrorCode reSetupProblem(BitRefLevel child_bit)
[Refine skin]
MoFEMErrorCode edgeFlips(BitRefLevel parent_bit, BitRefLevel child_bit)
[Output results]
MoFEMErrorCode projectResults(BitRefLevel parent_bit, BitRefLevel child_bit, BitRefLevel refine_bit)
[Solve]
MoFEMErrorCode solveSystem()
[Solve]
MoFEMErrorCode refineSkin(BitRefLevel parent_bit, BitRefLevel refine_bit)
[Edge flips]
MoFEMErrorCode runProblem()
[Run problem]
Definition plastic.cpp:256
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:226
MoFEMErrorCode setupProblem()
[Run problem]
Definition plastic.cpp:275
MoFEMErrorCode outputResults()
[Solve]
Managing BitRefLevels.
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:118
base operator to do operations at Gauss Pt. level
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
const VectorFieldEntities & getFieldEntities() const
Get field entities (const version)
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
Field evaluator interface.
boost::shared_ptr< SPD > getData(const double *ptr=nullptr, const int nb_eval_points=0, const double eps=1e-12, VERBOSITY_LEVELS verb=QUIET)
Get the Data object.
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
Get field gradients at integration pts for scalar field rank 0, i.e. vector field.
Specialization for double precision scalar field values calculation.
Specialization for double precision vector field values calculation.
Execute "this" element in the operator.
Post post-proc data at points from hash maps.
std::map< std::string, boost::shared_ptr< MatrixDouble > > DataMapMat
Template struct for dimension-specific finite element types.
PipelineManager interface.
MoFEMErrorCode setDomainRhsIntegrationRule(RuleHookFun rule)
Set integration rule for domain right-hand side finite element.
MoFEMErrorCode setDomainLhsIntegrationRule(RuleHookFun rule)
Set integration rule for domain left-hand side finite element.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition Simple.cpp:261
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition Simple.cpp:191
MoFEMErrorCode reSetUp(bool only_dm=false)
Rebuild internal MoFEM data structures.
Definition Simple.cpp:762
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:800
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:575
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition Simple.cpp:736
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
BitRefLevel & getBitRefLevel()
Get the BitRefLevel.
Definition Simple.hpp:415
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
auto save_range
constexpr int SPACE_DIM
DomainEle::UserDataOperator DomainEleOp