Skip to content

Commit

Permalink
Use inverse shape values for inverse mass operation
Browse files Browse the repository at this point in the history
  • Loading branch information
kronbichler committed Dec 9, 2019
1 parent dd934be commit b8421de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
27 changes: 15 additions & 12 deletions include/deal.II/matrix_free/evaluation_kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,9 @@ namespace internal



/**
* This struct implements the action of the inverse mass matrix operation
*/
template <int dim, int fe_degree, int n_components, typename Number>
struct CellwiseInverseMassMatrixImpl
{
Expand Down Expand Up @@ -3078,30 +3081,30 @@ namespace internal
Number * out = out_array + d * dofs_per_component;
// Need to select 'apply' method with hessian slot because values
// assume symmetries that do not exist in the inverse shapes
evaluator.template hessians<0, false, false>(in, out);
evaluator.template hessians<0, true, false>(in, out);
if (dim > 1)
{
evaluator.template hessians<1, false, false>(out, out);
evaluator.template hessians<1, true, false>(out, out);

if (dim == 3)
{
evaluator.template hessians<2, false, false>(out, out);
evaluator.template hessians<2, true, false>(out, out);
for (unsigned int q = 0; q < dofs_per_component; ++q)
out[q] *= inv_coefficient[q];
evaluator.template hessians<2, true, false>(out, out);
evaluator.template hessians<2, false, false>(out, out);
}
else if (dim == 2)
for (unsigned int q = 0; q < dofs_per_component; ++q)
out[q] *= inv_coefficient[q];

evaluator.template hessians<1, true, false>(out, out);
evaluator.template hessians<1, false, false>(out, out);
}
else
{
for (unsigned int q = 0; q < dofs_per_component; ++q)
out[q] *= inv_coefficient[q];
}
evaluator.template hessians<0, true, false>(out, out);
evaluator.template hessians<0, false, false>(out, out);

inv_coefficient += shift_coefficient;
}
Expand Down Expand Up @@ -3130,17 +3133,17 @@ namespace internal

if (dim == 3)
{
evaluator.template hessians<2, true, false>(in, out);
evaluator.template hessians<1, true, false>(out, out);
evaluator.template hessians<0, true, false>(out, out);
evaluator.template hessians<2, false, false>(in, out);
evaluator.template hessians<1, false, false>(out, out);
evaluator.template hessians<0, false, false>(out, out);
}
if (dim == 2)
{
evaluator.template hessians<1, true, false>(in, out);
evaluator.template hessians<0, true, false>(out, out);
evaluator.template hessians<1, false, false>(in, out);
evaluator.template hessians<0, false, false>(out, out);
}
if (dim == 1)
evaluator.template hessians<0, true, false>(in, out);
evaluator.template hessians<0, false, false>(in, out);
}
}
};
Expand Down
53 changes: 15 additions & 38 deletions include/deal.II/matrix_free/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,6 @@ namespace MatrixFreeOperators
Number,
false,
VectorizedArrayType> &fe_eval;

/**
* A structure to hold inverse shape functions
*/
AlignedVector<VectorizedArrayType> inverse_shape;
};


Expand Down Expand Up @@ -958,26 +953,7 @@ namespace MatrixFreeOperators
false,
VectorizedArrayType> &fe_eval)
: fe_eval(fe_eval)
{
FullMatrix<double> shapes_1d(fe_degree + 1, fe_degree + 1);
for (unsigned int i = 0, c = 0; i < shapes_1d.m(); ++i)
for (unsigned int j = 0; j < shapes_1d.n(); ++j, ++c)
shapes_1d(i, j) = fe_eval.get_shape_info().shape_values[c][0];
shapes_1d.gauss_jordan();
const unsigned int stride = (fe_degree + 2) / 2;
inverse_shape.resize(stride * (fe_degree + 1));
for (unsigned int i = 0; i < stride; ++i)
for (unsigned int q = 0; q < (fe_degree + 2) / 2; ++q)
{
inverse_shape[i * stride + q] =
0.5 * (shapes_1d(i, q) + shapes_1d(i, fe_degree - q));
inverse_shape[(fe_degree - i) * stride + q] =
0.5 * (shapes_1d(i, q) - shapes_1d(i, fe_degree - q));
}
if (fe_degree % 2 == 0)
for (unsigned int q = 0; q < (fe_degree + 2) / 2; ++q)
inverse_shape[fe_degree / 2 * stride + q] = shapes_1d(fe_degree / 2, q);
}
{}



Expand Down Expand Up @@ -1030,15 +1006,15 @@ namespace MatrixFreeOperators
const VectorizedArrayType * in_array,
VectorizedArrayType * out_array) const
{
internal::CellwiseInverseMassMatrixImpl<
dim,
fe_degree,
n_components,
VectorizedArrayType>::apply(inverse_shape,
inverse_coefficients,
n_actual_components,
in_array,
out_array);
internal::CellwiseInverseMassMatrixImpl<dim,
fe_degree,
n_components,
VectorizedArrayType>::
apply(fe_eval.get_shape_info().inverse_shape_values_eo,
inverse_coefficients,
n_actual_components,
in_array,
out_array);
}


Expand All @@ -1062,10 +1038,11 @@ namespace MatrixFreeOperators
fe_degree,
n_components,
VectorizedArrayType>::
transform_from_q_points_to_basis(inverse_shape,
n_actual_components,
in_array,
out_array);
transform_from_q_points_to_basis(
fe_eval.get_shape_info().inverse_shape_values_eo,
n_actual_components,
in_array,
out_array);
}


Expand Down

0 comments on commit b8421de

Please sign in to comment.