v0.14.0
mofem_manager.cpp
Go to the documentation of this file.
1 /** \file mofem_manager.cpp
2  *
3  */
4 /* MoFEM is free software: you can redistribute it and/or modify it under the
5  * terms of the MIT License.
6  */
7 
9 using namespace MoFEM;
10 
11 #include <ElasticMaterials.hpp>
14 
16 
17 #ifdef WITH_MODULE_MORTAR_CONTACT
18 #include <Mortar.hpp>
19 #endif
20 
21 #ifdef WITH_MODULE_MFRONT_INTERFACE
22 #include <MFrontMoFEMInterface.hpp>
23 #endif
24 
25 #ifdef WITH_MODULE_HDIV_CONTACT
26 using namespace FTensor;
27 #include <AnalyticalSurfaces.hpp>
28 #include <RigidBodies.hpp>
29 #include <BasicFeTools.hpp>
30 #include <ContactOperators.hpp>
31 using namespace OpContactTools;
32 #include <HdivContactInterface.hpp>
33 
34 #endif
35 
42 
43 constexpr size_t SPACE_DIM = 3;
44 
45 static char help[] = "...\n\n";
46 
47 #include <MoFEMManager.hpp>
48 using namespace MoFEMManager;
49 
50 int main(int argc, char *argv[]) {
51 
52  const string default_options = "-ksp_type fgmres \n"
53  "-pc_type lu \n"
54  "-pc_factor_mat_solver_type mumps \n"
55  "-ksp_atol 1e-10 \n"
56  "-ksp_rtol 1e-10 \n"
57  "-snes_monitor \n"
58  "-snes_max_it 100 \n"
59  "-snes_linesearch_type bt \n"
60  "-snes_linesearch_max_it 3 \n"
61  "-snes_atol 1e-8 \n"
62  "-snes_rtol 1e-8 \n"
63  "-ts_monitor \n"
64  "-ts_alpha_radius 1 \n"
65  "-ts_monitor \n"
66  "-mat_mumps_icntl_20 0 \n"
67  "-mat_mumps_icntl_14 800 \n"
68  "-mat_mumps_icntl_24 1 \n"
69  "-mat_mumps_icntl_13 1 \n";
70 
71  string param_file = "param_file.petsc";
72  if (!static_cast<bool>(ifstream(param_file))) {
73  std::ofstream file(param_file.c_str(), std::ios::ate);
74  if (file.is_open()) {
75  file << default_options;
76  file.close();
77  }
78  }
79 
80  MoFEM::Core::Initialize(&argc, &argv, param_file.c_str(), help);
81 
82  // Add logging channel for example
83  auto core_log = logging::core::get();
84  core_log->add_sink(
86  LogManager::setLog("MManager");
87  MOFEM_LOG_TAG("MManager", "module_manager");
88 
89  try {
90 
91  moab::Core mb_instance;
92  moab::Interface &moab = mb_instance;
93  MoFEM::Core core(moab);
94  MoFEM::Interface &m_field = core;
95 
96  MFManager md(m_field);
97  CHKERR md.getParams();
98 
99  Simple *simple = m_field.getInterface<Simple>();
100  CHKERR simple->getOptions();
101 
102  if (md.isPartitioned)
103  CHKERR simple->loadFile("");
104  else
105  CHKERR simple->loadFile("", "");
106  simple->getProblemName() = "MoFEM Manager module";
107  simple->getDomainFEName() = "ELASTIC";
108  vector<string> volume_fe_elements{simple->getDomainFEName()};
109  simple->getBoundaryFEName() = "BOUNDARY_ELEMENT";
110 
111  // setup the modules
112  boost::ptr_vector<GenericElementInterface> m_modules;
113 
114  // Basic Boundary Conditions module should always be first (dirichlet)
115  m_modules.push_back(new BasicBoundaryConditionsInterface(
116  m_field, "U", "MESH_NODE_POSITIONS", simple->getProblemName(),
117  simple->getDomainFEName(), true, md.isQuasiStatic, nullptr,
118  md.isPartitioned));
119 
120 #ifdef WITH_MODULE_MORTAR_CONTACT
121  m_modules.push_back(new MortarContactInterface(
122  m_field, "U", "MESH_NODE_POSITIONS", true, md.isQuasiStatic));
123 #endif
124 
125  // // Nonlinear Elastic Element module
126  m_modules.push_back(new NonlinearElasticElementInterface(
127  m_field, "U", "MESH_NODE_POSITIONS", true, md.isQuasiStatic));
128 
129 #ifdef WITH_MODULE_MFRONT_INTERFACE
130  m_modules.push_back(new MFrontMoFEMInterface(
131  m_field, "U", "MESH_NODE_POSITIONS", true, md.isQuasiStatic));
132  volume_fe_elements.push_back("MFRONT_EL");
133 #endif
134 
135 #ifdef WITH_MODULE_HDIV_CONTACT
136  m_modules.push_back(new HdivContactInterface(
137  m_field, "U", "MESH_NODE_POSITIONS", simple->getProblemName(),
138  volume_fe_elements, {simple->getBoundaryFEName()}, PETSC_TRUE,
139  md.isQuasiStatic, md.isPartitioned));
140 #endif
141 
142  CHKERR md.setMainField();
143 
144  for (auto &&mod : m_modules) {
145  CHKERR mod.getCommandLineParameters();
146  CHKERR mod.addElementFields();
147  CHKERR mod.createElements();
148  }
149 
150  CHKERR m_field.build_fields();
151  CHKERR md.defineDM();
152 
153  for (auto &&mod : m_modules)
154  CHKERR mod.addElementsToDM(md.dM);
155 
156  Projection10NodeCoordsOnField ent_method(m_field, "MESH_NODE_POSITIONS");
157  CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method);
158  CHKERR m_field.build_finite_elements();
159  CHKERR m_field.build_adjacencies(simple->getBitRefLevel());
160 
161  CHKERR DMSetUp(md.dM);
162 
163  md.monitorPtr->preProcessHook = []() { return 0; };
164  md.monitorPtr->operatorHook = []() { return 0; };
165  md.monitorPtr->postProcessHook = [&]() {
167  auto ts_time = md.monitorPtr->ts_t;
168  auto ts_step = md.monitorPtr->ts_step;
169  auto &ts_u = md.monitorPtr->ts_u;
170 
171  for (auto &&mod : m_modules) {
172  CHKERR mod.updateElementVariables();
173  if (ts_step % md.saveEveryNthStep == 0)
174  CHKERR mod.postProcessElement(ts_step);
175  }
176 
177  if (md.doPrintMaxMin == PETSC_TRUE) {
178  CHKERR md.printMaxMin(md.vScatter[0], "Ux", ts_u, ts_time);
179  CHKERR md.printMaxMin(md.vScatter[1], "Uy", ts_u, ts_time);
180  CHKERR md.printMaxMin(md.vScatter[2], "Uz", ts_u, ts_time);
181  }
182 
184  };
185 
186  auto t_type = md.getTSType();
187  for (auto &&mod : m_modules) {
188  CHKERR mod.setMonitorPtr(md.monitorPtr);
189  CHKERR mod.setOperators();
190  CHKERR mod.setupSolverFunctionTS(t_type);
191  CHKERR mod.setupSolverJacobianTS(t_type);
192  }
193 
194  CHKERR md.tsSetup();
195  CHKERR md.tsSolve();
196  }
197  CATCH_ERRORS;
198 
200  return 0;
201 }
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
BoundaryEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Definition: child_and_parent.cpp:39
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
MoFEM::CoreInterface::loop_dofs
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
BasicBoundaryConditionsInterface
Set of functions declaring elements and setting operators for basic boundary conditions interface.
Definition: BasicBoundaryConditionsInterface.hpp:20
Mortar.hpp
BasicBoundaryConditionsInterface.hpp
Header file for BasicBoundaryConditionsInterface element implementation.
md
double md
Definition: free_surface.cpp:174
MortarContactInterface
Definition: MortarContactInterface.hpp:22
MoFEMManager
Definition: MoFEMManager.hpp:15
BasicFiniteElements.hpp
MoFEM::Projection10NodeCoordsOnField
Projection of edge entities with one mid-node on hierarchical basis.
Definition: Projection10NodeCoordsOnField.hpp:24
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::LogManager::createSink
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
Definition: LogManager.cpp:298
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MoFEM::PostProcBrokenMeshInMoab
Definition: PostProcBrokenMeshInMoabBase.hpp:667
SurfacePressureComplexForLazy.hpp
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEMManager::MFManager
Definition: MoFEMManager.hpp:17
SPACE_DIM
constexpr size_t SPACE_DIM
Definition: mofem_manager.cpp:43
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
default operator for TRI element
Definition: FaceElementForcesAndSourcesCore.hpp:94
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MoFEM::LogManager::getStrmWorld
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
Definition: LogManager.cpp:344
MoFEM::FaceElementForcesAndSourcesCore
Face finite element.
Definition: FaceElementForcesAndSourcesCore.hpp:23
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
ElasticMaterials.hpp
Elastic materials.
MoFEM::VolumeElementForcesAndSourcesCore
Volume finite element base.
Definition: VolumeElementForcesAndSourcesCore.hpp:26
NonlinearElasticElementInterface.hpp
MoFEMManager.hpp
PostProcFaceOnRefinedMesh
Postprocess on face.
Definition: PostProcOnRefMesh.hpp:1032
main
int main(int argc, char *argv[])
Definition: mofem_manager.cpp:50
DomainEleOp
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
PostProcVolumeOnRefinedMesh
Post processing.
Definition: PostProcOnRefMesh.hpp:955
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
MoFEM::LogManager::setLog
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
Definition: LogManager.cpp:389
NonlinearElasticElementInterface
Set of functions declaring elements and setting operators for generic element interface.
Definition: NonlinearElasticElementInterface.hpp:15
help
static char help[]
Definition: mofem_manager.cpp:45