84 * #include <deal.II/base/quadrature_lib.h>
85 * #include <deal.II/base/function.h>
86 * #include <deal.II/base/logstream.h>
87 * #include <deal.II/base/utilities.h>
88 * #include <deal.II/base/convergence_table.h>
89 * #include <deal.II/base/smartpointer.h>
90 * #include <deal.II/base/parameter_handler.h>
91 * #include <deal.II/base/timer.h>
93 * #include <deal.II/lac/vector.h>
94 * #include <deal.II/lac/full_matrix.h>
95 * #include <deal.II/lac/sparse_matrix.h>
96 * #include <deal.II/lac/solver_cg.h>
97 * #include <deal.II/lac/precondition.h>
98 * #include <deal.II/lac/affine_constraints.h>
99 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
101 * #include <deal.II/grid/
tria.h>
102 * #include <deal.II/grid/grid_generator.h>
103 * #include <deal.II/grid/tria_accessor.h>
104 * #include <deal.II/grid/tria_iterator.h>
105 * #include <deal.II/grid/manifold_lib.h>
106 * #include <deal.II/grid/grid_refinement.h>
107 * #include <deal.II/grid/grid_in.h>
109 * #include <deal.II/dofs/dof_handler.h>
110 * #include <deal.II/dofs/dof_accessor.h>
111 * #include <deal.II/dofs/dof_tools.h>
112 * #include <deal.II/dofs/dof_renumbering.h>
114 * #include <deal.II/fe/fe_values.h>
115 * #include <deal.II/fe/fe_q.h>
117 * #include <deal.II/numerics/vector_tools.h>
118 * #include <deal.II/numerics/matrix_tools.h>
119 * #include <deal.II/numerics/data_out.h>
120 * #include <deal.II/numerics/error_estimator.h>
121 * #include <deal.II/numerics/solution_transfer.h>
123 * #include <typeinfo>
125 * #include <iostream>
127 * #include <deal.II/numerics/solution_transfer.h>
131 * Open a
namespace for this program and import everything from the
132 *
dealii namespace into it.
141 * ********************************************************
148 *
void read_parameters(
const std::string);
150 *
void declare_parameters();
162 * void ParameterReader::declare_parameters()
165 * prm.enter_subsection (
"Global Parameters");
168 *
"Penalization parameter");
170 *
"Whether the exact solution is known");
172 * prm.leave_subsection ();
174 * prm.enter_subsection (
"Mesh & Refinement Parameters");
177 *
"Number identifying the domain in which we solve the problem");
179 *
"Number of global mesh refinement steps applied to initial coarse grid");
181 *
"Number of global adaptive mesh refinements");
183 *
"refinement threshold");
185 *
"coarsening threshold");
187 * prm.leave_subsection ();
190 * prm.enter_subsection (
"Algorithm Parameters");
193 *
"0: Preconditioned descent, 1: Newton Method");
199 *
"Maximum Number of CG iterations");
201 *
"Tolerance for CG iterations");
203 *
"Maximum Number of LS iterations");
205 *
"line search tolerance constant (c1 in Nocedal-Wright)");
207 *
"initial step length in line-search");
209 *
"Maximum Number of inner iterations");
211 *
"Threshold on norm of the derivative to declare optimality achieved");
213 *
"Threshold on norm of the derivative to declare optimality achieved in highly refined mesh");
215 *
"Number of adaptive refinement before change convergence threshold");
217 * prm.leave_subsection ();
220 *
void ParameterReader::read_parameters (
const std::string parameter_file)
222 * declare_parameters();
223 * prm.parse_input (parameter_file);
228 * ******************************************************************************************
229 * The solution of the elastoplastic torsion problem on the unit disk with rhs=4.
236 *
class Solution :
public Function<dim>
240 *
virtual double value (
const Point<dim> &pto,
const unsigned int component = 0)
const override;
245 *
double Solution<dim>::value (
const Point<dim> &pto,
const unsigned int)
const
247 *
double r=
sqrt(pto.square());
259 *
double r=
sqrt(pto.square());
271 * ******************************************************************************************
283 * ComputeMultiplier (
double pe);
286 *
void compute_derived_quantities_scalar (
287 *
const std::vector< double > &,
295 *
virtual std::vector<std::string>
get_names ()
const override;
298 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
306 * ComputeMultiplier<dim>::ComputeMultiplier (
double pe): p(pe)
311 * void ComputeMultiplier<dim>::compute_derived_quantities_scalar(
312 * const
std::vector< double > & ,
313 * const
std::vector<
Tensor< 1, dim > > &duh,
314 * const
std::vector<
Tensor< 2, dim > > & ,
315 * const
std::vector<
Point< dim > > & ,
316 * const
std::vector<
Point< dim > > & ,
317 *
std::vector<
Vector< double > > &computed_quantities ) const
319 * const unsigned
int n_quadrature_points = duh.size();
321 *
for (
unsigned int q=0; q<n_quadrature_points; ++q)
323 *
long double sqrGrad=duh[q]* duh[q];
324 *
long double exponent=(p-2.0)/2*
std::log(sqrGrad);
325 * computed_quantities[q](0) =
std::sqrt(sqrGrad);
326 * computed_quantities[q](1)=
std::exp(exponent);
335 * std::vector<std::string>
336 * ComputeMultiplier<dim>::get_names() const
338 * std::vector<std::string> solution_names;
339 * solution_names.push_back (
"Gradient norm");
340 * solution_names.push_back (
"Lagrange multiplier");
341 *
return solution_names;
347 * ComputeMultiplier<dim>::get_needed_update_flags () const
355 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
356 * ComputeMultiplier<dim>:: get_data_component_interpretation () const
358 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
368 * Lagrange multiplier
372 *
return interpretation;
381 * ***************************************************************************************
385 *
class ElastoplasticTorsion
389 * ~ElastoplasticTorsion ();
393 *
void setup_system (
const bool initial_step);
394 *
void assemble_system ();
395 *
bool solve (
const int inner_it);
397 *
void refine_mesh ();
398 *
void set_boundary_values ();
399 *
double phi (
const double alpha)
const;
400 *
bool checkWolfe(
double &alpha,
double &phi_alpha)
const;
401 *
bool determine_step_length (
const int inner_it);
402 *
void print_it_message (
const int counter,
bool ks);
403 *
void output_results (
unsigned int refinement)
const;
404 *
void format_convergence_tables();
405 *
void process_solution (
const unsigned int cycle);
406 *
void process_multiplier (
const unsigned int cycle,
const int iter,
double time);
407 *
double dual_error ()
const;
408 *
double dual_infty_error ()
const;
409 *
double W (
double Du2)
const;
410 *
double Wp (
double Du2)
const;
411 *
double G (
double Du2)
const;
430 *
double step_length,phi_zero,phi_alpha,phip,phip_zero;
431 *
double old_step,old_phi_zero,old_phip;
434 *
double Linfty_error;
435 *
double dual_L1_error;
436 *
double dual_L_infty_error;
439 *
double line_search_tolerence;
440 *
unsigned int dir_id;
441 * std::string elements;
442 * std::string Method;
456 *
class BoundaryValues :
public Function<dim>
459 * BoundaryValues () :
Function<dim>() {}
462 *
const unsigned int component = 0)
const override;
467 *
double BoundaryValues<dim>::value (
const Point<dim> &,
468 *
const unsigned int )
const
472 * could be anything
else (theory works provided |Dg|_infty < 1/2)
506 *
class RightHandSide :
public Function<dim>
509 * RightHandSide () :
Function<dim>() {}
511 *
const unsigned int component = 0)
const override;
515 *
double RightHandSide<dim>::value (
const Point<dim> &,
516 *
const unsigned int )
const
520 *
set to
constant = 4,
for which
explicit solution to compare exists
524 *
double return_value = 4.0;
525 *
return return_value;
533 * The ElastoplasticTorsion
class implementation
537 * Constructor of the
class
541 * ElastoplasticTorsion<dim>::ElastoplasticTorsion (
ParameterHandler ¶m):
547 * dual_L1_error(1.0),
548 * dual_L_infty_error(1.0),
551 * prm.enter_subsection (
"Global Parameters");
552 * p=prm.get_double(
"p");
553 * prm.leave_subsection ();
554 * prm.enter_subsection (
"Algorithm Parameters");
555 * line_search_tolerence=prm.get_double(
"line_search_tolerence");
556 * dir_id=prm.get_integer(
"Descent_direction");
557 * prm.leave_subsection ();
560 *
else elements=
"P2";
571 * ElastoplasticTorsion<dim>::~ElastoplasticTorsion ()
573 * dof_handler.clear ();
579 * print iteration message
586 *
void ElastoplasticTorsion<dim>::print_it_message (
const int counter,
bool ks)
590 * process_solution (counter);
591 * std::cout <<
"iteration="<< counter+1 <<
" J(u_h)= "<< phi_zero <<
", H1 error: "
592 * << H1_error <<
", W0-1,infty error: "<< Linfty_error<<
" J'(u_h)(w)= "<< phip
593 * <<
", |J'(u_h)|= "<< system_rhs.l2_norm()<<std::endl;
597 * std::cout <<
"iteration= " << counter+1 <<
" J(u_h)= "
598 * << phi_alpha <<
" J'(u_h)= "<< phip<<std::endl;
625 *
void ElastoplasticTorsion<dim>::format_convergence_tables()
627 * convergence_table.set_precision(
"L2", 3);
628 * convergence_table.set_precision(
"H1", 3);
629 * convergence_table.set_precision(
"Linfty", 3);
630 * convergence_table.set_precision(
"function value", 3);
631 * convergence_table.set_precision(
"derivative", 3);
632 * dual_convergence_table.set_precision(
"dual_L1", 3);
633 * dual_convergence_table.set_precision(
"dual_Linfty", 3);
634 * dual_convergence_table.set_precision(
"L2", 3);
635 * dual_convergence_table.set_precision(
"H1", 3);
636 * dual_convergence_table.set_precision(
"Linfty", 3);
637 * convergence_table.set_scientific(
"L2",
true);
638 * convergence_table.set_scientific(
"H1",
true);
639 * convergence_table.set_scientific(
"Linfty",
true);
640 * convergence_table.set_scientific(
"function value",
true);
641 * convergence_table.set_scientific(
"derivative",
true);
642 * dual_convergence_table.set_scientific(
"dual_L1",
true);
643 * dual_convergence_table.set_scientific(
"dual_Linfty",
true);
644 * dual_convergence_table.set_scientific(
"L2",
true);
645 * dual_convergence_table.set_scientific(
"H1",
true);
646 * dual_convergence_table.set_scientific(
"Linfty",
true);
653 * fill-in entry
for the solution
657 *
void ElastoplasticTorsion<dim>::process_solution (
const unsigned int it)
663 * compute
L2 error (save to difference_per_cell)
668 * L2_error = difference_per_cell.l2_norm();
672 * compute H1 error (save to difference_per_cell)
677 * H1_error = difference_per_cell.l2_norm();
681 * compute W1infty error (save to difference_per_cell)
688 * Linfty_error = difference_per_cell.linfty_norm();
691 * convergence_table.add_value(
"cycle", it);
692 * convergence_table.add_value(
"p", p);
693 * convergence_table.add_value(
"L2", L2_error);
694 * convergence_table.add_value(
"H1", H1_error);
695 * convergence_table.add_value(
"Linfty", Linfty_error);
696 * convergence_table.add_value(
"function value", phi_alpha);
697 * convergence_table.add_value(
"derivative", phip);
704 * fill-in entry
for the multiplier
708 *
void ElastoplasticTorsion<dim>::process_multiplier (
const unsigned int cycle,
const int iter,
double time)
711 *
const unsigned int n_dofs=dof_handler.n_dofs();
712 * dual_L1_error=dual_error();
713 * dual_L_infty_error=dual_infty_error();
716 * dual_convergence_table.add_value(
"cycle", cycle);
717 * dual_convergence_table.add_value(
"p", p);
718 * dual_convergence_table.add_value(
"iteration_number", iter);
719 * dual_convergence_table.add_value(
"cpu_time", time);
720 * dual_convergence_table.add_value(
"cells", n_active_cells);
721 * dual_convergence_table.add_value(
"dofs", n_dofs);
722 * dual_convergence_table.add_value(
"L2", L2_error);
723 * dual_convergence_table.add_value(
"H1", H1_error);
724 * dual_convergence_table.add_value(
"Linfty", Linfty_error);
725 * dual_convergence_table.add_value(
"dual_L1", dual_L1_error);
726 * dual_convergence_table.add_value(
"dual_Linfty", dual_L_infty_error);
736 * ElastoplasticTorsion::setup_system
737 * unchanged from @ref step_15
"step-15"
744 *
void ElastoplasticTorsion<dim>::setup_system (
const bool initial_step)
748 * dof_handler.distribute_dofs (fe);
749 * present_solution.reinit (dof_handler.n_dofs());
750 * grad_norm.reinit (dof_handler.n_dofs());
751 *
lambda.reinit (dof_handler.n_dofs());
753 * hanging_node_constraints.clear ();
755 * hanging_node_constraints);
756 * hanging_node_constraints.close ();
762 * The remaining parts of the function
768 * newton_update.reinit (dof_handler.n_dofs());
769 * system_rhs.reinit (dof_handler.n_dofs());
772 * hanging_node_constraints.condense (c_sparsity);
773 * sparsity_pattern.copy_from(c_sparsity);
774 * system_matrix.reinit (sparsity_pattern);
786 *
double ElastoplasticTorsion<dim>::W (
double Du2)
const
792 *
double ElastoplasticTorsion<dim>::Wp (
double )
const
798 *
double ElastoplasticTorsion<dim>::G (
double )
const
805 *
void ElastoplasticTorsion<dim>::assemble_system ()
810 *
const RightHandSide<dim> right_hand_side;
820 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
821 *
const unsigned int n_q_points = quadrature_formula.size();
826 * std::vector<Tensor<1, dim> > old_solution_gradients(n_q_points);
827 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
831 * cell = dof_handler.begin_active(),
832 * endc = dof_handler.end();
833 *
for (; cell!=endc; ++cell)
838 * fe_values.reinit (cell);
839 * fe_values.get_function_gradients(present_solution,
840 * old_solution_gradients);
842 *
for (
unsigned int q_point = 0; q_point < n_q_points; ++q_point)
844 *
long double coeff=0.0;
845 *
long double a=old_solution_gradients[q_point] * old_solution_gradients[q_point];
846 *
long double exponent=(p-2.0)/2*
std::log(a);
848 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
850 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
854 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
855 * * (G(a)+(p-1.0)*coeff) * fe_values.JxW(q_point);
859 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
861 * * fe_values.JxW(q_point);
865 * cell_rhs(i) -= ( fe_values.shape_grad(i, q_point)
866 * * old_solution_gradients[q_point]
868 * -right_hand_side.value(fe_values.quadrature_point(q_point))
869 * *fe_values.shape_value(i, q_point)
871 * * fe_values.JxW(q_point);
875 * cell->get_dof_indices (local_dof_indices);
876 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
878 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
879 * system_matrix.add (local_dof_indices[i],
880 * local_dof_indices[j],
883 * system_rhs(local_dof_indices[i]) += cell_rhs(i);
887 * hanging_node_constraints.condense (system_matrix);
888 * hanging_node_constraints.condense (system_rhs);
890 * std::map<types::global_dof_index,double> boundary_values;
907 * unchanged from @ref step_15
"step-15"
914 *
void ElastoplasticTorsion<dim>::refine_mesh ()
916 *
using FunctionMap = std::map<types::boundary_id, const Function<dim> *>;
923 * estimated_error_per_cell);
925 * prm.enter_subsection (
"Mesh & Refinement Parameters");
926 *
const double top_fraction=prm.get_double(
"top_fraction_of_cells");
927 *
const double bottom_fraction=prm.get_double(
"bottom_fraction_of_cells");
928 * prm.leave_subsection ();
930 * estimated_error_per_cell,
931 * top_fraction, bottom_fraction);
935 * solution_transfer.prepare_for_coarsening_and_refinement(present_solution);
937 * dof_handler.distribute_dofs(fe);
939 * solution_transfer.interpolate(present_solution, tmp);
940 * present_solution = tmp;
941 * set_boundary_values ();
942 * hanging_node_constraints.clear();
945 * hanging_node_constraints);
946 * hanging_node_constraints.close();
947 * hanging_node_constraints.distribute (present_solution);
948 * setup_system (
false);
955 * Dump the
norm of the
gradient and the lagrange multiplier in
vtu format
for visualization
959 *
void ElastoplasticTorsion<dim>::output_results (
unsigned int counter)
const
963 * multiplier
object contains both |Du| and
lambda.
966 * ComputeMultiplier<dim> multiplier(p);
970 * data_out.add_data_vector (present_solution,
"solution");
971 * data_out.add_data_vector (present_solution, multiplier);
972 * data_out.build_patches ();
973 * std::ostringstream p_str;
974 * p_str << p<<
"-cycle-"<<counter;
975 * std::string str = p_str.str();
976 *
const std::string filename =
"solution-" + str+
".vtu";
977 * std::ofstream output (filename.c_str());
978 * data_out.write_vtu (output);
984 * unchanged from @ref step_15
"step-15"
988 *
void ElastoplasticTorsion<dim>::set_boundary_values ()
990 * std::map<types::global_dof_index, double> boundary_values;
993 * BoundaryValues<dim>(),
995 *
for (std::map<types::global_dof_index, double>::const_iterator
996 * bp = boundary_values.begin();
997 * bp != boundary_values.end(); ++bp)
998 * present_solution(bp->first) = bp->second;
1005 * COMPUTE @f$\phi(\alpha)=J_p(u_h+\alpha w)@f$
1008 *
template <
int dim>
1009 *
double ElastoplasticTorsion<dim>::phi (
const double alpha)
const
1012 *
const RightHandSide<dim> right_hand_side;
1014 * evaluation_point = present_solution;
1015 * evaluation_point.add (alpha, newton_update);
1024 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1025 *
const unsigned int n_q_points = quadrature_formula.size();
1028 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1029 * std::vector<double>
values(n_q_points);
1032 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1035 * cell = dof_handler.begin_active(),
1036 * endc = dof_handler.end();
1037 *
for (; cell!=endc; ++cell)
1040 * fe_values.reinit (cell);
1041 * fe_values.get_function_gradients (evaluation_point, gradients);
1042 * fe_values.get_function_values (evaluation_point, values);
1045 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1056 * obj+= 1/2 W(|Du|^2)+1/p |Du|^p -fu (see (1))
1060 * (0.5*W(Du2)+penalty/p)- right_hand_side.value(fe_values.quadrature_point(q_point))*
values[q_point]
1061 * ) * fe_values.JxW(q_point);
1073 * Compute L^1 error
norm of Lagrange Multiplier
1074 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1080 *
template <
int dim>
1081 *
double ElastoplasticTorsion<dim>::dual_error () const
1091 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1092 *
const unsigned int n_q_points = quadrature_formula.size();
1095 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1097 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1100 * cell = dof_handler.begin_active(),
1101 * endc = dof_handler.end();
1102 *
for (; cell!=endc; ++cell)
1105 * fe_values.reinit (cell);
1106 * fe_values.get_function_gradients (present_solution, gradients);
1108 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1111 *
if (coeff<1.0e-15)
1114 * coeff=
std::pow(coeff,(p-2.0)/2.0);
1116 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1121 * obj+=(
std::abs(coeff-exact) ) * fe_values.JxW(q_point);
1132 * Compute L^infinity error
norm of Lagrange Multiplier
1133 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1139 *
template <
int dim>
1140 *
double ElastoplasticTorsion<dim>::dual_infty_error () const
1150 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1151 *
const unsigned int n_q_points = quadrature_formula.size();
1154 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1156 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1159 * cell = dof_handler.begin_active(),
1160 * endc = dof_handler.end();
1161 *
for (; cell!=endc; ++cell)
1164 * fe_values.reinit (cell);
1165 * fe_values.get_function_gradients (present_solution, gradients);
1167 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1170 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1176 * compute |Du|^(p-2) as
exp(p-2/2*
log(Du^2))
1179 *
long double exponent=(p-2.0)/2*
std::log(sqdGrad);
1180 *
long double coeff=
std::exp(exponent);
1194 *
check whether putative step-length satisfies sufficient decrease conditions
1197 *
template <
int dim>
1198 *
bool ElastoplasticTorsion<dim>::checkWolfe(
double &alpha,
double &phi_alpha)
const
1200 *
if (phi_alpha< phi_zero+line_search_tolerence*phip*alpha )
1210 * Find a step-length satisfying sufficient decrease condition by line-search
1211 * uses quadratic interpolation
1217 *
template <
int dim>
1218 *
bool ElastoplasticTorsion<dim>::determine_step_length(
const int inner_it)
1220 *
unsigned int it=0;
1222 *
double alpha,nalpha;
1223 * prm.enter_subsection (
"Algorithm Parameters");
1224 *
const unsigned int max_LS_it=prm.get_integer(
"max_LS_it");
1225 *
double init_SL=prm.get_double(
"init_step_length");
1226 * prm.leave_subsection ();
1231 * alpha=
std::min(1.45*old_step*old_phip/phip,1.0);
1233 * phi_alpha=phi(alpha);
1234 * std::cerr <<
"Step length=" << alpha <<
", Value= " << phi_alpha;
1237 *
check if step-size satisfies sufficient decrease condition
1240 * done=checkWolfe(alpha,phi_alpha);
1242 * std::cerr <<
" accepted" << std::endl;
1244 * std::cerr <<
" rejected" ;
1246 *
while ((!done) & (it<max_LS_it))
1250 *
new try obtained by quadratic interpolation
1253 * nalpha=-(phip*alpha*alpha)/(2*(phi_alpha-phi_zero-phip*alpha));
1255 *
if (nalpha<1e-3*alpha ||
std::abs(nalpha-alpha)/alpha<1
e-8)
1257 *
else if ( phi_alpha-phi_zero>1e3*
std::abs(phi_zero) )
1260 * phi_alpha=phi(alpha);
1261 * done=checkWolfe(alpha,phi_alpha);
1263 * std::cerr <<
", finished with steplength= "<< alpha<<
", fcn value= "<< phi_alpha<<std::endl;
1268 * std::cerr <<
", max. no. of iterations reached wiht steplength= "<< alpha
1269 * <<
", fcn value= "<< phi_alpha<<std::endl;
1274 * step_length=alpha;
1283 * ElastoplasticTorsion::init_mesh()
1289 *
template <
int dim>
1290 *
void ElastoplasticTorsion<dim>::init_mesh ()
1297 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1298 *
const int domain_id=prm.get_integer(
"Code for the domain");
1299 *
const int init_ref=prm.get_integer(
"No of initial refinements");
1300 * prm.leave_subsection ();
1307 * For the unit disk around the origin
1314 *
else if (domain_id==1)
1318 * For the unit square
1323 *
else if (domain_id==2)
1363 * ElastoplasticTorsion::solve(inner_it)
1364 * Performs one inner iteration
1370 *
template <
int dim>
1371 *
bool ElastoplasticTorsion<dim>::solve (
const int inner_it)
1373 * prm.enter_subsection (
"Algorithm Parameters");
1374 *
const unsigned int max_CG_it=prm.get_integer(
"Max_CG_it");
1375 *
const double CG_tol=prm.get_double(
"CG_tol");
1376 * prm.leave_subsection ();
1382 * preconditioner.
initialize(system_matrix,0.25);
1384 * solver.solve (system_matrix, newton_update, system_rhs,
1386 * hanging_node_constraints.distribute (newton_update);
1390 * Recall that phi(alpha)=J(u+alpha w)
1393 * old_step=step_length;
1394 * old_phi_zero=phi_zero;
1397 * phip=-1.0*(newton_update*system_rhs);
1403 * std::cout <<
"Not a descent direction!" <<std::endl;
1404 * present_solution.add (-1.0*step_length, newton_update);
1405 * step_length=step_length/2;
1411 *
if (determine_step_length(inner_it))
1415 * update u_{n+1}=u_n+alpha w_n
1418 * present_solution.add (step_length, newton_update);
1421 *
else return false;
1430 * ElastoplasticTorsion::run
1433 *
template <
int dim>
1434 *
void ElastoplasticTorsion<dim>::run ()
1442 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1443 *
const int adapt_ref=prm.get_integer(
"No of adaptive refinements");
1444 * prm.leave_subsection ();
1445 * prm.enter_subsection (
"Algorithm Parameters");
1446 *
const int max_inner=prm.get_integer(
"Max_inner");
1447 *
const double eps=prm.get_double(
"eps");
1448 *
const double hi_eps=prm.get_double(
"hi_eps");
1449 *
const int hi_th=prm.get_integer(
"hi_th");
1450 *
const double init_p=prm.get_double(
"init_p");
1451 *
const double delta_p=prm.get_double(
"delta_p");
1452 * prm.leave_subsection ();
1453 * prm.enter_subsection (
"Global Parameters");
1454 *
bool known_solution=prm.get_bool(
"known_solution");
1455 *
double actual_p=prm.get_double(
"p");
1456 * prm.leave_subsection ();
1470 * initalize mesh
for the selected domain
1480 * setup_system (
true);
1481 * set_boundary_values ();
1490 *
int refinement = 0;
1499 *
bool well_solved=
true;
1503 *
while (p<actual_p)
1505 * std::cout <<
"--Preparing initial condition with p="<<p<<
" iter.= " << global_it<<
" .-- "<< std::endl;
1507 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1509 * assemble_system ();
1510 * well_solved=solve (inner_iteration);
1511 * print_it_message (global_it, known_solution);
1513 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-4) & (cycle<1)) |
1514 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-5) & (cycle>=1)) |
1519 * ptime=timer.cpu_time();
1521 * output_results (cycle);
1523 *
if (known_solution)
1525 * process_multiplier(cycle,global_it,ptime);
1528 * dual_convergence_table.write_tex(dual_error_table_file);
1551 * std::cout <<
"============ Solving problem with p=" <<p <<
" ==================" << std::endl;
1553 *
while ((cycle<adapt_ref) & well_solved)
1561 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1563 * assemble_system ();
1564 * well_solved=solve (inner_iteration);
1565 * print_it_message (global_it, known_solution);
1568 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) < eps) & (refinement<hi_th)) |
1569 * (( system_rhs.l2_norm()/
std::sqrt (system_rhs.size()) <hi_eps) | (!well_solved))
1575 * inner iterations finished
1578 * ptime=timer.cpu_time();
1580 * output_results (cycle);
1584 * compute and display error,
if the
explicit solution is known
1587 *
if (known_solution)
1589 * process_multiplier(cycle,global_it,ptime);
1590 * std::cout <<
"finished with H1 error: " << H1_error <<
", dual error (L1): "
1591 * << dual_L1_error <<
"dual error (L infty): "<<dual_L_infty_error <<std::endl;
1606 * std::cout <<
"******** Refined mesh " << cycle <<
" ********" << std::endl;
1612 * write convergence tables to file
1615 *
if (known_solution)
1617 * format_convergence_tables();
1618 * std::string error_filename =
"error"+Method+elements+
".tex";
1619 * std::ofstream error_table_file(error_filename.c_str());
1620 * std::string dual_error_filename =
"dual_error"+Method+elements+
".tex";
1621 * std::ofstream dual_error_table_file(dual_error_filename.c_str());
1622 * convergence_table.write_tex(error_table_file);
1623 * dual_convergence_table.write_tex(dual_error_table_file);
1639 *
using namespace dealii;
1640 *
using namespace nsp;
1644 * ParameterReader param(prm);
1645 * param.read_parameters(
"EPT.prm");
1646 * ElastoplasticTorsion<2> ElastoplasticTorsionProblem(prm);
1647 * ElastoplasticTorsionProblem .run ();
1649 *
catch (std::exception &exc)
1651 * std::cerr << std::endl << std::endl
1652 * <<
"----------------------------------------------------" << std::endl;
1653 * std::cerr <<
"Exception on processing: " << std::endl
1654 * << exc.what() << std::endl
1655 * <<
"Aborting!" << std::endl
1656 * <<
"----------------------------------------------------"
1663 * std::cerr << std::endl << std::endl
1664 * <<
"----------------------------------------------------"
1666 * std::cerr <<
"Unknown exception!" << std::endl
1667 * <<
"Aborting!" << std::endl
1668 * <<
"----------------------------------------------------"
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, typename InputVector::value_type > * > &neumann_bc, const InputVector &solution, Vector< float > &error, const ComponentMask &component_mask=ComponentMask(), 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())
__global__ void set(Number *val, const Number s, const size_type N)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(ITERATOR begin, std_cxx20::type_identity_t< ITERATOR > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &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=AffineConstraints< number >(), 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
const ::Triangulation< dim, spacedim > & tria