7#include "kernel/assembly/asm_traits.hpp"
8#include <kernel/assembly/surface_integrator.hpp>
10#include <kernel/trafo/inverse_mapping.hpp>
11#include <kernel/util/tiny_algebra.hpp>
13#include <unordered_map>
20 template<
typename AsmTraits_>
24 typedef typename AsmTraits_::TrafoType TrafoType;
25 static constexpr int dim = TrafoType::ShapeType::dimension;
26 typedef Index IndexType;
27 typedef typename AsmTraits_::DataType DataType;
28 typedef AsmTraits_ AsmTraits;
29 typedef typename AsmTraits::TrafoEvaluator TrafoEval;
30 typedef typename TrafoEval::DomainPointType DomainPointType;
31 typedef typename TrafoEval::ImagePointType ImagePointType;
34 const TrafoType& _trafo;
37 std::vector<IndexType> _cell_helper;
38 std::vector<BoundingBoxType<DataType, dim>> _cell_bb;
39 std::vector<ImagePointType> _domain_points;
40 std::vector<DataType> _point_weights;
41 std::vector<std::vector<IndexType>> _cell_to_domain_point;
43 ImagePointType _cur_img_point;
44 ImagePointType _cur_dom_point;
45 ImagePointType _normal;
46 DataType _face_volume;
47 IndexType _cur_surface_index;
49 DataType _integration_weight;
54 _inv_mapping(_trafo, DataType(1E-2), DataType(1E-4),
false),
59 _cell_to_domain_point(),
64 _cur_surface_index(~IndexType(0)),
65 _integration_weight(DataType(0))
68 template<
typename DT_,
typename ImgP_,
typename IT_>
69 void prepare(
const std::vector<IT_>& cells,
const std::vector<IT_>& cell_offsets,
const std::vector<ImgP_>& points,
70 const std::vector<DT_>& integration_weights,
const ImgP_&
normal, DT_ face_volume, IT_ surface_ind)
72 _normal = ImagePointType::convert_new(
normal);
73 _face_volume = DataType(face_volume);
74 _cell_helper.resize(cell_offsets.at(surface_ind+1)-cell_offsets.at(surface_ind));
75 std::copy(cells.begin()+
long(cell_offsets.at(surface_ind)), cells.begin()+
long(cell_offsets.at(surface_ind+1)), _cell_helper.begin());
76 _cur_surface_index = surface_ind;
77 _cell_bb.resize(_cell_helper.size());
79 const auto& vtx_set = _trafo.get_mesh().get_vertex_set();
80 const auto& vtx_ind = _trafo.get_mesh().template get_index_set<dim, 0>();
81 for(IndexType k = 0; k < _cell_helper.size(); ++k)
83 _cell_bb[k] = Intern::get_boundingbox<DataType, dim>(vtx_set, vtx_ind[_cell_helper[k]], DataType(1E-4));
86 _cell_to_domain_point.resize(_cell_helper.size());
87 std::for_each(_cell_to_domain_point.begin(), _cell_to_domain_point.end(), [](
auto& ele){ele.clear();});
88 _domain_points.clear();
89 _point_weights.clear();
91 std::unordered_map<IndexType, std::size_t> cell_to_index_map;
92 for(std::size_t k = 0; k < _cell_helper.size(); ++k)
94 cell_to_index_map.insert({_cell_helper[k], k});
97 std::vector<IndexType> pt_helper;
98 for(std::size_t pti = 0; pti < points.size(); ++pti)
101 for(IndexType k = 0; k < _cell_helper.size(); ++k)
103 if(Intern::check_point(ImagePointType(points[pti]), _cell_bb[k]))
105 pt_helper.push_back(_cell_helper[k]);
108 if(pt_helper.empty())
111 const auto& inv_mapping_data = _inv_mapping.
unmap_point(ImagePointType(points[pti]), pt_helper,
true);
114 const DataType point_weight = DataType(integration_weights[pti])/DataType(inv_mapping_data.size());
116 for(std::size_t l = 0; l < inv_mapping_data.size(); ++l)
118 _domain_points.push_back(inv_mapping_data.dom_points[l]);
119 _point_weights.push_back(point_weight);
120 _cell_to_domain_point.at(cell_to_index_map[inv_mapping_data.cells[l]]).push_back(_point_weights.size()-1);
126 void prepare_point(
const DomainPointType&
dom_point, DataType point_weight)
129 _integration_weight = point_weight;
151 template<
typename AsmTraits_,
typename DataType_,
int domain_dim_,
int image_dim_>
154 static constexpr int domain_dim = domain_dim_;
155 static constexpr int image_dim = image_dim_;
165 static constexpr bool has_value = *(AsmTraits_::space_config &
SpaceTags::value);
166 static constexpr bool has_grad = *(AsmTraits_::space_config &
SpaceTags::grad);
167 static constexpr bool has_hess = *(AsmTraits_::space_config &
SpaceTags::hess);
170 template<
typename AsmTraits_,
typename DataType_,
int domain_dim_>
173 static constexpr int domain_dim = domain_dim_;
174 static constexpr int image_dim = 1;
175 typedef DataType_ ValueType;
180 std::conditional_t<*(AsmTraits_::space_config &
SpaceTags::value), ValueType, Empty> value;
184 static constexpr bool has_value = *(AsmTraits_::space_config &
SpaceTags::value);
185 static constexpr bool has_grad = *(AsmTraits_::space_config &
SpaceTags::grad);
186 static constexpr bool has_hess = *(AsmTraits_::space_config &
SpaceTags::hess);
189 template<
typename ValueType_>
192 static constexpr int dim = 1;
195 template<
typename DT_,
int n_,
int sn_>
198 static constexpr int dim = n_;
202 template<
typename Derived_,
typename AsmTraits_,
typename Space_,
typename FEVector_>
208 typedef AsmTraits_ AsmTraits;
209 typedef typename BaseClass::IndexType IndexType;
210 typedef typename BaseClass::DomainPointType DomainPointType;
211 static constexpr int dim = BaseClass::dim;
212 typedef typename AsmTraits_::DataType DataType;
213 typedef typename FEVector_::ValueType ValueType;
220 return static_cast<Derived_&
>(*this);
223 const Derived_& cast()
const
225 return static_cast<const Derived_&
>(*this);
266 void _prepare_cell(IndexType cell)
276 void _prepare_point(
const DomainPointType& point)
280 const int num_loc_dofs = this->space_eval.get_num_local_dofs();
281 if constexpr(LocalValueHolder::has_value)
284 for(
int i = 0; i < num_loc_dofs; ++i)
289 if constexpr(LocalValueHolder::has_grad)
292 for(
int i = 0; i < num_loc_dofs; ++i)
294 if constexpr(image_dim == 1)
300 if constexpr(LocalValueHolder::has_hess)
302 XABORTM(
"Hessian not implemented yet");
306 void _integrate(DataType DOXY(weight), IndexType DOXY(point_idx))
308 XABORTM(
"Has to be implmented by derived class");
311 void _assemble_cell(
const std::vector<IndexType>& domain_point_idx)
313 for(
auto pti : domain_point_idx)
315 const auto dom_point = this->_domain_points[pti];
318 this->cast()._integrate(this->_point_weights[pti], pti);
324 for(IndexType k = 0; k < this->_cell_helper.size(); ++k)
326 const auto& domain_point_idx = this->_cell_to_domain_point.at(k);
327 if(domain_point_idx.empty())
330 this->cast()._prepare_cell(this->_cell_helper[k]);
332 this->cast()._assemble_cell(domain_point_idx);
338 void prepare_cell(IndexType cell)
340 this->cast()._prepare_cell(cell);
343 void prepare_point(
const DomainPointType& point)
345 this->cast()._prepare_point(point);
350 this->cast()._assemble();
355 template<
typename FaceVector_,
typename Space_,
typename FEVector_>
359 typedef Space_ SpaceType;
360 typedef FEVector_ FEVector;
361 typedef FaceVector_ FaceVector;
386 typedef typename BaseClass::IndexType IndexType;
387 typedef typename BaseClass::DomainPointType DomainPointType;
388 static constexpr int dim = BaseClass::dim;
402 face_val(DataType(0)),
411 BaseClass::_assemble();
416 void _integrate(DataType weight, [[maybe_unused]] IndexType point_idx)
418 auto normal_val =
Tiny::dot(this->loc_value_holder.value, this->_normal);
419 face_val += normal_val * weight;
424 FaceVector_& face_vec;
425 const FEVector_& primal_vec;
429 explicit NormalValueSurfaceIntegratorJob(FaceVector_& face_vec_,
const FEVector_& primal_vec_,
const Space_& space_,
DataType scatter_alpha_ =
DataType(1)) :
431 primal_vec(primal_vec_),
433 scatter_alpha(scatter_alpha_)
439 template<
typename FaceVector_,
typename Space_,
typename FEVector_>
443 typedef Space_ SpaceType;
444 typedef FEVector_ FEVector;
445 typedef FaceVector_ FaceVector;
470 typedef typename BaseClass::IndexType IndexType;
471 typedef typename BaseClass::DomainPointType DomainPointType;
472 static constexpr int dim = BaseClass::dim;
495 BaseClass::_assemble();
500 void _integrate(DataType weight, [[maybe_unused]] IndexType point_idx)
502 auto normal_grad = this->loc_value_holder.grad * this->_normal;
508 FaceVector_& face_vec;
509 const FEVector_& primal_vec;
513 explicit NormalGradientSurfaceIntegratorJob(FaceVector_& face_vec_,
const FEVector_& primal_vec_,
const Space_& space_,
DataType scatter_alpha_ =
DataType(1)) :
515 primal_vec(primal_vec_),
517 scatter_alpha(scatter_alpha_)
#define XABORTM(msg)
Abortion macro definition with custom message.
Common single-space assembly traits class template.
AsmTraits::DofMapping dof_mapping
the space dof-mapping
FEVectorIntegratorTaskCRTP(const Space_ &space_, const FEVector_ &primal_vec_)
Constructor.
LocalValueHolder loc_value_holder
local fe point/grad/hess values
AsmTraits::template TLocalVector< ValueType > local_vector
the local vector to be gathered
const FEVector_ & primal_vector
the vector from which to gather the values
FEVector_::GatherAxpy gather_axpy
the gather object
AsmTraits::SpaceEvaluator space_eval
the space evaluator
AsmTraits::SpaceEvalData space_data
the space evaluation data
AsmTraits::TrafoEvaluator trafo_eval
the trafo evaluator
const Space_ & space
the test-/trial-space to be used
AsmTraits::TrafoEvalData trafo_data
the trafo evaluation data
DataType scatter_alpha
the scatter scaling factor
FaceVector_ & vector
the vector that is to be assembled
Task(NormalGradientSurfaceIntegratorJob &job)
Constructor.
Assembly::AsmTraits1< DataType, Space_, trafo_config_, space_config_ > AsmTraits
our assembly traits
FEVector_::DataType DataType
the data-type of the vector
FEVector_::ValueType ValueType
the value-type of the vector
FaceVector_ & vector
the vector that is to be assembled
DataType scatter_alpha
the scatter scaling factor
Task(NormalValueSurfaceIntegratorJob &job)
Constructor.
FEVector_::DataType DataType
the data-type of the vector
Assembly::AsmTraits1< DataType, Space_, trafo_config_, space_config_ > AsmTraits
our assembly traits
FEVector_::ValueType ValueType
the value-type of the vector
Tiny Matrix class template.
Tiny Tensor3 class template.
Tiny Vector class template.
Inverse Trafo mapping class template.
InvMapDataType unmap_point(const ImagePointType &img_point, bool ignore_failures=false) const
Unmaps a given image point.
T_ sqrt(T_ x)
Returns the square-root of a value.
CUDA_HOST_DEVICE T_ dot(const T_ &a, const T_ &b)
Computes the dot-product of two scalars.
CUDA_HOST_DEVICE void axpy(T_ &y, const T_ &x, const T_ &alpha)
Performs an AXPY of two scalars.
SpaceTags
Space configuration tags enum.
@ value
specifies whether the space should supply basis function values
@ hess
specifies whether the space should supply basis function hessians
@ grad
specifies whether the space should supply basis function gradients
std::uint64_t Index
Index data type.
TrafoTags
Trafo configuration tags enum.
@ img_point
specifies whether the trafo should supply image point coordinates
@ dom_point
specifies whether the trafo should supply domain point coordinates