Skip to content

Commit

Permalink
Vectorize MappingInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bergbauer committed May 2, 2023
1 parent 09cb141 commit 0f1cad6
Show file tree
Hide file tree
Showing 9 changed files with 1,267 additions and 852 deletions.
20 changes: 20 additions & 0 deletions include/deal.II/base/derivative_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class DerivativeForm
DerivativeForm &
operator=(const Tensor<1, dim, Number> &);

/**
* Number conversion operator.
*/
template <typename OtherNumber>
DerivativeForm &
operator=(const DerivativeForm<order, dim, spacedim, OtherNumber> &df);

/**
* Converts a DerivativeForm <order, dim, dim, Number> to Tensor<order+1, dim,
* Number>. In particular, if order == 1 and the derivative is the Jacobian of
Expand Down Expand Up @@ -252,6 +259,19 @@ DerivativeForm<order, dim, spacedim, Number>::operator=(



template <int order, int dim, int spacedim, typename Number>
template <typename OtherNumber>
inline DerivativeForm<order, dim, spacedim, Number> &
DerivativeForm<order, dim, spacedim, Number>::operator=(
const DerivativeForm<order, dim, spacedim, OtherNumber> &df)
{
for (unsigned int j = 0; j < spacedim; ++j)
(*this)[j] = df[j];
return *this;
}



template <int order, int dim, int spacedim, typename Number>
inline Tensor<order, dim, Number> &
DerivativeForm<order, dim, spacedim, Number>::operator[](const unsigned int i)
Expand Down
129 changes: 115 additions & 14 deletions include/deal.II/base/vectorization.h
Original file line number Diff line number Diff line change
Expand Up @@ -5478,49 +5478,150 @@ namespace internal
template <typename T>
struct VectorizedArrayTrait
{
using value_type = T;
/**
* Define scalar value type.
*/
using value_type = T;

/**
* Define width of template type.
*/
static constexpr std::size_t width = 1;

static T &
get(T &value, unsigned int c)
/**
* Define vectorized value type for internal vectorization.
*/
using vectorized_value_type = VectorizedArray<T>;

/**
* Define a stride which defines how often the template type T fits into the
* vectorized_value_type. This is useful to write vectorized templated code
* where the internal computation is vectorized and the user interface is
* optionally scalar or also vectorized.
*/
static constexpr std::size_t stride = vectorized_value_type::size();

/**
* Get a reference to scalar value (on lane 0).
*/
static value_type &
get(value_type &value, unsigned int c)
{
AssertDimension(c, 0);
AssertIndexRange(c, width);
(void)c;

return value;
}

static const T &
get(const T &value, unsigned int c)
/**
* Get a read-only reference to scalar value (on lane 0).
*/
static const value_type &
get(const value_type &value, unsigned int c)
{
AssertDimension(c, 0);
AssertIndexRange(c, width);
(void)c;

return value;
}

/**
* Get a reference to scalar value on lane c from a vectorized values field.
*/
static value_type &
get_from_vectorized(vectorized_value_type &values, unsigned int c)
{
AssertIndexRange(c, stride);

return values[c];
}

/**
* Get a read-only reference to scalar value on lane c from a vectorized
* values field.
*/
static const value_type &
get_from_vectorized(const vectorized_value_type &values, unsigned int c)
{
AssertIndexRange(c, stride);

return values[c];
}
};

template <typename T, std::size_t width_>
struct VectorizedArrayTrait<VectorizedArray<T, width_>>
{
using value_type = T;
/**
* Define scalar value type.
*/
using value_type = T;

/**
* Define width of template type.
*/
static constexpr std::size_t width = width_;

static T &
get(VectorizedArray<T, width_> &values, unsigned int c)
/**
* Define vectorized value type for internal vectorization.
*/
using vectorized_value_type = VectorizedArray<T, width_>;

/**
* Define a stride which defines how often the template type
* VectorizedArray<T, width_> fits into the vectorized value type. This is
* useful to write vectorized templated code where the internal computation
* is vectorized and the user interface is optionally scalar or also
* vectorized.
*/
static constexpr std::size_t stride = 1;

/**
* Get a reference to scalar value on lane c.
*/
static value_type &
get(vectorized_value_type &values, unsigned int c)
{
AssertIndexRange(c, width_);
AssertIndexRange(c, width);

return values[c];
}

static const T &
get(const VectorizedArray<T, width_> &values, unsigned int c)
/**
* Get a read-only reference to scalar value on lane c.
*/
static const value_type &
get(const vectorized_value_type &values, unsigned int c)
{
AssertIndexRange(c, width_);
AssertIndexRange(c, width);

return values[c];
}

/**
* Get a reference to vectorized values from a vectorized values field.
*/
static vectorized_value_type &
get_from_vectorized(vectorized_value_type &values, unsigned int c)
{
(void)c;
AssertIndexRange(c, stride);

return values;
}

/**
* Get a read-only reference to vectorized values from a vectorized values
* field.
*/
static const vectorized_value_type &
get_from_vectorized(const vectorized_value_type &values, unsigned int c)
{
(void)c;
AssertIndexRange(c, stride);

return values;
}
};
} // namespace internal

Expand Down
9 changes: 6 additions & 3 deletions include/deal.II/fe/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ namespace NonMatching
{
template <int dim>
class FEImmersedSurfaceValues;
template <int dim, int spacedim>
class MappingInfo;
namespace internal
{
template <int dim, int spacedim>
class ComputeMappingDataHelper;
}
} // namespace NonMatching


Expand Down Expand Up @@ -1320,7 +1323,7 @@ class Mapping : public Subscriptor
friend class FEFaceValues<dim, spacedim>;
friend class FESubfaceValues<dim, spacedim>;
friend class NonMatching::FEImmersedSurfaceValues<dim>;
friend class NonMatching::MappingInfo<dim, spacedim>;
friend class NonMatching::internal::ComputeMappingDataHelper<dim, spacedim>;
};


Expand Down

0 comments on commit 0f1cad6

Please sign in to comment.