22 using namespace MoFEM;
24 static char help[] =
"...\n\n";
71 OpRhs(boost::shared_ptr<MatrixDouble> u_grad_ptr);
87 CHKERR boundaryCondition();
89 CHKERR setIntegrationRules();
101 CHKERR mField.getInterface(simpleInterface);
102 CHKERR simpleInterface->getOptions();
103 CHKERR simpleInterface->loadFile();
109 CHKERR mField.get_moab().get_entities_by_type(0, MBVERTEX, nodes);
111 pinchNodes.insert(nodes[0]);
114 CHKERR mField.get_moab().get_adjacencies(pinchNodes, 1,
false, edges,
115 moab::Interface::UNION);
117 for (
auto e : edges) {
119 CHKERR mField.get_moab().get_connectivity(
Range(e, e), nodes,
false);
121 CHKERR mField.get_moab().get_coords(nodes, &coords(0, 0));
123 for (
int j = 0;
j != 3; ++
j) {
124 l2e += pow(coords(0,
j) - coords(1,
j), 2);
126 l2 = std::max(l2, l2e);
141 constexpr
int order = 1;
143 CHKERR simpleInterface->setUp();
154 auto rule = [](
int,
int,
int p) ->
int {
return 2 * p; };
187 auto grad_u_ptr = boost::make_shared<MatrixDouble>();
191 auto set_domain_general = [&](
auto &pipeline) {
192 auto det_ptr = boost::make_shared<VectorDouble>();
193 auto jac_ptr = boost::make_shared<MatrixDouble>();
194 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
201 auto set_domain_lhs_first = [&](
auto &pipeline) {
203 pipeline.push_back(
new OpGradGrad(
"U",
"U", one));
205 pipeline.push_back(
new OpMass(
"U",
"U",
rho));
211 auto set_domain_rhs_first = [&](
auto &pipeline) {};
215 auto set_domain_lhs_second = [&](
auto &pipeline) {
217 pipeline.push_back(
new OpGradGrad(
"U",
"U", one));
221 auto set_domain_rhs_second = [&](
auto &pipeline) {
223 pipeline.push_back(
new OpRhs(grad_u_ptr));
227 auto solve_first = [&]() {
232 auto solver = pipeline_mng->createKSP();
233 CHKERR KSPSetFromOptions(solver);
236 auto dm = simpleInterface->getDM();
242 auto problem_ptr = mField.get_problem(
simple->getProblemName());
243 auto bit_number = mField.get_field_bit_number(
"U");
244 auto dofs_ptr = problem_ptr->getNumeredRowDofsPtr();
245 for (
auto v : pinchNodes) {
249 if (dof != dofs_ptr->end())
250 VecSetValue(
F, (*dof)->getPetscGlobalDofIdx(), 1, INSERT_VALUES);
257 CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
258 CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
264 auto solve_second = [&]() {
270 CHKERR prb_mng->removeDofsOnEntities(
simple->getProblemName(),
"U",
275 auto solver = pipeline_mng->createKSP();
276 CHKERR KSPSetFromOptions(solver);
279 auto dm = simpleInterface->getDM();
284 CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
285 CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
291 auto post_proc = [&](
const std::string out_name) {
296 auto det_ptr = boost::make_shared<VectorDouble>();
297 auto jac_ptr = boost::make_shared<MatrixDouble>();
298 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
302 boost::make_shared<PostProcBrokenMeshInMoab<DomainEle>>(mField);
304 post_proc_fe->getOpPtrVector().push_back(
306 post_proc_fe->getOpPtrVector().push_back(
308 post_proc_fe->getOpPtrVector().push_back(
311 auto u_ptr = boost::make_shared<VectorDouble>();
312 auto grad_ptr = boost::make_shared<MatrixDouble>();
314 post_proc_fe->getOpPtrVector().push_back(
316 post_proc_fe->getOpPtrVector().push_back(
321 post_proc_fe->getOpPtrVector().push_back(
new OpPPMap(
322 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
326 {{
"GRAD_U", grad_ptr}},
332 CHKERR post_proc_fe->writeFile(out_name);
344 CHKERR post_proc(
"out_heat_method_first.h5m");
355 CHKERR post_proc(
"out_heat_method_second.h5m");
382 int main(
int argc,
char *argv[]) {
385 const char param_file[] =
"param_file.petsc";
389 auto core_log = logging::core::get();
391 LogManager::createSink(LogManager::getStrmWorld(),
"EXAMPLE"));
392 LogManager::setLog(
"EXAMPLE");
398 DMType dm_name =
"DMMOFEM";
434 auto t_grad = getFTensor1FromMat<3>(*uGradPtr);
436 auto nb_base_functions = data.
getN().size2();
437 auto nb_gauss_pts = getGaussPts().size2();
438 std::array<double, MAX_DOFS_ON_ENTITY> nf;
439 std::fill(nf.begin(), &nf[nb_dofs], 0);
442 auto t_w = getFTensor0IntegrationWeight();
443 auto a = getMeasure();
445 for (
size_t gg = 0; gg != nb_gauss_pts; ++gg) {
446 double alpha = t_w *
a;
448 const auto l2 = t_grad(
i) * t_grad(
i);
450 if (l2 > std::numeric_limits<double>::epsilon())
451 t_one(
i) = t_grad(
i) / std::sqrt(l2);
456 for (; bb != nb_dofs; ++bb) {
457 nf[bb] -= alpha * t_diff_base(
i) * t_one(
i);
461 for (; bb < nb_base_functions; ++bb) {
468 CHKERR VecSetValues<MoFEM::EssentialBcStorage>(getKSPf(), data, &nf[0],