75 * #include <deal.II/base/quadrature_lib.h>
76 * #include <deal.II/base/function.h>
77 * #include <deal.II/base/logstream.h>
78 * #include <deal.II/base/utilities.h>
79 * #include <deal.II/base/convergence_table.h>
80 * #include <deal.II/base/smartpointer.h>
81 * #include <deal.II/base/parameter_handler.h>
82 * #include <deal.II/base/timer.h>
84 * #include <deal.II/lac/vector.h>
85 * #include <deal.II/lac/full_matrix.h>
86 * #include <deal.II/lac/sparse_matrix.h>
87 * #include <deal.II/lac/solver_cg.h>
88 * #include <deal.II/lac/precondition.h>
89 * #include <deal.II/lac/affine_constraints.h>
90 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
92 * #include <deal.II/grid/tria.h>
93 * #include <deal.II/grid/grid_generator.h>
94 * #include <deal.II/grid/tria_accessor.h>
95 * #include <deal.II/grid/tria_iterator.h>
96 * #include <deal.II/grid/manifold_lib.h>
97 * #include <deal.II/grid/grid_refinement.h>
98 * #include <deal.II/grid/grid_in.h>
100 * #include <deal.II/dofs/dof_handler.h>
101 * #include <deal.II/dofs/dof_accessor.h>
102 * #include <deal.II/dofs/dof_tools.h>
103 * #include <deal.II/dofs/dof_renumbering.h>
105 * #include <deal.II/fe/fe_values.h>
106 * #include <deal.II/fe/fe_q.h>
108 * #include <deal.II/numerics/vector_tools.h>
109 * #include <deal.II/numerics/matrix_tools.h>
110 * #include <deal.II/numerics/data_out.h>
111 * #include <deal.II/numerics/error_estimator.h>
112 * #include <deal.II/numerics/solution_transfer.h>
114 * #include <typeinfo>
116 * #include <iostream>
118 * #include <deal.II/numerics/solution_transfer.h>
122 * Open a
namespace for this program and import everything from the
123 *
dealii namespace into it.
132 * ********************************************************
139 *
void read_parameters(
const std::string);
141 *
void declare_parameters();
153 * void ParameterReader::declare_parameters()
156 * prm.enter_subsection (
"Global Parameters");
159 *
"Penalization parameter");
161 *
"Whether the exact solution is known");
163 * prm.leave_subsection ();
165 * prm.enter_subsection (
"Mesh & Refinement Parameters");
168 *
"Number identifying the domain in which we solve the problem");
170 *
"Number of global mesh refinement steps applied to initial coarse grid");
172 *
"Number of global adaptive mesh refinements");
174 *
"refinement threshold");
176 *
"coarsening threshold");
178 * prm.leave_subsection ();
181 * prm.enter_subsection (
"Algorithm Parameters");
184 *
"0: Preconditioned descent, 1: Newton Method");
190 *
"Maximum Number of CG iterations");
192 *
"Tolerance for CG iterations");
194 *
"Maximum Number of LS iterations");
196 *
"line search tolerance constant (c1 in Nocedal-Wright)");
198 *
"initial step length in line-search");
200 *
"Maximum Number of inner iterations");
202 *
"Threshold on norm of the derivative to declare optimality achieved");
204 *
"Threshold on norm of the derivative to declare optimality achieved in highly refined mesh");
206 *
"Number of adaptive refinement before change convergence threshold");
208 * prm.leave_subsection ();
211 *
void ParameterReader::read_parameters (
const std::string parameter_file)
213 * declare_parameters();
214 * prm.parse_input (parameter_file);
219 * ******************************************************************************************
220 * The solution of the elastoplastic torsion problem on the unit disk with rhs=4.
227 *
class Solution :
public Function<dim>
231 *
virtual double value (
const Point<dim> &pto,
const unsigned int component = 0)
const override;
236 *
double Solution<dim>::value (
const Point<dim> &pto,
const unsigned int)
const
238 *
double r=
sqrt(pto.square());
250 *
double r=
sqrt(pto.square());
262 * ******************************************************************************************
274 * ComputeMultiplier (
double pe);
277 *
void compute_derived_quantities_scalar (
278 *
const std::vector< double > &,
286 *
virtual std::vector<std::string>
get_names ()
const override;
289 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
297 * ComputeMultiplier<dim>::ComputeMultiplier (
double pe): p(pe)
302 * void ComputeMultiplier<dim>::compute_derived_quantities_scalar(
303 * const
std::vector< double > & ,
304 * const
std::vector<
Tensor< 1, dim > > &duh,
305 * const
std::vector<
Tensor< 2, dim > > & ,
306 * const
std::vector<
Point< dim > > & ,
307 * const
std::vector<
Point< dim > > & ,
308 *
std::vector<
Vector< double > > &computed_quantities ) const
310 * const unsigned
int n_quadrature_points = duh.
size();
312 *
for (
unsigned int q=0; q<n_quadrature_points; ++q)
314 *
long double sqrGrad=duh[q]* duh[q];
315 *
long double exponent=(p-2.0)/2*
std::log(sqrGrad);
316 * computed_quantities[q](0) =
std::sqrt(sqrGrad);
317 * computed_quantities[q](1)=
std::exp(exponent);
326 * std::vector<std::string>
327 * ComputeMultiplier<dim>::get_names() const
329 * std::vector<std::string> solution_names;
330 * solution_names.push_back (
"Gradient_norm");
331 * solution_names.push_back (
"Lagrange_multiplier");
332 *
return solution_names;
338 * ComputeMultiplier<dim>::get_needed_update_flags () const
346 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
347 * ComputeMultiplier<dim>:: get_data_component_interpretation () const
349 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
359 * Lagrange multiplier
363 *
return interpretation;
372 * ***************************************************************************************
376 *
class ElastoplasticTorsion
380 * ~ElastoplasticTorsion ();
384 *
void setup_system (
const bool initial_step);
385 *
void assemble_system ();
386 *
bool solve (
const int inner_it);
388 *
void refine_mesh ();
389 *
void set_boundary_values ();
390 *
double phi (
const double alpha)
const;
391 *
bool checkWolfe(
double &alpha,
double &phi_alpha)
const;
392 *
bool determine_step_length (
const int inner_it);
393 *
void print_it_message (
const int counter,
bool ks);
394 *
void output_results (
unsigned int refinement)
const;
395 *
void format_convergence_tables();
396 *
void process_solution (
const unsigned int cycle);
397 *
void process_multiplier (
const unsigned int cycle,
const int iter,
double time);
398 *
double dual_error ()
const;
399 *
double dual_infty_error ()
const;
400 *
double W (
double Du2)
const;
401 *
double Wp (
double Du2)
const;
402 *
double G (
double Du2)
const;
421 *
double step_length,phi_zero,phi_alpha,phip,phip_zero;
422 *
double old_step,old_phi_zero,old_phip;
425 *
double Linfty_error;
426 *
double dual_L1_error;
427 *
double dual_L_infty_error;
430 *
double line_search_tolerence;
431 *
unsigned int dir_id;
432 * std::string elements;
433 * std::string Method;
447 *
class BoundaryValues :
public Function<dim>
450 * BoundaryValues () :
Function<dim>() {}
453 *
const unsigned int component = 0)
const override;
458 *
double BoundaryValues<dim>::value (
const Point<dim> &,
459 *
const unsigned int )
const
463 * could be anything
else (theory works provided |Dg|_infty < 1/2)
497 *
class RightHandSide :
public Function<dim>
500 * RightHandSide () :
Function<dim>() {}
502 *
const unsigned int component = 0)
const override;
506 *
double RightHandSide<dim>::value (
const Point<dim> &,
507 *
const unsigned int )
const
511 * set to
constant = 4,
for which
explicit solution to compare exists
515 *
double return_value = 4.0;
516 *
return return_value;
524 * The ElastoplasticTorsion
class implementation
528 * Constructor of the
class
532 * ElastoplasticTorsion<dim>::ElastoplasticTorsion (
ParameterHandler ¶m):
538 * dual_L1_error(1.0),
539 * dual_L_infty_error(1.0),
542 * prm.enter_subsection (
"Global Parameters");
543 * p=prm.get_double(
"p");
544 * prm.leave_subsection ();
545 * prm.enter_subsection (
"Algorithm Parameters");
546 * line_search_tolerence=prm.get_double(
"line_search_tolerence");
547 * dir_id=prm.get_integer(
"Descent_direction");
548 * prm.leave_subsection ();
551 *
else elements=
"P2";
562 * ElastoplasticTorsion<dim>::~ElastoplasticTorsion ()
564 * dof_handler.clear ();
570 * print iteration message
577 *
void ElastoplasticTorsion<dim>::print_it_message (
const int counter,
bool ks)
581 * process_solution (counter);
582 * std::cout <<
"iteration="<< counter+1 <<
" J(u_h)= "<< phi_zero <<
", H1 error: "
583 * << H1_error <<
", W0-1,infty error: "<< Linfty_error<<
" J'(u_h)(w)= "<< phip
584 * <<
", |J'(u_h)|= "<< system_rhs.l2_norm()<<std::endl;
588 * std::cout <<
"iteration= " << counter+1 <<
" J(u_h)= "
589 * << phi_alpha <<
" J'(u_h)= "<< phip<<std::endl;
616 *
void ElastoplasticTorsion<dim>::format_convergence_tables()
618 * convergence_table.set_precision(
"L2", 3);
619 * convergence_table.set_precision(
"H1", 3);
620 * convergence_table.set_precision(
"Linfty", 3);
621 * convergence_table.set_precision(
"function value", 3);
622 * convergence_table.set_precision(
"derivative", 3);
623 * dual_convergence_table.set_precision(
"dual_L1", 3);
624 * dual_convergence_table.set_precision(
"dual_Linfty", 3);
625 * dual_convergence_table.set_precision(
"L2", 3);
626 * dual_convergence_table.set_precision(
"H1", 3);
627 * dual_convergence_table.set_precision(
"Linfty", 3);
628 * convergence_table.set_scientific(
"L2",
true);
629 * convergence_table.set_scientific(
"H1",
true);
630 * convergence_table.set_scientific(
"Linfty",
true);
631 * convergence_table.set_scientific(
"function value",
true);
632 * convergence_table.set_scientific(
"derivative",
true);
633 * dual_convergence_table.set_scientific(
"dual_L1",
true);
634 * dual_convergence_table.set_scientific(
"dual_Linfty",
true);
635 * dual_convergence_table.set_scientific(
"L2",
true);
636 * dual_convergence_table.set_scientific(
"H1",
true);
637 * dual_convergence_table.set_scientific(
"Linfty",
true);
644 * fill-in entry
for the solution
648 *
void ElastoplasticTorsion<dim>::process_solution (
const unsigned int it)
654 * compute
L2 error (save to difference_per_cell)
659 * L2_error = difference_per_cell.l2_norm();
663 * compute H1 error (save to difference_per_cell)
668 * H1_error = difference_per_cell.l2_norm();
672 * compute W1infty error (save to difference_per_cell)
679 * Linfty_error = difference_per_cell.linfty_norm();
682 * convergence_table.add_value(
"cycle", it);
683 * convergence_table.add_value(
"p", p);
684 * convergence_table.add_value(
"L2", L2_error);
685 * convergence_table.add_value(
"H1", H1_error);
686 * convergence_table.add_value(
"Linfty", Linfty_error);
687 * convergence_table.add_value(
"function value", phi_alpha);
688 * convergence_table.add_value(
"derivative", phip);
695 * fill-in entry
for the multiplier
699 *
void ElastoplasticTorsion<dim>::process_multiplier (
const unsigned int cycle,
const int iter,
double time)
702 *
const unsigned int n_dofs=dof_handler.n_dofs();
703 * dual_L1_error=dual_error();
704 * dual_L_infty_error=dual_infty_error();
707 * dual_convergence_table.add_value(
"cycle", cycle);
708 * dual_convergence_table.add_value(
"p", p);
709 * dual_convergence_table.add_value(
"iteration_number", iter);
710 * dual_convergence_table.add_value(
"cpu_time", time);
711 * dual_convergence_table.add_value(
"cells", n_active_cells);
712 * dual_convergence_table.add_value(
"dofs", n_dofs);
713 * dual_convergence_table.add_value(
"L2", L2_error);
714 * dual_convergence_table.add_value(
"H1", H1_error);
715 * dual_convergence_table.add_value(
"Linfty", Linfty_error);
716 * dual_convergence_table.add_value(
"dual_L1", dual_L1_error);
717 * dual_convergence_table.add_value(
"dual_Linfty", dual_L_infty_error);
727 * ElastoplasticTorsion::setup_system
728 * unchanged from @ref step_15
"step-15"
735 *
void ElastoplasticTorsion<dim>::setup_system (
const bool initial_step)
739 * dof_handler.distribute_dofs (fe);
740 * present_solution.reinit (dof_handler.n_dofs());
741 * grad_norm.reinit (dof_handler.n_dofs());
742 *
lambda.reinit (dof_handler.n_dofs());
744 * hanging_node_constraints.clear ();
746 * hanging_node_constraints);
747 * hanging_node_constraints.close ();
753 * The remaining parts of the function
759 * newton_update.reinit (dof_handler.n_dofs());
760 * system_rhs.reinit (dof_handler.n_dofs());
763 * hanging_node_constraints.condense (c_sparsity);
764 * sparsity_pattern.copy_from(c_sparsity);
765 * system_matrix.reinit (sparsity_pattern);
777 *
double ElastoplasticTorsion<dim>::W (
double Du2)
const
783 *
double ElastoplasticTorsion<dim>::Wp (
double )
const
789 *
double ElastoplasticTorsion<dim>::G (
double )
const
796 *
void ElastoplasticTorsion<dim>::assemble_system ()
801 *
const RightHandSide<dim> right_hand_side;
811 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
812 *
const unsigned int n_q_points = quadrature_formula.size();
817 * std::vector<Tensor<1, dim> > old_solution_gradients(n_q_points);
818 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
822 * cell = dof_handler.begin_active(),
823 * endc = dof_handler.end();
824 *
for (; cell!=endc; ++cell)
829 * fe_values.reinit (cell);
830 * fe_values.get_function_gradients(present_solution,
831 * old_solution_gradients);
833 *
for (
unsigned int q_point = 0; q_point < n_q_points; ++q_point)
835 *
long double coeff=0.0;
836 *
long double a=old_solution_gradients[q_point] * old_solution_gradients[q_point];
837 *
long double exponent=(p-2.0)/2*
std::log(a);
839 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
841 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
845 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
846 * * (G(a)+(p-1.0)*coeff) * fe_values.JxW(q_point);
850 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
852 * * fe_values.JxW(q_point);
856 * cell_rhs(i) -= ( fe_values.shape_grad(i, q_point)
857 * * old_solution_gradients[q_point]
859 * -right_hand_side.value(fe_values.quadrature_point(q_point))
860 * *fe_values.shape_value(i, q_point)
862 * * fe_values.JxW(q_point);
866 * cell->get_dof_indices (local_dof_indices);
867 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
869 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
870 * system_matrix.add (local_dof_indices[i],
871 * local_dof_indices[j],
874 * system_rhs(local_dof_indices[i]) += cell_rhs(i);
878 * hanging_node_constraints.condense (system_matrix);
879 * hanging_node_constraints.condense (system_rhs);
881 * std::map<types::global_dof_index,double> boundary_values;
898 * unchanged from @ref step_15
"step-15"
905 *
void ElastoplasticTorsion<dim>::refine_mesh ()
907 *
using FunctionMap = std::map<types::boundary_id, const Function<dim> *>;
914 * estimated_error_per_cell);
916 * prm.enter_subsection (
"Mesh & Refinement Parameters");
917 *
const double top_fraction=prm.get_double(
"top_fraction_of_cells");
918 *
const double bottom_fraction=prm.get_double(
"bottom_fraction_of_cells");
919 * prm.leave_subsection ();
921 * estimated_error_per_cell,
922 * top_fraction, bottom_fraction);
926 * solution_transfer.prepare_for_coarsening_and_refinement(present_solution);
928 * dof_handler.distribute_dofs(fe);
930 * present_solution.reinit(dof_handler.n_dofs());
931 * solution_transfer.interpolate(present_solution);
934 * solution_transfer.interpolate(present_solution, tmp);
935 * present_solution = tmp;
937 * set_boundary_values ();
938 * hanging_node_constraints.clear();
941 * hanging_node_constraints);
942 * hanging_node_constraints.close();
943 * hanging_node_constraints.distribute (present_solution);
944 * setup_system (
false);
951 * Dump the
norm of the
gradient and the lagrange multiplier in
vtu format
for visualization
955 *
void ElastoplasticTorsion<dim>::output_results (
unsigned int counter)
const
959 * multiplier
object contains both |Du| and
lambda.
962 * ComputeMultiplier<dim> multiplier(p);
966 * data_out.add_data_vector (present_solution,
"solution");
967 * data_out.add_data_vector (present_solution, multiplier);
968 * data_out.build_patches ();
969 * std::ostringstream p_str;
970 * p_str << p<<
"-cycle-"<<counter;
971 * std::string str = p_str.str();
972 *
const std::string filename =
"solution-" + str+
".vtu";
973 * std::ofstream output (filename.c_str());
974 * data_out.write_vtu (output);
980 * unchanged from @ref step_15
"step-15"
984 *
void ElastoplasticTorsion<dim>::set_boundary_values ()
986 * std::map<types::global_dof_index, double> boundary_values;
989 * BoundaryValues<dim>(),
991 *
for (std::map<types::global_dof_index, double>::const_iterator
992 * bp = boundary_values.begin();
993 * bp != boundary_values.end(); ++bp)
994 * present_solution(bp->first) = bp->second;
1001 * COMPUTE @f$\phi(\alpha)=J_p(u_h+\alpha w)@f$
1004 *
template <
int dim>
1005 *
double ElastoplasticTorsion<dim>::phi (
const double alpha)
const
1008 *
const RightHandSide<dim> right_hand_side;
1010 * evaluation_point = present_solution;
1011 * evaluation_point.add (alpha, newton_update);
1020 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1021 *
const unsigned int n_q_points = quadrature_formula.size();
1024 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1025 * std::vector<double>
values(n_q_points);
1028 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1031 * cell = dof_handler.begin_active(),
1032 * endc = dof_handler.end();
1033 *
for (; cell!=endc; ++cell)
1036 * fe_values.reinit (cell);
1037 * fe_values.get_function_gradients (evaluation_point, gradients);
1038 * fe_values.get_function_values (evaluation_point, values);
1041 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1052 * obj+= 1/2 W(|Du|^2)+1/p |Du|^p -fu (see (1))
1056 * (0.5*W(Du2)+penalty/p)- right_hand_side.value(fe_values.quadrature_point(q_point))*
values[q_point]
1057 * ) * fe_values.JxW(q_point);
1069 * Compute L^1 error
norm of Lagrange Multiplier
1070 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1076 *
template <
int dim>
1077 *
double ElastoplasticTorsion<dim>::dual_error () const
1087 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1088 *
const unsigned int n_q_points = quadrature_formula.size();
1091 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1093 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1096 * cell = dof_handler.begin_active(),
1097 * endc = dof_handler.end();
1098 *
for (; cell!=endc; ++cell)
1101 * fe_values.reinit (cell);
1102 * fe_values.get_function_gradients (present_solution, gradients);
1104 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1107 *
if (coeff<1.0e-15)
1110 * coeff=
std::pow(coeff,(p-2.0)/2.0);
1112 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1117 * obj+=(
std::abs(coeff-exact) ) * fe_values.JxW(q_point);
1128 * Compute L^infinity error
norm of Lagrange Multiplier
1129 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1135 *
template <
int dim>
1136 *
double ElastoplasticTorsion<dim>::dual_infty_error () const
1146 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1147 *
const unsigned int n_q_points = quadrature_formula.size();
1150 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1152 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1155 * cell = dof_handler.begin_active(),
1156 * endc = dof_handler.end();
1157 *
for (; cell!=endc; ++cell)
1160 * fe_values.reinit (cell);
1161 * fe_values.get_function_gradients (present_solution, gradients);
1163 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1166 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1172 * compute |Du|^(p-2) as
exp(p-2/2*
log(Du^2))
1175 *
long double exponent=(p-2.0)/2*
std::log(sqdGrad);
1176 *
long double coeff=
std::exp(exponent);
1190 *
check whether putative step-length satisfies sufficient decrease conditions
1193 *
template <
int dim>
1194 *
bool ElastoplasticTorsion<dim>::checkWolfe(
double &alpha,
double &phi_alpha)
const
1196 *
if (phi_alpha< phi_zero+line_search_tolerence*phip*alpha )
1206 * Find a step-length satisfying sufficient decrease condition by line-search
1207 * uses quadratic interpolation
1213 *
template <
int dim>
1214 *
bool ElastoplasticTorsion<dim>::determine_step_length(
const int inner_it)
1216 *
unsigned int it=0;
1218 *
double alpha,nalpha;
1219 * prm.enter_subsection (
"Algorithm Parameters");
1220 *
const unsigned int max_LS_it=prm.get_integer(
"max_LS_it");
1221 *
double init_SL=prm.get_double(
"init_step_length");
1222 * prm.leave_subsection ();
1227 * alpha=
std::min(1.45*old_step*old_phip/phip,1.0);
1229 * phi_alpha=phi(alpha);
1230 * std::cerr <<
"Step length=" << alpha <<
", Value= " << phi_alpha;
1233 *
check if step-
size satisfies sufficient decrease condition
1236 * done=checkWolfe(alpha,phi_alpha);
1238 * std::cerr <<
" accepted" << std::endl;
1240 * std::cerr <<
" rejected" ;
1242 *
while ((!done) & (it<max_LS_it))
1246 *
new try obtained by quadratic interpolation
1249 * nalpha=-(phip*alpha*alpha)/(2*(phi_alpha-phi_zero-phip*alpha));
1251 *
if (nalpha<1e-3*alpha ||
std::abs(nalpha-alpha)/alpha<1
e-8)
1253 *
else if ( phi_alpha-phi_zero>1e3*
std::abs(phi_zero) )
1256 * phi_alpha=phi(alpha);
1257 * done=checkWolfe(alpha,phi_alpha);
1259 * std::cerr <<
", finished with steplength= "<< alpha<<
", fcn value= "<< phi_alpha<<std::endl;
1264 * std::cerr <<
", max. no. of iterations reached with steplength= "<< alpha
1265 * <<
", fcn value= "<< phi_alpha<<std::endl;
1270 * step_length=alpha;
1279 * ElastoplasticTorsion::init_mesh()
1285 *
template <
int dim>
1286 *
void ElastoplasticTorsion<dim>::init_mesh ()
1293 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1294 *
const int domain_id=prm.get_integer(
"Code for the domain");
1295 *
const int init_ref=prm.get_integer(
"No of initial refinements");
1296 * prm.leave_subsection ();
1303 * For the unit disk around the origin
1310 *
else if (domain_id==1)
1314 * For the unit square
1319 *
else if (domain_id==2)
1359 * ElastoplasticTorsion::solve(inner_it)
1360 * Performs one inner iteration
1366 *
template <
int dim>
1367 *
bool ElastoplasticTorsion<dim>::solve (
const int inner_it)
1369 * prm.enter_subsection (
"Algorithm Parameters");
1370 *
const unsigned int max_CG_it=prm.get_integer(
"Max_CG_it");
1371 *
const double CG_tol=prm.get_double(
"CG_tol");
1372 * prm.leave_subsection ();
1378 * preconditioner.
initialize(system_matrix,0.25);
1380 * solver.solve (system_matrix, newton_update, system_rhs,
1382 * hanging_node_constraints.distribute (newton_update);
1386 * Recall that phi(alpha)=J(u+alpha w)
1389 * old_step=step_length;
1390 * old_phi_zero=phi_zero;
1393 * phip=-1.0*(newton_update*system_rhs);
1399 * std::cout <<
"Not a descent direction!" <<std::endl;
1400 * present_solution.add (-1.0*step_length, newton_update);
1401 * step_length=step_length/2;
1407 *
if (determine_step_length(inner_it))
1411 * update u_{n+1}=u_n+alpha w_n
1414 * present_solution.add (step_length, newton_update);
1417 *
else return false;
1426 * ElastoplasticTorsion::run
1429 *
template <
int dim>
1430 *
void ElastoplasticTorsion<dim>::run ()
1438 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1439 *
const int adapt_ref=prm.get_integer(
"No of adaptive refinements");
1440 * prm.leave_subsection ();
1441 * prm.enter_subsection (
"Algorithm Parameters");
1442 *
const int max_inner=prm.get_integer(
"Max_inner");
1443 *
const double eps=prm.get_double(
"eps");
1444 *
const double hi_eps=prm.get_double(
"hi_eps");
1445 *
const int hi_th=prm.get_integer(
"hi_th");
1446 *
const double init_p=prm.get_double(
"init_p");
1447 *
const double delta_p=prm.get_double(
"delta_p");
1448 * prm.leave_subsection ();
1449 * prm.enter_subsection (
"Global Parameters");
1450 *
bool known_solution=prm.get_bool(
"known_solution");
1451 *
double actual_p=prm.get_double(
"p");
1452 * prm.leave_subsection ();
1466 * initialize mesh
for the selected domain
1476 * setup_system (
true);
1477 * set_boundary_values ();
1486 *
int refinement = 0;
1495 *
bool well_solved=
true;
1499 *
while (p<actual_p)
1501 * std::cout <<
"--Preparing initial condition with p="<<p<<
" iter.= " << global_it<<
" .-- "<< std::endl;
1503 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1505 * assemble_system ();
1506 * well_solved=solve (inner_iteration);
1507 * print_it_message (global_it, known_solution);
1509 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-4) & (cycle<1)) |
1510 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-5) & (cycle>=1)) |
1515 * ptime=timer.cpu_time();
1517 * output_results (cycle);
1519 *
if (known_solution)
1521 * process_multiplier(cycle,global_it,ptime);
1524 * dual_convergence_table.write_tex(dual_error_table_file);
1547 * std::cout <<
"============ Solving problem with p=" <<p <<
" ==================" << std::endl;
1549 *
while ((cycle<adapt_ref) & well_solved)
1557 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1559 * assemble_system ();
1560 * well_solved=solve (inner_iteration);
1561 * print_it_message (global_it, known_solution);
1564 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) < eps) & (refinement<hi_th)) |
1565 * (( system_rhs.l2_norm()/
std::sqrt (system_rhs.size()) <hi_eps) | (!well_solved))
1571 * inner iterations finished
1574 * ptime=timer.cpu_time();
1576 * output_results (cycle);
1580 * compute and display error,
if the
explicit solution is known
1583 *
if (known_solution)
1585 * process_multiplier(cycle,global_it,ptime);
1586 * std::cout <<
"finished with H1 error: " << H1_error <<
", dual error (L1): "
1587 * << dual_L1_error <<
"dual error (L infty): "<<dual_L_infty_error <<std::endl;
1602 * std::cout <<
"******** Refined mesh " << cycle <<
" ********" << std::endl;
1608 * write convergence tables to file
1611 *
if (known_solution)
1613 * format_convergence_tables();
1614 * std::string error_filename =
"error"+Method+elements+
".tex";
1615 * std::ofstream error_table_file(error_filename.c_str());
1616 * std::string dual_error_filename =
"dual_error"+Method+elements+
".tex";
1617 * std::ofstream dual_error_table_file(dual_error_filename.c_str());
1618 * convergence_table.write_tex(error_table_file);
1619 * dual_convergence_table.write_tex(dual_error_table_file);
1635 *
using namespace dealii;
1636 *
using namespace nsp;
1640 * ParameterReader param(prm);
1641 * param.read_parameters(
"EPT.prm");
1642 * ElastoplasticTorsion<2> ElastoplasticTorsionProblem(prm);
1643 * ElastoplasticTorsionProblem .run ();
1645 *
catch (std::exception &exc)
1647 * std::cerr << std::endl << std::endl
1648 * <<
"----------------------------------------------------" << std::endl;
1649 * std::cerr <<
"Exception on processing: " << std::endl
1650 * << exc.what() << std::endl
1651 * <<
"Aborting!" << std::endl
1652 * <<
"----------------------------------------------------"
1659 * std::cerr << std::endl << std::endl
1660 * <<
"----------------------------------------------------"
1662 * std::cerr <<
"Unknown exception!" << std::endl
1663 * <<
"Aborting!" << std::endl
1664 * <<
"----------------------------------------------------"
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
virtual UpdateFlags get_needed_update_flags() const =0
virtual std::vector< std::string > get_names() const =0
virtual std::vector< DataComponentInterpretation::DataComponentInterpretation > get_data_component_interpretation() const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
static void estimate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim - 1 > &quadrature, const std::map< types::boundary_id, const Function< spacedim, Number > * > &neumann_bc, const ReadVector< Number > &solution, Vector< float > &error, const ComponentMask &component_mask={}, const Function< spacedim > *coefficients=nullptr, const unsigned int n_threads=numbers::invalid_unsigned_int, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id, const types::material_id material_id=numbers::invalid_material_id, const Strategy strategy=cell_diameter_over_24)
unsigned int depth_console(const unsigned int n)
void initialize(const MatrixType &A, const AdditionalData ¶meters=AdditionalData())
#define DEAL_II_VERSION_GTE(major, minor, subminor)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(IteratorType begin, std_cxx20::type_identity_t< IteratorType > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, AssemblerType &assembler, const LoopControl &lctrl=LoopControl())
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ update_values
Shape function values.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
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 hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
void merge_triangulations(const Triangulation< dim, spacedim > &triangulation_1, const Triangulation< dim, spacedim > &triangulation_2, Triangulation< dim, spacedim > &result, const double duplicated_vertex_tolerance=1.0e-12, const bool copy_manifold_ids=false, const bool copy_boundary_ids=false)
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
void refine_and_coarsen_fixed_number(Triangulation< dim, spacedim > &triangulation, const Vector< Number > &criteria, const double top_fraction_of_cells, const double bottom_fraction_of_cells, const unsigned int max_n_cells=std::numeric_limits< unsigned int >::max())
void cell_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const FEValuesBase< dim > &fetest, const ArrayView< const std::vector< double > > &velocity, const double factor=1.)
void cell_residual(Vector< double > &result, const FEValuesBase< dim > &fe, const std::vector< Tensor< 1, dim > > &input, const ArrayView< const std::vector< double > > &velocity, double factor=1.)
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
void L2(Vector< number > &result, const FEValuesBase< dim > &fe, const std::vector< double > &input, const double factor=1.)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
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)
bool check(const ConstraintKinds kind_in, const unsigned int dim)
unsigned int n_active_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > exp(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, 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