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/observer_pointer.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(
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):
534 *
dof_handler (triangulation),
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)
650 *
Vector<float> difference_per_cell (triangulation.n_active_cells());
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)
701 *
const unsigned int n_active_cells=triangulation.n_active_cells();
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> *>;
909 *
Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
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);
924 *
triangulation.prepare_coarsening_and_refinement ();
926 *
solution_transfer.prepare_for_coarsening_and_refinement(present_solution);
927 *
triangulation.execute_coarsening_and_refinement();
928 *
dof_handler.distribute_dofs(fe);
929 *
present_solution.reinit(dof_handler.n_dofs());
930 *
solution_transfer.interpolate(present_solution);
931 *
set_boundary_values ();
932 *
hanging_node_constraints.clear();
935 *
hanging_node_constraints);
936 *
hanging_node_constraints.close();
937 *
hanging_node_constraints.distribute (present_solution);
938 *
setup_system (
false);
945 * Dump the
norm of the
gradient and the lagrange multiplier in
vtu format
for visualization
949 *
void ElastoplasticTorsion<dim>::output_results (
unsigned int counter)
const
953 * multiplier
object contains both |Du| and
lambda.
956 *
ComputeMultiplier<dim> multiplier(p);
960 *
data_out.add_data_vector (present_solution,
"solution");
961 *
data_out.add_data_vector (present_solution, multiplier);
962 *
data_out.build_patches ();
963 *
std::ostringstream p_str;
964 *
p_str << p<<
"-cycle-"<<counter;
965 *
std::string str = p_str.str();
966 *
const std::string filename =
"solution-" + str+
".vtu";
967 *
std::ofstream output (filename.c_str());
968 *
data_out.write_vtu (output);
974 * unchanged from @ref step_15
"step-15"
978 *
void ElastoplasticTorsion<dim>::set_boundary_values ()
980 *
std::map<types::global_dof_index, double> boundary_values;
983 *
BoundaryValues<dim>(),
985 *
for (std::map<types::global_dof_index, double>::const_iterator
986 *
bp = boundary_values.begin();
987 *
bp != boundary_values.end(); ++bp)
988 *
present_solution(bp->first) = bp->second;
995 * COMPUTE @f$\phi(\alpha)=J_p(u_h+\alpha w)@f$
999 *
double ElastoplasticTorsion<dim>::phi (
const double alpha)
const
1002 *
const RightHandSide<dim> right_hand_side;
1004 *
evaluation_point = present_solution;
1005 *
evaluation_point.add (alpha, newton_update);
1014 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1015 *
const unsigned int n_q_points = quadrature_formula.size();
1018 *
std::vector<Tensor<1, dim> >
gradients(n_q_points);
1019 *
std::vector<double>
values(n_q_points);
1022 *
std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1025 *
cell = dof_handler.begin_active(),
1026 *
endc = dof_handler.end();
1027 *
for (; cell!=endc; ++cell)
1030 *
fe_values.reinit (cell);
1031 *
fe_values.get_function_gradients (evaluation_point, gradients);
1032 *
fe_values.get_function_values (evaluation_point, values);
1035 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1046 * obj+= 1/2 W(|Du|^2)+1/p |Du|^p -fu (see (1))
1050 *
(0.5*W(Du2)+penalty/p)- right_hand_side.value(fe_values.quadrature_point(q_point))*
values[q_point]
1051 *
) * fe_values.JxW(q_point);
1063 * Compute
L^1 error
norm of Lagrange Multiplier
1064 * with respect to exact solution (
cf. Alvarez & Flores, 2015)
1070 *
template <
int dim>
1071 *
double ElastoplasticTorsion<dim>::dual_error () const
1081 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1082 *
const unsigned int n_q_points = quadrature_formula.size();
1085 *
std::vector<Tensor<1, dim> >
gradients(n_q_points);
1087 *
std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1090 *
cell = dof_handler.begin_active(),
1091 *
endc = dof_handler.end();
1092 *
for (; cell!=endc; ++cell)
1095 *
fe_values.reinit (cell);
1096 *
fe_values.get_function_gradients (present_solution, gradients);
1098 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1101 *
if (coeff<1.0e-15)
1104 *
coeff=
std::pow(coeff,(p-2.0)/2.0);
1106 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1111 *
obj+=(
std::abs(coeff-exact) ) * fe_values.JxW(q_point);
1122 * Compute
L^infinity error
norm of Lagrange Multiplier
1123 * with respect to exact solution (
cf. Alvarez & Flores, 2015)
1129 *
template <
int dim>
1130 *
double ElastoplasticTorsion<dim>::dual_infty_error () const
1140 *
const unsigned int dofs_per_cell = fe.dofs_per_cell;
1141 *
const unsigned int n_q_points = quadrature_formula.size();
1144 *
std::vector<Tensor<1, dim> >
gradients(n_q_points);
1146 *
std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1149 *
cell = dof_handler.begin_active(),
1150 *
endc = dof_handler.end();
1151 *
for (; cell!=endc; ++cell)
1154 *
fe_values.reinit (cell);
1155 *
fe_values.get_function_gradients (present_solution, gradients);
1157 *
for (
unsigned int q_point=0; q_point<n_q_points; ++q_point)
1160 *
double r=
std::sqrt(fe_values.quadrature_point(q_point).square());
1166 * compute |Du|^(p-2) as
exp(p-2/2*
log(Du^2))
1169 *
long double exponent=(p-2.0)/2*
std::log(sqdGrad);
1170 *
long double coeff=
std::exp(exponent);
1184 *
check whether putative step-length satisfies sufficient decrease conditions
1187 *
template <
int dim>
1188 *
bool ElastoplasticTorsion<dim>::checkWolfe(
double &alpha,
double &phi_alpha)
const
1190 *
if (phi_alpha< phi_zero+line_search_tolerence*phip*alpha )
1200 * Find a step-length satisfying sufficient decrease condition by line-search
1201 * uses quadratic interpolation
1207 *
template <
int dim>
1208 *
bool ElastoplasticTorsion<dim>::determine_step_length(
const int inner_it)
1210 *
unsigned int it=0;
1212 *
double alpha,nalpha;
1213 *
prm.enter_subsection (
"Algorithm Parameters");
1214 *
const unsigned int max_LS_it=prm.get_integer(
"max_LS_it");
1215 *
double init_SL=prm.get_double(
"init_step_length");
1216 *
prm.leave_subsection ();
1221 *
alpha=
std::min(1.45*old_step*old_phip/phip,1.0);
1223 *
phi_alpha=phi(alpha);
1224 *
std::cerr <<
"Step length=" << alpha <<
", Value= " << phi_alpha;
1227 *
check if step-
size satisfies sufficient decrease condition
1230 *
done=checkWolfe(alpha,phi_alpha);
1232 *
std::cerr <<
" accepted" << std::endl;
1234 *
std::cerr <<
" rejected" ;
1236 *
while ((!done) & (it<max_LS_it))
1240 *
new try obtained by quadratic interpolation
1243 *
nalpha=-(phip*alpha*alpha)/(2*(phi_alpha-phi_zero-phip*alpha));
1245 *
if (nalpha<1e-3*alpha ||
std::abs(nalpha-alpha)/alpha<1
e-8)
1247 *
else if ( phi_alpha-phi_zero>1e3*
std::abs(phi_zero) )
1250 *
phi_alpha=phi(alpha);
1251 *
done=checkWolfe(alpha,phi_alpha);
1253 *
std::cerr <<
", finished with steplength= "<< alpha<<
", fcn value= "<< phi_alpha<<std::endl;
1258 *
std::cerr <<
", max. no. of iterations reached with steplength= "<< alpha
1259 *
<<
", fcn value= "<< phi_alpha<<std::endl;
1264 *
step_length=alpha;
1273 * ElastoplasticTorsion::init_mesh()
1279 *
template <
int dim>
1280 *
void ElastoplasticTorsion<dim>::init_mesh ()
1287 *
prm.enter_subsection (
"Mesh & Refinement Parameters");
1288 *
const int domain_id=prm.get_integer(
"Code for the domain");
1289 *
const int init_ref=prm.get_integer(
"No of initial refinements");
1290 *
prm.leave_subsection ();
1297 * For the unit disk around the origin
1302 *
triangulation.set_manifold (0, boundary);
1304 *
else if (domain_id==1)
1308 * For the unit square
1313 *
else if (domain_id==2)
1347 *
triangulation.refine_global(init_ref);
1353 * ElastoplasticTorsion::solve(inner_it)
1354 * Performs
one inner iteration
1360 *
template <
int dim>
1361 *
bool ElastoplasticTorsion<dim>::solve (
const int inner_it)
1363 *
prm.enter_subsection (
"Algorithm Parameters");
1364 *
const unsigned int max_CG_it=prm.get_integer(
"Max_CG_it");
1365 *
const double CG_tol=prm.get_double(
"CG_tol");
1366 *
prm.leave_subsection ();
1372 *
preconditioner.
initialize(system_matrix,0.25);
1374 *
solver.solve (system_matrix, newton_update, system_rhs,
1376 *
hanging_node_constraints.distribute (newton_update);
1380 * Recall that phi(alpha)=
J(u+alpha w)
1383 *
old_step=step_length;
1384 *
old_phi_zero=phi_zero;
1387 *
phip=-1.0*(newton_update*system_rhs);
1393 *
std::cout <<
"Not a descent direction!" <<std::endl;
1394 *
present_solution.add (-1.0*step_length, newton_update);
1395 *
step_length=step_length/2;
1401 *
if (determine_step_length(inner_it))
1405 * update u_{n+1}=u_n+alpha w_n
1408 *
present_solution.add (step_length, newton_update);
1411 *
else return false;
1420 * ElastoplasticTorsion::run
1423 *
template <
int dim>
1424 *
void ElastoplasticTorsion<dim>::run ()
1432 *
prm.enter_subsection (
"Mesh & Refinement Parameters");
1433 *
const int adapt_ref=prm.get_integer(
"No of adaptive refinements");
1434 *
prm.leave_subsection ();
1435 *
prm.enter_subsection (
"Algorithm Parameters");
1436 *
const int max_inner=prm.get_integer(
"Max_inner");
1437 *
const double eps=prm.get_double(
"eps");
1438 *
const double hi_eps=prm.get_double(
"hi_eps");
1439 *
const int hi_th=prm.get_integer(
"hi_th");
1440 *
const double init_p=prm.get_double(
"init_p");
1441 *
const double delta_p=prm.get_double(
"delta_p");
1442 *
prm.leave_subsection ();
1443 *
prm.enter_subsection (
"Global Parameters");
1444 *
bool known_solution=prm.get_bool(
"known_solution");
1445 *
double actual_p=prm.get_double(
"p");
1446 *
prm.leave_subsection ();
1460 * initialize mesh
for the selected domain
1470 *
setup_system (
true);
1471 *
set_boundary_values ();
1480 *
int refinement = 0;
1489 *
bool well_solved=
true;
1493 *
while (p<actual_p)
1495 *
std::cout <<
"--Preparing initial condition with p="<<p<<
" iter.= " << global_it<<
" .-- "<< std::endl;
1497 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1499 *
assemble_system ();
1500 *
well_solved=solve (inner_iteration);
1501 *
print_it_message (global_it, known_solution);
1503 *
((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-4) & (cycle<1)) |
1504 *
((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) <1e-5) & (cycle>=1)) |
1509 *
ptime=timer.cpu_time();
1511 *
output_results (cycle);
1513 *
if (known_solution)
1515 *
process_multiplier(cycle,global_it,ptime);
1518 * dual_convergence_table.write_tex(dual_error_table_file);
1541 *
std::cout <<
"============ Solving problem with p=" <<p <<
" ==================" << std::endl;
1543 *
while ((cycle<adapt_ref) & well_solved)
1551 *
for (
int inner_iteration=0; inner_iteration<max_inner; ++inner_iteration,++global_it)
1553 *
assemble_system ();
1554 *
well_solved=solve (inner_iteration);
1555 *
print_it_message (global_it, known_solution);
1558 *
((system_rhs.l2_norm()/
std::sqrt(system_rhs.size()) < eps) & (refinement<hi_th)) |
1559 *
(( system_rhs.l2_norm()/
std::sqrt (system_rhs.size()) <hi_eps) | (!well_solved))
1565 * inner iterations finished
1568 *
ptime=timer.cpu_time();
1570 *
output_results (cycle);
1574 * compute and display error,
if the
explicit solution is known
1577 *
if (known_solution)
1579 *
process_multiplier(cycle,global_it,ptime);
1580 *
std::cout <<
"finished with H1 error: " << H1_error <<
", dual error (L1): "
1581 *
<< dual_L1_error <<
"dual error (L infty): "<<dual_L_infty_error <<std::endl;
1596 *
std::cout <<
"******** Refined mesh " << cycle <<
" ********" << std::endl;
1602 * write convergence tables to file
1605 *
if (known_solution)
1607 *
format_convergence_tables();
1608 *
std::string error_filename =
"error"+Method+elements+
".tex";
1609 *
std::ofstream error_table_file(error_filename.c_str());
1610 *
std::string dual_error_filename =
"dual_error"+Method+elements+
".tex";
1611 *
std::ofstream dual_error_table_file(dual_error_filename.c_str());
1612 *
convergence_table.write_tex(error_table_file);
1613 *
dual_convergence_table.write_tex(dual_error_table_file);
1629 *
using namespace dealii;
1630 *
using namespace nsp;
1634 *
ParameterReader param(prm);
1635 *
param.read_parameters(
"EPT.prm");
1636 *
ElastoplasticTorsion<2> ElastoplasticTorsionProblem(prm);
1637 *
ElastoplasticTorsionProblem .run ();
1639 *
catch (std::exception &exc)
1641 *
std::cerr << std::endl << std::endl
1642 *
<<
"----------------------------------------------------" << std::endl;
1643 *
std::cerr <<
"Exception on processing: " << std::endl
1644 *
<< exc.what() << std::endl
1645 *
<<
"Aborting!" << std::endl
1646 *
<<
"----------------------------------------------------"
1653 *
std::cerr << std::endl << std::endl
1654 *
<<
"----------------------------------------------------"
1656 *
std::cerr <<
"Unknown exception!" << std::endl
1657 *
<<
"Aborting!" << std::endl
1658 *
<<
"----------------------------------------------------"
* * for(const auto &cell :triangulation.active_cell_iterators())
* * int main(int argc, char **argv)
* x_component_mask set(0, true)
* * * struct InterferenceTaperTransform *
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())
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_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void hyper_ball(Triangulation< dim, spacedim > &tria, const Point< spacedim > ¢er={}, const double radius=1., const bool attach_spherical_manifold_on_boundary_cells=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())
constexpr types::blas_int one
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)
* * * * std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters const
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 > &)