3 #include "../../include/matrixFreePDE.h" 4 #include <deal.II/lac/solver_cg.h> 7 template <
int dim,
int degree>
11 computing_timer.enter_section(
"matrixFreePDE: setNonlinearEqInitialGuess");
15 for(
unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
16 if ( (userInputs.var_eq_type[fieldIndex] ==
TIME_INDEPENDENT) && userInputs.var_nonlinear[fieldIndex] && userInputs.nonlinear_solver_parameters.getLaplaceInitializationFlag(fieldIndex)){
17 currentFieldIndex = fieldIndex;
19 computeLaplaceRHS(fieldIndex);
21 for (std::map<types::global_dof_index, double>::const_iterator it=valuesDirichletSet[fieldIndex]->begin(); it!=valuesDirichletSet[fieldIndex]->end(); ++it){
22 if (residualSet[fieldIndex]->in_local_range(it->first)){
23 (*residualSet[fieldIndex])(it->first) = 0.0;
29 if (userInputs.linear_solver_parameters.getToleranceType(fieldIndex) ==
ABSOLUTE_RESIDUAL){
30 tol_value = userInputs.linear_solver_parameters.getToleranceValue(fieldIndex);
33 tol_value = userInputs.linear_solver_parameters.getToleranceValue(fieldIndex)*residualSet[fieldIndex]->l2_norm();
36 SolverControl solver_control(userInputs.linear_solver_parameters.getMaxIterations(fieldIndex), tol_value);
39 SolverCG<vectorType> solver(solver_control);
43 if (fields[fieldIndex].type ==
SCALAR){
45 solver.solve(*
this, dU_scalar, *residualSet[fieldIndex], IdentityMatrix(solutionSet[fieldIndex]->size()));
49 solver.solve(*
this, dU_vector, *residualSet[fieldIndex], IdentityMatrix(solutionSet[fieldIndex]->size()));
53 pcout <<
"\nWarning: implicit solver did not converge as per set tolerances. consider increasing maxSolverIterations or decreasing solverTolerance.\n";
56 if (fields[fieldIndex].type ==
SCALAR){
57 *solutionSet[fieldIndex] += dU_scalar;
60 *solutionSet[fieldIndex] += dU_vector;
63 if (currentIncrement%userInputs.skip_print_steps==0){
65 if (fields[fieldIndex].type ==
SCALAR){
66 dU_norm = dU_scalar.l2_norm();
69 dU_norm = dU_vector.l2_norm();
71 sprintf(buffer,
"field '%2s' [laplace solve for initial guess]: initial residual:%12.6e, current residual:%12.6e, nsteps:%u, tolerance criterion:%12.6e, solution: %12.6e, dU: %12.6e\n", \
72 fields[fieldIndex].name.c_str(), \
73 residualSet[fieldIndex]->l2_norm(), \
74 solver_control.last_value(), \
75 solver_control.last_step(), solver_control.tolerance(), solutionSet[fieldIndex]->l2_norm(), dU_norm);
84 if (currentIncrement%userInputs.skip_print_steps==0){
85 pcout <<
"wall time: " << time.wall_time() <<
"s\n";
88 computing_timer.exit_section(
"matrixFreePDE: setNonlinearEqInitialGuess");
92 template <
int dim,
int degree>
95 computing_timer.enter_section(
"matrixFreePDE: computeLaplaceRHS");
98 (*residualSet[fieldIndex])=0.0;
105 computing_timer.exit_section(
"matrixFreePDE: computeLaplaceRHS");
108 template <
int dim,
int degree>
112 const std::pair<unsigned int,unsigned int> &cell_range)
const{
114 FEEvaluation<dim,degree> mat(data);
116 for (
unsigned int cell=cell_range.first; cell<cell_range.second; ++cell)
119 mat.read_dof_values(src);
120 mat.evaluate (
false,
true,
false);
121 for (
unsigned int q=0; q<mat.n_q_points; ++q){
122 mat.submit_gradient(mat.get_gradient(q),q);
124 mat.integrate (
false,
true);
125 mat.distribute_local_to_global (dst);
130 template <
int dim,
int degree>
134 const std::pair<unsigned int,unsigned int> &cell_range)
const{
136 FEEvaluation<dim,degree> mat(data);
138 for (
unsigned int cell=cell_range.first; cell<cell_range.second; ++cell)
141 mat.read_dof_values(src);
142 mat.evaluate (
false,
true,
false);
143 for (
unsigned int q=0; q<mat.n_q_points; ++q){
144 mat.submit_gradient(-mat.get_gradient(q),q);
146 mat.integrate (
false,
true);
147 mat.distribute_local_to_global (dst);
151 #include "../../include/matrixFreePDE_template_instantiations.h"
void getLaplaceRHS(const MatrixFree< dim, double > &data, vectorType &dst, const vectorType &src, const std::pair< unsigned int, unsigned int > &cell_range) const
void setNonlinearEqInitialGuess()
void computeLaplaceRHS(unsigned int fieldIndex)
void getLaplaceLHS(const MatrixFree< dim, double > &data, vectorType &dst, const vectorType &src, const std::pair< unsigned int, unsigned int > &cell_range) const
dealii::parallel::distributed::Vector< double > vectorType