From 609c6093e8478243dd8e8a3038c1969cccfc82a4 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 17 Apr 2018 22:16:28 +0200 Subject: [PATCH] Add FEEvaluation::gather_evaluate and integrate_scatter. --- include/deal.II/matrix_free/fe_evaluation.h | 160 ++++++++++++++++++-- 1 file changed, 149 insertions(+), 11 deletions(-) diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index bf3155f9db..c30dc9faf7 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -1981,26 +1981,99 @@ public: /** * Evaluates the function values, the gradients, and the Hessians of the - * FE function given at the DoF values in the input vector at the quadrature - * points on the unit cell. The function arguments specify which parts - * shall actually be computed. Needs to be called before the functions @p - * get_value(), @p get_gradient() or @p get_laplacian give useful - * information (unless these values have been set manually). + * polynomial interpolation from the DoF values in the input vector to the + * quadrature points on the unit cell. The function arguments specify which + * parts shall actually be computed. This function has to be called first so + * that the access functions @p get_value(), @p get_gradient() or @p + * get_laplacian give useful information (unless these values have been set + * manually). */ void evaluate (const bool evaluate_values, const bool evaluate_gradients, const bool evaluate_hessians = false); + /** + * Evaluates the function values, the gradients, and the Hessians of the + * polynomial interpolation from the DoF values in the input array @p + * values_array to the quadrature points on the unit cell. If multiple + * components are involved in the current FEEvaluation object, the sorting + * in @p values_array is such that all degrees of freedom for the first + * component come first, then all degrees of freedom for the second, and so + * on. The function arguments specify which parts shall actually be + * computed. This function has to be called first so that the access + * functions @p get_value(), @p get_gradient() or @p get_laplacian give + * useful information (unless these values have been set manually). + */ + void evaluate (const VectorizedArray *values_array, + const bool evaluate_values, + const bool evaluate_gradients, + const bool evaluate_hessians = false); + + /** + * Reads from the input vector and evaluates the function values, the + * gradients, and the Hessians of the polynomial interpolation of the vector + * entries from @p input_vector associated with the current cell to the + * quadrature points on the unit cell. The function arguments specify which + * parts shall actually be computed. This function has to be called first so + * that the access functions @p get_value(), @p get_gradient() or @p + * get_laplacian give useful information (unless these values have been set + * manually). + * + * This call is equivalent to calling read_dof_values() followed by + * evaluate(), but might internally use some additional optimizations. + */ + template + void gather_evaluate (const VectorType &input_vector, + const bool evaluate_values, + const bool evaluate_gradients, + const bool evaluate_hessians = false); + /** * This function takes the values and/or gradients that are stored on * quadrature points, tests them by all the basis functions/gradients on the * cell and performs the cell integration. The two function arguments - * @p integrate_values and @p integrate_gradients define which of the values - * or gradients (or both) are summed together. + * @p integrate_values and @p integrate_gradients are used to enable/disable + * summation of the contributions submitted to the values or gradients slots, + * respectively. The result is written into the internal data field + * @p dof_values (that is usually written into the result vector by the + * distribute_local_to_global() or set_dof_values() methods). */ void integrate (const bool integrate_values, const bool integrate_gradients); + /** + * This function takes the values and/or gradients that are stored on + * quadrature points, tests them by all the basis functions/gradients on the + * cell and performs the cell integration. The two function arguments @p + * integrate_values and @p integrate_gradients are used to enable/disable + * summation of the contributions submitted to the values or gradients + * slots, respectively. As opposed to the other integrate() method, this + * call stores the result of the testing in the given array @p values_array, + * whose previous results is overwritten, rather than writing it on the + * internal data structures behind begin_dof_values(). + */ + void integrate (const bool integrate_values, + const bool integrate_gradients, + VectorizedArray *values_array); + + /** + * This function takes the values and/or gradients that are stored on + * quadrature points, tests them by all the basis functions/gradients on the + * cell, performs the cell integration, and adds the result into the global + * vector @p output_vector on the degrees of freedom associated with the + * present cell index. The two function arguments @p integrate_values and + * @p integrate_gradients are used to enable/disable summation of the + * contributions submitted to the values or gradients slots, respectively. + * + * This call is equivalent to calling integrate() followed by + * distribute_local_to_global(), but might internally use + * some additional optimizations. + */ + template + void integrate_scatter (const bool integrate_values, + const bool integrate_gradients, + VectorType &output_vector); + /** * Return the q-th quadrature point stored in MappingInfo. */ @@ -5334,11 +5407,24 @@ FEEvaluation { Assert (this->dof_values_initialized == true, internal::ExcAccessToUninitializedField()); - Assert(this->matrix_info != nullptr || - this->mapped_geometry->is_initialized(), ExcNotInitialized()); + evaluate(this->values_dofs[0], evaluate_values, evaluate_gradients, evaluate_hessians); +} + + +template +inline +void +FEEvaluation +::evaluate (const VectorizedArray *values_array, + const bool evaluate_values, + const bool evaluate_gradients, + const bool evaluate_hessians) +{ SelectEvaluator > - ::evaluate (*this->data, this->values_dofs[0], this->values_quad[0], + ::evaluate (*this->data, const_cast*>(values_array), + this->values_quad[0], this->gradients_quad[0][0], this->hessians_quad[0][0], this->scratch_data, evaluate_values, evaluate_gradients, evaluate_hessians); @@ -5354,6 +5440,24 @@ FEEvaluation +template +template +inline +void +FEEvaluation +::gather_evaluate (const VectorType &input_vector, + const bool evaluate_values, + const bool evaluate_gradients, + const bool evaluate_hessians) +{ + this->read_dof_values(input_vector); + evaluate(this->begin_dof_values(), evaluate_values, evaluate_gradients, + evaluate_hessians); +} + + + template inline @@ -5361,6 +5465,24 @@ void FEEvaluation ::integrate (const bool integrate_values, const bool integrate_gradients) +{ + integrate(integrate_values, integrate_gradients, this->values_dofs[0]); + +#ifdef DEBUG + this->dof_values_initialized = true; +#endif +} + + + +template +inline +void +FEEvaluation +::integrate (const bool integrate_values, + const bool integrate_gradients, + VectorizedArray *values_array) { if (integrate_values == true) Assert (this->values_quad_submitted == true, @@ -5372,7 +5494,7 @@ FEEvaluation this->mapped_geometry->is_initialized(), ExcNotInitialized()); SelectEvaluator > - ::integrate (*this->data, this->values_dofs[0], this->values_quad[0], + ::integrate (*this->data, values_array, this->values_quad[0], this->gradients_quad[0][0], this->scratch_data, integrate_values, integrate_gradients); @@ -5383,6 +5505,22 @@ FEEvaluation +template +template +inline +void +FEEvaluation +::integrate_scatter (const bool integrate_values, + const bool integrate_gradients, + VectorType &destination) +{ + integrate(integrate_values, integrate_gradients, this->begin_dof_values()); + this->distribute_local_to_global(destination); +} + + + #endif // ifndef DOXYGEN -- 2.39.5