From 955fa75822b6bd16f7d559f7f0744792aaa279f4 Mon Sep 17 00:00:00 2001 From: Fabian Castelli Date: Thu, 20 May 2021 15:09:32 +0200 Subject: [PATCH] Indent intro code snippets --- examples/step-66/doc/intro.dox | 125 ++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 58 deletions(-) diff --git a/examples/step-66/doc/intro.dox b/examples/step-66/doc/intro.dox index 01718b44d8..61c5581c41 100644 --- a/examples/step-66/doc/intro.dox +++ b/examples/step-66/doc/intro.dox @@ -130,15 +130,15 @@ use of the member functions FEValuesBase::get_function_values() and FEValuesBase::get_function_gradients(). The assemble_system() function would then looks like: @code -template -void -GelfandProblem::assemble_system() +template +void GelfandProblem::assemble_system() { system_matrix = 0; system_rhs = 0; - const QGauss quadrature_formula(fe.degree+1); - FEValues fe_values(fe, quadrature_formula, + const QGauss quadrature_formula(fe.degree + 1); + FEValues fe_values(fe, + quadrature_formula, update_values | update_gradients | update_JxW_values); const unsigned int n_q_points = fe_values.n_quadrature_points; @@ -148,49 +148,51 @@ GelfandProblem::assemble_system() Vector cell_rhs(dofs_per_cell); std::vector local_dof_indices(dofs_per_cell); - std::vector > newton_step_gradients(n_q_points); + std::vector> newton_step_gradients(n_q_points); std::vector newton_step_values(n_q_points); - for(const auto &cell : dof_handler.active_cell_iterators()) - { - cell_matrix = 0.0; - cell_rhs = 0.0; + for (const auto &cell : dof_handler.active_cell_iterators()) + { + cell_matrix = 0.0; + cell_rhs = 0.0; - fe_values.reinit(cell); + fe_values.reinit(cell); - fe_values.get_function_values(solution, newton_step_values); - fe_values.get_function_gradients(solution, newton_step_gradients); + fe_values.get_function_values(solution, newton_step_values); + fe_values.get_function_gradients(solution, newton_step_gradients); - for(unsigned int q=0; q grad_phi_i = fe_values.shape_grad(i,q); - for(unsigned int j=0; j grad_phi_j = fe_values.shape_grad(j,q); - - cell_matrix(i,j) += ( grad_phi_i*grad_phi_j - phi_i*nonlinearity*phi_j ) * dx; + const double nonlinearity = std::exp(newton_step_values[q]); + const double dx = fe_values.JxW(q); + + for (unsigned int i = 0; i < dofs_per_cell; ++i) + { + const double phi_i = fe_values.shape_value(i, q); + const Tensor<1, dim> grad_phi_i = fe_values.shape_grad(i, q); + + for (unsigned int j = 0; j < dofs_per_cell; ++j) + { + const double phi_j = fe_values.shape_value(j, q); + const Tensor<1, dim> grad_phi_j = fe_values.shape_grad(j, q); + + cell_matrix(i, j) += + (grad_phi_i * grad_phi_j - phi_i * nonlinearity * phi_j) * + dx; + } + + cell_rhs(i) += (-grad_phi_i * newton_step_gradients[q] + + phi_i * newton_step_values[q]) * + dx; + } } - cell_rhs(i) += ( -grad_phi_i*newton_step_gradients[q] + phi_i*newton_step_values[q] ) * dx; + cell->get_dof_indices(local_dof_indices); - } + constraints.distribute_local_to_global( + cell_matrix, cell_rhs, local_dof_indices, system_matrix, system_rhs); } - - cell->get_dof_indices(local_dof_indices); - - constraints.distribute_local_to_global(cell_matrix, cell_rhs, - local_dof_indices, - system_matrix, system_rhs); - - } - } @endcode @@ -206,28 +208,31 @@ the vector containing the last Newton step has to be interpolated to all levels of the triangulation. In the code this task will be done by the function MGTransferMatrixFree::interpolate_to_mg(): @code -void -GelfandProblem::compute_update() +template +void GelfandProblem::compute_update() { + TimerOutput::Scope t(computing_timer, "compute update"); + solution.update_ghost_values(); system_matrix.evaluate_newton_step(solution); - MGTransferMatrixFree mg_transfer(mg_constrained_dofs); - mg_transfer.interpolate_to_mg(dof_handler, mg_solution, solution); + // Set up options for the multilevel preconditioner - for(unsigned int level=0; levelevaluate_coefficient from step-37 evaluating a coefficient function. The idea is to use an FEEvaluation object to evaluate the Newton step and store the expression in a table for all cells and all quadrature points: @code -void -JacobianOperator::evaluate_newton_step(const LinearAlgebra::distributed::Vector &src) +template +void JacobianOperator::evaluate_newton_step( + const LinearAlgebra::distributed::Vector &newton_step) { const unsigned int n_cells = this->data->n_cell_batches(); - FEEvaluation phi(*this->data); + + FEEvaluation phi(*this->data); nonlinear_values.reinit(n_cells, phi.n_q_points); - for(unsigned int cell=0; cell