76 * #include <deal.II/base/quadrature_lib.h>
77 * #include <deal.II/base/function.h>
78 * #include <deal.II/base/logstream.h>
79 * #include <deal.II/base/utilities.h>
80 * #include <deal.II/base/convergence_table.h>
81 * #include <deal.II/base/smartpointer.h>
82 * #include <deal.II/base/parameter_handler.h>
83 * #include <deal.II/base/timer.h>
85 * #include <deal.II/lac/vector.h>
86 * #include <deal.II/lac/full_matrix.h>
87 * #include <deal.II/lac/sparse_matrix.h>
88 * #include <deal.II/lac/solver_cg.h>
89 * #include <deal.II/lac/precondition.h>
90 * #include <deal.II/lac/affine_constraints.h>
91 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
93 * #include <deal.II/grid/tria.h>
94 * #include <deal.II/grid/grid_generator.h>
95 * #include <deal.II/grid/tria_accessor.h>
96 * #include <deal.II/grid/tria_iterator.h>
97 * #include <deal.II/grid/manifold_lib.h>
98 * #include <deal.II/grid/grid_refinement.h>
99 * #include <deal.II/grid/grid_in.h>
101 * #include <deal.II/dofs/dof_handler.h>
102 * #include <deal.II/dofs/dof_accessor.h>
103 * #include <deal.II/dofs/dof_tools.h>
104 * #include <deal.II/dofs/dof_renumbering.h>
106 * #include <deal.II/fe/fe_values.h>
107 * #include <deal.II/fe/fe_q.h>
109 * #include <deal.II/numerics/vector_tools.h>
110 * #include <deal.II/numerics/matrix_tools.h>
111 * #include <deal.II/numerics/data_out.h>
112 * #include <deal.II/numerics/error_estimator.h>
113 * #include <deal.II/numerics/solution_transfer.h>
115 * #include <typeinfo>
117 * #include <iostream>
119 * #include <deal.II/numerics/solution_transfer.h>
123 * Open a
namespace for this program and import everything from the
124 *
dealii namespace into it.
133 * ********************************************************
140 *
void read_parameters(
const std::string);
142 *
void declare_parameters();
154 * void ParameterReader::declare_parameters()
157 * prm.enter_subsection (
"Global Parameters");
160 *
"Penalization parameter");
162 *
"Whether the exact solution is known");
164 * prm.leave_subsection ();
166 * prm.enter_subsection (
"Mesh & Refinement Parameters");
169 *
"Number identifying the domain in which we solve the problem");
171 *
"Number of global mesh refinement steps applied to initial coarse grid");
173 *
"Number of global adaptive mesh refinements");
175 *
"refinement threshold");
177 *
"coarsening threshold");
179 * prm.leave_subsection ();
182 * prm.enter_subsection (
"Algorithm Parameters");
185 *
"0: Preconditioned descent, 1: Newton Method");
191 *
"Maximum Number of CG iterations");
193 *
"Tolerance for CG iterations");
195 *
"Maximum Number of LS iterations");
197 *
"line search tolerance constant (c1 in Nocedal-Wright)");
199 *
"initial step length in line-search");
201 *
"Maximum Number of inner iterations");
203 *
"Threshold on norm of the derivative to declare optimality achieved");
205 *
"Threshold on norm of the derivative to declare optimality achieved in highly refined mesh");
207 *
"Number of adaptive refinement before change convergence threshold");
209 * prm.leave_subsection ();
212 *
void ParameterReader::read_parameters (
const std::string parameter_file)
214 * declare_parameters();
215 * prm.parse_input (parameter_file);
220 * ******************************************************************************************
221 * The solution of the elastoplastic torsion problem on the unit disk with rhs=4.
228 *
class Solution :
public Function<dim>
232 *
virtual double value (
const Point<dim> &pto,
const unsigned int component = 0)
const override;
237 *
double Solution<dim>::value (
const Point<dim> &pto,
const unsigned int)
const
239 *
double r=
sqrt(pto.square());
251 *
double r=
sqrt(pto.square());
263 * ******************************************************************************************
275 * ComputeMultiplier (
double pe);
278 *
void compute_derived_quantities_scalar (
279 *
const std::vector< double > &,
282 *
const std::vector< Point< dim > > &,
283 *
const std::vector< Point< dim > > &,
287 *
virtual std::vector<std::string>
get_names ()
const override;
290 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
298 * ComputeMultiplier<dim>::ComputeMultiplier (
double pe): p(pe)
303 * void ComputeMultiplier<dim>::compute_derived_quantities_scalar(
304 * const
std::vector< double > & ,
305 * const
std::vector<
Tensor< 1, dim > > &duh,
306 * const
std::vector<
Tensor< 2, dim > > & ,
307 * const
std::vector<
Point< dim > > & ,
308 * const
std::vector<
Point< dim > > & ,
309 *
std::vector<
Vector< double > > &computed_quantities ) const
311 * const unsigned
int n_quadrature_points = duh.size();
313 *
for (
unsigned int q=0; q<n_quadrature_points; ++q)
315 *
long double sqrGrad=duh[q]* duh[q];
316 *
long double exponent=(p-2.0)/2*
std::log(sqrGrad);
317 * computed_quantities[q](0) =
std::sqrt(sqrGrad);
318 * computed_quantities[q](1)=
std::exp(exponent);
327 * std::vector<std::string>
328 * ComputeMultiplier<dim>::get_names() const
330 * std::vector<std::string> solution_names;
331 * solution_names.push_back (
"Gradient norm");
332 * solution_names.push_back (
"Lagrange multiplier");
333 *
return solution_names;
339 * ComputeMultiplier<dim>::get_needed_update_flags () const
347 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
348 * ComputeMultiplier<dim>:: get_data_component_interpretation () const
350 * std::vector<DataComponentInterpretation::DataComponentInterpretation>
360 * Lagrange multiplier
364 *
return interpretation;
373 * ***************************************************************************************
377 *
class ElastoplasticTorsion
381 * ~ElastoplasticTorsion ();
385 *
void setup_system (
const bool initial_step);
386 *
void assemble_system ();
387 *
bool solve (
const int inner_it);
389 *
void refine_mesh ();
390 *
void set_boundary_values ();
391 *
double phi (
const double alpha)
const;
392 *
bool checkWolfe(
double &alpha,
double &phi_alpha)
const;
393 *
bool determine_step_length (
const int inner_it);
394 *
void print_it_message (
const int counter,
bool ks);
395 *
void output_results (
unsigned int refinement)
const;
396 *
void format_convergence_tables();
397 *
void process_solution (
const unsigned int cycle);
398 *
void process_multiplier (
const unsigned int cycle,
const int iter,
double time);
399 *
double dual_error ()
const;
400 *
double dual_infty_error ()
const;
401 *
double W (
double Du2)
const;
402 *
double Wp (
double Du2)
const;
403 *
double G (
double Du2)
const;
422 *
double step_length,phi_zero,phi_alpha,phip,phip_zero;
423 *
double old_step,old_phi_zero,old_phip;
426 *
double Linfty_error;
427 *
double dual_L1_error;
428 *
double dual_L_infty_error;
431 *
double line_search_tolerence;
432 *
unsigned int dir_id;
433 * std::string elements;
434 * std::string Method;
448 *
class BoundaryValues :
public Function<dim>
451 * BoundaryValues () :
Function<dim>() {}
454 *
const unsigned int component = 0)
const override;
459 *
double BoundaryValues<dim>::value (
const Point<dim> &,
460 *
const unsigned int )
const
464 * could be anything
else (theory works provided |Dg|_infty < 1/2)
498 *
class RightHandSide :
public Function<dim>
501 * RightHandSide () :
Function<dim>() {}
503 *
const unsigned int component = 0)
const override;
507 *
double RightHandSide<dim>::value (
const Point<dim> &,
508 *
const unsigned int )
const
512 *
set to
constant = 4,
for which
explicit solution to compare exists
516 *
double return_value = 4.0;
517 *
return return_value;
525 * The ElastoplasticTorsion
class implementation
529 * Constructor of the
class
533 * ElastoplasticTorsion<dim>::ElastoplasticTorsion (
ParameterHandler ¶m):
539 * dual_L1_error(1.0),
540 * dual_L_infty_error(1.0),
543 * prm.enter_subsection (
"Global Parameters");
544 * p=prm.get_double(
"p");
545 * prm.leave_subsection ();
546 * prm.enter_subsection (
"Algorithm Parameters");
547 * line_search_tolerence=prm.get_double(
"line_search_tolerence");
548 * dir_id=prm.get_integer(
"Descent_direction");
549 * prm.leave_subsection ();
552 *
else elements=
"P2";
563 * ElastoplasticTorsion<dim>::~ElastoplasticTorsion ()
565 * dof_handler.clear ();
571 * print iteration message
578 *
void ElastoplasticTorsion<dim>::print_it_message (
const int counter,
bool ks)
582 * process_solution (counter);
583 * std::cout <<
"iteration="<< counter+1 <<
" J(u_h)= "<< phi_zero <<
", H1 error: "
584 * << H1_error <<
", W0-1,infty error: "<< Linfty_error<<
" J'(u_h)(w)= "<< phip
585 * <<
", |J'(u_h)|= "<< system_rhs.l2_norm()<<std::endl;
589 * std::cout <<
"iteration= " << counter+1 <<
" J(u_h)= "
590 * << phi_alpha <<
" J'(u_h)= "<< phip<<std::endl;
617 *
void ElastoplasticTorsion<dim>::format_convergence_tables()
619 * convergence_table.set_precision(
"L2", 3);
620 * convergence_table.set_precision(
"H1", 3);
621 * convergence_table.set_precision(
"Linfty", 3);
622 * convergence_table.set_precision(
"function value", 3);
623 * convergence_table.set_precision(
"derivative", 3);
624 * dual_convergence_table.set_precision(
"dual_L1", 3);
625 * dual_convergence_table.set_precision(
"dual_Linfty", 3);
626 * dual_convergence_table.set_precision(
"L2", 3);
627 * dual_convergence_table.set_precision(
"H1", 3);
628 * dual_convergence_table.set_precision(
"Linfty", 3);
629 * convergence_table.set_scientific(
"L2",
true);
630 * convergence_table.set_scientific(
"H1",
true);
631 * convergence_table.set_scientific(
"Linfty",
true);
632 * convergence_table.set_scientific(
"function value",
true);
633 * convergence_table.set_scientific(
"derivative",
true);
634 * dual_convergence_table.set_scientific(
"dual_L1",
true);
635 * dual_convergence_table.set_scientific(
"dual_Linfty",
true);
636 * dual_convergence_table.set_scientific(
"L2",
true);
637 * dual_convergence_table.set_scientific(
"H1",
true);
638 * dual_convergence_table.set_scientific(
"Linfty",
true);
645 * fill-in entry
for the solution
649 *
void ElastoplasticTorsion<dim>::process_solution (
const unsigned int it)
655 * compute
L2 error (save to difference_per_cell)
660 * L2_error = difference_per_cell.l2_norm();
664 * compute H1 error (save to difference_per_cell)
669 * H1_error = difference_per_cell.l2_norm();
673 * compute W1infty error (save to difference_per_cell)
680 * Linfty_error = difference_per_cell.linfty_norm();
683 * convergence_table.add_value(
"cycle", it);
684 * convergence_table.add_value(
"p", p);
685 * convergence_table.add_value(
"L2", L2_error);
686 * convergence_table.add_value(
"H1", H1_error);
687 * convergence_table.add_value(
"Linfty", Linfty_error);
688 * convergence_table.add_value(
"function value", phi_alpha);
689 * convergence_table.add_value(
"derivative", phip);
696 * fill-in entry
for the multiplier
700 *
void ElastoplasticTorsion<dim>::process_multiplier (
const unsigned int cycle,
const int iter,
double time)
703 *
const unsigned int n_dofs=dof_handler.n_dofs();
704 * dual_L1_error=dual_error();
705 * dual_L_infty_error=dual_infty_error();
708 * dual_convergence_table.add_value(
"cycle", cycle);
709 * dual_convergence_table.add_value(
"p", p);
710 * dual_convergence_table.add_value(
"iteration_number", iter);
711 * dual_convergence_table.add_value(
"cpu_time", time);
712 * dual_convergence_table.add_value(
"cells", n_active_cells);
713 * dual_convergence_table.add_value(
"dofs", n_dofs);
714 * dual_convergence_table.add_value(
"L2", L2_error);
715 * dual_convergence_table.add_value(
"H1", H1_error);
716 * dual_convergence_table.add_value(
"Linfty", Linfty_error);
717 * dual_convergence_table.add_value(
"dual_L1", dual_L1_error);
718 * dual_convergence_table.add_value(
"dual_Linfty", dual_L_infty_error);
728 * ElastoplasticTorsion::setup_system
729 * unchanged from @ref step_15
"step-15"
736 *
void ElastoplasticTorsion<dim>::setup_system (
const bool initial_step)
740 * dof_handler.distribute_dofs (fe);
741 * present_solution.reinit (dof_handler.n_dofs());
742 * grad_norm.reinit (dof_handler.n_dofs());
743 *
lambda.reinit (dof_handler.n_dofs());
745 * hanging_node_constraints.clear ();
747 * hanging_node_constraints);
748 * hanging_node_constraints.close ();
754 * The remaining parts of the function
760 * newton_update.reinit (dof_handler.n_dofs());
761 * system_rhs.reinit (dof_handler.n_dofs());
764 * hanging_node_constraints.condense (c_sparsity);
765 * sparsity_pattern.copy_from(c_sparsity);
766 * system_matrix.reinit (sparsity_pattern);
778 *
double ElastoplasticTorsion<dim>::W (
double Du2)
const
784 *
double ElastoplasticTorsion<dim>::Wp (
double )
const
790 *
double ElastoplasticTorsion<dim>::G (
double )
const
797 *
void ElastoplasticTorsion<dim>::assemble_system ()
802 *
const RightHandSide<dim> right_hand_side;
812 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
813 *
const unsigned int n_q_points = quadrature_formula.size();
818 * std::vector<Tensor<1, dim> > old_solution_gradients(n_q_points);
819 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
823 * cell = dof_handler.begin_active(),
824 * endc = dof_handler.end();
825 *
for (; cell!=endc; ++cell)
830 * fe_values.reinit (cell);
831 * fe_values.get_function_gradients(present_solution,
832 * old_solution_gradients);
834 *
for (
unsigned int q_point = 0; q_point < n_q_points; ++q_point)
836 *
long double coeff=0.0;
837 *
long double a=old_solution_gradients[q_point] * old_solution_gradients[q_point];
838 *
long double exponent=(p-2.0)/2*
std::log(a);
840 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
842 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
846 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
847 * * (G(a)+(p-1.0)*coeff) * fe_values.JxW(q_point);
851 *
cell_matrix(i, j) += fe_values.shape_grad(i, q_point) * fe_values.shape_grad(j, q_point)
853 * * fe_values.JxW(q_point);
857 * cell_rhs(i) -= ( fe_values.shape_grad(i, q_point)
858 * * old_solution_gradients[q_point]
860 * -right_hand_side.value(fe_values.quadrature_point(q_point))
861 * *fe_values.shape_value(i, q_point)
863 * * fe_values.JxW(q_point);
867 * cell->get_dof_indices (local_dof_indices);
868 *
for (
unsigned int i=0; i<dofs_per_cell; ++i)
870 *
for (
unsigned int j=0; j<dofs_per_cell; ++j)
871 * system_matrix.add (local_dof_indices[i],
872 * local_dof_indices[j],
875 * system_rhs(local_dof_indices[i]) += cell_rhs(i);
879 * hanging_node_constraints.condense (system_matrix);
880 * hanging_node_constraints.condense (system_rhs);
882 * std::map<types::global_dof_index,double> boundary_values;
899 * unchanged from @ref step_15
"step-15"
906 *
void ElastoplasticTorsion<dim>::refine_mesh ()
908 *
using FunctionMap = std::map<types::boundary_id, const Function<dim> *>;
915 * estimated_error_per_cell);
917 * prm.enter_subsection (
"Mesh & Refinement Parameters");
918 *
const double top_fraction=prm.get_double(
"top_fraction_of_cells");
919 *
const double bottom_fraction=prm.get_double(
"bottom_fraction_of_cells");
920 * prm.leave_subsection ();
922 * estimated_error_per_cell,
923 * top_fraction, bottom_fraction);
927 * solution_transfer.prepare_for_coarsening_and_refinement(present_solution);
929 * dof_handler.distribute_dofs(fe);
931 * solution_transfer.interpolate(present_solution, tmp);
932 * present_solution = tmp;
933 * set_boundary_values ();
934 * hanging_node_constraints.clear();
937 * hanging_node_constraints);
938 * hanging_node_constraints.close();
939 * hanging_node_constraints.distribute (present_solution);
940 * setup_system (
false);
947 * Dump the
norm of the
gradient and the lagrange multiplier in
vtu format
for visualization
951 *
void ElastoplasticTorsion<dim>::output_results (
unsigned int counter)
const
955 * multiplier
object contains both |Du| and
lambda.
958 * ComputeMultiplier<dim> multiplier(p);
962 * data_out.add_data_vector (present_solution,
"solution");
963 * data_out.add_data_vector (present_solution, multiplier);
964 * data_out.build_patches ();
965 * std::ostringstream p_str;
966 * p_str << p<<
"-cycle-"<<counter;
967 * std::string str = p_str.str();
968 *
const std::string filename =
"solution-" + str+
".vtu";
969 * std::ofstream output (filename.c_str());
970 * data_out.write_vtu (output);
976 * unchanged from @ref step_15
"step-15"
980 *
void ElastoplasticTorsion<dim>::set_boundary_values ()
982 * std::map<types::global_dof_index, double> boundary_values;
985 * BoundaryValues<dim>(),
987 *
for (std::map<types::global_dof_index, double>::const_iterator
988 * bp = boundary_values.begin();
989 * bp != boundary_values.end(); ++bp)
990 * present_solution(bp->first) = bp->second;
997 * COMPUTE @f$\phi(\alpha)=J_p(u_h+\alpha w)@f$
1000 *
template <
int dim>
1001 *
double ElastoplasticTorsion<dim>::phi (
const double alpha)
const
1004 *
const RightHandSide<dim> right_hand_side;
1006 * evaluation_point = present_solution;
1007 * evaluation_point.add (alpha, newton_update);
1016 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1017 *
const unsigned int n_q_points = quadrature_formula.size();
1020 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1021 * std::vector<double> values(n_q_points);
1024 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1027 * cell = dof_handler.begin_active(),
1028 * endc = dof_handler.end();
1029 *
for (; cell!=endc; ++cell)
1032 * fe_values.reinit (cell);
1033 * fe_values.get_function_gradients (evaluation_point, gradients);
1034 * fe_values.get_function_values (evaluation_point, values);
1037 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1048 * obj+= 1/2 W(|Du|^2)+1/p |Du|^p -fu (see (1))
1052 * (0.5*W(Du2)+penalty/p)- right_hand_side.value(fe_values.quadrature_point(q_point))*values[q_point]
1053 * ) * fe_values.JxW(q_point);
1065 * Compute L^1 error
norm of Lagrange Multiplier
1066 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1072 *
template <
int dim>
1073 *
double ElastoplasticTorsion<dim>::dual_error () const
1083 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1084 *
const unsigned int n_q_points = quadrature_formula.size();
1087 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1089 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1092 * cell = dof_handler.begin_active(),
1093 * endc = dof_handler.end();
1094 *
for (; cell!=endc; ++cell)
1097 * fe_values.reinit (cell);
1098 * fe_values.get_function_gradients (present_solution, gradients);
1100 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1103 *
if (coeff<1.0e-15)
1106 * coeff=
std::pow(coeff,(p-2.0)/2.0);
1108 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1113 * obj+=(
std::abs(coeff-exact) ) * fe_values.JxW(q_point);
1124 * Compute L^infinity error
norm of Lagrange Multiplier
1125 * with respect to exact solution (cf. Alvarez & Flores, 2015)
1131 *
template <
int dim>
1132 *
double ElastoplasticTorsion<dim>::dual_infty_error () const
1142 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1143 *
const unsigned int n_q_points = quadrature_formula.size();
1146 * std::vector<Tensor<1, dim> >
gradients(n_q_points);
1148 * std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1151 * cell = dof_handler.begin_active(),
1152 * endc = dof_handler.end();
1153 *
for (; cell!=endc; ++cell)
1156 * fe_values.reinit (cell);
1157 * fe_values.get_function_gradients (present_solution, gradients);
1159 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1162 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1168 * compute |Du|^(p-2) as
exp(p-2/2*
log(Du^2))
1171 *
long double exponent=(p-2.0)/2*
std::log(sqdGrad);
1172 *
long double coeff=
std::exp(exponent);
1186 *
check whether putative step-length satisfies sufficient decrease conditions
1189 *
template <
int dim>
1190 *
bool ElastoplasticTorsion<dim>::checkWolfe(
double &alpha,
double &phi_alpha)
const
1192 *
if (phi_alpha< phi_zero+line_search_tolerence*phip*alpha )
1202 * Find a step-length satisfying sufficient decrease condition by line-search
1203 * uses quadratic interpolation
1209 *
template <
int dim>
1210 *
bool ElastoplasticTorsion<dim>::determine_step_length(
const int inner_it)
1212 *
unsigned int it=0;
1214 *
double alpha,nalpha;
1215 * prm.enter_subsection (
"Algorithm Parameters");
1216 *
const unsigned int max_LS_it=prm.get_integer(
"max_LS_it");
1217 *
double init_SL=prm.get_double(
"init_step_length");
1218 * prm.leave_subsection ();
1223 * alpha=
std::min(1.45*old_step*old_phip/phip,1.0);
1225 * phi_alpha=phi(alpha);
1226 * std::cerr <<
"Step length=" << alpha <<
", Value= " << phi_alpha;
1229 *
check if step-size satisfies sufficient decrease condition
1232 * done=checkWolfe(alpha,phi_alpha);
1234 * std::cerr <<
" accepted" << std::endl;
1236 * std::cerr <<
" rejected" ;
1238 *
while ((!done) & (it<max_LS_it))
1242 *
new try obtained by quadratic interpolation
1245 * nalpha=-(phip*alpha*alpha)/(2*(phi_alpha-phi_zero-phip*alpha));
1247 *
if (nalpha<1e-3*alpha ||
std::abs(nalpha-alpha)/alpha<1
e-8)
1249 *
else if ( phi_alpha-phi_zero>1e3*
std::abs(phi_zero) )
1252 * phi_alpha=phi(alpha);
1253 * done=checkWolfe(alpha,phi_alpha);
1255 * std::cerr <<
", finished with steplength= "<< alpha<<
", fcn value= "<< phi_alpha<<std::endl;
1260 * std::cerr <<
", max. no. of iterations reached with steplength= "<< alpha
1261 * <<
", fcn value= "<< phi_alpha<<std::endl;
1266 * step_length=alpha;
1275 * ElastoplasticTorsion::init_mesh()
1281 *
template <
int dim>
1282 *
void ElastoplasticTorsion<dim>::init_mesh ()
1289 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1290 *
const int domain_id=prm.get_integer(
"Code for the domain");
1291 *
const int init_ref=prm.get_integer(
"No of initial refinements");
1292 * prm.leave_subsection ();
1299 * For the unit disk around the origin
1306 *
else if (domain_id==1)
1310 * For the unit square
1315 *
else if (domain_id==2)
1355 * ElastoplasticTorsion::solve(inner_it)
1356 * Performs one inner iteration
1362 *
template <
int dim>
1363 *
bool ElastoplasticTorsion<dim>::solve (
const int inner_it)
1365 * prm.enter_subsection (
"Algorithm Parameters");
1366 *
const unsigned int max_CG_it=prm.get_integer(
"Max_CG_it");
1367 *
const double CG_tol=prm.get_double(
"CG_tol");
1368 * prm.leave_subsection ();
1374 * preconditioner.
initialize(system_matrix,0.25);
1376 * solver.solve (system_matrix, newton_update, system_rhs,
1378 * hanging_node_constraints.distribute (newton_update);
1382 * Recall that phi(alpha)=J(u+alpha w)
1385 * old_step=step_length;
1386 * old_phi_zero=phi_zero;
1389 * phip=-1.0*(newton_update*system_rhs);
1395 * std::cout <<
"Not a descent direction!" <<std::endl;
1396 * present_solution.add (-1.0*step_length, newton_update);
1397 * step_length=step_length/2;
1403 *
if (determine_step_length(inner_it))
1407 * update u_{n+1}=u_n+alpha w_n
1410 * present_solution.add (step_length, newton_update);
1413 *
else return false;
1422 * ElastoplasticTorsion::run
1425 *
template <
int dim>
1426 *
void ElastoplasticTorsion<dim>::run ()
1434 * prm.enter_subsection (
"Mesh & Refinement Parameters");
1435 *
const int adapt_ref=prm.get_integer(
"No of adaptive refinements");
1436 * prm.leave_subsection ();
1437 * prm.enter_subsection (
"Algorithm Parameters");
1438 *
const int max_inner=prm.get_integer(
"Max_inner");
1439 *
const double eps=prm.get_double(
"eps");
1440 *
const double hi_eps=prm.get_double(
"hi_eps");
1441 *
const int hi_th=prm.get_integer(
"hi_th");
1442 *
const double init_p=prm.get_double(
"init_p");
1443 *
const double delta_p=prm.get_double(
"delta_p");
1444 * prm.leave_subsection ();
1445 * prm.enter_subsection (
"Global Parameters");
1446 *
bool known_solution=prm.get_bool(
"known_solution");
1447 *
double actual_p=prm.get_double(
"p");
1448 * prm.leave_subsection ();
1462 * initialize mesh
for the selected domain
1472 * setup_system (
true);
1473 * set_boundary_values ();
1482 *
int refinement = 0;
1491 *
bool well_solved=
true;
1495 *
while (p<actual_p)
1497 * std::cout <<
"--Preparing initial condition with p="<<p<<
" iter.= " << global_it<<
" .-- "<< std::endl;
1499 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1501 * assemble_system ();
1502 * well_solved=solve (inner_iteration);
1503 * print_it_message (global_it, known_solution);
1505 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-4) & (cycle<1)) |
1506 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-5) & (cycle>=1)) |
1511 * ptime=timer.cpu_time();
1513 * output_results (cycle);
1515 *
if (known_solution)
1517 * process_multiplier(cycle,global_it,ptime);
1520 * dual_convergence_table.write_tex(dual_error_table_file);
1543 * std::cout <<
"============ Solving problem with p=" <<p <<
" ==================" << std::endl;
1545 *
while ((cycle<adapt_ref) & well_solved)
1553 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1555 * assemble_system ();
1556 * well_solved=solve (inner_iteration);
1557 * print_it_message (global_it, known_solution);
1560 * ((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) < eps) & (refinement<hi_th)) |
1561 * (( system_rhs.l2_norm()/
std::sqrt (system_rhs.size()) <hi_eps) | (!well_solved))
1567 * inner iterations finished
1570 * ptime=timer.cpu_time();
1572 * output_results (cycle);
1576 * compute and display error,
if the
explicit solution is known
1579 *
if (known_solution)
1581 * process_multiplier(cycle,global_it,ptime);
1582 * std::cout <<
"finished with H1 error: " << H1_error <<
", dual error (L1): "
1583 * << dual_L1_error <<
"dual error (L infty): "<<dual_L_infty_error <<std::endl;
1598 * std::cout <<
"******** Refined mesh " << cycle <<
" ********" << std::endl;
1604 * write convergence tables to file
1607 *
if (known_solution)
1609 * format_convergence_tables();
1610 * std::string error_filename =
"error"+Method+elements+
".tex";
1611 * std::ofstream error_table_file(error_filename.c_str());
1612 * std::string dual_error_filename =
"dual_error"+Method+elements+
".tex";
1613 * std::ofstream dual_error_table_file(dual_error_filename.c_str());
1614 * convergence_table.write_tex(error_table_file);
1615 * dual_convergence_table.write_tex(dual_error_table_file);
1631 *
using namespace dealii;
1632 *
using namespace nsp;
1636 * ParameterReader param(prm);
1637 * param.read_parameters(
"EPT.prm");
1638 * ElastoplasticTorsion<2> ElastoplasticTorsionProblem(prm);
1639 * ElastoplasticTorsionProblem .run ();
1641 *
catch (std::exception &exc)
1643 * std::cerr << std::endl << std::endl
1644 * <<
"----------------------------------------------------" << std::endl;
1645 * std::cerr <<
"Exception on processing: " << std::endl
1646 * << exc.what() << std::endl
1647 * <<
"Aborting!" << std::endl
1648 * <<
"----------------------------------------------------"
1655 * std::cerr << std::endl << std::endl
1656 * <<
"----------------------------------------------------"
1658 * std::cerr <<
"Unknown exception!" << std::endl
1659 * <<
"Aborting!" << std::endl
1660 * <<
"----------------------------------------------------"
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())
unsigned int n_active_cells() const
void refine_global(const unsigned int times=1)
virtual void execute_coarsening_and_refinement() override
virtual bool prepare_coarsening_and_refinement() override
__global__ void set(Number *val, const Number s, const size_type N)
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 set_manifold(const types::manifold_id number, const Manifold< dim, spacedim > &manifold_object)
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