v0.9.2
PipelineManager.cpp
Go to the documentation of this file.
1 /** \file PipelineManager.cpp
2  * \brief Implementation of basic interface
3  * \ingroup mofem_basic_interface
4  */
5 
6 /* MoFEM is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
18  */
19 
20 namespace MoFEM {
21 
23  UnknownInterface **iface) const {
25  *iface = NULL;
26  if (uuid == IDD_MOFEMBasic) {
27  *iface = const_cast<PipelineManager *>(this);
29  }
30  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "unknown interface");
32 }
33 
34 PipelineManager::PipelineManager(const MoFEM::Core &core) : cOre(const_cast<Core &>(core)) {}
35 
38  Interface &m_field = cOre;
39  Simple *simple_interface = m_field.getInterface<Simple>();
40  if (!dm)
41  dm = simple_interface->getDM();
42 
43  // Add element to calculate lhs of stiff part
44  if (feDomainLhs)
45  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getDomainFEName(),
46  feDomainLhs);
47  if (feBoundaryLhs)
48  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getBoundaryFEName(),
50  if (feSkeletonLhs)
51  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getSkeletonFEName(),
53 
54  // Add element to calculate rhs of stiff part
55  if (feDomainRhs)
56  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getDomainFEName(),
57  feDomainRhs);
58  if (feBoundaryRhs)
59  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getBoundaryFEName(),
61  if (feSkeletonRhs)
62  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getSkeletonFEName(),
64 
66 }
67 
69  Interface &m_field = cOre;
70  Simple *simple_interface = m_field.getInterface<Simple>();
71 
72  auto copy_dm_struture = [&](auto simple_dm) {
73  MPI_Comm comm;
74  CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
75  DMType type;
76  CHKERR DMGetType(simple_dm, &type);
77  dm = createSmartDM(comm, type);
78  CHKERR DMMoFEMDuplicateDMCtx(simple_interface->getDM(), dm);
79  return dm;
80  };
81 
82  if (!dm)
83  dm = copy_dm_struture(simple_interface->getDM());
84  else
85  dm = copy_dm_struture(dm);
86 
87  auto set_dm_section = [&](auto dm) {
89  PetscSection section;
90  CHKERR m_field.getInterface<ISManager>()->sectionCreate(
91  simple_interface->getProblemName(), &section);
92  CHKERR DMSetDefaultSection(dm, section);
93  CHKERR DMSetDefaultGlobalSection(dm, section);
94  CHKERR PetscSectionDestroy(&section);
96  };
97  CHKERR set_dm_section(dm);
98 
99  boost::shared_ptr<FEMethod> null;
100 
101  // Add element to calculate lhs of stiff part
102  if (feDomainLhs)
104  dm, simple_interface->getDomainFEName(), feDomainLhs, null, null);
105  if (feBoundaryLhs)
107  dm, simple_interface->getBoundaryFEName(), feBoundaryLhs, null, null);
108  if (feSkeletonLhs)
110  dm, simple_interface->getSkeletonFEName(), feSkeletonLhs, null, null);
111 
112  // Add element to calculate rhs of stiff part
113  if (feDomainRhs)
114  CHKERR DMMoFEMKSPSetComputeRHS(dm, simple_interface->getDomainFEName(),
115  feDomainRhs, null, null);
116  if (feBoundaryRhs)
117  CHKERR DMMoFEMKSPSetComputeRHS(dm, simple_interface->getBoundaryFEName(),
118  feBoundaryRhs, null, null);
119  if (feSkeletonRhs)
120  CHKERR DMMoFEMKSPSetComputeRHS(dm, simple_interface->getSkeletonFEName(),
121  feSkeletonRhs, null, null);
122 
123  auto ksp = MoFEM::createKSP(m_field.get_comm());
124  CHKERR KSPSetDM(ksp, dm);
125  return ksp;
126 }
127 
129  Interface &m_field = cOre;
130  Simple *simple_interface = m_field.getInterface<Simple>();
131 
132  auto copy_dm_struture = [&](auto simple_dm) {
133  MPI_Comm comm;
134  CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
135  DMType type;
136  CHKERR DMGetType(simple_dm, &type);
137  dm = createSmartDM(comm, type);
138  CHKERR DMMoFEMDuplicateDMCtx(simple_interface->getDM(), dm);
139  return dm;
140  };
141 
142  if (!dm)
143  dm = copy_dm_struture(simple_interface->getDM());
144  else
145  dm = copy_dm_struture(dm);
146 
147  auto set_dm_section = [&](auto dm) {
149  PetscSection section;
150  CHKERR m_field.getInterface<ISManager>()->sectionCreate(
151  simple_interface->getProblemName(), &section);
152  CHKERR DMSetDefaultSection(dm, section);
153  CHKERR DMSetDefaultGlobalSection(dm, section);
154  CHKERR PetscSectionDestroy(&section);
156  };
157  CHKERR set_dm_section(dm);
158 
159  boost::shared_ptr<FEMethod> null;
160 
161  // Add element to calculate lhs of stiff part
162  if (feDomainLhs)
163  CHKERR DMMoFEMSNESSetJacobian(dm, simple_interface->getDomainFEName(),
164  feDomainLhs, null, null);
165  if (feBoundaryLhs)
166  CHKERR DMMoFEMSNESSetJacobian(dm, simple_interface->getBoundaryFEName(),
167  feBoundaryLhs, null, null);
168  if (feSkeletonLhs)
169  CHKERR DMMoFEMSNESSetJacobian(dm, simple_interface->getSkeletonFEName(),
170  feSkeletonLhs, null, null);
171 
172  // Add element to calculate rhs of stiff part
173  if (feDomainRhs)
174  CHKERR DMMoFEMSNESSetFunction(dm, simple_interface->getDomainFEName(),
175  feDomainRhs, null, null);
176  if (feBoundaryRhs)
177  CHKERR DMMoFEMSNESSetFunction(dm, simple_interface->getBoundaryFEName(),
178  feBoundaryRhs, null, null);
179  if (feSkeletonRhs)
180  CHKERR DMMoFEMSNESSetFunction(dm, simple_interface->getSkeletonFEName(),
181  feSkeletonRhs, null, null);
182 
183  auto snes = MoFEM::createSNES(m_field.get_comm());
184  CHKERR SNESSetDM(snes, dm);
185  return snes;
186 }
187 
189  Interface &m_field = cOre;
190  Simple *simple_interface = m_field.getInterface<Simple>();
191 
192  auto copy_dm_struture = [&](auto simple_dm) {
193  MPI_Comm comm;
194  CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
195  DMType type;
196  CHKERR DMGetType(simple_dm, &type);
197  dm = createSmartDM(comm, type);
198  CHKERR DMMoFEMDuplicateDMCtx(simple_interface->getDM(), dm);
199  return dm;
200  };
201 
202  if (!dm)
203  dm = copy_dm_struture(simple_interface->getDM());
204  else
205  dm = copy_dm_struture(dm);
206 
207  auto set_dm_section = [&](auto dm) {
209  PetscSection section;
210  CHKERR m_field.getInterface<ISManager>()->sectionCreate(
211  simple_interface->getProblemName(), &section);
212  CHKERR DMSetDefaultSection(dm, section);
213  CHKERR DMSetDefaultGlobalSection(dm, section);
214  CHKERR PetscSectionDestroy(&section);
216  };
217  CHKERR set_dm_section(dm);
218 
219  boost::shared_ptr<FEMethod> null;
220 
221  // Add element to calculate lhs of stiff part
222  if (feDomainLhs)
223  CHKERR DMMoFEMTSSetIJacobian(dm, simple_interface->getDomainFEName(),
224  feDomainLhs, null, null);
225  if (feBoundaryLhs)
226  CHKERR DMMoFEMTSSetIJacobian(dm, simple_interface->getBoundaryFEName(),
227  feBoundaryLhs, null, null);
228  if (feSkeletonLhs)
229  CHKERR DMMoFEMTSSetIJacobian(dm, simple_interface->getSkeletonFEName(),
230  feSkeletonLhs, null, null);
231 
232  // Add element to calculate rhs of stiff part
233  if (feDomainRhs)
234  CHKERR DMMoFEMTSSetIFunction(dm, simple_interface->getDomainFEName(),
235  feDomainRhs, null, null);
236  if (feBoundaryRhs)
237  CHKERR DMMoFEMTSSetIFunction(dm, simple_interface->getBoundaryFEName(),
238  feBoundaryRhs, null, null);
239  if (feSkeletonRhs)
240  CHKERR DMMoFEMTSSetIFunction(dm, simple_interface->getSkeletonFEName(),
241  feSkeletonRhs, null, null);
242 
243  // Note: More cases for explit, and implicit time ingeration cases can be
244  // implemented here.
245 
246  auto ts = MoFEM::createTS(m_field.get_comm());
247  CHKERR TSSetDM(ts, dm);
248  return ts;
249 }
250 
251 } // namespace MoFEM
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
Definition: DMMMoFEM.cpp:637
Deprecated interface functions.
MoFEM interface unique ID.
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
Definition: Simple.hpp:288
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:706
PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set compute operator for KSP solver via sub-matrix and IS.
Definition: DMMMoFEM.cpp:556
boost::shared_ptr< FEMethod > feBoundaryLhs
Element to assemble LHS side by integrating boundary.
auto createTS
Definition: AuxPETSc.hpp:275
Section manager is used to create indexes and sectionsFIXME: ISManager is not properly testsed by ato...
Definition: ISManager.hpp:36
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
SmartPetscObj< TS > createTS(SmartPetscObj< DM > dm=nullptr)
Create TS (time) solver.
base class for all interface classes
const std::string getSkeletonFEName() const
Get the Skeleton FE Name.
Definition: Simple.hpp:295
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
boost::shared_ptr< FEMethod > feDomainLhs
Element to assemble LHS side by integrating domain.
boost::shared_ptr< FEMethod > feSkeletonRhs
Element to assemble RHS side by integrating skeleton.
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data struture.
Definition: DMMMoFEM.cpp:160
auto createSNES
Definition: AuxPETSc.hpp:282
PetscObject getPetscObject(T obj)
Definition: AuxPETSc.hpp:23
Core (interface) class.
Definition: Core.hpp:50
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set KSP operators and push mofem finite element methods.
Definition: DMMMoFEM.cpp:597
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition: DMMMoFEM.cpp:772
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method)
Executes FEMethod for finite elements in DM.
Definition: DMMMoFEM.cpp:507
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
Simple interface for fast problem set-up.
Definition: Simple.hpp:36
boost::shared_ptr< FEMethod > feDomainRhs
Element to assemble RHS side by integrating domain.
MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
static const MOFEMuuid IDD_MOFEMBasic
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
Definition: DMMMoFEM.cpp:678
const std::string getProblemName() const
Get the Problem Name.
Definition: Simple.hpp:302
#define CHKERR
Inline error check.
Definition: definitions.h:602
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
SmartPetscObj< SNES > createSNES(SmartPetscObj< DM > dm=nullptr)
Create SNES (nonlinear) solver.
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition: Simple.hpp:281
auto createKSP
Definition: AuxPETSc.hpp:289
PipelineManager(const MoFEM::Core &core)
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
Definition: DMMMoFEM.cpp:719
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413
virtual MPI_Comm & get_comm() const =0
auto createSmartDM
Creates smart DM object.
Definition: AuxPETSc.hpp:174
boost::shared_ptr< FEMethod > feBoundaryRhs
Element to assemble RHS side by integrating boundary.
boost::shared_ptr< FEMethod > feSkeletonLhs
Element to assemble LHS side by integrating skeleton.