v0.9.2
mian_snippet.cpp
Go to the documentation of this file.
1 /**
2  * \file main_snippet.cpp
3  * \example main_snippet.cpp
4  *
5  * Using PipelineManager interface calculate the divergence of base functions, and
6  * integral of flux on the boundary. Since the h-div space is used, volume
7  * integral and boundary integral should give the same result.
8  */
9 
10 /* This file is part of MoFEM.
11  * MoFEM is free software: you can redistribute it and/or modify it under
12  * the terms of the GNU Lesser General Public License as published by the
13  * Free Software Foundation, either version 3 of the License, or (at your
14  * option) any later version.
15  *
16  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19  * License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
23 
24 #include <MoFEM.hpp>
25 
26 using namespace MoFEM;
27 
28 struct Example {
29 
30  Example(MoFEM::Interface &m_field) : mField(m_field) {}
31 
32  MoFEMErrorCode runProblem();
33 
34 private:
35  MoFEM::Interface &mField;
36 
37  MoFEMErrorCode setUP();
38  MoFEMErrorCode createCommonData();
39  MoFEMErrorCode bC();
40  MoFEMErrorCode OPs();
41  MoFEMErrorCode kspSolve();
42  MoFEMErrorCode postProcess();
43  MoFEMErrorCode checkResults();
44 
45  struct CommonData {
46  };
47  boost::shared_ptr<CommonData> commonDataPtr;
48 
49 
50 };
51 
54  CHKERR setUP();
55  CHKERR createCommonData();
56  CHKERR bC();
57  CHKERR OPs();
58  CHKERR kspSolve();
59  CHKERR postProcess();
60  CHKERR checkResults();
62 }
63 
64 //! [Set up problem]
67  Simple *simple = mField.getInterface<Simple>();
68  // Add field
69  CHKERR simple->addDomainField("U", H1, AINSWORTH_LEGENDRE_BASE, 1);
70  CHKERR simple->addBoundaryField("U", H1, AINSWORTH_LEGENDRE_BASE, 1);
71  constexpr int order = 5;
72  CHKERR simple->setFieldOrder("U", order);
73  CHKERR simple->setUp();
75 }
76 //! [Set up problem]
77 
78 //! [Create common data]
82 }
83 //! [Create common data]
84 
85 //! [Boundary condition]
89 }
90 //! [Boundary condition]
91 
92 //! [Push operators to pipeline]
96 }
97 //! [Push operators to pipeline]
98 
99 //! [Solve]
102  Simple *simple = mField.getInterface<Simple>();
103  PipelineManager *pipeline_mng = mField.getInterface<PipelineManager>();
104  auto solver = pipeline_mng->createKSP();
105  CHKERR KSPSetFromOptions(solver);
106  CHKERR KSPSetUp(solver);
107 
108  auto dm = simple->getDM();
109  auto D = smartCreateDMVector(dm);
110  auto F = smartVectorDuplicate(D);
111 
112  CHKERR KSPSolve(solver, F, D);
113  CHKERR VecGhostUpdateBegin(D, INSERT_VALUES, SCATTER_FORWARD);
114  CHKERR VecGhostUpdateEnd(D, INSERT_VALUES, SCATTER_FORWARD);
115  CHKERR DMoFEMMeshToLocalVector(dm, D, INSERT_VALUES, SCATTER_REVERSE);
117 }
118 //! [Solve]
119 
120 //! [Postprocess results]
124 }
125 //! [Postprocess results]
126 
127 //! [Check]
131 }
132 //! [Check]
133 
134 static char help[] = "...\n\n";
135 
136 int main(int argc, char *argv[]) {
137 
138  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
139 
140  try {
141 
142  //! [Register MoFEM discrete manager in PETSc]
143  DMType dm_name = "DMMOFEM";
144  CHKERR DMRegister_MoFEM(dm_name);
145  //! [Register MoFEM discrete manager in PETSc
146 
147  //! [Create MoAB]
148  moab::Core mb_instance; ///< mesh database
149  moab::Interface &moab = mb_instance; ///< mesh database interface
150  //! [Create MoAB]
151 
152  //! [Create MoFEM]
153  MoFEM::Core core(moab); ///< finite element database
154  MoFEM::Interface &m_field = core; ///< finite element database insterface
155  //! [Create MoFEM]
156 
157  //! [Load mesh]
158  Simple *simple = m_field.getInterface<Simple>();
159  CHKERR simple->getOptions();
160  CHKERR simple->loadFile("");
161  //! [Load mesh]
162 
163  //! [Example]
164  Example ex(m_field);
165  CHKERR ex.runProblem();
166  //! [Example]
167  }
168  CATCH_ERRORS;
169 
171 }
172 
Deprecated interface functions.
MoFEMErrorCode createCommonData()
[Set up problem]
MoFEMErrorCode kspSolve()
[Push operators to pipeline]
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMMoFEM.cpp:445
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
Example(MoFEM::Interface &m_field)
Core (interface) class.
Definition: Core.hpp:50
SmartPetscObj< Vec > smartVectorDuplicate(SmartPetscObj< Vec > &vec)
Create duplicate vector of smart vector.
Definition: AuxPETSc.hpp:238
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
Simple interface for fast problem set-up.
Definition: Simple.hpp:36
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:51
auto smartCreateDMVector
Get smart vector from DM.
Definition: DMMoFEM.hpp:939
MoFEMErrorCode runProblem()
[Operator]
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MoFEMErrorCode OPs()
[Boundary condition]
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
MoFEMErrorCode checkResults()
[Print results]
MoFEMErrorCode bC()
[Create common data]
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMMoFEM.cpp:48
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:152
PipelineManager interface.
#define CHKERR
Inline error check.
Definition: definitions.h:602
MoFEMErrorCode setUP()
[Set up problem]
constexpr int order
static char help[]
[Check]
MoFEMErrorCode postProcess()
[Integrate]
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:439
int main(int argc, char *argv[])
continuous field
Definition: definitions.h:177
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:69