591 auto set_section_monitor = [&](
auto solver) {
594 CHKERR TSGetSNES(solver, &snes);
595 PetscViewerAndFormat *vf;
596 CHKERR PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,
597 PETSC_VIEWER_DEFAULT, &vf);
600 (
MoFEMErrorCode(*)(SNES, PetscInt, PetscReal,
void *))SNESMonitorFields,
605 auto scatter_create = [&](
auto D,
auto coeff) {
607 CHKERR is_manager->isCreateProblemFieldAndRank(
simple->getProblemName(),
608 ROW,
"U", coeff, coeff, is);
610 CHKERR ISGetLocalSize(is, &loc_size);
614 CHKERR VecScatterCreate(
D, is,
v, PETSC_NULL, &scatter);
619 auto create_post_process_elements = [&]() {
620 auto pp_fe = boost::make_shared<PostProcEle>(
mField);
621 auto &pip = pp_fe->getOpPtrVector();
623 auto push_vol_ops = [
this](
auto &pip) {
631 auto push_vol_post_proc_ops = [
this](
auto &pp_fe,
auto &&p) {
634 auto &pip = pp_fe->getOpPtrVector();
638 auto x_ptr = boost::make_shared<MatrixDouble>();
641 auto u_ptr = boost::make_shared<MatrixDouble>();
644 auto pressure_ptr = boost::make_shared<VectorDouble>();
647 auto div_u_ptr = boost::make_shared<VectorDouble>();
651 auto grad_u_ptr = boost::make_shared<MatrixDouble>();
655 auto strain_ptr = boost::make_shared<MatrixDouble>();
658 auto stress_ptr = boost::make_shared<MatrixDouble>();
660 mu, stress_ptr, strain_ptr, pressure_ptr));
666 pp_fe->getPostProcMesh(), pp_fe->getMapGaussPts(),
668 {{
"P", pressure_ptr}},
670 {{
"U", u_ptr}, {
"GEOMETRY", x_ptr}},
674 {{
"STRAIN", strain_ptr}, {
"STRESS", stress_ptr}}
683 auto vol_post_proc = [
this, push_vol_post_proc_ops, push_vol_ops]() {
684 PetscBool post_proc_vol = PETSC_FALSE;
686 &post_proc_vol, PETSC_NULL);
687 if (post_proc_vol == PETSC_FALSE)
688 return boost::shared_ptr<PostProcEle>();
689 auto pp_fe = boost::make_shared<PostProcEle>(
mField);
691 push_vol_post_proc_ops(pp_fe, push_vol_ops(pp_fe->getOpPtrVector())),
692 "push_vol_post_proc_ops");
696 auto skin_post_proc = [
this, push_vol_post_proc_ops, push_vol_ops]() {
697 PetscBool post_proc_skin = PETSC_TRUE;
699 &post_proc_skin, PETSC_NULL);
700 if (post_proc_skin == PETSC_FALSE)
701 return boost::shared_ptr<SkinPostProcEle>();
704 auto pp_fe = boost::make_shared<SkinPostProcEle>(
mField);
707 pp_fe->getOpPtrVector().push_back(op_side);
709 pp_fe, push_vol_ops(op_side->getOpPtrVector())),
710 "push_vol_post_proc_ops");
714 return std::make_pair(vol_post_proc(), skin_post_proc());
717 boost::shared_ptr<SetPtsData> field_eval_data;
718 boost::shared_ptr<MatrixDouble> vector_field_ptr;
720 std::array<double, SPACE_DIM> field_eval_coords;
723 field_eval_coords.data(), &coords_dim,
727 vector_field_ptr = boost::make_shared<MatrixDouble>();
732 field_eval_data,
simple->getDomainFEName());
735 field_eval_data,
simple->getDomainFEName());
738 field_eval_data->setEvalPoints(field_eval_coords.data(), 1);
739 auto no_rule = [](
int,
int,
int) {
return -1; };
740 auto field_eval_fe_ptr = field_eval_data->feMethodPtr.lock();
741 field_eval_fe_ptr->getRuleHook = no_rule;
742 field_eval_fe_ptr->getOpPtrVector().push_back(
746 auto set_time_monitor = [&](
auto dm,
auto solver) {
748 boost::shared_ptr<MonitorIncompressible> monitor_ptr(
750 create_post_process_elements(),
uXScatter,
752 field_eval_data, vector_field_ptr));
753 boost::shared_ptr<ForcesAndSourcesCore>
null;
755 monitor_ptr,
null,
null);
759 auto set_essential_bc = [&]() {
763 auto pre_proc_ptr = boost::make_shared<FEMethod>();
764 auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
767 auto time_scale = boost::make_shared<TimeScale>();
770 mField, pre_proc_ptr, {time_scale},
false);
771 post_proc_rhs_ptr->postProcessHook =
774 ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
775 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
776 ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
780 auto set_schur_pc = [&](
auto solver) {
782 CHKERR TSGetSNES(solver, &snes);
784 CHKERR SNESGetKSP(snes, &ksp);
786 CHKERR KSPGetPC(ksp, &pc);
787 PetscBool is_pcfs = PETSC_FALSE;
788 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
789 boost::shared_ptr<SetUpSchur> schur_ptr;
798 auto pre_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
799 auto post_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
800 pre_proc_schur_lhs_ptr->preProcessHook = [pre_proc_schur_lhs_ptr]() {
802 MOFEM_LOG(
"INCOMP_ELASTICITY", Sev::verbose) <<
"Lhs Zero matrices";
803 CHKERR MatZeroEntries(pre_proc_schur_lhs_ptr->A);
804 CHKERR MatZeroEntries(pre_proc_schur_lhs_ptr->B);
807 post_proc_schur_lhs_ptr->postProcessHook = [
this,
808 post_proc_schur_lhs_ptr]() {
810 MOFEM_LOG(
"INCOMP_ELASTICITY", Sev::verbose) <<
"Lhs Assemble Begin";
811 *(post_proc_schur_lhs_ptr->matAssembleSwitch) =
false;
812 CHKERR MatAssemblyBegin(post_proc_schur_lhs_ptr->A, MAT_FINAL_ASSEMBLY);
813 CHKERR MatAssemblyEnd(post_proc_schur_lhs_ptr->A, MAT_FINAL_ASSEMBLY);
815 mField, post_proc_schur_lhs_ptr, 1.,
818 CHKERR MatAssemblyBegin(post_proc_schur_lhs_ptr->B, MAT_FINAL_ASSEMBLY);
819 CHKERR MatAssemblyEnd(post_proc_schur_lhs_ptr->B, MAT_FINAL_ASSEMBLY);
820 CHKERR MatAXPY(post_proc_schur_lhs_ptr->B, 1, post_proc_schur_lhs_ptr->A,
821 SAME_NONZERO_PATTERN);
822 MOFEM_LOG(
"INCOMP_ELASTICITY", Sev::verbose) <<
"Lhs Assemble End";
825 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_schur_lhs_ptr);
826 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_schur_lhs_ptr);
828 if (is_pcfs == PETSC_TRUE) {
831 CHK_MOAB_THROW(schur_ptr->setUp(solver),
"setup schur preconditioner");
833 auto set_pcfieldsplit_preconditioned_ts = [&](
auto solver) {
836 auto name_prb =
simple->getProblemName();
839 name_prb,
ROW,
"P", 0, 1, is_p);
840 CHKERR PCFieldSplitSetIS(pc, PETSC_NULL, is_p);
844 "set pcfieldsplit preconditioned");
846 return boost::make_tuple(schur_ptr,
A, B);
849 return boost::make_tuple(schur_ptr,
A, B);
852 auto dm =
simple->getDM();
862 CHKERR set_essential_bc();
864 auto solver = pip_mng->createTSIM();
865 CHKERR TSSetFromOptions(solver);
867 CHKERR set_section_monitor(solver);
868 CHKERR set_time_monitor(dm, solver);
869 auto [schur_pc_ptr,
A, B] = set_schur_pc(solver);
871 CHKERR TSSetSolution(solver,
D);
873 CHKERR TSSolve(solver, NULL);