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);
705 * prm.parse_input(input_file);
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) ?
1274 * BodyForce<dim>(0.0,
Tensor<1,dim>({0,0,1})) ),
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;
1384 *
Assert(profile(pt_0).distance(pt) < tol, ExcInternalError());
1385 *
Assert(inv_profile(pt_eps_p).distance(pt_0_eps_p) < tol, ExcInternalError());
1386 *
Assert(inv_profile(pt_eps_m).distance(pt_0_eps_m) < tol, ExcInternalError());
1389 * dir /= dir.
norm();
1394 *
const double ax_lgth;
1395 *
const double r_ins_orig;
1396 *
const double r_mid;
1398 *
double get_radial_scaling_factor (
const double &x)
const
1402 * Expect all grid points with X>=0, but we provide a
1403 * tolerant location
for points
"on" the Cartesian plane X=0
1406 *
const double lgth_frac =
std::max(x/ax_lgth,0.0);
1407 *
const double amplitude = 0.25*(r_mid - r_ins_orig);
1408 *
const double phase_shift = M_PI;
1409 *
const double y_shift = 1.0;
1410 *
const double wave_func = y_shift +
std::cos(phase_shift + 2.0*M_PI*lgth_frac);
1411 *
Assert(wave_func >= 0.0, ExcInternalError());
1412 *
return std::sqrt(amplitude*wave_func);
1418 * ExcMessage(
"All points must have x-coordinate > 0"));
1420 *
const double r_scale = get_radial_scaling_factor(pt[0]);
1421 *
const double trans_inv_scale = 1.0/(1.0+r_scale);
1422 *
return Point<dim>(pt[0], trans_inv_scale*pt[1], trans_inv_scale*pt[2]);
1426 *
template <
int dim>
1427 *
void LinearMuscleModelProblem<dim>::make_grid ()
1429 *
Assert (dim == 3, ExcNotImplemented());
1431 *
if (parameters.problem ==
"IsotonicContraction")
1433 *
const Point<dim> p1(-parameters.half_length_x,
1434 * -parameters.half_length_y,
1435 * -parameters.half_length_z);
1436 *
const Point<dim> p2( parameters.half_length_x,
1437 * parameters.half_length_y,
1438 * parameters.half_length_z);
1444 *
for (; cell != endc; ++cell)
1446 *
for (
unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
1448 *
if (cell->face(face)->at_boundary() ==
true)
1450 *
if (cell->face(face)->center()[0] == -parameters.half_length_x)
1451 * cell->face(face)->set_boundary_id(parameters.bid_CC_dirichlet_symm_X);
1452 *
else if (cell->face(face)->center()[0] == parameters.half_length_x)
1453 * cell->face(face)->set_boundary_id(parameters.bid_CC_neumann);
1454 *
else if (
std::abs(cell->face(face)->center()[2]) == parameters.half_length_z)
1455 * cell->face(face)->set_boundary_id(parameters.bid_CC_dirichlet_symm_Z);
1462 *
else if (parameters.problem ==
"BicepsBrachii")
1468 * parameters.radius_insertion_origin);
1470 * cell = tria_cap.begin_active();
1471 * cell != tria_cap.end(); ++cell)
1473 *
for (
unsigned int face = 0; face < GeometryInfo<2>::faces_per_cell; ++face)
1475 *
if (cell->face(face)->at_boundary() ==
true)
1476 * cell->face(face)->set_all_manifold_ids(0);
1479 * tria_cap.set_manifold (0, manifold_cap);
1480 * tria_cap.refine_global(parameters.n_refinements_radial);
1486 * parameters.elements_along_axis,
1487 * parameters.axial_length,
1501 * Rotate grid so that the length is axially
1502 * coincident and aligned with the X-axis
1509 * Deform the grid into something that vaguely
1510 * resemble
's a Biceps Brachii
1513 * GridTools::transform (BicepsGeometry<dim>(parameters.axial_length,
1514 * parameters.radius_insertion_origin,
1515 * parameters.radius_midpoint), triangulation);
1522 * typename Triangulation<dim>::active_cell_iterator cell =
1523 * triangulation.begin_active(), endc = triangulation.end();
1524 * for (; cell != endc; ++cell)
1526 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
1528 * if (cell->face(face)->at_boundary() == true)
1530 * static const double tol =1e-6;
1531 * if (std::abs(cell->face(face)->center()[0]) < tol) // -X oriented face
1532 * cell->face(face)->set_boundary_id(parameters.bid_BB_dirichlet_X); // Dirichlet
1533 * else if (std::abs(cell->face(face)->center()[0] - parameters.axial_length) < tol) // +X oriented face
1534 * cell->face(face)->set_boundary_id(parameters.bid_BB_neumann); // Neumann
1541 * Finally resize the grid
1544 * GridTools::scale (parameters.scale, triangulation);
1547 * AssertThrow(false, ExcNotImplemented());
1553 * <a name="LinearMuscleModelProblemsetup_muscle_fibres"></a>
1554 * <h4>LinearMuscleModelProblem::setup_muscle_fibres</h4>
1560 * template <int dim>
1561 * void LinearMuscleModelProblem<dim>::setup_muscle_fibres ()
1563 * fibre_data.clear();
1564 * const unsigned int n_cells = triangulation.n_active_cells();
1565 * fibre_data.resize(n_cells);
1566 * const unsigned int n_q_points_cell = qf_cell.size();
1568 * if (parameters.problem == "IsotonicContraction")
1570 * MuscleFibre<dim> fibre_template (Tensor<1,dim>({1,0,0}));
1572 * for (unsigned int cell_no=0; cell_no<triangulation.n_active_cells(); ++cell_no)
1574 * fibre_data[cell_no].resize(n_q_points_cell);
1575 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1577 * fibre_data[cell_no][q_point_cell] = fibre_template;
1581 * else if (parameters.problem == "BicepsBrachii")
1583 * FEValues<dim> fe_values (fe, qf_cell, update_quadrature_points);
1584 * BicepsGeometry<dim> bicep_geom (parameters.axial_length,
1585 * parameters.radius_insertion_origin,
1586 * parameters.radius_midpoint);
1588 * unsigned int cell_no = 0;
1589 * for (typename Triangulation<dim>::active_cell_iterator
1590 * cell = triangulation.begin_active();
1591 * cell != triangulation.end();
1592 * ++cell, ++cell_no)
1594 * Assert(cell_no<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1595 * fe_values.reinit(cell);
1597 * fibre_data[cell_no].resize(n_q_points_cell);
1598 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1600 * const Point<dim> pt = fe_values.get_quadrature_points()[q_point_cell];
1601 * fibre_data[cell_no][q_point_cell] = MuscleFibre<dim>(bicep_geom.direction(pt,parameters.scale));
1606 * AssertThrow(false, ExcNotImplemented());
1612 * <a name="LinearMuscleModelProblemupdate_fibre_state"></a>
1613 * <h4>LinearMuscleModelProblem::update_fibre_state</h4>
1619 * template <int dim>
1620 * double LinearMuscleModelProblem<dim>::get_neural_signal (const double time)
1624 * Note: 40 times less force generated than Martins2006
1625 * This is necessary due to the (compliant) linear tissue model
1628 * return (time > parameters.neural_signal_start_time && time < parameters.neural_signal_end_time ?
1633 * template <int dim>
1634 * void LinearMuscleModelProblem<dim>::update_fibre_activation (const double time)
1636 * const double u = get_neural_signal(time);
1638 * const unsigned int n_q_points_cell = qf_cell.size();
1639 * for (unsigned int cell=0; cell<triangulation.n_active_cells(); ++cell)
1641 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1643 * MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1644 * fibre.update_alpha(u,dt);
1649 * template <int dim>
1650 * void LinearMuscleModelProblem<dim>::update_fibre_state ()
1652 * const unsigned int n_q_points_cell = qf_cell.size();
1654 * FEValues<dim> fe_values (fe, qf_cell, update_gradients);
1658 * Displacement gradient
1661 * std::vector< std::vector< Tensor<1,dim> > > u_grads (n_q_points_cell,
1662 * std::vector<Tensor<1,dim> >(dim));
1664 * unsigned int cell_no = 0;
1665 * for (typename DoFHandler<dim>::active_cell_iterator
1666 * cell = dof_handler.begin_active();
1667 * cell!=dof_handler.end(); ++cell, ++cell_no)
1669 * Assert(cell_no<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1670 * fe_values.reinit(cell);
1671 * fe_values.get_function_gradients (solution, u_grads);
1673 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1675 * Assert(q_point_cell<fibre_data[cell_no].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1677 * const SymmetricTensor<2,dim> strain_tensor = get_small_strain (u_grads[q_point_cell]);
1678 * MuscleFibre<dim> &fibre = fibre_data[cell_no][q_point_cell];
1679 * fibre.update_state(strain_tensor, dt);
1687 * <a name="LinearMuscleModelProblemsetup_system"></a>
1688 * <h4>LinearMuscleModelProblem::setup_system</h4>
1694 * template <int dim>
1695 * void LinearMuscleModelProblem<dim>::setup_system ()
1697 * dof_handler.distribute_dofs (fe);
1698 * hanging_node_constraints.clear ();
1699 * DoFTools::make_hanging_node_constraints (dof_handler,
1700 * hanging_node_constraints);
1701 * hanging_node_constraints.close ();
1702 * sparsity_pattern.reinit (dof_handler.n_dofs(),
1703 * dof_handler.n_dofs(),
1704 * dof_handler.max_couplings_between_dofs());
1705 * DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
1707 * hanging_node_constraints.condense (sparsity_pattern);
1709 * sparsity_pattern.compress();
1711 * system_matrix.reinit (sparsity_pattern);
1713 * solution.reinit (dof_handler.n_dofs());
1714 * system_rhs.reinit (dof_handler.n_dofs());
1716 * std::cout << " Number of active cells: "
1717 * << triangulation.n_active_cells()
1720 * std::cout << " Number of degrees of freedom: "
1721 * << dof_handler.n_dofs()
1728 * <a name="LinearMuscleModelProblemassemble_system"></a>
1729 * <h4>LinearMuscleModelProblem::assemble_system</h4>
1735 * template <int dim>
1736 * SymmetricTensor<4,dim>
1737 * LinearMuscleModelProblem<dim>::get_stiffness_tensor (const unsigned int cell,
1738 * const unsigned int q_point_cell) const
1740 * static const SymmetricTensor<2,dim> I = unit_symmetric_tensor<dim>();
1742 * Assert(cell<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1743 * Assert(q_point_cell<fibre_data[cell].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1744 * const MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1751 * const double lambda = MuscleMatrix::lambda;
1752 * const double mu = MuscleMatrix::mu;
1758 * const double m_p = fibre.get_m_p();
1759 * const double m_s = fibre.get_m_s();
1760 * const double beta = fibre.get_beta(dt);
1761 * AssertThrow(beta != 0.0, ExcInternalError());
1762 * const double Cf = T0*(m_p + m_s*(1.0 - m_s/beta));
1763 * const Tensor<1,dim> &M = fibre.get_M();
1765 * SymmetricTensor<4,dim> C;
1766 * for (unsigned int i=0; i < dim; ++i)
1767 * for (unsigned int j=i; j < dim; ++j)
1768 * for (unsigned int k=0; k < dim; ++k)
1769 * for (unsigned int l=k; l < dim; ++l)
1773 * Matrix contribution
1776 * C[i][j][k][l] = lambda * I[i][j]*I[k][l]
1777 * + mu * (I[i][k]*I[j][l] + I[i][l]*I[j][k]);
1781 * Fibre contribution (Passive + active branches)
1784 * C[i][j][k][l] += Cf * M[i]*M[j]*M[k]*M[l];
1790 * template <int dim>
1791 * SymmetricTensor<2,dim>
1792 * LinearMuscleModelProblem<dim>::get_rhs_tensor (const unsigned int cell,
1793 * const unsigned int q_point_cell) const
1795 * Assert(cell<fibre_data.size(), ExcMessage("Trying to access fibre data not stored for this cell index"));
1796 * Assert(q_point_cell<fibre_data[cell].size(), ExcMessage("Trying to access fibre data not stored for this cell and qp index"));
1797 * const MuscleFibre<dim> &fibre = fibre_data[cell][q_point_cell];
1799 * const double m_s = fibre.get_m_s();
1800 * const double beta = fibre.get_beta(dt);
1801 * const double gamma = fibre.get_gamma(dt);
1802 * AssertThrow(beta != 0.0, ExcInternalError());
1803 * const double Sf = T0*(m_s*gamma/beta);
1804 * const Tensor<1,dim> &M = fibre.get_M();
1806 * SymmetricTensor<2,dim> S;
1807 * for (unsigned int i=0; i < dim; ++i)
1808 * for (unsigned int j=i; j < dim; ++j)
1812 * Fibre contribution (Active branch)
1815 * S[i][j] = Sf * M[i]*M[j];
1824 * <a name="LinearMuscleModelProblemassemble_system"></a>
1825 * <h4>LinearMuscleModelProblem::assemble_system</h4>
1831 * template <int dim>
1832 * void LinearMuscleModelProblem<dim>::assemble_system (const double time)
1839 * system_matrix = 0;
1842 * FEValues<dim> fe_values (fe, qf_cell,
1843 * update_values | update_gradients |
1844 * update_quadrature_points | update_JxW_values);
1845 * FEFaceValues<dim> fe_face_values (fe, qf_face,
1847 * update_quadrature_points | update_JxW_values);
1849 * const unsigned int dofs_per_cell = fe.dofs_per_cell;
1850 * const unsigned int n_q_points_cell = qf_cell.size();
1851 * const unsigned int n_q_points_face = qf_face.size();
1853 * FullMatrix<double> cell_matrix (dofs_per_cell, dofs_per_cell);
1854 * Vector<double> cell_rhs (dofs_per_cell);
1856 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1863 * std::vector<Vector<double> > body_force_values (n_q_points_cell,
1864 * Vector<double>(dim));
1865 * std::vector<Vector<double> > traction_values (n_q_points_face,
1866 * Vector<double>(dim));
1868 * unsigned int cell_no = 0;
1869 * for (typename DoFHandler<dim>::active_cell_iterator
1870 * cell = dof_handler.begin_active();
1871 * cell!=dof_handler.end(); ++cell, ++cell_no)
1876 * fe_values.reinit (cell);
1877 * body_force.vector_value_list (fe_values.get_quadrature_points(),
1878 * body_force_values);
1880 * for (unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell)
1882 * const SymmetricTensor<4,dim> C = get_stiffness_tensor (cell_no, q_point_cell);
1883 * const SymmetricTensor<2,dim> R = get_rhs_tensor(cell_no, q_point_cell);
1885 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1887 * const unsigned int
1888 * component_I = fe.system_to_component_index(I).first;
1890 * for (unsigned int J=0; J<dofs_per_cell; ++J)
1892 * const unsigned int
1893 * component_J = fe.system_to_component_index(J).first;
1895 * for (unsigned int k=0; k < dim; ++k)
1896 * for (unsigned int l=0; l < dim; ++l)
1898 * += (fe_values.shape_grad(I,q_point_cell)[k] *
1899 * C[component_I][k][component_J][l] *
1900 * fe_values.shape_grad(J,q_point_cell)[l]) *
1901 * fe_values.JxW(q_point_cell);
1905 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1907 * const unsigned int
1908 * component_I = fe.system_to_component_index(I).first;
1911 * += fe_values.shape_value(I,q_point_cell) *
1912 * body_force_values[q_point_cell](component_I) *
1913 * fe_values.JxW(q_point_cell);
1915 * for (unsigned int k=0; k < dim; ++k)
1917 * += (fe_values.shape_grad(I,q_point_cell)[k] *
1918 * R[component_I][k]) *
1919 * fe_values.JxW(q_point_cell);
1923 * for (unsigned int face = 0; face <GeometryInfo<dim>::faces_per_cell; ++face)
1925 * if (cell->face(face)->at_boundary() == true &&
1926 * ((parameters.problem == "IsotonicContraction" &&
1927 * cell->face(face)->boundary_id() == parameters.bid_CC_neumann) ||
1928 * (parameters.problem == "BicepsBrachii" &&
1929 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)) )
1931 * fe_face_values.reinit(cell, face);
1932 * traction.vector_value_list (fe_face_values.get_quadrature_points(),
1937 * Scale applied traction according to time
1940 * const double ramp = (time <= t_ramp_end ? time/t_ramp_end : 1.0);
1941 * Assert(ramp >= 0.0 && ramp <= 1.0, ExcMessage("Invalid force ramp"));
1942 * for (unsigned int q_point_face = 0; q_point_face < n_q_points_face; ++q_point_face)
1943 * traction_values[q_point_face] *= ramp;
1945 * for (unsigned int q_point_face = 0; q_point_face < n_q_points_face; ++q_point_face)
1947 * for (unsigned int I=0; I<dofs_per_cell; ++I)
1949 * const unsigned int
1950 * component_I = fe.system_to_component_index(I).first;
1953 * += fe_face_values.shape_value(I,q_point_face)*
1954 * traction_values[q_point_face][component_I]*
1955 * fe_face_values.JxW(q_point_face);
1961 * cell->get_dof_indices (local_dof_indices);
1962 * for (unsigned int i=0; i<dofs_per_cell; ++i)
1964 * for (unsigned int j=0; j<dofs_per_cell; ++j)
1965 * system_matrix.add (local_dof_indices[i],
1966 * local_dof_indices[j],
1967 * cell_matrix(i,j));
1969 * system_rhs(local_dof_indices[i]) += cell_rhs(i);
1973 * hanging_node_constraints.condense (system_matrix);
1974 * hanging_node_constraints.condense (system_rhs);
1977 * template <int dim>
1978 * void LinearMuscleModelProblem<dim>::apply_boundary_conditions ()
1980 * std::map<types::global_dof_index,double> boundary_values;
1982 * if (parameters.problem == "IsotonicContraction")
1986 * Symmetry condition on -X faces
1990 * ComponentMask component_mask_x (dim, false);
1991 * component_mask_x.set(0, true);
1992 * VectorTools::interpolate_boundary_values (dof_handler,
1993 * parameters.bid_CC_dirichlet_symm_X,
1994 * Functions::ZeroFunction<dim>(dim),
1996 * component_mask_x);
2000 * Symmetry condition on -Z/+Z faces
2004 * ComponentMask component_mask_z (dim, false);
2005 * component_mask_z.set(2, true);
2006 * VectorTools::interpolate_boundary_values (dof_handler,
2007 * parameters.bid_CC_dirichlet_symm_Z,
2008 * Functions::ZeroFunction<dim>(dim),
2010 * component_mask_z);
2014 * Fixed point on -X face
2018 * const Point<dim> fixed_point (-parameters.half_length_x,0.0,0.0);
2019 * std::vector<types::global_dof_index> fixed_dof_indices;
2020 * bool found_point_of_interest = false;
2022 * for (typename DoFHandler<dim>::active_cell_iterator
2023 * cell = dof_handler.begin_active(),
2024 * endc = dof_handler.end(); cell != endc; ++cell)
2026 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2030 * We know that the fixed point is on the -X Dirichlet boundary
2033 * if (cell->face(face)->at_boundary() == true &&
2034 * cell->face(face)->boundary_id() == parameters.bid_CC_dirichlet_symm_X)
2036 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2038 * if (cell->face(face)->vertex(face_vertex_index).distance(fixed_point) < 1e-6)
2040 * found_point_of_interest = true;
2041 * for (unsigned int index_component = 0; index_component < dim; ++index_component)
2042 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2043 * index_component));
2046 * if (found_point_of_interest == true) break;
2049 * if (found_point_of_interest == true) break;
2051 * if (found_point_of_interest == true) break;
2054 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2055 * AssertThrow(fixed_dof_indices.size() == dim, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2057 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2058 * boundary_values[fixed_dof_indices[i]] = 0.0;
2061 * else if (parameters.problem == "BicepsBrachii")
2063 * if (parameters.include_gravity == false)
2067 * Symmetry condition on -X surface
2071 * ComponentMask component_mask_x (dim, false);
2072 * component_mask_x.set(0, true);
2073 * VectorTools::interpolate_boundary_values (dof_handler,
2074 * parameters.bid_BB_dirichlet_X,
2075 * Functions::ZeroFunction<dim>(dim),
2077 * component_mask_x);
2082 * Fixed central point on -X surface
2086 * const Point<dim> fixed_point (0.0,0.0,0.0);
2087 * std::vector<types::global_dof_index> fixed_dof_indices;
2088 * bool found_point_of_interest = false;
2090 * for (typename DoFHandler<dim>::active_cell_iterator
2091 * cell = dof_handler.begin_active(),
2092 * endc = dof_handler.end(); cell != endc; ++cell)
2094 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2098 * We know that the fixed point is on the -X Dirichlet boundary
2101 * if (cell->face(face)->at_boundary() == true &&
2102 * cell->face(face)->boundary_id() == parameters.bid_BB_dirichlet_X)
2104 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2106 * if (cell->face(face)->vertex(face_vertex_index).distance(fixed_point) < 1e-6)
2108 * found_point_of_interest = true;
2109 * for (unsigned int index_component = 0; index_component < dim; ++index_component)
2110 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2111 * index_component));
2114 * if (found_point_of_interest == true) break;
2117 * if (found_point_of_interest == true) break;
2119 * if (found_point_of_interest == true) break;
2122 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2123 * AssertThrow(fixed_dof_indices.size() == dim, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2125 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2126 * boundary_values[fixed_dof_indices[i]] = 0.0;
2133 * When we apply gravity, some additional constraints
2134 * are required to support the load of the muscle, as
2135 * the material response is more compliant than would
2136 * be the case in reality.
2140 * Symmetry condition on -X surface
2144 * ComponentMask component_mask_x (dim, true);
2145 * VectorTools::interpolate_boundary_values (dof_handler,
2146 * parameters.bid_BB_dirichlet_X,
2147 * Functions::ZeroFunction<dim>(dim),
2149 * component_mask_x);
2153 * Symmetry condition on -X surface
2157 * ComponentMask component_mask_x (dim, false);
2158 * component_mask_x.set(1, true);
2159 * component_mask_x.set(2, true);
2160 * VectorTools::interpolate_boundary_values (dof_handler,
2161 * parameters.bid_BB_neumann,
2162 * Functions::ZeroFunction<dim>(dim),
2164 * component_mask_x);
2170 * Roller condition at central point on +X face
2174 * const Point<dim> roller_point (parameters.axial_length*parameters.scale,0.0,0.0);
2175 * std::vector<types::global_dof_index> fixed_dof_indices;
2176 * bool found_point_of_interest = false;
2178 * for (typename DoFHandler<dim>::active_cell_iterator
2179 * cell = dof_handler.begin_active(),
2180 * endc = dof_handler.end(); cell != endc; ++cell)
2182 * for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2186 * We know that the fixed point is on the +X Neumann boundary
2189 * if (cell->face(face)->at_boundary() == true &&
2190 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)
2192 * for (unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2194 * if (cell->face(face)->vertex(face_vertex_index).distance(roller_point) < 1e-6)
2196 * found_point_of_interest = true;
2197 * for (unsigned int index_component = 1; index_component < dim; ++index_component)
2198 * fixed_dof_indices.push_back(cell->face(face)->vertex_dof_index(face_vertex_index,
2199 * index_component));
2202 * if (found_point_of_interest == true) break;
2205 * if (found_point_of_interest == true) break;
2207 * if (found_point_of_interest == true) break;
2210 * Assert(found_point_of_interest == true, ExcMessage("Didn't find
point of interest
"));
2211 * AssertThrow(fixed_dof_indices.size() == dim-1, ExcMessage("Didn
't find the correct number of DoFs to fix"));
2213 * for (unsigned int i=0; i < fixed_dof_indices.size(); ++i)
2214 * boundary_values[fixed_dof_indices[i]] = 0.0;
2218 * AssertThrow(false, ExcNotImplemented());
2220 * MatrixTools::apply_boundary_values (boundary_values,
2230 * <a name="LinearMuscleModelProblemsolve"></a>
2231 * <h4>LinearMuscleModelProblem::solve</h4>
2237 * template <int dim>
2238 * void LinearMuscleModelProblem<dim>::solve ()
2240 * SolverControl solver_control (system_matrix.m(), 1e-12);
2241 * SolverCG<> cg (solver_control);
2243 * PreconditionSSOR<> preconditioner;
2244 * preconditioner.initialize(system_matrix, 1.2);
2246 * cg.solve (system_matrix, solution, system_rhs,
2249 * hanging_node_constraints.distribute (solution);
2256 * <a name="LinearMuscleModelProblemoutput_results"></a>
2257 * <h4>LinearMuscleModelProblem::output_results</h4>
2266 * template <int dim>
2267 * void LinearMuscleModelProblem<dim>::output_results (const unsigned int timestep,
2268 * const double time) const
2272 * Visual output: FEM results
2276 * std::string filename = "solution-";
2277 * filename += Utilities::int_to_string(timestep,4);
2278 * filename += ".vtk";
2279 * std::ofstream output (filename.c_str());
2281 * DataOut<dim> data_out;
2282 * data_out.attach_dof_handler (dof_handler);
2284 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
2285 * data_component_interpretation(dim,
2286 * DataComponentInterpretation::component_is_part_of_vector);
2287 * std::vector<std::string> solution_name(dim, "displacement");
2289 * data_out.add_data_vector (solution, solution_name,
2290 * DataOut<dim>::type_dof_data,
2291 * data_component_interpretation);
2292 * data_out.build_patches ();
2293 * data_out.write_vtk (output);
2298 * Visual output: FEM data
2302 * std::string filename = "fibres-";
2303 * filename += Utilities::int_to_string(timestep,4);
2304 * filename += ".vtk";
2305 * std::ofstream output (filename.c_str());
2308 * << "# vtk DataFile Version 3.0" << std::endl
2309 * << "# " << std::endl
2310 * << "ASCII"<< std::endl
2311 * << "DATASET POLYDATA"<< std::endl << std::endl;
2315 * Extract fibre data from quadrature points
2318 * const unsigned int n_cells = triangulation.n_active_cells();
2319 * const unsigned int n_q_points_cell = qf_cell.size();
2323 * Data that we'll be outputting
2326 * std::vector<std::string> results_fibre_names;
2327 * results_fibre_names.push_back(
"alpha");
2328 * results_fibre_names.push_back(
"epsilon_f");
2329 * results_fibre_names.push_back(
"epsilon_c");
2330 * results_fibre_names.push_back(
"epsilon_c_dot");
2332 *
const unsigned int n_results = results_fibre_names.size();
2333 *
const unsigned int n_data_points =
n_cells*n_q_points_cell;
2334 * std::vector< Point<dim> > output_points(n_data_points);
2335 * std::vector< Tensor<1,dim> > output_displacements(n_data_points);
2336 * std::vector< Tensor<1,dim> > output_directions(n_data_points);
2337 * std::vector< std::vector<double> > output_values(n_results, std::vector<double>(n_data_points));
2344 * std::vector< Vector<double> > u_values (n_q_points_cell,
2351 * std::vector< std::vector< Tensor<1,dim> > > u_grads (n_q_points_cell,
2356 *
unsigned int cell_no = 0;
2357 *
unsigned int fibre_no = 0;
2359 * cell = dof_handler.begin_active();
2360 * cell != dof_handler.end();
2361 * ++cell, ++cell_no)
2363 * fe_values.reinit (cell);
2364 * fe_values.get_function_values (solution, u_values);
2365 * fe_values.get_function_gradients (solution, u_grads);
2367 *
for (
unsigned int q_point_cell=0; q_point_cell<n_q_points_cell; ++q_point_cell, ++fibre_no)
2369 *
const MuscleFibre<dim> &fibre = fibre_data[cell_no][q_point_cell];
2370 * output_points[fibre_no] = fe_values.get_quadrature_points()[q_point_cell];
2371 *
for (
unsigned int d=0;
d<dim; ++
d)
2372 * output_displacements[fibre_no][d] = u_values[q_point_cell][d];
2375 * Direction (spatial configuration)
2378 * output_directions[fibre_no] = get_deformation_gradient(u_grads[q_point_cell])*fibre.get_M();
2379 * output_directions[fibre_no] /= output_directions[fibre_no].norm();
2386 * output_values[0][fibre_no] = fibre.get_alpha();
2387 * output_values[1][fibre_no] = fibre.get_epsilon_f();
2388 * output_values[2][fibre_no] = fibre.get_epsilon_c();
2389 * output_values[3][fibre_no] = fibre.get_epsilon_c_dot();
2401 * <<
" float" << std::endl;
2402 *
for (
unsigned int i=0; i < n_data_points; ++i)
2404 *
for (
unsigned int j=0; j < dim; ++j)
2406 * output << (output_points)[i][j] <<
"\t";
2408 * output << std::endl;
2413 * HEADER FOR POINT DATA
2416 * output <<
"\nPOINT_DATA "
2418 * << std::endl << std::endl;
2422 * FIBRE DISPLACEMENTS
2426 * <<
"VECTORS displacement float"
2428 *
for (
unsigned int i = 0; i < n_data_points; ++i)
2430 *
for (
unsigned int j=0; j < dim; ++j)
2432 * output << (output_displacements)[i][j] <<
"\t";
2434 * output << std::endl;
2436 * output << std::endl;
2444 * <<
"VECTORS direction float"
2446 *
for (
unsigned int i = 0; i < n_data_points; ++i)
2448 *
for (
unsigned int j=0; j < dim; ++j)
2450 * output << (output_directions)[i][j] <<
"\t";
2452 * output << std::endl;
2454 * output << std::endl;
2461 *
for (
unsigned int v=0; v < n_results; ++v)
2465 * << results_fibre_names[v]
2466 * <<
" float 1" << std::endl
2467 * <<
"LOOKUP_TABLE default "
2469 *
for (
unsigned int i=0; i<n_data_points; ++i)
2471 * output << (output_values)[v][i] <<
" ";
2473 * output << std::endl;
2479 * Output X-displacement at measured
point
2483 *
const Point<dim> meas_pt (parameters.problem ==
"IsotonicContraction" ?
2484 *
Point<dim>(parameters.half_length_x, 0.0, 0.0) :
2485 *
Point<dim>(parameters.axial_length*parameters.
scale, 0.0, 0.0) );
2488 *
const unsigned int index_of_interest = 0;
2489 *
bool found_point_of_interest =
false;
2493 * cell = dof_handler.begin_active(),
2494 * endc = dof_handler.end(); cell != endc; ++cell)
2496 *
for (
unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
2500 * We know that the measurement
point is on the Neumann boundary
2503 *
if (cell->face(face)->at_boundary() ==
true &&
2504 * ((parameters.problem ==
"IsotonicContraction" &&
2505 * cell->face(face)->boundary_id() == parameters.bid_CC_neumann) ||
2506 * (parameters.problem ==
"BicepsBrachii" &&
2507 * cell->face(face)->boundary_id() == parameters.bid_BB_neumann)) )
2509 *
for (
unsigned int face_vertex_index = 0; face_vertex_index < GeometryInfo<dim>::vertices_per_face; ++face_vertex_index)
2511 *
if (cell->face(face)->vertex(face_vertex_index).distance(meas_pt) < 1
e-6)
2513 * found_point_of_interest =
true;
2514 * dof_of_interest = cell->face(face)->vertex_dof_index(face_vertex_index,
2515 * index_of_interest);
2518 *
if (found_point_of_interest ==
true)
break;
2521 *
if (found_point_of_interest ==
true)
break;
2523 *
if (found_point_of_interest ==
true)
break;
2526 *
Assert(found_point_of_interest ==
true, ExcMessage(
"Didn't find point of interest"));
2528 *
Assert(dof_of_interest < dof_handler.n_dofs(), ExcMessage(
"DoF index out of range"));
2530 *
const std::string filename =
"displacement_POI.csv";
2531 * std::ofstream output;
2532 *
if (timestep == 0)
2534 * output.open(filename.c_str(), std::ofstream::out);
2536 * <<
"Time [s]" <<
"," <<
"X-displacement [mm]" << std::endl;
2539 * output.open(filename.c_str(), std::ios_base::app);
2544 * << solution[dof_of_interest]*1e3
2554 * <a name=
"LinearMuscleModelProblemrun"></a>
2555 * <h4>LinearMuscleModelProblem::run</h4>
2561 *
template <
int dim>
2562 *
void LinearMuscleModelProblem<dim>::run ()
2566 * setup_muscle_fibres ();
2570 *
const bool do_grid_refinement =
false;
2573 *
double time = 0.0;
2574 *
for (
unsigned int timestep=0; time<=t_end; ++timestep, time+=dt)
2577 * <<
"Timestep " << timestep
2578 * <<
" @ time " << time
2583 * First we update the fibre activation
level
2584 * based on the current time
2587 * update_fibre_activation(time);
2591 * Next we
assemble the system and enforce boundary
2593 * Here we assume that the system and fibres have
2594 * a fixed state, and we will
assemble based on how
2595 * epsilon_c will update given the current state of
2599 * assemble_system (time);
2600 * apply_boundary_conditions ();
2604 * Then we solve the linear system
2611 * Now we update the fibre state based on the
new
2612 * displacement solution and the constitutive
2613 * parameters assumed to govern the stiffness of
2614 * the fibres at the previous state. i.e. We
2615 * follow through with assumed update conditions
2616 * used in the assembly phase.
2619 * update_fibre_state();
2623 * Output some
values to file
2626 * output_results (timestep, time);
2634 * <a name=
"Thecodemaincodefunction"></a>
2635 * <h3>The <code>main</code> function</h3>
2645 * ::deallog.depth_console (0);
2646 *
const unsigned int dim = 3;
2648 * LMM::LinearMuscleModelProblem<dim> lmm_problem (
"parameters.prm");
2649 * lmm_problem.run ();
2651 *
catch (std::exception &exc)
2653 * std::cerr << std::endl << std::endl
2654 * <<
"----------------------------------------------------"
2656 * std::cerr <<
"Exception on processing: " << std::endl
2657 * << exc.what() << std::endl
2658 * <<
"Aborting!" << std::endl
2659 * <<
"----------------------------------------------------"
2666 * std::cerr << std::endl << std::endl
2667 * <<
"----------------------------------------------------"
2669 * std::cerr <<
"Unknown exception!" << std::endl
2670 * <<
"Aborting!" << std::endl
2671 * <<
"----------------------------------------------------"
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
numbers::NumberTraits< Number >::real_type norm() const
__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
@ update_values
Shape function values.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
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 std_cxx20::type_identity_t< Iterator > &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 Function &function, 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