openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
mechanics.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
27 #ifndef _MECHANICS_H
28 #define _MECHANICS_H
29 #define WITH_MECH
30 
31 #include "physics_types.h"
32 #include "sim_utils.h"
33 #include "stimulate.h"
34 #include "sf_interface.h"
35 #include "timers.h"
36 #include "constitutive_model_library.h"
37 #include "constitutive_model.h"
38 
39 
40 namespace opencarp {
41 
45 class mech_bcs
46 {
47  public:
48 
50  enum nbc_t {pressure, force};
51  enum dbc_t {all, x, y, z, xy, xz, yz};
52 
59  std::string input_filename;
60 
61  void setup(int idx);
62 };
63 
69 {
70  public:
84  sf_mat* K_eq = nullptr;
85 
88 
89  sf_nl_sol* nonlin_solver = nullptr;
90 
91  // solver config
92  double tol = 1e-8;
93  int max_it = 300;
94 
95  void init();
96  void rebuild_matrices(MaterialType mtype, FILE_SPEC logger);
97  void rebuild_stiffness(MaterialType mtype, FILE_SPEC logger);
98  void calc_internal_forces(MaterialType mtype, FILE_SPEC logger);
100  void apply_external_forces(MaterialType mtype, FILE_SPEC logger, sf_mesh surfmesh, mech_bcs nmbcs);
101  void solve();
102  inline void apply_bcs_forces()
103  {
104  double * f_int = f_internal->ptr();
105  double * f_ext = f_external->ptr();
106  double * dbcs = dirichlet_bcs->ptr();
107  for(int i = 0; i<dirichlet_bcs->lsize(); i++)
108  {
109  if(!dbcs[i])
110  {
111  f_int[i] = 0.0;
112  f_ext[i] = 0.0;
113  }
114  }
115  f_internal->release_ptr(f_int);
116  f_external->release_ptr(f_ext);
117  dirichlet_bcs->release_ptr(dbcs);
118  }
119 
120  inline void apply_bcs_jacobian()
121  {
124  }
125 
126  inline void update_node_coords()
127  {
128  sf_mesh & mesh = get_mesh(elasticity_msh);
130  const SF::vector<mesh_int_t> & alg_nod = mesh.pl.algebraic_nodes();
131  double * pos = position->ptr();
132  for(std::size_t i = 0; i < alg_nod.size(); i++)
133  {
134  for(std::size_t k = 0; k < position->dpn; k++)
135  {
136  mesh.xyz_Euler[3 * alg_nod[i] + k] = pos[3 * i + k];
137  }
138  }
139  position->release_ptr(pos);
140  }
141  private:
142  void setup_nonlinear_solver(FILE_SPEC logger);
143 };
144 
145 class Mechanics : public Basic_physic
146 {
147  public:
151 
154 
159  {
160  name = "Mechanics";
161  }
170  void initialize();
171 
172  void destroy();
173 
174  // This funcs from the Basic_physic interface are currently empty
175  void compute_step();
176  void output_step();
177 
178 
180 
182  double timer_val(const int timer_id);
183 
185  std::string timer_unit(const int timer_id);
186 
187 
188  private:
189 
191  void setup_solvers();
192 
194  void setup_mappings();
195 
197  void setup_output();
198 
200  void dump_matrices();
201 
203  void checkpointing();
204 
206  void register_material_model();
207 };
208 } // namespace opencarp
209 
210 #endif
virtual void mult_LR(const abstract_vector< T, S > &L, const abstract_vector< T, S > &R)=0
virtual void diag_add(const abstract_vector< T, S > &diag)=0
virtual S * ptr()=0
virtual void release_ptr(S *&p)=0
virtual T lsize() const =0
int dpn
d.o.f. per mesh vertex.
overlapping_layout< T > pl
nodal parallel layout
Definition: SF_container.h:419
vector< S > xyz_Euler
node coordinates in Euler formulation
Definition: SF_container.h:417
vector< T > & get_numbering(SF_nbr nbr_type)
Get the vector defining a certain numbering.
Definition: SF_container.h:454
size_t size() const
The current size of the vector.
Definition: SF_vector.h:104
The abstract physics interface we can use to trigger all physics.
Definition: physics_types.h:59
const char * name
The name of the physic, each physic should have one.
Definition: physics_types.h:62
void destroy()
Currently we only need to close the file logger.
Definition: mechanics.cc:253
std::string timer_unit(const int timer_id)
figure out units of a signal linked to a given timer
Definition: mechanics.cc:290
double timer_val(const int timer_id)
figure out current value of a signal linked to a given timer
Definition: mechanics.cc:280
Mechanics()
Most of the initialization is done with initialize()
Definition: mechanics.h:158
equilibrium_solver eq_solver
Definition: mechanics.h:149
MaterialType mtype
Definition: mechanics.h:148
void initialize()
Initialize the Mechanics.
Definition: mechanics.cc:145
igb_output_manager output_manager
class handling the igb output
Definition: mechanics.h:153
void compute_step()
Main function for every compute step.
Definition: mechanics.cc:209
void calc_internal_forces(MaterialType mtype, FILE_SPEC logger)
Calculation of the internal forces based on the deformation.
Definition: mechanics.cc:596
void rebuild_stiffness(MaterialType mtype, FILE_SPEC logger)
rebuild stiffness matrix
Definition: mechanics.cc:572
sf_vec * dirichlet_bcs_1
Dirichlet boundary conditions but with 1 = dbc exists.
Definition: mechanics.h:83
sf_vec * position
position x
Definition: mechanics.h:71
sf_vec * du
incremental displacement du
Definition: mechanics.h:74
sf_mat * K_eq
stiffness matrix for static equilibrium solver K
Definition: mechanics.h:84
int max_it
maximum number of iterations
Definition: mechanics.h:93
sf_vec * f_surf
external forces applied on surfaces
Definition: mechanics.h:78
double tol
CG stopping tolerance.
Definition: mechanics.h:92
sf_vec * residuum
residuum r
Definition: mechanics.h:79
sf_vec * displacement
absolute displacement u
Definition: mechanics.h:73
void apply_external_forces(MaterialType mtype, FILE_SPEC logger, sf_mesh surfmesh, mech_bcs nmbcs)
Applying external forces from Neumann boundary conditions.
Definition: mechanics.cc:610
sf_vec * f_internal
internal forces f_int
Definition: mechanics.h:76
sf_vec * dirichlet_bcs
Dirichlet boundary conditions, 0 = dbc exists.
Definition: mechanics.h:82
SF::vector< mesh_int_t > dbc_idx
Indices for Dirichlet boundary conditions.
Definition: mechanics.h:80
sf_nl_sol * nonlin_solver
the nonlinear solver
Definition: mechanics.h:89
void rebuild_matrices(MaterialType mtype, FILE_SPEC logger)
rebuild the matrices
Definition: mechanics.cc:561
SF::vector< mesh_int_t > nbc_idx
Indices for Neumann boundary conditions.
Definition: mechanics.h:81
sf_vec * initial_guess
needed for initial guess for nonlinear solver
Definition: mechanics.h:75
mech_bcs nmbcs[10]
Neumann boundary conditions.
Definition: mechanics.h:87
mech_bcs dmbcs[10]
Dirichlet boundary condtions.
Definition: mechanics.h:86
void init()
Initialize equlibirum solver.
Definition: mechanics.cc:335
void calc_internal_forces_jacobian(MaterialType mtype, FILE_SPEC logger)
sf_vec * reference_pos
reference position X
Definition: mechanics.h:72
sf_vec * f_external
external forces f_ext
Definition: mechanics.h:77
void setup(int idx)
Setup of both Neumann and Dirichlet mechanics boundary conditions.
Definition: mechanics.cc:766
SF::Point direction
direction in which the bc is applied
Definition: mechanics.h:56
dbc_t dbc_type
fixed coordinates
Definition: mechanics.h:55
SF::vector< mesh_int_t > vertices
list of nodes that bc is active on
Definition: mechanics.h:57
std::string input_filename
filename with list of nodes
Definition: mechanics.h:59
SF::vector< SF_real > scaling
scaling for Neumann bcs
Definition: mechanics.h:58
nbc_t nbc_type
pressure given for elements, force given for nodes
Definition: mechanics.h:54
def_t definition
type of boundary condition
Definition: mechanics.h:53
@ NBR_REF
The nodal numbering of the reference mesh (the one stored on HD).
Definition: SF_container.h:190
sf_mesh & get_mesh(const mesh_t gt)
Get a mesh by specifying the gridID.
Definition: sf_interface.cc:33
@ elasticity_msh
Definition: sf_interface.h:64
Basic physics types.
Interface to SlimFem.
Simulator-level utility execution control functions.
Electrical stimulation functions.
Point and vector struct.
Definition: SF_container.h:66
NOTE: A LOT OF THESE THINGS NEED TO BE CHANGED AT A LATER STAGE. THEY ARE CURRENTLY COPIED FROM THE A...
description of materal properties in a mesh
Definition: fem_types.h:155
File descriptor struct.
Definition: basics.h:133