From 6fe5a8780a0bb5a8435b76d8dba1e9f87abb4a88 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 20 May 2008 04:03:43 +0000 Subject: [PATCH] Go on commenting. git-svn-id: https://svn.dealii.org/trunk@16131 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-33/step-33.cc | 135 ++++++++++++++++++---------- 1 file changed, 90 insertions(+), 45 deletions(-) diff --git a/deal.II/examples/step-33/step-33.cc b/deal.II/examples/step-33/step-33.cc index dcf0ea8529..2476946222 100644 --- a/deal.II/examples/step-33/step-33.cc +++ b/deal.II/examples/step-33/step-33.cc @@ -1936,60 +1936,105 @@ assemble_cell_term (const FEValues &fe_v, Table<2,double> W_old (n_q_points, EulerEquations::n_components); - std::vector,EulerEquations::n_components> > - W_theta (n_q_points); - + Table<2,Sacado::Fad::DFad > + W_theta (n_q_points, EulerEquations::n_components); + Table<3,Sacado::Fad::DFad > grad_W (n_q_points, EulerEquations::n_components, dim); - // We will define the dofs on this cell in - // these fad variables. + // Next, we have to define the independent + // variables that we will try to determine + // by solving a Newton step. These + // independent variables are the values of + // the local degrees of freedom which we + // extract here: std::vector > independent_local_dof_values(dofs_per_cell); + for (unsigned int i=0; i::n_components; di++) { - W[q][di] = 0; - W_old[q][di] = 0; - W_theta[q][di] = 0; - for (unsigned int d = 0; d < dim; d++) { - grad_W[q][di][d] = 0; + // The next step incorporates all the + // magic: we declare a subset of the + // autodifferentiation variables as + // independent degrees of freedom, whereas + // all the other ones remain dependent + // functions. These are precisely the local + // degrees of freedom just extracted. All + // calculations that reference them (either + // directly or indirectly) will accumulate + // sensitivies with respect to these + // variables. + // + // In order to mark the variables as + // independent, the following does the + // trick, marking + // independent_local_dof_values[i] + // as the $i$th independent variable out of + // a total of dofs_per_cell: + for (unsigned int i=0; iW, + // W_old, + // W_theta, and + // grad_W, which we can + // compute from the local DoF values by + // using the formula $W(x_q)=\sum_i \mathbf + // W_i \Phi_i(x_q)$, where $\mathbf W_i$ is + // the $i$th entry of the (local part of + // the) solution vector, and $\Phi_i(x_q)$ + // the value of the $i$th vector-valued + // shape function evaluated at quadrature + // point $x_q$. The gradient can be + // computed in a similar way. + // + // Ideally, we could compute this + // information using a call into something + // like FEValues::get_function_values and + // FEValues::get_function_grads, but since + // (i) we would have to extend the FEValues + // class for this, and (ii) we don't want + // to make the entire + // old_solution vector fad + // types, only the local cell variables, we + // explicitly code the loop above. Before + // this, we add another loop that + // initializes all the fad variables to + // zero: + for (unsigned int q=0; q::n_components; ++c) + { + W[q][c] = 0; + W_old[q][c] = 0; + W_theta[q][c] = 0; + for (unsigned int d=0; d