v0.14.0
bone_adaptation.cpp

Main program for running bone adaptation

/**
* \file bone_adaptation.cpp
* \example bone_adaptation.cpp
* \ingroup bone_remodelling
*
* \brief Main program for running bone adaptation
*
*/
/* This file is part of MoFEM.
* MoFEM is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* MoFEM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
#include <boost/program_options.hpp>
using namespace std;
namespace po = boost::program_options;
#include <Remodeling.hpp>
using namespace BoneRemodeling;
static char help[] = "\n";
// #ifndef WITH_METAIO
// #error "You need compile users modules with MetaIO -DWITH_METAIO=1"
// #endif
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
char mesh_file_name[255];
PetscBool flg_file = PETSC_FALSE;
PetscBool flg_elastic_only = PETSC_FALSE;
CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Main set up", "none");
CHKERR PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
mesh_file_name, 255, &flg_file);
CHKERR PetscOptionsBool(
"-elastic_only", "is used for testing, calculates only elastic problem",
"", PETSC_FALSE, &flg_elastic_only, PETSC_NULL);
ierr = PetscOptionsEnd();
CHKERRQ(ierr);
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
// Read parameters from line command
if (flg_file != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
}
const char *option;
// option = "";
option = "PARALLEL=READ_PART;"
"PARALLEL_RESOLVE_SHARED_ENTS;"
"PARTITION=PARALLEL_PARTITION;";
CHKERR moab.load_file(mesh_file_name, 0, option);
ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
if (pcomm == NULL)
pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
// Add meshsets with material and boundary conditions
MeshsetsManager *meshsets_manager_ptr;
CHKERR m_field.getInterface<MeshsetsManager>(meshsets_manager_ptr);
CHKERR meshsets_manager_ptr->setMeshsetFromFile();
PetscPrintf(PETSC_COMM_WORLD, "Read meshset. Added meshsets for bc.cfg\n");
for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, it)) {
PetscPrintf(PETSC_COMM_WORLD, "%s",
static_cast<std::ostringstream &>(
std::ostringstream().seekp(0) << *it << endl)
.str()
.c_str());
cerr << *it << endl;
}
common_data.feRhs =
boost::shared_ptr<Remodeling::Fe>(new Remodeling::Fe(m_field));
common_data.feLhs =
boost::shared_ptr<Remodeling::Fe>(new Remodeling::Fe(m_field));
common_data.preProcRhs = boost::shared_ptr<Remodeling::FePrePostProcessRhs>(
common_data.preProcLhs = boost::shared_ptr<Remodeling::FePrePostProcessLhs>(
CHKERR common_data.getParameters();
Remodeling remodelling(m_field, common_data);
// Remodeling
if (!flg_elastic_only) {
remodelling.getParameters();
remodelling.addFields();
remodelling.addMomentumFluxes();
remodelling.addElements();
remodelling.buildDM();
bool flag_cubit_disp = false;
m_field, NODESET | DISPLACEMENTSET, it)) {
flag_cubit_disp = true;
}
boost::shared_ptr<FEMethod> dirihlet_bc_ptr;
// if normally defined boundary conditions are not found, try to use
// DISPLACEMENT blockset
if (!flag_cubit_disp) {
dirihlet_bc_ptr =
boost::shared_ptr<FEMethod>(new DirichletSetFieldFromBlockWithFlags(
m_field, "DISPLACEMENTS", "DISPLACEMENT"));
dynamic_cast<DirichletSetFieldFromBlockWithFlags &>(*dirihlet_bc_ptr)
.methodsOp.push_back(new TimeForceScale("-my_load_history", false));
} else {
dirihlet_bc_ptr = boost::shared_ptr<FEMethod>(
new DirichletDisplacementBc(m_field, "DISPLACEMENTS"));
dynamic_cast<DirichletDisplacementBc &>(*dirihlet_bc_ptr)
.methodsOp.push_back(new TimeForceScale("-my_load_history", false));
}
// Add elements Time Solver via DM interface.
// This part is to calculate residual vector.
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL,
common_data.preProcRhs.get(), NULL);
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL,
dirihlet_bc_ptr.get(), NULL);
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING",
common_data.feRhs.get(), NULL, NULL);
if (common_data.nOremodellingBlock) {
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "ELASTIC",
&(common_data.elasticPtr->getLoopFeRhs()),
NULL, NULL);
}
// Add surface forces
for (boost::ptr_map<string, NeummanForcesSurface>::iterator fit =
common_data.neumannForces.begin();
fit != common_data.neumannForces.end(); fit++) {
CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
&fit->second->getLoopFe(), NULL, NULL);
}
// Add edge forces
for (boost::ptr_map<std::string, EdgeForce>::iterator fit =
common_data.edgeForces.begin();
fit != common_data.edgeForces.end(); fit++) {
CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
&fit->second->getLoopFe(), NULL, NULL);
}
// Add nodal forces
for (boost::ptr_map<std::string, NodalForce>::iterator fit =
common_data.nodalForces.begin();
fit != common_data.nodalForces.end(); fit++) {
CHKERR DMMoFEMTSSetIFunction(common_data.dm, fit->first.c_str(),
&fit->second->getLoopFe(), NULL, NULL);
}
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL, NULL,
dirihlet_bc_ptr.get());
CHKERR DMMoFEMTSSetIFunction(common_data.dm, "FE_REMODELLING", NULL, NULL,
common_data.preProcRhs.get());
// Add elements Time Solver via DM interface.
// This part is to calculate tangent matrix.
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL,
common_data.preProcLhs.get(), NULL);
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL,
dirihlet_bc_ptr.get(), NULL);
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING",
common_data.feLhs.get(), NULL, NULL);
if (common_data.nOremodellingBlock) {
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "ELASTIC",
&common_data.elasticPtr->getLoopFeLhs(),
NULL, NULL);
}
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL, NULL,
dirihlet_bc_ptr.get());
CHKERR DMMoFEMTSSetIJacobian(common_data.dm, "FE_REMODELLING", NULL, NULL,
common_data.preProcLhs.get());
CHKERR DMCreateMatrix(common_data.dm, &common_data.A);
CHKERR DMCreateGlobalVector(common_data.dm, &common_data.D);
CHKERR DMCreateGlobalVector(common_data.dm, &common_data.F);
// Initialize vectors with initial data from mesh
CHKERR DMoFEMMeshToLocalVector(common_data.dm, common_data.D,
INSERT_VALUES, SCATTER_FORWARD);
CHKERR TSCreate(PETSC_COMM_WORLD, &common_data.ts);
CHKERR TSSetType(common_data.ts, TSBEULER);
CHKERR remodelling.solveDM();
CHKERR MatDestroy(&common_data.A);
CHKERR VecDestroy(&common_data.D);
CHKERR VecDestroy(&common_data.F);
CHKERR TSDestroy(&common_data.ts);
}
}
return 0;
}
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
BoneRemodeling::Remodeling::CommonData::nOremodellingBlock
bool nOremodellingBlock
Definition: Remodeling.hpp:164
BoneRemodeling::Remodeling::buildDM
MoFEMErrorCode buildDM()
Set problem and DM.
Definition: Remodeling.cpp:1832
BoneRemodeling::Remodeling::addFields
MoFEMErrorCode addFields()
Set and add entities to approximation fields.
Definition: Remodeling.cpp:1607
BoneRemodeling::Remodeling::CommonData::feRhs
boost::shared_ptr< Fe > feRhs
FE to make right hand side.
Definition: Remodeling.hpp:131
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
BoneRemodeling::Remodeling::CommonData::ts
TS ts
Time solver.
Definition: Remodeling.hpp:128
BoneRemodeling::Remodeling::CommonData::neumannForces
boost::ptr_map< string, NeummanForcesSurface > neumannForces
Forces on surface.
Definition: Remodeling.hpp:136
BoneRemodeling::Remodeling::CommonData::nodalForces
boost::ptr_map< string, NodalForce > nodalForces
Nodal forces.
Definition: Remodeling.hpp:137
BoneRemodeling::Remodeling
Implementation of bone remodeling finite element.
Definition: Remodeling.hpp:36
_IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
Definition: MeshsetsManager.hpp:49
MoFEM::DMoFEMMeshToLocalVector
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:523
BasicFiniteElements.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
DirichletSetFieldFromBlockWithFlags
Add boundary conditions form block set having 6 attributes.
Definition: DirichletBC.hpp:356
Remodeling.hpp
DirichletDisplacementBc
Set Dirichlet boundary conditions on displacements.
Definition: DirichletBC.hpp:57
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
NODESET
@ NODESET
Definition: definitions.h:159
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::DMMoFEMTSSetIJacobian
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:853
BoneRemodeling::Remodeling::getParameters
MoFEMErrorCode getParameters()
Get parameters form line command or config file.
Definition: Remodeling.cpp:1579
BoneRemodeling::Remodeling::CommonData::D
Vec D
Definition: Remodeling.hpp:120
TimeForceScale
Force scale operator for reading two columns.
Definition: TimeForceScale.hpp:18
BoneRemodeling::Remodeling::CommonData::elasticPtr
boost::shared_ptr< NonlinearElasticElement > elasticPtr
Definition: Remodeling.hpp:140
DISPLACEMENTSET
@ DISPLACEMENTSET
Definition: definitions.h:163
BoneRemodeling::Remodeling::CommonData::edgeForces
boost::ptr_map< string, EdgeForce > edgeForces
Forces on edges.
Definition: Remodeling.hpp:138
help
static char help[]
Definition: bone_adaptation.cpp:35
BoneRemodeling
Definition: DensityMaps.hpp:27
BoneRemodeling::Remodeling::CommonData::F
Vec F
Definition: Remodeling.hpp:120
BoneRemodeling::Remodeling::Fe
Volume finite element.
Definition: Remodeling.hpp:41
BoneRemodeling::Remodeling::FePrePostProcessRhs
Not used at this stage. Could be used to do some calculations, before assembly of local elements.
Definition: Remodeling.hpp:53
BoneRemodeling::Remodeling::addMomentumFluxes
MoFEMErrorCode addMomentumFluxes()
Finite elements to calculate tractions.
Definition: Remodeling.cpp:1792
ElasticMaterials.hpp
Elastic materials.
main
int main(int argc, char *argv[])
Definition: bone_adaptation.cpp:41
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
BoneRemodeling::Remodeling::solveDM
MoFEMErrorCode solveDM()
Solve problem set up in DM.
Definition: Remodeling.cpp:1863
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
BoneRemodeling::Remodeling::CommonData::feLhs
boost::shared_ptr< Fe > feLhs
FE to make left hand side.
Definition: Remodeling.hpp:130
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
BoneRemodeling::Remodeling::CommonData
Definition: Remodeling.hpp:117
BoneRemodeling::Remodeling::addElements
MoFEMErrorCode addElements()
Set and add finite elements.
Definition: Remodeling.cpp:1694
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
std
Definition: enable_if.hpp:5
BoneRemodeling::Remodeling::CommonData::getParameters
MoFEMErrorCode getParameters()
Definition: Remodeling.cpp:62
BoneRemodeling::Remodeling::CommonData::dm
DM dm
Discretization manager.
Definition: Remodeling.hpp:127
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MoFEM::DMMoFEMTSSetIFunction
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:800
DirichletDisplacementBc::methodsOp
boost::ptr_vector< MethodForForceScaling > methodsOp
Definition: DirichletBC.hpp:76
BoneRemodeling::Remodeling::CommonData::A
Mat A
Definition: Remodeling.hpp:119
_IT_CUBITMESHSETS_FOR_LOOP_
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
Definition: MeshsetsManager.hpp:34
BoneRemodeling::Remodeling::FePrePostProcessLhs
Not used at this stage. Could be used to do some calculations, before assembly of local elements.
Definition: Remodeling.hpp:79
BoneRemodeling::Remodeling::CommonData::preProcLhs
boost::shared_ptr< FePrePostProcessLhs > preProcLhs
Definition: Remodeling.hpp:133
BoneRemodeling::Remodeling::CommonData::preProcRhs
boost::shared_ptr< FePrePostProcessRhs > preProcRhs
Definition: Remodeling.hpp:132