282 * <a name=
"Includefiles"></a>
283 * <h3>Include files</h3>
289 * #include <deal.II/base/quadrature_lib.h>
290 * #include <deal.II/base/function.h>
291 * #include <deal.II/base/logstream.h>
292 * #include <deal.II/base/parameter_handler.h>
293 * #include <deal.II/lac/affine_constraints.h>
294 * #include <deal.II/lac/vector.h>
295 * #include <deal.II/lac/full_matrix.h>
296 * #include <deal.II/lac/sparse_matrix.h>
297 * #include <deal.II/lac/solver_cg.h>
298 * #include <deal.II/lac/precondition.h>
299 * #include <deal.II/grid/grid_out.h>
300 * #include <deal.II/grid/manifold_lib.h>
301 * #include <deal.II/grid/
tria.h>
302 * #include <deal.II/grid/grid_generator.h>
303 * #include <deal.II/grid/grid_refinement.h>
304 * #include <deal.II/grid/grid_tools.h>
305 * #include <deal.II/grid/tria_accessor.h>
306 * #include <deal.II/grid/tria_iterator.h>
307 * #include <deal.II/dofs/dof_handler.h>
308 * #include <deal.II/dofs/dof_accessor.h>
309 * #include <deal.II/dofs/dof_tools.h>
310 * #include <deal.II/fe/fe_values.h>
311 * #include <deal.II/fe/fe_system.h>
312 * #include <deal.II/fe/fe_q.h>
313 * #include <deal.II/numerics/vector_tools.h>
314 * #include <deal.II/numerics/matrix_tools.h>
315 * #include <deal.II/numerics/data_out.h>
316 * #include <deal.II/numerics/error_estimator.h>
317 * #include <deal.II/physics/transformations.h>
320 * #include <iostream>
330 * <a name=
"Runtimeparameters"></a>
331 * <h3>Run-time parameters</h3>
335 * There are several parameters that can be
set in the code so we
set up a
339 *
namespace Parameters
344 * <a name=
"FiniteElementsystem"></a>
345 * <h4>Finite Element system</h4>
349 * Here we specify the polynomial order used to
approximate the solution.
350 * The quadrature order should be adjusted accordingly.
355 *
unsigned int poly_degree;
356 *
unsigned int quad_order;
367 * prm.enter_subsection(
"Finite element system");
369 * prm.declare_entry(
"Polynomial degree",
"1",
371 *
"Displacement system polynomial order");
373 * prm.declare_entry(
"Quadrature order",
"2",
375 *
"Gauss quadrature order");
377 * prm.leave_subsection();
382 * prm.enter_subsection(
"Finite element system");
384 * poly_degree = prm.get_integer(
"Polynomial degree");
385 * quad_order = prm.get_integer(
"Quadrature order");
387 * prm.leave_subsection();
393 * <a name=
"Problem"></a>
398 * Choose which problem is going to be solved
403 * std::string problem;
414 * prm.enter_subsection(
"Problem");
416 * prm.declare_entry(
"Problem",
"IsotonicContraction",
418 *
"The problem that is to be solved");
420 * prm.leave_subsection();
425 * prm.enter_subsection(
"Problem");
427 * problem = prm.get(
"Problem");
429 * prm.leave_subsection();
435 * <a name=
"IsotonicContractionGeometry"></a>
436 * <h4>IsotonicContractionGeometry</h4>
440 * Make adjustments to the geometry and discretisation of the
441 * isotonic contraction model from Martins2006.
447 *
struct IsotonicContraction
449 *
const double half_length_x = 10
e-3/2.0;
450 *
const double half_length_y = 10
e-3/2.0;
451 *
const double half_length_z = 1
e-3/2.0;
476 * <a name=
"BicepsBrachiiGeometry"></a>
477 * <h4>BicepsBrachiiGeometry</h4>
481 * Make adjustments to the geometry and discretisation of the
488 *
struct BicepsBrachii
490 *
double axial_length;
491 *
double radius_insertion_origin;
492 *
double radius_midpoint;
494 *
unsigned int elements_along_axis;
495 *
unsigned int n_refinements_radial;
496 *
bool include_gravity;
497 *
double axial_force;
512 * prm.enter_subsection(
"Biceps Brachii geometry");
514 * prm.declare_entry(
"Axial length",
"250",
516 *
"Axial length of the muscle");
518 * prm.declare_entry(
"Radius insertion and origin",
"5",
520 *
"Insertion and origin radius");
522 * prm.declare_entry(
"Radius midpoint",
"7.5",
524 *
"Radius at the midpoint of the muscle");
526 * prm.declare_entry(
"Grid scale",
"1e-3",
528 *
"Global grid scaling factor");
530 * prm.declare_entry(
"Elements along axis",
"32",
532 *
"Number of elements along the muscle axis");
534 * prm.declare_entry(
"Radial refinements",
"4",
536 *
"Control the discretisation in the radial direction");
538 * prm.declare_entry(
"Gravity",
"false",
540 *
"Include the effects of gravity (in the y-direction; "
541 *
" perpendicular to the muscle axis)");
543 * prm.declare_entry(
"Axial force",
"1",
545 *
"Applied distributed axial force (in Newtons)");
547 * prm.leave_subsection();
552 * prm.enter_subsection(
"Biceps Brachii geometry");
554 * axial_length = prm.get_double(
"Axial length");
555 * radius_insertion_origin = prm.get_double(
"Radius insertion and origin");
556 * radius_midpoint = prm.get_double(
"Radius midpoint");
557 *
scale = prm.get_double(
"Grid scale");
558 * elements_along_axis = prm.get_integer(
"Elements along axis");
559 * n_refinements_radial = prm.get_integer(
"Radial refinements");
560 * include_gravity = prm.get_bool(
"Gravity");
561 * axial_force = prm.get_double(
"Axial force");
563 * prm.leave_subsection();
565 *
AssertThrow(radius_midpoint >= radius_insertion_origin,
566 * ExcMessage(
"Unrealistic geometry"));
572 * <a name=
"Neurologicalsignal"></a>
573 * <h4>Neurological signal</h4>
579 *
struct NeurologicalSignal
581 *
double neural_signal_start_time;
582 *
double neural_signal_end_time;
593 * prm.enter_subsection(
"Neurological signal");
595 * prm.declare_entry(
"Start time",
"1.0",
597 *
"Time at which to start muscle activation");
599 * prm.declare_entry(
"End time",
"2.0",
601 *
"Time at which to remove muscle activation signal");
603 * prm.leave_subsection();
608 * prm.enter_subsection(
"Neurological signal");
610 * neural_signal_start_time = prm.get_double(
"Start time");
611 * neural_signal_end_time = prm.get_double(
"End time");
613 * prm.leave_subsection();
615 *
Assert(neural_signal_start_time < neural_signal_end_time,
616 * ExcMessage(
"Invalid neural signal times."));
622 * <a name=
"Time"></a>
627 * Set the timestep size @f$ \varDelta t @f$ and the simulation
end-time.
634 *
double end_ramp_time;
645 * prm.enter_subsection(
"Time");
647 * prm.declare_entry(
"End time",
"3",
651 * prm.declare_entry(
"End ramp time",
"1",
653 *
"Force ramp end time");
655 * prm.declare_entry(
"Time step size",
"0.1",
659 * prm.leave_subsection();
664 * prm.enter_subsection(
"Time");
666 * end_time = prm.get_double(
"End time");
667 * end_ramp_time = prm.get_double(
"End ramp time");
668 * delta_t = prm.get_double(
"Time step size");
670 * prm.leave_subsection();
676 * <a name=
"Allparameters"></a>
677 * <h4>All parameters</h4>
681 * Finally we consolidate all of the above structures into a single container
682 * that holds all of our
run-time selections.
685 *
struct AllParameters :
public FESystem,
687 *
public IsotonicContraction,
688 *
public BicepsBrachii,
689 *
public NeurologicalSignal,
692 * AllParameters(
const std::string &input_file);
701 * AllParameters::AllParameters(
const std::string &input_file)
704 * declare_parameters(prm);
706 * parse_parameters(prm);
711 * FESystem::declare_parameters(prm);
712 * Problem::declare_parameters(prm);
713 * IsotonicContraction::declare_parameters(prm);
714 * BicepsBrachii::declare_parameters(prm);
715 * NeurologicalSignal::declare_parameters(prm);
716 * Time::declare_parameters(prm);
721 * FESystem::parse_parameters(prm);
722 * Problem::parse_parameters(prm);
723 * IsotonicContraction::parse_parameters(prm);
724 * BicepsBrachii::parse_parameters(prm);
725 * NeurologicalSignal::parse_parameters(prm);
726 * Time::parse_parameters(prm);
730 * Override time setting
for test defined
734 *
if (problem ==
"IsotonicContraction")
737 * end_ramp_time = 1.0;
740 * neural_signal_start_time = 1.0;
741 * neural_signal_end_time = 2.0;
749 * <a name=
"Bodyforcevalues"></a>
750 * <h3>Body force
values</h3>
757 *
class BodyForce :
public Function<dim>
760 * BodyForce (
const double rho,
762 *
virtual ~BodyForce () {}
777 * BodyForce<dim>::BodyForce (
const double rho,
785 *
Assert(M.norm() == 1.0, ExcMessage(
"Direction vector is not a unit vector"));
791 *
void BodyForce<dim>::vector_value (
const Point<dim> &,
795 * ExcDimensionMismatch (
values.size(), dim));
796 *
Assert (dim >= 2, ExcNotImplemented());
797 *
for (
unsigned int d=0;
d<dim; ++
d)
805 *
void BodyForce<dim>::vector_value_list (
const std::vector<
Point<dim> > &points,
808 *
Assert (value_list.size() == points.size(),
809 * ExcDimensionMismatch (value_list.size(), points.size()));
811 *
const unsigned int n_points = points.size();
813 *
for (
unsigned int p=0; p<n_points; ++p)
814 * BodyForce<dim>::vector_value (points[p],
819 *
class Traction :
public Function<dim>
822 * Traction (
const double force,
823 *
const double area);
824 *
virtual ~Traction () {}
837 * Traction<dim>::Traction (
const double force,
847 *
void Traction<dim>::vector_value (
const Point<dim> &,
851 * ExcDimensionMismatch (
values.size(), dim));
852 *
Assert (dim == 3, ExcNotImplemented());
856 * Assume uniform distributed load
866 *
void Traction<dim>::vector_value_list (
const std::vector<
Point<dim> > &points,
869 *
Assert (value_list.size() == points.size(),
870 * ExcDimensionMismatch (value_list.size(), points.size()));
872 *
const unsigned int n_points = points.size();
874 *
for (
unsigned int p=0; p<n_points; ++p)
875 * Traction<dim>::vector_value (points[p],
882 * <a name=
"Utilityfunctions"></a>
893 *
Assert (grad.size() == dim, ExcInternalError());
896 *
for (
unsigned int i=0; i<dim; ++i)
897 *
for (
unsigned int j=0; j<dim; ++j)
898 * F[i][j] += grad[i][j];
906 *
Assert (grad.size() == dim, ExcInternalError());
909 *
for (
unsigned int i=0; i<dim; ++i)
910 * strain[i][i] = grad[i][i];
912 *
for (
unsigned int i=0; i<dim; ++i)
913 *
for (
unsigned int j=i+1; j<dim; ++j)
914 * strain[i][j] = (grad[i][j] + grad[j][i]) / 2;
921 * <a name=
"Propertiesformusclematrix"></a>
922 * <h3>Properties
for muscle
matrix</h3>
928 *
struct MuscleMatrix
930 *
static const double E;
931 *
static const double nu;
933 *
static const double mu;
934 *
static const double lambda;
937 *
const double MuscleMatrix::E = 26e3;
938 *
const double MuscleMatrix::nu = 0.45;
939 *
const double MuscleMatrix::mu = MuscleMatrix::E/(2.0*(1.0 + MuscleMatrix::nu));
940 *
const double MuscleMatrix::lambda = 2.0*MuscleMatrix::mu *MuscleMatrix::nu/(1.0 - 2.0*MuscleMatrix::nu);
945 * <a name=
"Localdataformusclefibres"></a>
946 * <h3>Local data
for muscle fibres</h3>
952 * #define convert_gf_to_N 1.0/101.97
953 * #define convert_gf_per_cm2_to_N_per_m2 convert_gf_to_N*1e2*1e2
954 * #define T0 6280.0*convert_gf_per_cm2_to_N_per_m2
958 * A
struct that governs the functioning of a single muscle fibre
969 * epsilon_c_t1 (0.0),
970 * epsilon_c_dot (0.0)
981 * epsilon_c_t1 (0.0),
982 * epsilon_c_dot (0.0)
985 * ExcMessage(
"Fibre direction is not a unit vector"));
988 *
void update_alpha (
const double u,
998 *
double get_m_p ()
const;
999 *
double get_m_s ()
const;
1000 *
double get_beta (
const double dt)
const;
1001 *
double get_gamma (
const double dt)
const;
1008 *
const double &get_alpha() const
1012 *
const double &get_epsilon_f() const
1016 *
const double &get_epsilon_c() const
1020 *
const double &get_epsilon_c_dot() const
1022 *
return epsilon_c_dot;
1033 *
double epsilon_c_t1;
1034 *
double epsilon_c_dot;
1036 *
double get_f_c_L ()
const;
1037 *
double get_m_c_V ()
const;
1038 *
double get_c_c_V ()
const;
1041 *
template <
int dim>
1042 *
void MuscleFibre<dim>::update_alpha (
const double u,
1045 *
static const double tau_r = 0.15;
1046 *
static const double tau_f = 0.15;
1047 *
static const double alpha_min = 0;
1050 * alpha = (alpha_t1*tau_r*tau_f + dt*tau_f) / (tau_r*tau_f + dt*tau_f);
1052 * alpha = (alpha_t1*tau_r*tau_f + dt*alpha_min*tau_r) / (tau_r*tau_f + dt*tau_r);
1055 *
const double b = 1.0/tau_r - 1.0/tau_f;
1056 *
const double c = 1.0/tau_f;
1057 *
const double d = alpha_min/tau_f;
1058 *
const double f1 = 1.0/tau_r - alpha_min/tau_f;
1059 *
const double p =
b*u + c;
1060 *
const double q = f1*u +
d;
1062 * alpha = (q*dt + alpha_t1)/(1.0 + p*dt);
1067 *
template <
int dim>
1068 *
double MuscleFibre<dim>::get_m_p () const
1070 *
static const double A = 8.568e-4*convert_gf_per_cm2_to_N_per_m2;
1071 *
static const double a = 12.43;
1072 *
if (epsilon_f >= 0.0)
1076 * 100 times more compliant than Martins2006
1079 *
static const double m_p = 2.0*A*a/1e2;
1086 *
template <
int dim>
1087 *
double MuscleFibre<dim>::get_m_s (
void)
const
1089 *
const double epsilon_s = epsilon_f - epsilon_c;
1090 *
if (epsilon_s >= -1e-6)
1096 *
template <
int dim>
1097 *
double MuscleFibre<dim>::get_f_c_L (
void)
const
1099 *
if (epsilon_c <= 0.5 && epsilon_c >= -0.5)
1105 *
template <
int dim>
1106 *
double MuscleFibre<dim>::get_m_c_V (
void)
const
1108 *
if (epsilon_c_dot < -5.0)
1110 *
else if (epsilon_c_dot <= 3.0)
1116 *
template <
int dim>
1117 *
double MuscleFibre<dim>::get_c_c_V (
void)
const
1119 *
if (epsilon_c_dot < -5.0)
1121 *
else if (epsilon_c_dot <= 3.0)
1127 *
template <
int dim>
1128 *
double MuscleFibre<dim>::get_beta(
const double dt)
const
1130 *
return get_f_c_L()*get_m_c_V()*alpha/dt + get_m_s();
1133 *
template <
int dim>
1134 *
double MuscleFibre<dim>::get_gamma(
const double dt)
const
1136 *
return get_f_c_L()*alpha*(get_m_c_V()*epsilon_c_t1/dt - get_c_c_V());
1139 *
template <
int dim>
1145 * Values from previous state
1146 * These were the
values that were used in the assembly,
1147 * so we must use them in the update step to be consistant.
1148 * Need to compute these before we overwrite epsilon_c_t1
1151 *
const double m_s = get_m_s();
1152 *
const double beta = get_beta(dt);
1153 *
const double gamma = get_gamma(dt);
1157 * Update current state
1161 * epsilon_f = M*
static_cast< Tensor<2,dim> >(strain_tensor)*M;
1162 * epsilon_c_t1 = epsilon_c;
1163 * epsilon_c = (m_s*epsilon_f +
gamma)/beta;
1164 * epsilon_c_dot = (epsilon_c - epsilon_c_t1)/dt;
1171 * <a name=
"ThecodeLinearMuscleModelProblemcodeclasstemplate"></a>
1172 * <h3>The <code>LinearMuscleModelProblem</code>
class template</h3>
1178 *
template <
int dim>
1179 *
class LinearMuscleModelProblem
1182 * LinearMuscleModelProblem (
const std::string &input_file);
1183 * ~LinearMuscleModelProblem ();
1187 *
void make_grid ();
1188 *
void setup_muscle_fibres ();
1189 *
double get_neural_signal (
const double time);
1190 *
void update_fibre_activation (
const double time);
1191 *
void update_fibre_state ();
1192 *
void setup_system ();
1193 *
void assemble_system (
const double time);
1194 *
void apply_boundary_conditions ();
1196 *
void output_results (
const unsigned int timestep,
1197 *
const double time)
const;
1199 * Parameters::AllParameters parameters;
1221 *
const double t_end;
1223 *
const double t_ramp_end;
1230 *
const BodyForce<dim> body_force;
1231 *
const Traction<dim> traction;
1238 * std::vector< std::vector<MuscleFibre<dim> > > fibre_data;
1246 *
const unsigned int q_point_cell)
const;
1248 *
const unsigned int q_point_cell)
const;
1254 * <a name=
"LinearMuscleModelProblemLinearMuscleModelProblem"></a>
1255 * <h4>LinearMuscleModelProblem::LinearMuscleModelProblem</h4>
1261 *
template <
int dim>
1262 * LinearMuscleModelProblem<dim>::LinearMuscleModelProblem (
const std::string &input_file)
1264 * parameters(input_file),
1266 * fe (
FE_Q<dim>(parameters.poly_degree), dim),
1267 * qf_cell (parameters.quad_order),
1268 * qf_face (parameters.quad_order),
1269 * t_end (parameters.end_time),
1270 * dt (parameters.delta_t),
1271 * t_ramp_end(parameters.end_ramp_time),
1272 * body_force ((parameters.problem ==
"BicepsBrachii" &¶meters.include_gravity ==
true) ?
1275 * traction (parameters.problem ==
"BicepsBrachii" ?
1276 * Traction<dim>(parameters.axial_force,
1277 * M_PI*
std::pow(parameters.radius_insertion_origin *parameters.scale,2.0) ) :
1278 * Traction<dim>(4.9*convert_gf_to_N,
1279 * (2.0*parameters.half_length_y)*(2.0*parameters.half_length_z)) )
1281 *
Assert(dim==3, ExcNotImplemented());
1288 * <a name=
"LinearMuscleModelProblemLinearMuscleModelProblem"></a>
1289 * <h4>LinearMuscleModelProblem::~LinearMuscleModelProblem</h4>
1295 *
template <
int dim>
1296 * LinearMuscleModelProblem<dim>::~LinearMuscleModelProblem ()
1298 * dof_handler.clear ();
1305 * <a name=
"LinearMuscleModelProblemmake_grid"></a>
1306 * <h4>LinearMuscleModelProblem::make_grid</h4>
1313 *
struct BicepsGeometry
1315 * BicepsGeometry(
const double axial_length,
1316 *
const double radius_ins_orig,
1317 *
const double radius_mid)
1319 * ax_lgth (axial_length),
1320 * r_ins_orig (radius_ins_orig),
1321 * r_mid (radius_mid)
1326 * The radial profile of the muscle
1327 * This provides the
new coordinates
for points @p pt
1328 * on a
cylinder of radius r_ins_orig and length
1329 * ax_lgth to be moved to in order to create the
1330 * physiologically representative geometry of
1336 *
Assert(pt_0[0] > -1e-6,
1337 * ExcMessage(
"All points must have x-coordinate > 0"));
1339 *
const double r_scale = get_radial_scaling_factor(pt_0[0]);
1340 *
return pt_0 +
Point<dim>(0.0, r_scale*pt_0[1], r_scale*pt_0[2]);
1345 *
return profile(pt);
1350 * Provides the muscle direction at the
point @p pt
1351 * in the real geometry (one that has undergone the
1352 * transformation given by the profile() function)
1353 * and subequent grid rescaling.
1354 * The directions are given by the
gradient of the
1355 * transformation function (i.e. the fibres are
1356 * orientated by the curvature of the muscle).
1361 * to the original
point on the completely unscaled
1362 * cylindrical grid. We then evaluate the transformation
1363 * at two points (axially displaced) very close to the
1364 *
point of interest. The normalised vector joining the
1365 * transformed counterparts of the perturbed points is
1366 * the
gradient of the transformation function and,
1367 * thus, defines the fibre direction.
1371 *
const double &grid_scale)
const
1373 *
const Point<dim> pt = (1.0/grid_scale)*pt_scaled;
1376 *
static const double eps = 1
e-6;
1379 *
const Point<dim> pt_eps_p = profile(pt_0_eps_p);
1380 *
const Point<dim> pt_eps_m = profile(pt_0_eps_m);
1382 *
static const double tol = 1
e-9;
1383 *
Assert(profile(pt_0).distance(pt) < tol, ExcInternalError());
1384 *
Assert(inv_profile(pt_eps_p).distance(pt_0_eps_p) < tol, ExcInternalError());
1385 *
Assert(inv_profile(pt_eps_m).distance(pt_0_eps_m) < tol, ExcInternalError());
1388 * dir /= dir.
norm();
1393 *
const double ax_lgth;
1394 *
const double r_ins_orig;
1395 *
const double r_mid;
1397 *
double get_radial_scaling_factor (
const double &x)
const
1401 * Expect all grid points with X>=0, but we provide a
1402 * tolerant location
for points
"on" the Cartesian plane X=0
1405 *
const double lgth_frac =
std::max(x/ax_lgth,0.0);
1406 *
const double amplitude = 0.25*(r_mid - r_ins_orig);
1407 *
const double phase_shift = M_PI;
1408 *
const double y_shift = 1.0;
1409 *
const double wave_func = y_shift +
std::cos(phase_shift + 2.0*M_PI*lgth_frac);
1410 *
Assert(wave_func >= 0.0, ExcInternalError());
1411 *
return std::sqrt(amplitude*wave_func);
1417 * ExcMessage(
"All points must have x-coordinate > 0"));
1419 *
const double r_scale = get_radial_scaling_factor(pt[0]);
1420 *
const double trans_inv_scale = 1.0/(1.0+r_scale);
1421 *
return Point<dim>(pt[0], trans_inv_scale*pt[1], trans_inv_scale*pt[2]);
1425 *
template <
int dim>
1426 *
void LinearMuscleModelProblem<dim>::make_grid ()
1428 *
Assert (dim == 3, ExcNotImplemented());
1430 *
if (parameters.problem ==
"IsotonicContraction")
1432 *
const Point<dim> p1(-parameters.half_length_x,
1433 * -parameters.half_length_y,
1434 * -parameters.half_length_z);
1435 *
const Point<dim> p2( parameters.half_length_x,
1436 * parameters.half_length_y,
1437 * parameters.half_length_z);
1443 *
for (; cell != endc; ++cell)
1445 *
for (
unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
1447 *
if (cell->face(face)->at_boundary() ==
true)
1449 *
if (cell->face(face)->center()[0] == -parameters.half_length_x)
1450 * cell->face(face)->set_boundary_id(parameters.bid_CC_dirichlet_symm_X);
1451 *
else if (cell->face(face)->center()[0] == parameters.half_length_x)
1452 * cell->face(face)->set_boundary_id(parameters.bid_CC_neumann);
1453 *
else if (
std::abs(cell->face(face)->center()[2]) == parameters.half_length_z)
1454 * cell->face(face)->set_boundary_id(parameters.bid_CC_dirichlet_symm_Z);
1461 *
else if (parameters.problem ==
"BicepsBrachii")
1467 * parameters.radius_insertion_origin);
1470 * cell != tria_cap.
end(); ++cell)
1472 *
for (
unsigned int face = 0; face < GeometryInfo<2>::faces_per_cell; ++face)
1474 *
if (cell->face(face)->at_boundary() ==
true)
1475 * cell->face(face)->set_all_manifold_ids(0);
1485 * parameters.elements_along_axis,
1486 * parameters.axial_length,
1500 * Rotate grid so that the length is axially
1501 * coincident and aligned with the X-axis
1508 * Deform the grid into something that vaguely
1509 * resemble
's a Biceps Brachii
1512 * GridTools::transform (BicepsGeometry<dim>(parameters.axial_length,
1513 * parameters.radius_insertion_origin,
1514 * parameters.radius_midpoint), triangulation);
1521 * typename Triangulation<dim>::active_cell_iterator cell =
1522 * triangulation.begin_active(), endc = triangulation.end();
1523 * for (; cell != endc; ++cell)
1525 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
1527 * if (cell->face(face)->at_boundary() == true)
1529 * static const double tol =1e-6;
1530 * if (std::abs(cell->face(face)->center()[0]) < tol) // -X oriented face
1531 * cell->face(face)->set_boundary_id(parameters.bid_BB_dirichlet_X); // Dirichlet
1532 * else if (std::abs(cell->face(face)->center()[0] - parameters.axial_length) < tol) // +X oriented face
1533 * cell->face(face)->set_boundary_id(parameters.bid_BB_neumann); // Neumann
1540 * Finally resize the grid
1543 * GridTools::scale (parameters.scale, triangulation);
1546 * AssertThrow(false, ExcNotImplemented());
1552 * <a name="LinearMuscleModelProblemsetup_muscle_fibres"></a>
1553 * <h4>LinearMuscleModelProblem::setup_muscle_fibres</h4>
1559 * template <int dim>
1560 * void LinearMuscleModelProblem<dim>::setup_muscle_fibres ()
1562 * fibre_data.clear();
1563 * const unsigned int n_cells = triangulation.n_active_cells();
1564 * fibre_data.resize(n_cells);
1565 * const unsigned int n_q_points_cell = qf_cell.size();
1567 * if (parameters.problem == "IsotonicContraction")
1569 * MuscleFibre<dim> fibre_template (Tensor<1,dim>({1,0,0}));
1571 * for (unsigned int cell_no=0; cell_no<triangulation.n_active_cells(); ++cell_no)
1573 * fibre_data[cell_no].resize(n_q_points_cell);
1574 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1576 * fibre_data[cell_no][q_point_cell] = fibre_template;
1580 * else if (parameters.problem == "BicepsBrachii")
1582 * FEValues<dim> fe_values (fe, qf_cell, update_quadrature_points);
1583 * BicepsGeometry<dim> bicep_geom (parameters.axial_length,
1584 * parameters.radius_insertion_origin,
1585 * parameters.radius_midpoint);
1587 * unsigned int cell_no = 0;
1588 * for (typename Triangulation<dim>::active_cell_iterator
1589 * cell = triangulation.begin_active();
1590 * cell != triangulation.end();
1591 * ++cell, ++cell_no)
1593 * Assert(cell_no<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1594 * fe_values.reinit(cell);
1596 * fibre_data[cell_no].resize(n_q_points_cell);
1597 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1599 * const Point<dim> pt = fe_values.get_quadrature_points()[q_point_cell];
1600 * fibre_data[cell_no][q_point_cell] = MuscleFibre<dim>(bicep_geom.direction(pt,parameters.scale));
1605 * AssertThrow(false, ExcNotImplemented());
1611 * <a name="LinearMuscleModelProblemupdate_fibre_state"></a>
1612 * <h4>LinearMuscleModelProblem::update_fibre_state</h4>
1618 * template <int dim>
1619 * double LinearMuscleModelProblem<dim>::get_neural_signal (const double time)
1623 * Note: 40 times less force generated than Martins2006
1624 * This is necessary due to the (compliant) linear tissue model
1627 * return (time > parameters.neural_signal_start_time && time < parameters.neural_signal_end_time ?
1632 * template <int dim>
1633 * void LinearMuscleModelProblem<dim>::update_fibre_activation (const double time)
1635 * const double u = get_neural_signal(time);
1637 * const unsigned int n_q_points_cell = qf_cell.size();
1638 * for (unsigned int cell=0; cell<triangulation.n_active_cells(); ++cell)
1640 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1642 * MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1643 * fibre.update_alpha(u,dt);
1648 * template <int dim>
1649 * void LinearMuscleModelProblem<dim>::update_fibre_state ()
1651 * const unsigned int n_q_points_cell = qf_cell.size();
1653 * FEValues<dim> fe_values (fe, qf_cell, update_gradients);
1657 * Displacement gradient
1660 * std::vector< std::vector< Tensor<1,dim> > > u_grads (n_q_points_cell,
1661 * std::vector<Tensor<1,dim> >(dim));
1663 * unsigned int cell_no = 0;
1664 * for (typename DoFHandler<dim>::active_cell_iterator
1665 * cell = dof_handler.begin_active();
1666 * cell!=dof_handler.end(); ++cell, ++cell_no)
1668 * Assert(cell_no<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1669 * fe_values.reinit(cell);
1670 * fe_values.get_function_gradients (solution, u_grads);
1672 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1674 * Assert(q_point_cell<fibre_data[cell_no].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1676 * const SymmetricTensor<2,dim> strain_tensor = get_small_strain (u_grads[q_point_cell]);
1677 * MuscleFibre<dim> &fibre = fibre_data[cell_no][q_point_cell];
1678 * fibre.update_state(strain_tensor, dt);
1686 * <a name="LinearMuscleModelProblemsetup_system"></a>
1687 * <h4>LinearMuscleModelProblem::setup_system</h4>
1693 * template <int dim>
1694 * void LinearMuscleModelProblem<dim>::setup_system ()
1696 * dof_handler.distribute_dofs (fe);
1697 * hanging_node_constraints.clear ();
1698 * DoFTools::make_hanging_node_constraints (dof_handler,
1699 * hanging_node_constraints);
1700 * hanging_node_constraints.close ();
1701 * sparsity_pattern.reinit (dof_handler.n_dofs(),
1702 * dof_handler.n_dofs(),
1703 * dof_handler.max_couplings_between_dofs());
1704 * DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
1706 * hanging_node_constraints.condense (sparsity_pattern);
1708 * sparsity_pattern.compress();
1710 * system_matrix.reinit (sparsity_pattern);
1712 * solution.reinit (dof_handler.n_dofs());
1713 * system_rhs.reinit (dof_handler.n_dofs());
1715 * std::cout << " Number of active cells: "
1716 * << triangulation.n_active_cells()
1719 * std::cout << " Number of degrees of freedom: "
1720 * << dof_handler.n_dofs()
1727 * <a name="LinearMuscleModelProblemassemble_system"></a>
1728 * <h4>LinearMuscleModelProblem::assemble_system</h4>
1734 * template <int dim>
1735 * SymmetricTensor<4,dim>
1736 * LinearMuscleModelProblem<dim>::get_stiffness_tensor (const unsigned int cell,
1737 * const unsigned int q_point_cell) const
1739 * static const SymmetricTensor<2,dim> I = unit_symmetric_tensor<dim>();
1741 * Assert(cell<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1742 * Assert(q_point_cell<fibre_data[cell].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1743 * const MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1750 * const double lambda = MuscleMatrix::lambda;
1751 * const double mu = MuscleMatrix::mu;
1757 * const double m_p = fibre.get_m_p();
1758 * const double m_s = fibre.get_m_s();
1759 * const double beta = fibre.get_beta(dt);
1760 * AssertThrow(beta != 0.0, ExcInternalError());
1761 * const double Cf = T0*(m_p + m_s*(1.0 - m_s/beta));
1762 * const Tensor<1,dim> &M = fibre.get_M();
1764 * SymmetricTensor<4,dim> C;
1765 * for (unsigned int i=0; i < dim; ++i)
1766 * for (unsigned int j=i; j < dim; ++j)
1767 * for (unsigned int k=0; k < dim; ++k)
1768 * for (unsigned int l=k; l < dim; ++l)
1772 * Matrix contribution
1775 * C[i][j][k][l] = lambda * I[i][j]*I[k][l]
1776 * + mu * (I[i][k]*I[j][l] + I[i][l]*I[j][k]);
1780 * Fibre contribution (Passive + active branches)
1783 * C[i][j][k][l] += Cf * M[i]*M[j]*M[k]*M[l];
1789 * template <int dim>
1790 * SymmetricTensor<2,dim>
1791 * LinearMuscleModelProblem<dim>::get_rhs_tensor (const unsigned int cell,
1792 * const unsigned int q_point_cell) const
1794 * Assert(cell<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1795 * Assert(q_point_cell<fibre_data[cell].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1796 * const MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1798 * const double m_s = fibre.get_m_s();
1799 * const double beta = fibre.get_beta(dt);
1800 * const double gamma = fibre.get_gamma(dt);
1801 * AssertThrow(beta != 0.0, ExcInternalError());
1802 * const double Sf = T0*(m_s*gamma/beta);
1803 * const Tensor<1,dim> &M = fibre.get_M();
1805 * SymmetricTensor<2,dim> S;
1806 * for (unsigned int i=0; i < dim; ++i)
1807 * for (unsigned int j=i; j < dim; ++j)
1811 * Fibre contribution (Active branch)
1814 * S[i][j] = Sf * M[i]*M[j];
1823 * <a name="LinearMuscleModelProblemassemble_system"></a>
1824 * <h4>LinearMuscleModelProblem::assemble_system</h4>
1830 * template <int dim>
1831 * void LinearMuscleModelProblem<dim>::assemble_system (const double time)
1838 * system_matrix = 0;
1841 * FEValues<dim> fe_values (fe, qf_cell,
1842 * update_values | update_gradients |
1843 * update_quadrature_points | update_JxW_values);
1844 * FEFaceValues<dim> fe_face_values (fe, qf_face,
1846 * update_quadrature_points | update_JxW_values);
1848 * const unsigned int dofs_per_cell = fe.dofs_per_cell;
1849 * const unsigned int n_q_points_cell = qf_cell.size();
1850 * const unsigned int n_q_points_face = qf_face.size();
1852 * FullMatrix<double> cell_matrix (dofs_per_cell, dofs_per_cell);
1853 * Vector<double> cell_rhs (dofs_per_cell);
1855 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1862 * std::vector<Vector<double> > body_force_values (n_q_points_cell,
1863 * Vector<double>(dim));
1864 * std::vector<Vector<double> > traction_values (n_q_points_face,
1865 * Vector<double>(dim));
1867 * unsigned int cell_no = 0;
1868 * for (typename DoFHandler<dim>::active_cell_iterator
1869 * cell = dof_handler.begin_active();
1870 * cell!=dof_handler.end(); ++cell, ++cell_no)
1875 * fe_values.reinit (cell);
1876 * body_force.vector_value_list (fe_values.get_quadrature_points(),
1877 * body_force_values);
1879 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1881 * const SymmetricTensor<4,dim> C = get_stiffness_tensor (cell_no, q_point_cell);
1882 * const SymmetricTensor<2,dim> R = get_rhs_tensor(cell_no, q_point_cell);
1884 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1886 * const unsigned int
1887 * component_I = fe.system_to_component_index(I).first;
1889 * for (unsigned int J=0; J<dofs_per_cell; ++J)
1891 * const unsigned int
1892 * component_J = fe.system_to_component_index(J).first;
1894 * for (unsigned int k=0; k < dim; ++k)
1895 * for (unsigned int l=0; l < dim; ++l)
1897 * += (fe_values.shape_grad(I,q_point_cell)[k] *
1898 * C[component_I][k][component_J][l] *
1899 * fe_values.shape_grad(J,q_point_cell)[l]) *
1900 * fe_values.JxW(q_point_cell);
1904 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1906 * const unsigned int
1907 * component_I = fe.system_to_component_index(I).first;
1910 * += fe_values.shape_value(I,q_point_cell) *
1911 * body_force_values[q_point_cell](component_I) *
1912 * fe_values.JxW(q_point_cell);
1914 * for (unsigned int k=0; k < dim; ++k)
1916 * += (fe_values.shape_grad(I,q_point_cell)[k] *
1917 * R[component_I][k]) *
1918 * fe_values.JxW(q_point_cell);
1922 * for (unsigned int face = 0; face <GeometryInfo<dim>::faces_per_cell; ++face)
1924 * if (cell->face(face)->at_boundary() == true &&
1925 * ((parameters.problem == "IsotonicContraction" &&
1926 * cell->face(face)->boundary_id() == parameters.bid_CC_neumann) ||
1927 * (parameters.problem == "BicepsBrachii" &&
1928 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)) )
1930 * fe_face_values.reinit(cell, face);
1931 * traction.vector_value_list (fe_face_values.get_quadrature_points(),
1936 * Scale applied traction according to time
1939 * const double ramp = (time <= t_ramp_end ? time/t_ramp_end : 1.0);
1940 * Assert(ramp >= 0.0 && ramp <= 1.0, ExcMessage("Invalid force ramp"));
1941 * for (unsigned int q_point_face = 0; q_point_face < n_q_points_face; ++q_point_face)
1942 * traction_values[q_point_face] *= ramp;
1944 * for (unsigned int q_point_face = 0; q_point_face < n_q_points_face; ++q_point_face)
1946 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1948 * const unsigned int
1949 * component_I = fe.system_to_component_index(I).first;
1952 * += fe_face_values.shape_value(I,q_point_face)*
1953 * traction_values[q_point_face][component_I]*
1954 * fe_face_values.JxW(q_point_face);
1960 * cell->get_dof_indices (local_dof_indices);
1961 * for (unsigned int i=0; i<dofs_per_cell; ++i)
1963 * for (unsigned int j=0; j<dofs_per_cell; ++j)
1964 * system_matrix.add (local_dof_indices[i],
1965 * local_dof_indices[j],
1966 * cell_matrix(i,j));
1968 * system_rhs(local_dof_indices[i]) += cell_rhs(i);
1972 * hanging_node_constraints.condense (system_matrix);
1973 * hanging_node_constraints.condense (system_rhs);
1976 * template <int dim>
1977 * void LinearMuscleModelProblem<dim>::apply_boundary_conditions ()
1979 * std::map<types::global_dof_index,double> boundary_values;
1981 * if (parameters.problem == "IsotonicContraction")
1985 * Symmetry condition on -X faces
1989 * ComponentMask component_mask_x (dim, false);
1990 * component_mask_x.set(0, true);
1991 * VectorTools::interpolate_boundary_values (dof_handler,
1992 * parameters.bid_CC_dirichlet_symm_X,
1993 * Functions::ZeroFunction<dim>(dim),
1995 * component_mask_x);
1999 * Symmetry condition on -Z/+Z faces
2003 * ComponentMask component_mask_z (dim, false);
2004 * component_mask_z.set(2, true);
2005 * VectorTools::interpolate_boundary_values (dof_handler,
2006 * parameters.bid_CC_dirichlet_symm_Z,
2007 * Functions::ZeroFunction<dim>(dim),
2009 * component_mask_z);
2013 * Fixed point on -X face
2017 * const Point<dim> fixed_point (-parameters.half_length_x,0.0,0.0);
2018 * std::vector<types::global_dof_index> fixed_dof_indices;
2019 * bool found_point_of_interest = false;
2021 * for (typename DoFHandler<dim>::active_cell_iterator
2022 * cell = dof_handler.begin_active(),
2023 * endc = dof_handler.end(); cell != endc; ++cell)
2025 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2029 * We know that the fixed point is on the -X Dirichlet boundary
2032 * if (cell->face(face)->at_boundary() == true &&
2033 * cell->face(face)->boundary_id() == parameters.bid_CC_dirichlet_symm_X)
2035 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2037 * if (cell->face(face)->vertex(face_vertex_index).distance(fixed_point) < 1e-6)
2039 * found_point_of_interest = true;
2040 * for (unsigned int index_component = 0; index_component < dim; ++index_component)
2041 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2042 * index_component));
2045 * if (found_point_of_interest == true) break;
2048 * if (found_point_of_interest == true) break;
2050 * if (found_point_of_interest == true) break;
2053 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2054 * AssertThrow(fixed_dof_indices.size() == dim, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2056 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2057 * boundary_values[fixed_dof_indices[i]] = 0.0;
2060 * else if (parameters.problem == "BicepsBrachii")
2062 * if (parameters.include_gravity == false)
2066 * Symmetry condition on -X surface
2070 * ComponentMask component_mask_x (dim, false);
2071 * component_mask_x.set(0, true);
2072 * VectorTools::interpolate_boundary_values (dof_handler,
2073 * parameters.bid_BB_dirichlet_X,
2074 * Functions::ZeroFunction<dim>(dim),
2076 * component_mask_x);
2081 * Fixed central point on -X surface
2085 * const Point<dim> fixed_point (0.0,0.0,0.0);
2086 * std::vector<types::global_dof_index> fixed_dof_indices;
2087 * bool found_point_of_interest = false;
2089 * for (typename DoFHandler<dim>::active_cell_iterator
2090 * cell = dof_handler.begin_active(),
2091 * endc = dof_handler.end(); cell != endc; ++cell)
2093 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2097 * We know that the fixed point is on the -X Dirichlet boundary
2100 * if (cell->face(face)->at_boundary() == true &&
2101 * cell->face(face)->boundary_id() == parameters.bid_BB_dirichlet_X)
2103 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2105 * if (cell->face(face)->vertex(face_vertex_index).distance(fixed_point) < 1e-6)
2107 * found_point_of_interest = true;
2108 * for (unsigned int index_component = 0; index_component < dim; ++index_component)
2109 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2110 * index_component));
2113 * if (found_point_of_interest == true) break;
2116 * if (found_point_of_interest == true) break;
2118 * if (found_point_of_interest == true) break;
2121 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2122 * AssertThrow(fixed_dof_indices.size() == dim, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2124 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2125 * boundary_values[fixed_dof_indices[i]] = 0.0;
2132 * When we apply gravity, some additional constraints
2133 * are required to support the load of the muscle, as
2134 * the material response is more compliant than would
2135 * be the case in reality.
2139 * Symmetry condition on -X surface
2143 * ComponentMask component_mask_x (dim, true);
2144 * VectorTools::interpolate_boundary_values (dof_handler,
2145 * parameters.bid_BB_dirichlet_X,
2146 * Functions::ZeroFunction<dim>(dim),
2148 * component_mask_x);
2152 * Symmetry condition on -X surface
2156 * ComponentMask component_mask_x (dim, false);
2157 * component_mask_x.set(1, true);
2158 * component_mask_x.set(2, true);
2159 * VectorTools::interpolate_boundary_values (dof_handler,
2160 * parameters.bid_BB_neumann,
2161 * Functions::ZeroFunction<dim>(dim),
2163 * component_mask_x);
2169 * Roller condition at central point on +X face
2173 * const Point<dim> roller_point (parameters.axial_length*parameters.scale,0.0,0.0);
2174 * std::vector<types::global_dof_index> fixed_dof_indices;
2175 * bool found_point_of_interest = false;
2177 * for (typename DoFHandler<dim>::active_cell_iterator
2178 * cell = dof_handler.begin_active(),
2179 * endc = dof_handler.end(); cell != endc; ++cell)
2181 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2185 * We know that the fixed point is on the +X Neumann boundary
2188 * if (cell->face(face)->at_boundary() == true &&
2189 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)
2191 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2193 * if (cell->face(face)->vertex(face_vertex_index).distance(roller_point) < 1e-6)
2195 * found_point_of_interest = true;
2196 * for (unsigned int index_component = 1; index_component < dim; ++index_component)
2197 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2198 * index_component));
2201 * if (found_point_of_interest == true) break;
2204 * if (found_point_of_interest == true) break;
2206 * if (found_point_of_interest == true) break;
2209 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2210 * AssertThrow(fixed_dof_indices.size() == dim-1, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2212 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2213 * boundary_values[fixed_dof_indices[i]] = 0.0;
2217 * AssertThrow(false, ExcNotImplemented());
2219 * MatrixTools::apply_boundary_values (boundary_values,
2229 * <a name="LinearMuscleModelProblemsolve"></a>
2230 * <h4>LinearMuscleModelProblem::solve</h4>
2236 * template <int dim>
2237 * void LinearMuscleModelProblem<dim>::solve ()
2239 * SolverControl solver_control (system_matrix.m(), 1e-12);
2240 * SolverCG<> cg (solver_control);
2242 * PreconditionSSOR<> preconditioner;
2243 * preconditioner.initialize(system_matrix, 1.2);
2245 * cg.solve (system_matrix, solution, system_rhs,
2248 * hanging_node_constraints.distribute (solution);
2255 * <a name="LinearMuscleModelProblemoutput_results"></a>
2256 * <h4>LinearMuscleModelProblem::output_results</h4>
2265 * template <int dim>
2266 * void LinearMuscleModelProblem<dim>::output_results (const unsigned int timestep,
2267 * const double time) const
2271 * Visual output: FEM results
2275 * std::string filename = "solution-";
2276 * filename += Utilities::int_to_string(timestep,4);
2277 * filename += ".vtk";
2278 * std::ofstream output (filename.c_str());
2280 * DataOut<dim> data_out;
2281 * data_out.attach_dof_handler (dof_handler);
2283 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
2284 * data_component_interpretation(dim,
2285 * DataComponentInterpretation::component_is_part_of_vector);
2286 * std::vector<std::string> solution_name(dim, "displacement");
2288 * data_out.add_data_vector (solution, solution_name,
2289 * DataOut<dim>::type_dof_data,
2290 * data_component_interpretation);
2291 * data_out.build_patches ();
2292 * data_out.write_vtk (output);
2297 * Visual output: FEM data
2301 * std::string filename = "fibres-";
2302 * filename += Utilities::int_to_string(timestep,4);
2303 * filename += ".vtk";
2304 * std::ofstream output (filename.c_str());
2307 * << "# vtk DataFile Version 3.0" << std::endl
2308 * << "# " << std::endl
2309 * << "ASCII"<< std::endl
2310 * << "DATASET POLYDATA"<< std::endl << std::endl;
2314 * Extract fibre data from quadrature points
2317 * const unsigned int n_cells = triangulation.n_active_cells();
2318 * const unsigned int n_q_points_cell = qf_cell.size();
2322 * Data that we'll be outputting
2325 * std::vector<std::string> results_fibre_names;
2326 * results_fibre_names.push_back(
"alpha");
2327 * results_fibre_names.push_back(
"epsilon_f");
2328 * results_fibre_names.push_back(
"epsilon_c");
2329 * results_fibre_names.push_back(
"epsilon_c_dot");
2331 *
const unsigned int n_results = results_fibre_names.size();
2332 *
const unsigned int n_data_points =
n_cells*n_q_points_cell;
2333 * std::vector< Point<dim> > output_points(n_data_points);
2334 * std::vector< Tensor<1,dim> > output_displacements(n_data_points);
2335 * std::vector< Tensor<1,dim> > output_directions(n_data_points);
2336 * std::vector< std::vector<double> > output_values(n_results, std::vector<double>(n_data_points));
2343 * std::vector< Vector<double> > u_values (n_q_points_cell,
2350 * std::vector< std::vector< Tensor<1,dim> > > u_grads (n_q_points_cell,
2355 *
unsigned int cell_no = 0;
2356 *
unsigned int fibre_no = 0;
2358 * cell = dof_handler.begin_active();
2359 * cell != dof_handler.end();
2360 * ++cell, ++cell_no)
2362 * fe_values.reinit (cell);
2363 * fe_values.get_function_values (solution, u_values);
2364 * fe_values.get_function_gradients (solution, u_grads);
2366 *
for (
unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell, ++fibre_no)
2368 *
const MuscleFibre<dim> &fibre = fibre_data[cell_no][q_point_cell];
2369 * output_points[fibre_no] = fe_values.get_quadrature_points()[q_point_cell];
2370 *
for (
unsigned int d=0;
d<dim; ++
d)
2371 * output_displacements[fibre_no][d] = u_values[q_point_cell][d];
2374 * Direction (spatial configuration)
2377 * output_directions[fibre_no] = get_deformation_gradient(u_grads[q_point_cell])*fibre.get_M();
2378 * output_directions[fibre_no] /= output_directions[fibre_no].norm();
2385 * output_values[0][fibre_no] = fibre.get_alpha();
2386 * output_values[1][fibre_no] = fibre.get_epsilon_f();
2387 * output_values[2][fibre_no] = fibre.get_epsilon_c();
2388 * output_values[3][fibre_no] = fibre.get_epsilon_c_dot();
2400 * <<
" float" << std::endl;
2401 *
for (
unsigned int i=0; i < n_data_points; ++i)
2403 *
for (
unsigned int j=0; j < dim; ++j)
2405 * output << (output_points)[i][j] <<
"\t";
2407 * output << std::endl;
2412 * HEADER FOR POINT DATA
2415 * output <<
"\nPOINT_DATA "
2417 * << std::endl << std::endl;
2421 * FIBRE DISPLACEMENTS
2425 * <<
"VECTORS displacement float"
2427 *
for (
unsigned int i = 0; i < n_data_points; ++i)
2429 *
for (
unsigned int j=0; j < dim; ++j)
2431 * output << (output_displacements)[i][j] <<
"\t";
2433 * output << std::endl;
2435 * output << std::endl;
2443 * <<
"VECTORS direction float"
2445 *
for (
unsigned int i = 0; i < n_data_points; ++i)
2447 *
for (
unsigned int j=0; j < dim; ++j)
2449 * output << (output_directions)[i][j] <<
"\t";
2451 * output << std::endl;
2453 * output << std::endl;
2460 *
for (
unsigned int v=0; v < n_results; ++v)
2464 * << results_fibre_names[v]
2465 * <<
" float 1" << std::endl
2466 * <<
"LOOKUP_TABLE default "
2468 *
for (
unsigned int i=0; i<n_data_points; ++i)
2470 * output << (output_values)[v][i] <<
" ";
2472 * output << std::endl;
2478 * Output X-displacement at measured
point
2482 *
const Point<dim> meas_pt (parameters.problem ==
"IsotonicContraction" ?
2483 *
Point<dim>(parameters.half_length_x, 0.0, 0.0) :
2484 *
Point<dim>(parameters.axial_length*parameters.scale, 0.0, 0.0) );
2487 *
const unsigned int index_of_interest = 0;
2488 *
bool found_point_of_interest =
false;
2492 * cell = dof_handler.begin_active(),
2493 * endc = dof_handler.end(); cell != endc; ++cell)
2495 *
for (
unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2499 * We know that the measurement
point is on the Neumann boundary
2502 *
if (cell->face(face)->at_boundary() ==
true &&
2503 * ((parameters.problem ==
"IsotonicContraction" &&
2504 * cell->face(face)->boundary_id() == parameters.bid_CC_neumann) ||
2505 * (parameters.problem ==
"BicepsBrachii" &&
2506 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)) )
2508 *
for (
unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2510 *
if (cell->face(face)->vertex(face_vertex_index).distance(meas_pt) < 1e-6)
2512 * found_point_of_interest =
true;
2513 * dof_of_interest = cell->face(face)->vertex_dof_index(face_vertex_index,
2514 * index_of_interest);
2517 *
if (found_point_of_interest ==
true)
break;
2520 *
if (found_point_of_interest ==
true)
break;
2522 *
if (found_point_of_interest ==
true)
break;
2525 *
Assert(found_point_of_interest ==
true, ExcMessage(
"Didn't find point of interest"));
2527 *
Assert(dof_of_interest < dof_handler.n_dofs(), ExcMessage(
"DoF index out of range"));
2529 *
const std::string filename =
"displacement_POI.csv";
2530 * std::ofstream output;
2531 *
if (timestep == 0)
2533 * output.open(filename.c_str(), std::ofstream::out);
2535 * <<
"Time [s]" <<
"," <<
"X-displacement [mm]" << std::endl;
2538 * output.open(filename.c_str(), std::ios_base::app);
2543 * << solution[dof_of_interest]*1e3
2553 * <a name=
"LinearMuscleModelProblemrun"></a>
2554 * <h4>LinearMuscleModelProblem::run</h4>
2560 *
template <
int dim>
2561 *
void LinearMuscleModelProblem<dim>::run ()
2565 * setup_muscle_fibres ();
2569 *
const bool do_grid_refinement =
false;
2572 *
double time = 0.0;
2573 *
for (
unsigned int timestep=0; time<=t_end; ++timestep, time+=dt)
2576 * <<
"Timestep " << timestep
2577 * <<
" @ time " << time
2582 * First we update the fibre activation
level
2583 * based on the current time
2586 * update_fibre_activation(time);
2590 * Next we
assemble the system and enforce boundary
2592 * Here we assume that the system and fibres have
2593 * a fixed state, and we will
assemble based on how
2594 * epsilon_c will update given the current state of
2598 * assemble_system (time);
2599 * apply_boundary_conditions ();
2603 * Then we solve the linear system
2610 * Now we update the fibre state based on the
new
2611 * displacement solution and the constitutive
2612 * parameters assumed to govern the stiffness of
2613 * the fibres at the previous state. i.e. We
2614 * follow through with assumed update conditions
2615 * used in the assembly phase.
2618 * update_fibre_state();
2622 * Output some
values to file
2625 * output_results (timestep, time);
2633 * <a name=
"Thecodemaincodefunction"></a>
2634 * <h3>The <code>main</code> function</h3>
2645 *
const unsigned int dim = 3;
2647 * LMM::LinearMuscleModelProblem<dim> lmm_problem (
"parameters.prm");
2648 * lmm_problem.run ();
2650 *
catch (std::exception &exc)
2652 * std::cerr << std::endl << std::endl
2653 * <<
"----------------------------------------------------"
2655 * std::cerr <<
"Exception on processing: " << std::endl
2656 * << exc.what() << std::endl
2657 * <<
"Aborting!" << std::endl
2658 * <<
"----------------------------------------------------"
2665 * std::cerr << std::endl << std::endl
2666 * <<
"----------------------------------------------------"
2668 * std::cerr <<
"Unknown exception!" << std::endl
2669 * <<
"Aborting!" << std::endl
2670 * <<
"----------------------------------------------------"
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
unsigned int depth_console(const unsigned int n)
virtual void parse_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="", const bool skip_undefined=false)
numbers::NumberTraits< Number >::real_type norm() const
void refine_global(const unsigned int times=1)
cell_iterator end() const
active_cell_iterator begin_active(const unsigned int level=0) const
@ update_values
Shape function values.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
__global__ void set(Number *val, const Number s, const size_type N)
#define Assert(cond, exc)
#define AssertThrow(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void set_manifold(const types::manifold_id number, const Manifold< dim, spacedim > &manifold_object)
void approximate(SynchronousIterators< std::tuple< typename DoFHandler< dim, spacedim >::active_cell_iterator, Vector< float >::iterator > > const &cell, const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof_handler, const InputVector &solution, const unsigned int component)
void hyper_ball(Triangulation< dim > &tria, const Point< dim > ¢er=Point< dim >(), const double radius=1., const bool attach_spherical_manifold_on_boundary_cells=false)
void hyper_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void cylinder(Triangulation< dim > &tria, const double radius=1., const double half_length=1.)
void extrude_triangulation(const Triangulation< 2, 2 > &input, const unsigned int n_slices, const double height, Triangulation< 3, 3 > &result, const bool copy_manifold_ids=false, const std::vector< types::manifold_id > &manifold_priorities={})
void flatten_triangulation(const Triangulation< dim, spacedim1 > &in_tria, Triangulation< dim, spacedim2 > &out_tria)
@ matrix
Contents is actually a matrix.
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
SymmetricTensor< 2, dim, Number > E(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Tensor< 2, dim, Number > F(const Tensor< 2, dim, Number > &Grad_u)
VectorType::value_type * end(VectorType &V)
void run(const Iterator &begin, const typename identity< Iterator >::type &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
long double gamma(const unsigned int n)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
int(&) functions(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
const types::global_dof_index invalid_dof_index
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Predicate &predicate, const unsigned int grainsize)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
const ::Triangulation< dim, spacedim > & tria