v0.15.0
Loading...
Searching...
No Matches
bone_adaptation.cpp
Go to the documentation of this file.
1/**
2 * \file bone_adaptation.cpp
3 * \example bone_adaptation.cpp
4 * \ingroup bone_remodelling
5 *
6 * \brief Main program for running bone adaptation
7 *
8 */
9
10/* This file is part of MoFEM.
11
12* MoFEM is free software: you can redistribute it and/or modify it under
13* the terms of the GNU Lesser General Public License as published by the
14* Free Software Foundation, either version 3 of the License, or (at your
15* option) any later version.
16*
17* MoFEM is distributed in the hope that it will be useful, but WITHOUT
18* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20* License for more details.
21*
22* You should have received a copy of the GNU Lesser General Public
23* License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
24
25#include <boost/program_options.hpp>
26using namespace std;
27namespace po = boost::program_options;
28
30#include <ElasticMaterials.hpp>
31#include <Remodeling.hpp>
32
33using namespace BoneRemodeling;
34
35static char help[] = "\n";
36
37// #ifndef WITH_METAIO
38// #error "You need compile users modules with MetaIO -DWITH_METAIO=1"
39// #endif
40
41int main(int argc, char *argv[]) {
42
43 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
44
45 try {
46
47 char mesh_file_name[255];
48 PetscBool flg_file = PETSC_FALSE;
49 PetscBool flg_elastic_only = PETSC_FALSE;
50
51 PetscOptionsBegin(PETSC_COMM_WORLD, "", "Main set up", "none");
52 CHKERR PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
53 mesh_file_name, 255, &flg_file);
54
55 CHKERR PetscOptionsBool(
56 "-elastic_only", "is used for testing, calculates only elastic problem",
57 "", PETSC_FALSE, &flg_elastic_only, PETSC_NULL);
58
59 PetscOptionsEnd();
60
61 moab::Core mb_instance;
62 moab::Interface &moab = mb_instance;
63
64 // Read parameters from line command
65 if (flg_file != PETSC_TRUE) {
66 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
67 }
68 const char *option;
69
70 // option = "";
71 option = "PARALLEL=READ_PART;"
72 "PARALLEL_RESOLVE_SHARED_ENTS;"
73 "PARTITION=PARALLEL_PARTITION;";
74 CHKERR moab.load_file(mesh_file_name, 0, option);
75 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
76 if (pcomm == NULL)
77 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
78
79 MoFEM::Core core(moab);
80 MoFEM::Interface &m_field = core;
81
82 // Add meshsets with material and boundary conditions
83 MeshsetsManager *meshsets_manager_ptr;
84 CHKERR m_field.getInterface<MeshsetsManager>(meshsets_manager_ptr);
85 CHKERR meshsets_manager_ptr->setMeshsetFromFile();
86
87 PetscPrintf(PETSC_COMM_WORLD, "Read meshset. Added meshsets for bc.cfg\n");
88 for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, it)) {
89 PetscPrintf(PETSC_COMM_WORLD, "%s",
90 static_cast<std::ostringstream &>(
91 std::ostringstream().seekp(0) << *it << endl)
92 .str()
93 .c_str());
94 cerr << *it << endl;
95 }
96
97 Remodeling::CommonData common_data;
98 common_data.feRhs =
99 boost::shared_ptr<Remodeling::Fe>(new Remodeling::Fe(m_field));
100 common_data.feLhs =
101 boost::shared_ptr<Remodeling::Fe>(new Remodeling::Fe(m_field));
102 common_data.preProcRhs = boost::shared_ptr<Remodeling::FePrePostProcessRhs>(
104 common_data.preProcLhs = boost::shared_ptr<Remodeling::FePrePostProcessLhs>(
106
107 CHKERR common_data.getParameters();
108
109 Remodeling remodelling(m_field, common_data);
110
111 // Remodeling
112 if (!flg_elastic_only) {
113 remodelling.getParameters();
114 remodelling.addFields();
115 remodelling.addMomentumFluxes();
116 remodelling.addElements();
117 remodelling.buildDM();
118
119 bool flag_cubit_disp = false;
121 m_field, NODESET | DISPLACEMENTSET, it)) {
122 flag_cubit_disp = true;
123 }
124
125 boost::shared_ptr<FEMethod> dirihlet_bc_ptr;
126 // if normally defined boundary conditions are not found, try to use
127 // DISPLACEMENT blockset
128 if (!flag_cubit_disp) {
129 dirihlet_bc_ptr =
130 boost::shared_ptr<FEMethod>(new DirichletSetFieldFromBlockWithFlags(
131 m_field, "DISPLACEMENTS", "DISPLACEMENT"));
132 dynamic_cast<DirichletSetFieldFromBlockWithFlags &>(*dirihlet_bc_ptr)
133 .methodsOp.push_back(new TimeForceScale("-my_load_history", false));
134 } else {
135 dirihlet_bc_ptr = boost::shared_ptr<FEMethod>(
136 new DirichletDisplacementBc(m_field, "DISPLACEMENTS"));
137 dynamic_cast<DirichletDisplacementBc &>(*dirihlet_bc_ptr)
138 .methodsOp.push_back(new TimeForceScale("-my_load_history", false));
139 }
140
141 // Add elements Time Solver via DM interface.
142 // This part is to calculate residual vector.
143 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL,
144 common_data.preProcRhs.get(), NULL);
145 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL,
146 dirihlet_bc_ptr.get(), NULL);
147 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING",
148 common_data.feRhs.get(), NULL, NULL);
149 if (common_data.nOremodellingBlock) {
150 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "ELASTIC",
151 &(common_data.elasticPtr->getLoopFeRhs()),
152 NULL, NULL);
153 }
154
155 // Add surface forces
156 for (boost::ptr_map<string, NeummanForcesSurface>::iterator fit =
157 common_data.neumannForces.begin();
158 fit != common_data.neumannForces.end(); fit++) {
159 CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
160 &fit->second->getLoopFe(), NULL, NULL);
161 }
162
163 // Add edge forces
164 for (boost::ptr_map<std::string, EdgeForce>::iterator fit =
165 common_data.edgeForces.begin();
166 fit != common_data.edgeForces.end(); fit++) {
167 CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
168 &fit->second->getLoopFe(), NULL, NULL);
169 }
170
171 // Add nodal forces
172 for (boost::ptr_map<std::string, NodalForce>::iterator fit =
173 common_data.nodalForces.begin();
174 fit != common_data.nodalForces.end(); fit++) {
175 CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
176 &fit->second->getLoopFe(), NULL, NULL);
177 }
178
179 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL, NULL,
180 dirihlet_bc_ptr.get());
181 CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL, NULL,
182 common_data.preProcRhs.get());
183
184 // Add elements Time Solver via DM interface.
185 // This part is to calculate tangent matrix.
186 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL,
187 common_data.preProcLhs.get(), NULL);
188 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL,
189 dirihlet_bc_ptr.get(), NULL);
190 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING",
191 common_data.feLhs.get(), NULL, NULL);
192 if (common_data.nOremodellingBlock) {
193 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "ELASTIC",
194 &common_data.elasticPtr->getLoopFeLhs(),
195 NULL, NULL);
196 }
197 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL, NULL,
198 dirihlet_bc_ptr.get());
199 CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL, NULL,
200 common_data.preProcLhs.get());
201
202 CHKERR DMCreateMatrix(common_data.dm, &common_data.A);
203 CHKERR DMCreateGlobalVector(common_data.dm, &common_data.D);
204 CHKERR DMCreateGlobalVector(common_data.dm, &common_data.F);
205
206 // Initialize vectors with initial data from mesh
207 CHKERR DMoFEMMeshToLocalVector(common_data.dm, common_data.D,
208 INSERT_VALUES, SCATTER_FORWARD);
209
210 CHKERR TSCreate(PETSC_COMM_WORLD, &common_data.ts);
211 CHKERR TSSetType(common_data.ts, TSBEULER);
212
213 CHKERR remodelling.solveDM();
214
215 CHKERR MatDestroy(&common_data.A);
216 CHKERR VecDestroy(&common_data.D);
217 CHKERR VecDestroy(&common_data.F);
218 CHKERR TSDestroy(&common_data.ts);
219 }
220
221 }
223
225 return 0;
226}
Elastic materials.
int main()
static char help[]
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
@ NODESET
@ DISPLACEMENTSET
#define CHKERR
Inline error check.
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 DMMoFEM.cpp:790
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:514
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 DMMoFEM.cpp:843
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
char mesh_file_name[255]
boost::shared_ptr< FePrePostProcessRhs > preProcRhs
boost::shared_ptr< Fe > feLhs
FE to make left hand side.
boost::shared_ptr< Fe > feRhs
FE to make right hand side.
boost::ptr_map< string, NeummanForcesSurface > neumannForces
Forces on surface.
boost::ptr_map< string, EdgeForce > edgeForces
Forces on edges.
boost::shared_ptr< FePrePostProcessLhs > preProcLhs
boost::ptr_map< string, NodalForce > nodalForces
Nodal forces.
boost::shared_ptr< NonlinearElasticElement > elasticPtr
Not used at this stage. Could be used to do some calculations, before assembly of local elements.
Not used at this stage. Could be used to do some calculations, before assembly of local elements.
Volume finite element.
Implementation of bone remodeling finite element.
MoFEMErrorCode addElements()
Set and add finite elements.
MoFEMErrorCode solveDM()
Solve problem set up in DM.
MoFEMErrorCode buildDM()
Set problem and DM.
MoFEMErrorCode getParameters()
Get parameters form line command or config file.
MoFEMErrorCode addFields()
Set and add entities to approximation fields.
MoFEMErrorCode addMomentumFluxes()
Finite elements to calculate tractions.
Set Dirichlet boundary conditions on displacements.
boost::ptr_vector< MethodForForceScaling > methodsOp
Add boundary conditions form block set having 6 attributes.
Core (interface) class.
Definition Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:118
Deprecated interface functions.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Force scale operator for reading two columns.