v0.16.3
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SetUpSchurImpl Struct Reference
Inheritance diagram for SetUpSchurImpl:
[legend]
Collaboration diagram for SetUpSchurImpl:
[legend]

Public Member Functions

 SetUpSchurImpl (MoFEM::Interface &m_field)
 
virtual ~SetUpSchurImpl ()=default
 
MoFEMErrorCode setUp (SmartPetscObj< KSP >)
 
 SetUpSchurImpl (MoFEM::Interface &m_field, SmartPetscObj< DM > sub_dm, SmartPetscObj< IS > field_split_is, SmartPetscObj< AO > ao_up)
 
virtual ~SetUpSchurImpl ()
 
MoFEMErrorCode setUp (TS solver)
 
MoFEMErrorCode preProc ()
 
MoFEMErrorCode postProc ()
 
 SetUpSchurImpl (MoFEM::Interface &m_field)
 
virtual ~SetUpSchurImpl ()
 
MoFEMErrorCode setUp (SmartPetscObj< TS > solver)
 
 SetUpSchurImpl (MoFEM::Interface &m_field)
 
virtual ~SetUpSchurImpl ()
 
MoFEMErrorCode setUp (SmartPetscObj< TS > solver)
 
 SetUpSchurImpl (MoFEM::Interface &m_field)
 
virtual ~SetUpSchurImpl ()=default
 
MoFEMErrorCode setUp (SmartPetscObj< KSP > solver)
 

Private Member Functions

MoFEMErrorCode createSubDM ()
 
MoFEMErrorCode setOperator ()
 
MoFEMErrorCode setPC (PC pc)
 
MoFEMErrorCode setDiagonalPC (PC pc)
 
MoFEMErrorCode setOperator ()
 
MoFEMErrorCode setPC (PC pc)
 
SmartPetscObj< DM > createSubDM ()
 
MoFEMErrorCode setEntities ()
 
MoFEMErrorCode createSubDM ()
 
MoFEMErrorCode setOperator ()
 
MoFEMErrorCode setPC (PC pc)
 
MoFEMErrorCode setDiagonalPC (PC pc)
 

Private Attributes

MoFEM::Interface & mField
 
SmartPetscObj< Mat > S
 
SmartPetscObj< DM > subDM
 field split sub dm
 
SmartPetscObj< IS > fieldSplitIS
 IS for split Schur block.
 
SmartPetscObj< AO > aoSchur
 
SmartPetscObj< DM > schurDM
 
SmartPetscObj< DM > blockDM
 
Range volEnts
 
Range subEnts
 

Additional Inherited Members

- Static Public Member Functions inherited from SetUpSchur
static boost::shared_ptr< SetUpSchur > createSetUpSchur (MoFEM::Interface &m_field)
 
static boost::shared_ptr< SetUpSchur > createSetUpSchur (MoFEM::Interface &m_field, SmartPetscObj< DM > sub_dm, SmartPetscObj< IS > field_split_it, SmartPetscObj< AO > ao_map)
 Create data structure for handling Schur complement.
 
static boost::shared_ptr< SetUpSchur > createSetUpSchur (MoFEM::Interface &m_field)
 
static boost::shared_ptr< SetUpSchur > createSetUpSchur (MoFEM::Interface &m_field)
 
static boost::shared_ptr< SetUpSchur > createSetUpSchur (MoFEM::Interface &m_field)
 
- Protected Member Functions inherited from SetUpSchur
 SetUpSchur ()=default
 
virtual ~SetUpSchur ()=default
 
 SetUpSchur ()=default
 
 SetUpSchur ()=default
 
 SetUpSchur ()=default
 
 SetUpSchur ()=default
 

Detailed Description

Examples
mofem/atom_tests/test_broken_space.cpp, mofem/tutorials/adv-0_plasticity/plastic.cpp, and mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 552 of file test_broken_space.cpp.

Constructor & Destructor Documentation

◆ SetUpSchurImpl() [1/5]

SetUpSchurImpl::SetUpSchurImpl ( MoFEM::Interface &  m_field)
inline

Definition at line 554 of file test_broken_space.cpp.

554: SetUpSchur(), mField(m_field) {}
MoFEM::Interface & mField
SetUpSchur()=default

◆ ~SetUpSchurImpl() [1/5]

virtual SetUpSchurImpl::~SetUpSchurImpl ( )
virtualdefault

◆ SetUpSchurImpl() [2/5]

SetUpSchurImpl::SetUpSchurImpl ( MoFEM::Interface &  m_field,
SmartPetscObj< DM >  sub_dm,
SmartPetscObj< IS >  field_split_is,
SmartPetscObj< AO >  ao_up 
)
inline

Definition at line 1659 of file plastic.cpp.

1661 : SetUpSchur(), mField(m_field), subDM(sub_dm),
1662 fieldSplitIS(field_split_is), aoSchur(ao_up) {
1663 if (S) {
1665 "Is expected that schur matrix is not "
1666 "allocated. This is "
1667 "possible only is if PC is set up twice");
1668 }
1669 }
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
SmartPetscObj< DM > subDM
field split sub dm
Definition plastic.cpp:1680
SmartPetscObj< Mat > S
SmartPetscObj< AO > aoSchur
Definition plastic.cpp:1682
SmartPetscObj< IS > fieldSplitIS
IS for split Schur block.
Definition plastic.cpp:1681

◆ ~SetUpSchurImpl() [2/5]

virtual SetUpSchurImpl::~SetUpSchurImpl ( )
inlinevirtual

Definition at line 1670 of file plastic.cpp.

1670{ S.reset(); }

◆ SetUpSchurImpl() [3/5]

SetUpSchurImpl::SetUpSchurImpl ( MoFEM::Interface &  m_field)
inline

Definition at line 1002 of file contact.cpp.

1002: SetUpSchur(), mField(m_field) {}

◆ ~SetUpSchurImpl() [3/5]

virtual SetUpSchurImpl::~SetUpSchurImpl ( )
inlinevirtual

Definition at line 1004 of file contact.cpp.

1004{}

◆ SetUpSchurImpl() [4/5]

SetUpSchurImpl::SetUpSchurImpl ( MoFEM::Interface &  m_field)
inline

Definition at line 996 of file incompressible_elasticity.cpp.

996: SetUpSchur(), mField(m_field) {}

◆ ~SetUpSchurImpl() [4/5]

virtual SetUpSchurImpl::~SetUpSchurImpl ( )
inlinevirtual

Definition at line 997 of file incompressible_elasticity.cpp.

997{ S.reset(); }

◆ SetUpSchurImpl() [5/5]

SetUpSchurImpl::SetUpSchurImpl ( MoFEM::Interface &  m_field)
inline

Definition at line 180 of file schur_elastic.cpp.

180 : SetUpSchur(), mField(m_field) {
181 if (S) {
184 "Is expected that schur matrix is not allocated. This is "
185 "possible only is if PC is set up twice");
186 }
187 }

◆ ~SetUpSchurImpl() [5/5]

virtual SetUpSchurImpl::~SetUpSchurImpl ( )
virtualdefault

Member Function Documentation

◆ createSubDM() [1/3]

MoFEMErrorCode SetUpSchurImpl::createSubDM ( )
private
Examples
mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 1096 of file contact.cpp.

1096 {
1098 auto simple = mField.getInterface<Simple>();
1099
1100 auto create_dm = [&](const char *name, const char *field_name, auto dm_type) {
1101 auto dm = createDM(mField.get_comm(), dm_type);
1102 auto create_dm_imp = [&]() {
1104 CHKERR DMMoFEMCreateSubDM(dm, simple->getDM(), name);
1105 CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
1106 CHKERR DMMoFEMAddElement(dm, simple->getDomainFEName());
1109 CHKERR DMSetUp(dm);
1111 };
1113 create_dm_imp(),
1114 "Error in creating schurDM. It is possible that schurDM is "
1115 "already created");
1116 return dm;
1117 };
1118
1119 // Note: here we can make block with bubbles of "U" and "SIGMA" fields. See
1120 // vec-0_elasticity where bubbles are added.
1121
1122 schurDM = create_dm("SCHUR", "U", "DMMOFEM_MG");
1123 blockDM = create_dm("BLOCK", "SIGMA", "DMMOFEM");
1124
1125 if constexpr (AT == AssemblyType::BLOCK_SCHUR) {
1126
1127 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
1128 auto block_mat_data = createBlockMatStructure(
1129 simple->getDM(),
1130
1131 {{
1132
1133 simple->getDomainFEName(),
1134
1135 {
1136
1137 {"U", "U"}, {"SIGMA", "U"}, {"U", "SIGMA"}, {"SIGMA", "SIGMA"}
1138
1139 }}}
1140
1141 );
1142
1144
1145 {schur_dm, block_dm}, block_mat_data,
1146
1147 {"SIGMA"}, {nullptr}, true
1148
1149 );
1150 };
1151
1152 auto nested_mat_data = get_nested_mat_data(schurDM, blockDM);
1153 CHKERR DMMoFEMSetNestSchurData(simple->getDM(), nested_mat_data);
1154
1155 } else {
1156 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1157 "Only BLOCK_SCHUR is implemented");
1158 }
1159
1161}
std::string name
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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.
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:244
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:574
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:536
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:267
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:309
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 DMMoFEMSetNestSchurData(DM dm, boost::shared_ptr< NestSchurData >)
Definition DMMoFEM.cpp:1641
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
constexpr auto field_name
virtual MPI_Comm & get_comm() const =0
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
SmartPetscObj< DM > schurDM
Definition contact.cpp:1017
SmartPetscObj< DM > blockDM
Definition contact.cpp:1018
constexpr AssemblyType AT

◆ createSubDM() [2/3]

SmartPetscObj< DM > SetUpSchurImpl::createSubDM ( )
private

◆ createSubDM() [3/3]

MoFEMErrorCode SetUpSchurImpl::createSubDM ( )
private

◆ postProc()

MoFEMErrorCode SetUpSchurImpl::postProc ( )

◆ preProc()

MoFEMErrorCode SetUpSchurImpl::preProc ( )

◆ setDiagonalPC() [1/2]

MoFEMErrorCode SetUpSchurImpl::setDiagonalPC ( PC  pc)
private
Examples
mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 1246 of file contact.cpp.

1246 {
1248 KSP *subksp;
1249 CHKERR PCFieldSplitSchurGetSubKSP(pc, PETSC_NULLPTR, &subksp);
1250 auto get_pc = [](auto ksp) {
1251 PC pc_raw;
1252 CHKERR KSPGetPC(ksp, &pc_raw);
1253 return SmartPetscObj<PC>(pc_raw, true); // bump reference
1254 };
1255 CHKERR setSchurA00MatSolvePC(get_pc(subksp[0]));
1256
1257 auto set_pc_p_mg = [](auto dm, auto pc, auto S) {
1259 CHKERR PCSetDM(pc, dm);
1260 PetscBool same = PETSC_FALSE;
1261 PetscObjectTypeCompare((PetscObject)pc, PCMG, &same);
1262 if (same) {
1264 pc, createPCMGSetUpViaApproxOrdersCtx(dm, S, true));
1265 CHKERR PCSetFromOptions(pc);
1266 }
1268 };
1269
1270 auto set_pc_ksp = [&](auto dm, auto pc, auto S) {
1272 PetscBool same = PETSC_FALSE;
1273 PetscObjectTypeCompare((PetscObject)pc, PCKSP, &same);
1274 if (same) {
1275 CHKERR PCSetFromOptions(pc);
1276 KSP inner_ksp;
1277 CHKERR PCKSPGetKSP(pc, &inner_ksp);
1278 CHKERR KSPSetFromOptions(inner_ksp);
1279 PC inner_pc;
1280 CHKERR KSPGetPC(inner_ksp, &inner_pc);
1281 CHKERR PCSetFromOptions(inner_pc);
1282 CHKERR set_pc_p_mg(dm, inner_pc, S);
1283 }
1285 };
1286
1287 CHKERR set_pc_ksp(schurDM, get_pc(subksp[1]), S);
1288 CHKERR set_pc_p_mg(schurDM, get_pc(subksp[1]), S);
1289
1290 CHKERR PetscFree(subksp);
1292}
SmartPetscObj< KSP > ksp
MoFEMErrorCode setSchurA00MatSolvePC(SmartPetscObj< PC > pc)
Set PC for A00 block.
Definition Schur.cpp:4934
boost::shared_ptr< PCMGSetUpViaApproxOrdersCtx > createPCMGSetUpViaApproxOrdersCtx(DM dm, Mat A, bool use_shell_mat)
createPCMGSetUpViaApproxOrdersCtx
MoFEMErrorCode PCMGSetUpViaApproxOrders(PC pc, boost::shared_ptr< PCMGSetUpViaApproxOrdersCtx > ctx, int verb)
Function build MG structure.
intrusive_ptr for managing petsc objects

◆ setDiagonalPC() [2/2]

MoFEMErrorCode SetUpSchurImpl::setDiagonalPC ( PC  pc)
private

◆ setEntities()

MoFEMErrorCode SetUpSchurImpl::setEntities ( )
private
Examples
mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 253 of file schur_elastic.cpp.

253 {
256 CHKERR mField.get_moab().get_entities_by_dimension(simple->getMeshset(),
258 CHKERR mField.get_moab().get_entities_by_handle(simple->getMeshset(),
259 subEnts);
260 subEnts = subtract(subEnts, volEnts);
262};
constexpr int SPACE_DIM
[Define dimension]
virtual moab::Interface & get_moab()=0

◆ setOperator() [1/3]

MoFEMErrorCode SetUpSchurImpl::setOperator ( )
private
Examples
mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 1163 of file contact.cpp.

1163 {
1165
1166 double eps_stab = 1e-4;
1167 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-eps_stab", &eps_stab,
1168 PETSC_NULLPTR);
1169
1172 using OpMassStab = B::OpMass<3, SPACE_DIM * SPACE_DIM>;
1173
1174 auto simple = mField.getInterface<Simple>();
1175 auto pip = mField.getInterface<PipelineManager>();
1176
1177 auto dm_is = getDMSubData(schurDM)->getSmartRowIs();
1178 auto ao_up = createAOMappingIS(dm_is, PETSC_NULLPTR);
1179
1180 // Boundary
1181 pip->getOpBoundaryLhsPipeline().push_front(createOpSchurAssembleBegin());
1182 pip->getOpBoundaryLhsPipeline().push_back(
1183 new OpMassStab("SIGMA", "SIGMA",
1184 [eps_stab](double, double, double) { return eps_stab; }));
1185 pip->getOpBoundaryLhsPipeline().push_back(
1186
1187 createOpSchurAssembleEnd({"SIGMA"}, {nullptr}, ao_up, S, false, false)
1188
1189 );
1190
1191 // Domain
1192 pip->getOpDomainLhsPipeline().push_front(createOpSchurAssembleBegin());
1193 pip->getOpDomainLhsPipeline().push_back(
1194
1195 createOpSchurAssembleEnd({"SIGMA"}, {nullptr}, ao_up, S, false, false)
1196
1197 );
1198
1199 auto pre_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
1200 auto post_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
1201
1202 pre_proc_schur_lhs_ptr->preProcessHook = [this]() {
1204 CHKERR MatZeroEntries(S);
1205 MOFEM_LOG("CONTACT", Sev::verbose) << "Lhs Assemble Begin";
1207 };
1208
1209 post_proc_schur_lhs_ptr->postProcessHook = [this, ao_up,
1210 post_proc_schur_lhs_ptr]() {
1212 MOFEM_LOG("CONTACT", Sev::verbose) << "Lhs Assemble End";
1213 [[maybe_unused]] auto print_mat_norm = [this](auto a, std::string prefix) {
1215 double nrm;
1216 CHKERR MatNorm(a, NORM_FROBENIUS, &nrm);
1217 MOFEM_LOG("CONTACT", Sev::noisy) << prefix << " norm = " << nrm;
1219 };
1220 CHKERR MatAssemblyBegin(S, MAT_FINAL_ASSEMBLY);
1221 CHKERR MatAssemblyEnd(S, MAT_FINAL_ASSEMBLY);
1223 mField, post_proc_schur_lhs_ptr, 1, S, ao_up)();
1224#ifndef NDEBUG
1225 CHKERR print_mat_norm(S, "S");
1226#endif // NDEBUG
1227 MOFEM_LOG("CONTACT", Sev::verbose) << "Lhs Assemble Finish";
1229 };
1230
1231 auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
1232 ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_schur_lhs_ptr);
1233 ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_schur_lhs_ptr);
1234
1236}
constexpr double a
@ BLOCK_PRECONDITIONER_SCHUR
Block preconditioner Schur assembly.
#define MOFEM_LOG(channel, severity)
Log.
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1321
OpSchurAssembleBase * createOpSchurAssembleEnd(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao, SmartPetscObj< Mat > schur, bool sym_schur, bool symm_op)
Construct a new Op Schur Assemble End object.
Definition Schur.cpp:4892
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
auto getDMSubData(DM dm)
Get sub problem data structure.
Definition DMMoFEM.hpp:1337
auto createAOMappingIS(IS isapp, IS ispetsc)
Creates an application mapping using two index sets.
OpSchurAssembleBase * createOpSchurAssembleBegin()
Definition Schur.cpp:4887
Class (Function) to enforce essential constrains on the left hand side diagonal.
Definition Essential.hpp:33
PipelineManager interface.

◆ setOperator() [2/3]

MoFEMErrorCode SetUpSchurImpl::setOperator ( )
private

◆ setOperator() [3/3]

MoFEMErrorCode SetUpSchurImpl::setOperator ( )
private

◆ setPC() [1/3]

MoFEMErrorCode SetUpSchurImpl::setPC ( PC  pc)
private
Examples
mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 1238 of file contact.cpp.

1238 {
1240 auto block_is = getDMSubData(blockDM)->getSmartRowIs();
1241 CHKERR PCFieldSplitSetIS(pc, NULL, block_is);
1242 CHKERR PCFieldSplitSetSchurPre(pc, PC_FIELDSPLIT_SCHUR_PRE_USER, S);
1244}

◆ setPC() [2/3]

MoFEMErrorCode SetUpSchurImpl::setPC ( PC  pc)
private

◆ setPC() [3/3]

MoFEMErrorCode SetUpSchurImpl::setPC ( PC  pc)
private

◆ setUp() [1/5]

MoFEMErrorCode SetUpSchurImpl::setUp ( SmartPetscObj< KSP >  solver)
virtual

Implements SetUpSchur.

◆ setUp() [2/5]

MoFEMErrorCode SetUpSchurImpl::setUp ( SmartPetscObj< KSP >  ksp)
virtual

Implements SetUpSchur.

Examples
mofem/atom_tests/test_broken_space.cpp, mofem/tutorials/adv-0_plasticity/plastic.cpp, and mofem/tutorials/vec-10_elasticity_schur/schur_elastic.cpp.

Definition at line 565 of file test_broken_space.cpp.

565 {
568 auto pip_mng = mField.getInterface<PipelineManager>();
569
570 CHKERR KSPSetFromOptions(ksp);
571 PC pc;
572 CHKERR KSPGetPC(ksp, &pc);
573
574 PetscBool is_pcfs = PETSC_FALSE;
575 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
576 if (is_pcfs) {
577
578 MOFEM_LOG("AT", Sev::inform) << "Setup Schur pc";
579
580 auto create_sub_dm = [&]() {
582
583 auto create_dm = [&](
584
585 std::string problem_name,
586 std::vector<std::string> fe_names,
587 std::vector<std::string> fields,
588
589 auto dm_type
590
591 ) {
592 auto dm = createDM(mField.get_comm(), dm_type);
593 auto create_dm_imp = [&]() {
595 CHKERR DMMoFEMCreateSubDM(dm, simple->getDM(), problem_name.c_str());
596 CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
597 for (auto fe : fe_names) {
599 }
600 CHKERR DMMoFEMAddElement(dm, simple->getSkeletonFEName());
601 for (auto field : fields) {
604 }
605 CHKERR DMSetUp(dm);
607 };
609 create_dm_imp(),
610 "Error in creating schurDM. It is possible that schurDM is "
611 "already created");
612 return dm;
613 };
614
615 auto schur_dm = create_dm(
616
617 "SCHUR",
618
619 {simple->getDomainFEName(), simple->getSkeletonFEName()},
620
621 {"HYBRID"},
622
623 "DMMOFEM_MG");
624
625 auto block_dm = create_dm(
626
627 "BLOCK",
628
629 {simple->getDomainFEName(), simple->getSkeletonFEName()},
630
631 {"BROKEN", "U"},
632
633 "DMMOFEM");
634
635 return std::make_tuple(schur_dm, block_dm);
636 };
637
638 auto get_nested_mat_data = [&](auto schur_dm, auto block_dm) {
639 auto block_mat_data = createBlockMatStructure(
640 simple->getDM(),
641
642 {
643
644 {
645
646 simple->getDomainFEName(),
647
648 {
649
650 {"BROKEN", "BROKEN"},
651 {"U", "U"},
652 {"BROKEN", "U"},
653 {"U", "BROKEN"}
654
655 }
656
657 },
658
659 {
660
661 simple->getSkeletonFEName(),
662
663 {
664
665 {"BROKEN", "HYBRID"}, {"HYBRID", "BROKEN"}
666
667 }
668
669 }
670
671 }
672
673 );
674
676
677 {schur_dm, block_dm}, block_mat_data,
678
679 {"BROKEN", "U"}, {nullptr, nullptr}, true
680
681 );
682 };
683
684 auto set_ops = [&](auto schur_dm) {
686 auto dm_is = getDMSubData(schur_dm)->getSmartRowIs();
687 auto ao_up = createAOMappingIS(dm_is, PETSC_NULLPTR);
688
689 boost::shared_ptr<BlockStructure> block_data;
690 CHKERR DMMoFEMGetBlocMatData(simple->getDM(), block_data);
691
692 if (AT == BLOCK_SCHUR) {
693 pip_mng->getOpDomainLhsPipeline().push_front(
695 pip_mng->getOpDomainLhsPipeline().push_back(
696
697 createOpSchurAssembleEnd({"BROKEN", "U"}, {nullptr, nullptr}, ao_up,
698 S, true, true)
699
700 );
701 }
702
703 auto pre_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
704 auto post_proc_schur_lhs_ptr = boost::make_shared<FEMethod>();
705
706 pre_proc_schur_lhs_ptr->preProcessHook = [this]() {
708 CHKERR MatZeroEntries(S);
709 MOFEM_LOG("AT", Sev::verbose) << "Lhs Assemble Begin";
711 };
712
713 post_proc_schur_lhs_ptr->postProcessHook = [this, ao_up,
714 post_proc_schur_lhs_ptr]() {
716 MOFEM_LOG("AT", Sev::verbose) << "Lhs Assemble End";
717
718 if (AT == BLOCK_SCHUR) {
719 CHKERR MatAssemblyBegin(S, MAT_FINAL_ASSEMBLY);
720 CHKERR MatAssemblyEnd(S, MAT_FINAL_ASSEMBLY);
721 if (1) {
722 auto S_from_block = matDuplicate(S, MAT_SHARE_NONZERO_PATTERN);
723 // Create matrix from block mat
724 CHKERR assembleBlockMatSchur(mField, post_proc_schur_lhs_ptr->B,
725 S_from_block, {"BROKEN", "U"},
726 {nullptr, nullptr}, ao_up);
727 CHKERR MatAssemblyBegin(S_from_block, MAT_FINAL_ASSEMBLY);
728 CHKERR MatAssemblyEnd(S_from_block, MAT_FINAL_ASSEMBLY);
729 CHKERR MatAYPX(S_from_block, -1, S, DIFFERENT_NONZERO_PATTERN);
730 double norm;
731 CHKERR MatNorm(S_from_block, NORM_FROBENIUS, &norm);
732 MOFEM_LOG("AT", Sev::inform) << "Norm of difference: " << norm;
733 if (norm > 1e-6)
734 SETERRQ(
735 PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
736 "Norm of difference between Schur and block matrix is larger "
737 "than accepted");
738 }
739 } else {
740 CHKERR assembleBlockMatSchur(mField, post_proc_schur_lhs_ptr->B, S,
741 {"BROKEN", "U"}, {nullptr, nullptr}, ao_up);
742 CHKERR MatAssemblyBegin(S, MAT_FINAL_ASSEMBLY);
743 CHKERR MatAssemblyEnd(S, MAT_FINAL_ASSEMBLY);
744 }
745
746 MOFEM_LOG("AT", Sev::verbose) << "Lhs Assemble Finish";
748 };
749
750 auto ksp_ctx_ptr = getDMKspCtx(simple->getDM());
751 ksp_ctx_ptr->getPreProcSetOperators().push_front(pre_proc_schur_lhs_ptr);
752 ksp_ctx_ptr->getPostProcSetOperators().push_back(post_proc_schur_lhs_ptr);
753
755 };
756
757 auto set_pc = [&](auto pc, auto block_dm) {
759 auto block_is = getDMSubData(block_dm)->getSmartRowIs();
760 CHKERR PCFieldSplitSetIS(pc, NULL, block_is);
761 CHKERR PCFieldSplitSetSchurPre(pc, PC_FIELDSPLIT_SCHUR_PRE_USER, S);
763 };
764
765
766
767 auto [schur_dm, block_dm] = create_sub_dm();
768 if (AT == BLOCK_SCHUR || AT == BLOCK_MAT) {
769 auto nested_mat_data = get_nested_mat_data(schur_dm, block_dm);
770 CHKERR DMMoFEMSetNestSchurData(simple->getDM(), nested_mat_data);
771 }
772 S = createDMHybridisedL2Matrix(schur_dm);
773 CHKERR MatSetDM(S, PETSC_NULLPTR);
774
775 int bs = (SPACE_DIM == 2) ? NBEDGE_L2(hybrid_approx_order)
777 CHKERR MatSetBlockSize(S, bs);
778
779 CHKERR set_ops(schur_dm);
780 CHKERR set_pc(pc, block_dm);
781 DM solver_dm;
782 CHKERR KSPGetDM(ksp, &solver_dm);
783 if (AT == BLOCK_SCHUR || AT == BLOCK_MAT)
784 CHKERR DMSetMatType(solver_dm, MATSHELL);
785
786 auto get_pc = [](auto ksp) {
787 PC pc_raw;
788 CHKERR KSPGetPC(ksp, &pc_raw);
789 return pc_raw;
790 };
791
792 auto set_diagonal_pc = [&](auto pc) {
794
795 if (AT == BLOCK_SCHUR || AT == BLOCK_MAT) {
796 auto A = createDMBlockMat(simple->getDM());
797 auto P = createDMNestSchurMat(simple->getDM());
798 CHKERR PCSetOperators(pc, A, P);
799 }
800
801 KSP *subksp;
802 CHKERR PCFieldSplitSchurGetSubKSP(pc, PETSC_NULLPTR, &subksp);
803 CHKERR setSchurA00MatSolvePC(SmartPetscObj<PC>(get_pc(subksp[0]), true));
804
805 CHKERR PetscFree(subksp);
807 };
808
809 auto set_mg_for_schur_complement = [&](auto pc, auto schur_dm, auto S) {
811
812 KSP *subksp;
813 CHKERR PCFieldSplitSchurGetSubKSP(pc, PETSC_NULLPTR, &subksp);
814 auto subpc = get_pc(subksp[1]);
815
816 auto set_pc_p_mg = [](auto dm, auto pc, auto S) {
818 CHKERR PCSetDM(pc, dm);
819 PetscBool same = PETSC_FALSE;
820 PetscObjectTypeCompare((PetscObject)pc, PCMG, &same);
821 if (same) {
822 MOFEM_LOG("TIMER", Sev::inform) << "Set up MG";
824 pc, createPCMGSetUpViaApproxOrdersCtx(dm, S, true));
825 CHKERR PCSetFromOptions(pc);
826 }
828 };
829
830 PetscBool same = PETSC_FALSE;
831 PetscObjectTypeCompare((PetscObject)subpc, PCKSP, &same);
832 if (same) {
833 CHKERR PCSetFromOptions(subpc);
834 KSP inner_ksp;
835 CHKERR PCKSPGetKSP(subpc, &inner_ksp);
836 CHKERR KSPSetFromOptions(inner_ksp);
837 PC inner_pc;
838 CHKERR KSPGetPC(inner_ksp, &inner_pc);
839 CHKERR PCSetFromOptions(inner_pc);
840 CHKERR set_pc_p_mg(schur_dm, inner_pc, S);
841 }
842
843 CHKERR PetscFree(subksp);
845 };
846
847 CHKERR KSPSetUp(ksp);
848 if (AT == BLOCK_SCHUR || AT == BLOCK_MAT) {
849 CHKERR set_diagonal_pc(pc);
850 CHKERR set_mg_for_schur_complement(pc, schur_dm, S);
851 }
852
853 } else {
854 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
855 "PC is not set to PCFIELDSPLIT");
856 }
858}
ProjectedField & field
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
@ BLOCK_MAT
Block matrix assembly.
@ BLOCK_SCHUR
Block Schur assembly.
#define NBFACETRI_L2(P)
Number of base functions on triangle for L2 space.
#define NBEDGE_L2(P)
Number of base functions on edge from L2 space.
MoFEMErrorCode DMMoFEMGetBlocMatData(DM dm, boost::shared_ptr< BlockStructure > &)
Get data for block mat.
Definition DMMoFEM.cpp:1621
auto getDMKspCtx(DM dm)
Get KSP context data structure used by DM.
Definition DMMoFEM.hpp:1293
auto createDMHybridisedL2Matrix(DM dm)
Get smart hybridised L2 matrix from DM.
Definition DMMoFEM.hpp:1249
SmartPetscObj< Mat > matDuplicate(Mat mat, MatDuplicateOption op)
auto createDMNestSchurMat(DM dm)
Definition DMMoFEM.hpp:1263
MoFEMErrorCode assembleBlockMatSchur(MoFEM::Interface &m_field, Mat B, Mat S, std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range > > field_ents, SmartPetscObj< AO > ao)
Assemble Schur complement S = A11 - A10 A00^{-1} A01 from block matrix.
Definition Schur.cpp:3650
auto createDMBlockMat(DM dm)
Definition DMMoFEM.hpp:1256
constexpr AssemblyType A
[Define dimension]
int hybrid_approx_order

◆ setUp() [3/5]

MoFEMErrorCode SetUpSchurImpl::setUp ( SmartPetscObj< TS >  solver)
virtual

Implements SetUpSchur.

Definition at line 1021 of file contact.cpp.

1021 {
1023 auto simple = mField.getInterface<Simple>();
1024 auto pip = mField.getInterface<PipelineManager>();
1025
1026 SNES snes;
1027 CHKERR TSGetSNES(solver, &snes);
1028 KSP ksp;
1029 CHKERR SNESGetKSP(snes, &ksp);
1030 CHKERR KSPSetFromOptions(ksp);
1031
1032 PC pc;
1033 CHKERR KSPGetPC(ksp, &pc);
1034
1035 PetscBool is_pcfs = PETSC_FALSE;
1036 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
1037 if (is_pcfs) {
1038
1039 MOFEM_LOG("CONTACT", Sev::inform) << "Setup Schur pc";
1040
1041 if (S) {
1044 "It is expected that Schur matrix is not allocated. This is "
1045 "possible only if PC is set up twice");
1046 }
1047
1049
1050 // Add data to DM storage
1052 CHKERR MatSetBlockSize(S, SPACE_DIM);
1053 // CHKERR MatSetOption(S, MAT_SYMMETRIC, PETSC_TRUE);
1054
1055 // Set DM to use shell block matrix
1056 DM solver_dm;
1057 CHKERR TSGetDM(solver, &solver_dm);
1058 CHKERR DMSetMatType(solver_dm, MATSHELL);
1059
1060 auto ts_ctx_ptr = getDMTsCtx(solver_dm);
1061 auto A = createDMBlockMat(simple->getDM());
1062 auto P = createDMNestSchurMat(simple->getDM());
1063
1064 if (is_quasi_static == PETSC_TRUE) {
1065 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a,
1066 Mat A, Mat B, void *ctx) {
1067 return TsSetIJacobian(ts, t, u, u_t, a, B, A, ctx);
1068 };
1069 CHKERR TSSetIJacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1070 } else {
1071 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, Vec utt,
1072 PetscReal a, PetscReal aa, Mat A, Mat B,
1073 void *ctx) {
1074 return TsSetI2Jacobian(ts, t, u, u_t, utt, a, aa, B, A, ctx);
1075 };
1076 CHKERR TSSetI2Jacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1077 }
1078 CHKERR KSPSetOperators(ksp, A, P);
1079
1081 CHKERR setPC(pc);
1082 CHKERR TSSetUp(solver);
1083 CHKERR KSPSetUp(ksp);
1085
1086 } else {
1087 MOFEM_LOG("CONTACT", Sev::inform) << "No Schur PC";
1088 pip->getOpBoundaryLhsPipeline().push_front(createOpSchurAssembleBegin());
1089 pip->getOpBoundaryLhsPipeline().push_back(createOpSchurAssembleEnd({}, {}));
1090 pip->getOpDomainLhsPipeline().push_front(createOpSchurAssembleBegin());
1091 pip->getOpDomainLhsPipeline().push_back(createOpSchurAssembleEnd({}, {}));
1092 }
1094}
Vec t
Removal: the ring edge.
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1236
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobian in TS solver.
Definition TsCtx.cpp:169
PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, PetscReal a, PetscReal aa, Mat A, Mat B, void *ctx)
Calculation Jacobian for second order PDE in time.
Definition TsCtx.cpp:519
PetscBool is_quasi_static
Definition plastic.cpp:144
MoFEMErrorCode createSubDM()
Definition contact.cpp:1096
MoFEMErrorCode setDiagonalPC(PC pc)
Definition contact.cpp:1246
MoFEMErrorCode setPC(PC pc)
Definition contact.cpp:1238
MoFEMErrorCode setOperator()
Definition contact.cpp:1163

◆ setUp() [4/5]

MoFEMErrorCode SetUpSchurImpl::setUp ( SmartPetscObj< TS >  solver)
virtual

Implements SetUpSchur.

◆ setUp() [5/5]

MoFEMErrorCode SetUpSchurImpl::setUp ( TS  solver)
virtual

Implements SetUpSchur.

Definition at line 1685 of file plastic.cpp.

1685 {
1687 auto simple = mField.getInterface<Simple>();
1688 auto pip_mng = mField.getInterface<PipelineManager>();
1689
1690 SNES snes;
1691 CHKERR TSGetSNES(solver, &snes);
1692 KSP ksp;
1693 CHKERR SNESGetKSP(snes, &ksp);
1694 CHKERR KSPSetFromOptions(ksp);
1695
1696 PC pc;
1697 CHKERR KSPGetPC(ksp, &pc);
1698 PetscBool is_pcfs = PETSC_FALSE;
1699 PetscObjectTypeCompare((PetscObject)pc, PCFIELDSPLIT, &is_pcfs);
1700 if (is_pcfs) {
1701 if (S) {
1703 "Is expected that schur matrix is not "
1704 "allocated. This is "
1705 "possible only is if PC is set up twice");
1706 }
1707
1709 CHKERR MatSetBlockSize(S, SPACE_DIM);
1710
1711 // Set DM to use shell block matrix
1712 DM solver_dm;
1713 CHKERR TSGetDM(solver, &solver_dm);
1714 CHKERR DMSetMatType(solver_dm, MATSHELL);
1715
1716 auto ts_ctx_ptr = getDMTsCtx(solver_dm);
1717 auto A = createDMBlockMat(simple->getDM());
1718 auto P = createDMNestSchurMat(simple->getDM());
1719
1720 if (is_quasi_static == PETSC_TRUE) {
1721 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a,
1722 Mat A, Mat B, void *ctx) {
1723 return TsSetIJacobian(ts, t, u, u_t, a, B, A, ctx);
1724 };
1725 CHKERR TSSetIJacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1726 } else {
1727 auto swap_assemble = [](TS ts, PetscReal t, Vec u, Vec u_t, Vec utt,
1728 PetscReal a, PetscReal aa, Mat A, Mat B,
1729 void *ctx) {
1730 return TsSetI2Jacobian(ts, t, u, u_t, utt, a, aa, B, A, ctx);
1731 };
1732 CHKERR TSSetI2Jacobian(solver, A, P, swap_assemble, ts_ctx_ptr.get());
1733 }
1734 CHKERR KSPSetOperators(ksp, A, P);
1735
1736 auto set_ops = [&]() {
1738 auto pip_mng = mField.getInterface<PipelineManager>();
1739
1740#ifndef ADD_CONTACT
1741 // Boundary
1742 pip_mng->getOpBoundaryLhsPipeline().push_front(
1744 pip_mng->getOpBoundaryLhsPipeline().push_back(createOpSchurAssembleEnd(
1745
1746 {"EP", "TAU"}, {nullptr, nullptr}, aoSchur, S, false, false
1747
1748 ));
1749 // Domain
1750 pip_mng->getOpDomainLhsPipeline().push_front(
1752 pip_mng->getOpDomainLhsPipeline().push_back(createOpSchurAssembleEnd(
1753
1754 {"EP", "TAU"}, {nullptr, nullptr}, aoSchur, S, false, false
1755
1756 ));
1757#else
1758
1759 double eps_stab = 1e-4;
1760 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-eps_stab", &eps_stab,
1761 PETSC_NULLPTR);
1762
1765 using OpMassStab = B::OpMass<3, SPACE_DIM * SPACE_DIM>;
1766
1767 // Boundary
1768 pip_mng->getOpBoundaryLhsPipeline().push_front(
1770 pip_mng->getOpBoundaryLhsPipeline().push_back(
1771 new OpMassStab("SIGMA", "SIGMA", [eps_stab](double, double, double) {
1772 return eps_stab;
1773 }));
1774 pip_mng->getOpBoundaryLhsPipeline().push_back(createOpSchurAssembleEnd(
1775
1776 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, aoSchur, S,
1777 false, false
1778
1779 ));
1780 // Domain
1781 pip_mng->getOpDomainLhsPipeline().push_front(
1783 pip_mng->getOpDomainLhsPipeline().push_back(createOpSchurAssembleEnd(
1784
1785 {"SIGMA", "EP", "TAU"}, {nullptr, nullptr, nullptr}, aoSchur, S,
1786 false, false
1787
1788 ));
1789#endif // ADD_CONTACT
1791 };
1792
1793 auto set_assemble_elems = [&]() {
1795 auto schur_asmb_pre_proc = boost::make_shared<FEMethod>();
1796 schur_asmb_pre_proc->preProcessHook = [this]() {
1798 CHKERR MatZeroEntries(S);
1799 MOFEM_LOG("TIMER", Sev::verbose) << "Lhs Assemble Begin";
1801 };
1802 auto schur_asmb_post_proc = boost::make_shared<FEMethod>();
1803 auto weak_schur_asmb_post_proc = boost::weak_ptr<FEMethod>(
1804 schur_asmb_post_proc); // fe method passed to lambda, have to be weak ptr to avoid circular shared ptr reference
1805
1806 schur_asmb_post_proc->postProcessHook = [this,
1807 weak_schur_asmb_post_proc]() {
1809 MOFEM_LOG("TIMER", Sev::verbose) << "Lhs Assemble End";
1810
1811 // Apply essential constrains to Schur complement
1812 CHKERR MatAssemblyBegin(S, MAT_FINAL_ASSEMBLY);
1813 CHKERR MatAssemblyEnd(S, MAT_FINAL_ASSEMBLY);
1815 mField, weak_schur_asmb_post_proc.lock(), 1, S, aoSchur)();
1816
1818 };
1819 auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
1820 ts_ctx_ptr->getPreProcessIJacobian().push_front(schur_asmb_pre_proc);
1821 ts_ctx_ptr->getPostProcessIJacobian().push_front(schur_asmb_post_proc);
1823 };
1824
1825 auto set_pc = [&]() {
1827 CHKERR PCFieldSplitSetIS(pc, NULL, fieldSplitIS);
1828 CHKERR PCFieldSplitSetSchurPre(pc, PC_FIELDSPLIT_SCHUR_PRE_USER, S);
1830 };
1831
1832 auto set_diagonal_pc = [&]() {
1834 KSP *subksp;
1835 CHKERR PCFieldSplitSchurGetSubKSP(pc, PETSC_NULLPTR, &subksp);
1836 auto get_pc = [](auto ksp) {
1837 PC pc_raw;
1838 CHKERR KSPGetPC(ksp, &pc_raw);
1839 return SmartPetscObj<PC>(pc_raw,
1840 true); // bump reference
1841 };
1842 CHKERR setSchurA00MatSolvePC(get_pc(subksp[0]));
1843 CHKERR PetscFree(subksp);
1845 };
1846
1847 CHKERR set_ops();
1848 CHKERR set_pc();
1849 CHKERR set_assemble_elems();
1850
1851 CHKERR TSSetUp(solver);
1852 CHKERR KSPSetUp(ksp);
1853 CHKERR set_diagonal_pc();
1854
1855 } else {
1856 pip_mng->getOpBoundaryLhsPipeline().push_front(
1858 pip_mng->getOpBoundaryLhsPipeline().push_back(
1859 createOpSchurAssembleEnd({}, {}));
1860 pip_mng->getOpDomainLhsPipeline().push_front(createOpSchurAssembleBegin());
1861 pip_mng->getOpDomainLhsPipeline().push_back(
1862 createOpSchurAssembleEnd({}, {}));
1863 }
1864
1865 // fieldSplitIS.reset();
1866 // aoSchur.reset();
1868}

Member Data Documentation

◆ aoSchur

SmartPetscObj<AO> SetUpSchurImpl::aoSchur
private
Examples
mofem/tutorials/adv-0_plasticity/plastic.cpp.

Definition at line 1682 of file plastic.cpp.

◆ blockDM

SmartPetscObj< DM > SetUpSchurImpl::blockDM
private

◆ fieldSplitIS

SmartPetscObj<IS> SetUpSchurImpl::fieldSplitIS
private

IS for split Schur block.

Examples
mofem/tutorials/adv-0_plasticity/plastic.cpp.

Definition at line 1681 of file plastic.cpp.

◆ mField

MoFEM::Interface & SetUpSchurImpl::mField
private

◆ S

SmartPetscObj< Mat > SetUpSchurImpl::S
private

◆ schurDM

SmartPetscObj< DM > SetUpSchurImpl::schurDM
private

◆ subDM

SmartPetscObj< DM > SetUpSchurImpl::subDM
private

field split sub dm

Examples
mofem/tutorials/adv-0_plasticity/plastic.cpp.

Definition at line 1680 of file plastic.cpp.

◆ subEnts

Range SetUpSchurImpl::subEnts
private

◆ volEnts

Range SetUpSchurImpl::volEnts
private

The documentation for this struct was generated from the following files: