16 #ifndef _d2k_dof_utilities_h 17 #define _d2k_dof_utilities_h 19 #include <deal2lkit/config.h> 41 #ifdef DEAL_II_WITH_TRILINOS 45 typedef Sacado::Fad::DFad<double> Sdouble;
46 typedef Sacado::Fad::DFad<Sdouble> SSdouble;
57 template <
typename Number,
typename VEC>
60 const std::vector<types::global_dof_index> &local_dof_indices,
61 std::vector<Number> &independent_local_dofs)
63 AssertDimension(local_dof_indices.size(),independent_local_dofs.size());
65 const unsigned int dofs_per_cell = local_dof_indices.size();
67 for (
unsigned int i=0; i < dofs_per_cell; ++i)
69 if (
typeid(Number) ==
typeid(
double))
71 independent_local_dofs[i] = global_vector (local_dof_indices[i]);
73 #ifdef DEAL_II_WITH_TRILINOS 74 else if (
typeid(Number) ==
typeid(Sdouble))
76 Sdouble ildv(dofs_per_cell, i, global_vector (local_dof_indices[i]));
77 ((Sdouble &)independent_local_dofs[i]) = ildv;
79 else if (
typeid(Number) ==
typeid(SSdouble))
81 SSdouble ildv(dofs_per_cell, i, global_vector(local_dof_indices[i]));
82 ildv.val() = Sdouble(dofs_per_cell, i, global_vector(local_dof_indices[i]));
83 ((SSdouble &)independent_local_dofs[i]) = ildv;
100 template <
int dim,
int spacedim,
typename Number>
103 const std::vector<Number> &independent_local_dof_values,
104 std::vector <std::vector<Number> > &us)
109 const unsigned int n_components = fe_values.
get_fe().n_components();
113 AssertDimension(independent_local_dof_values.size(), dofs_per_cell);
115 for (
unsigned int q=0; q<n_q_points; ++q)
117 us[q] = std::vector<Number> (n_components,0.0);
118 for (
unsigned int i=0; i<dofs_per_cell; ++i)
119 for (
unsigned int j=0; j<n_components; ++j)
122 us[q][j] += independent_local_dof_values[i]*fe_values[s].value(i,q);
134 template <
int dim,
int spacedim,
typename Number>
138 const std::vector<Number> &independent_local_dof_values,
149 for (
unsigned int q=0; q<n_q_points; ++q)
152 for (
unsigned int i=0; i<dofs_per_cell; ++i)
153 if (fe_values[vector_variable].
value(i,q).norm() > 0.0)
154 for (
unsigned int j=0; j<spacedim; ++j)
155 us[q][j] += independent_local_dof_values[i]*fe_values[vector_variable].
value(i,q)[j];
166 template <
int dim,
int spacedim,
typename Number>
169 const std::vector<Number> &independent_local_dof_values,
171 std::vector <Number> &us)
180 for (
unsigned int q=0; q<n_q_points; ++q)
183 for (
unsigned int i=0; i<dofs_per_cell; ++i)
184 us[q] += independent_local_dof_values[i]*fe_values[scalar_variable].
value(i,q);
196 template <
int dim,
int spacedim,
typename Number>
199 const std::vector<Number> &independent_local_dof_values,
201 std::vector <Number> &us)
210 for (
unsigned int q=0; q<n_q_points; ++q)
213 for (
unsigned int i=0; i<dofs_per_cell; ++i)
214 us[q] += independent_local_dof_values[i]*fe_values[vector_variable].divergence(i,q);
226 template <
int dim,
int spacedim,
typename Number>
229 const std::vector<Number> &independent_local_dof_values,
240 for (
unsigned int q=0; q<n_q_points; ++q)
243 for (
unsigned int i=0; i<dofs_per_cell; ++i)
244 for (
unsigned int d=0;
d<spacedim; ++
d)
245 for (
unsigned int dd=0; dd<spacedim; ++dd)
246 grad_us[q][
d][dd] += independent_local_dof_values[i]*fe_values[vector_variable].gradient(i,q)[
d][dd];
259 template <
int dim,
int spacedim,
typename Number>
262 const std::vector<Number> &independent_local_dof_values,
264 std::vector <
Tensor <1, (spacedim > 2 ? spacedim : 1), Number> > &curl_us)
273 for (
unsigned int q=0; q<n_q_points; ++q)
276 for (
unsigned int i=0; i<dofs_per_cell; ++i)
278 auto c = fe_values[vector_variable].curl(i,q);
279 for (
unsigned int d=0; d<(spacedim > 2 ? spacedim : 1); ++
d)
280 curl_us[q][
d] += independent_local_dof_values[i]*c[
d];
294 template <
int dim,
int spacedim,
typename Number>
297 const std::vector<Number> &independent_local_dof_values,
308 for (
unsigned int q=0; q<n_q_points; ++q)
311 for (
unsigned int i=0; i<dofs_per_cell; ++i)
312 for (
unsigned int d=0;
d<spacedim; ++
d)
313 grad_us[q][
d] += independent_local_dof_values[i]*fe_values[scalar_variable].gradient(i,q)[
d];
326 template <
int dim,
int spacedim,
typename Number>
329 const std::vector<Number> &independent_local_dof_values,
339 for (
unsigned int q=0; q<n_q_points; ++q)
340 for (
unsigned int d=0;
d<dim; ++
d)
351 template <
int dim,
int spacedim,
typename Number>
354 const std::vector<Number> &independent_local_dof_values,
363 for (
unsigned int q=0; q<n_q_points; ++q)
365 grad_us[q] += transpose(grad_us[q]);
379 template <
int dim,
int spacedim,
typename Number>
383 const std::vector<Number> &independent_local_dof_values,
385 std::vector <Number> &us)
394 for (
unsigned int q=0; q<n_q_points; ++q)
397 for (
unsigned int i=0; i<dofs_per_cell; ++i)
398 us[q] += independent_local_dof_values[i]*trace(fe_values[variable].hessian(i,q));
410 template <
int dim,
int spacedim,
typename Number>
414 const std::vector<Number> &independent_local_dof_values,
425 for (
unsigned int d=0;
d<spacedim; ++
d)
426 for (
unsigned int q=0; q<n_q_points; ++q)
429 for (
unsigned int i=0; i<dofs_per_cell; ++i)
430 us[q][
d] += independent_local_dof_values[i]*trace(fe_values[variable].hessian(i,q)[
d]);
441 template <
int dim,
int spacedim,
typename Number>
445 const std::vector<Number> &independent_local_dof_values,
456 for (
unsigned int d=0;
d<spacedim; ++
d)
457 for (
unsigned int q=0; q<n_q_points; ++q)
460 for (
unsigned int i=0; i<dofs_per_cell; ++i)
461 us[q] += independent_local_dof_values[i]*fe_values[variable].hessian(i,q);
473 template <
int dim,
int spacedim,
typename Number>
477 const std::vector<Number> &independent_local_dof_values,
488 for (
unsigned int d=0;
d<spacedim; ++
d)
489 for (
unsigned int q=0; q<n_q_points; ++q)
492 for (
unsigned int i=0; i<dofs_per_cell; ++i)
493 us[q] += independent_local_dof_values[i]*fe_values[variable].hessian(i,q);
#define AssertDimension(dim1, dim2)
const unsigned int dofs_per_cell
Define namespace "DOFUtilities" some utilities aimed at solving non-linear problems are implemented...
void get_gradients(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Scalar &scalar_variable, std::vector< Tensor< 1, spacedim, Number > > &grad_us)
Extract gradient values of a scalar_variable on face of a cell and store them in std::vector <Tensor ...
void extract_local_dofs(const VEC &global_vector, const std::vector< types::global_dof_index > &local_dof_indices, std::vector< Number > &independent_local_dofs)
Extract local dofs values and initialize the number of independent variables up to the second order d...
void get_divergences(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &vector_variable, std::vector< Number > &us)
Extract divergence values of a vector_variable on face of a cell and store them in std::vector <Numbe...
void get_values(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Scalar &scalar_variable, std::vector< Number > &us)
Extract independent local dofs values of a scalar_variable in a cell and store them in std::vector <N...
#define Assert(cond, exc)
void get_deformation_gradients(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &vector_variable, std::vector< Tensor< 2, spacedim, Number > > &Fs)
Compute the deformation gradient in each quadrature point of a cell and it is stored in std::vector <...
void get_hessians(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &variable, std::vector< Tensor< 3, spacedim, Number > > &us)
Extract hessians local dofs values of a vector variable in a cell and store them in std::vector <Tens...
void get_symmetric_gradients(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &vector_variable, std::vector< Tensor< 2, spacedim, Number > > &grad_us)
Extract symmetric gradient values of a vector_variable on face of a cell and store them in std::vecto...
void get_curls(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &vector_variable, std::vector< Tensor< 1,(spacedim > 2 ? spacedim :1), Number > > &curl_us)
Extract curl values of a vector_variable on face or cell and store them in std::vector <Tensor <1...
void get_laplacians(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &variable, std::vector< Tensor< 1, spacedim, Number > > &us)
Extract laplacians local dofs values of a vector variable in a cell and store them in std::vector <Te...
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
const unsigned int n_quadrature_points
static::ExceptionBase & ExcNotImplemented()
const FiniteElement< dim, spacedim > & get_fe() const
void get_gradients(const FEValuesBase< dim, spacedim > &fe_values, const std::vector< Number > &independent_local_dof_values, const FEValuesExtractors::Vector &vector_variable, std::vector< Tensor< 2, spacedim, Number > > &grad_us)
Extract gradient values of a vector_variable on face of a cell and store them in std::vector <Tensor ...