9#include <kernel/trafo/mapping_base.hpp>
21 template<
typename Shape_>
22 struct InverseMappingHelper;
47 template<
typename DT_,
int n_,
int s_>
71 template<
typename DataType_,
int shape_dim_,
int world_dim_ = shape_dim_>
111 cells = std::forward<std::vector<Index>>(other.cells);
112 dom_points = std::forward<std::vector<DomainPointType>>(other.dom_points);
122 return cells.empty();
156 template<
typename Trafo_,
typename DataType_>
214 bool init_boxes =
true
259 const auto& mesh =
_trafo.get_mesh();
261 const auto& vtx_set = mesh.get_vertex_set();
263 const auto& vert_idx = mesh.template get_index_set<shape_dim, 0>();
266 _bboxes.resize(std::size_t(mesh.get_num_elements()));
269 for(
Index cell(0); cell < vert_idx.get_num_entities(); ++cell)
272 const auto& vidx = vert_idx[cell];
278 bbox[0] = bbox[1] = vtx_set[vidx[0]];
279 for(
int i(1); i < vert_idx.get_num_indices(); ++i)
282 const auto& vtx = vtx_set[vidx[i]];
293 DataType bb_extra = bbox_tol * (bbox[1][j] - bbox[0][j]);
294 bbox[0][j] -= bb_extra;
295 bbox[1][j] += bb_extra;
343 std::vector<Index> cells;
348 for(
Index cell : cells)
370 inv_data.
cells.push_back(cell);
429 for(
Index cell : cells)
451 inv_data.
cells.push_back(cell);
484 XASSERTM(
_bboxes.size() ==
_trafo.get_mesh().get_num_elements(),
"Boundingbox are not initilialized correctly");
486 for(std::size_t cell(0); cell <
_bboxes.size(); ++cell)
491 cells.push_back(
Index(cell));
495 return !cells.empty();
533 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
534 TrafoEvaluator trafo_eval(
_trafo);
540 typename TrafoEvaluator::template ConfigTraits<trafo_tags>::EvalDataType trafo_data;
550 bool converged =
false;
553 trafo_eval.prepare(cell);
606 template<
typename InverseMappingType_,
typename CFMappingType_>
613 using TrafoType =
typename InverseMappingType::TrafoType;
615 using DataType =
typename InverseMappingType::DataType;
617 using ShapeType =
typename InverseMappingType::ShapeType;
634 std::deque<std::reference_wrapper<const InverseMappingType>>
_mappings;
690 XASSERT(
_mappings.back().get().get_trafo().get_mesh().get_num_elements() < imapping.get_trafo().get_mesh().get_num_elements());
691 XASSERT(cf_mapping.get_num_nodes_domain() ==
_mappings.back().get().get_trafo().get_mesh().get_num_elements());
692 XASSERT(cf_mapping.get_num_nodes_image() == imapping.get_trafo().get_mesh().get_num_elements());
701 return _mappings.back().get().get_trafo();
758 for(
Index level(1); level < num_layers; level++)
762 for(
Index cell : current.cells)
764 const auto fbegin = coarse_to_fine.image_begin(cell);
765 const auto fend = coarse_to_fine.image_end(cell);
767 for(
auto it = fbegin; it != fend; ++it)
772 next.cells.push_back(*it);
773 next.dom_points.push_back(domain_point);
779 std::swap(current, next);
783 next.dom_points.clear();
809 const bool ignore_failures =
false)
811 if(!mapping.is_in_bounding_box(cell,
img_point))
816 if(!mapping.unmap_point_by_newton(domain_point,
img_point, cell))
828 return mapping.test_domain_point(domain_point);
836 struct InverseMappingHelper<Shape::Simplex<dim_>>
839 template<
typename PT_,
typename DT_>
840 static bool is_on_ref(
const PT_& p,
const DT_ tol)
845 for(
int i(0); i < dim_; ++i)
848 if((p[i] < -tol) || (p[i] > DT_(1)+tol))
853 return (s <= DT_(1) + tol);
858 struct InverseMappingHelper<Shape::Hypercube<dim_>>
861 template<
typename PT_,
typename DT_>
862 static bool is_on_ref(
const PT_& p,
const DT_ tol)
865 for(
int i(0); i < dim_; ++i)
868 if((p[i] < -DT_(1)-tol) || (p[i] > DT_(1)+tol))
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
String class implementation.
Tiny Matrix class template.
Tiny Vector class template.
CUDA_HOST_DEVICE DataType norm_euclid_sqr() const
Computes the squared euclid norm of this vector.
Accelerated inverse mapping for multigrid hierarchies.
std::deque< CFMappingType_ > _coarse_fine_mappings
deque of mapping between levels
static constexpr int world_dim
the world dimension
typename InvMapDataType::ImagePointType ImagePointType
the image point type
virtual ~HierarchicalInverseMapping()=default
virtual destructor
static constexpr int shape_dim
the shape dimension
HierarchicalInverseMapping(HierarchicalInverseMapping &&other)=default
Move constructor.
void push_level(const InverseMappingType &imapping)
Push the coarse level into the hierarchy.
InverseMappingType_ InverseMappingType
the type of the inverse mapping on each level
HierarchicalInverseMapping & operator=(HierarchicalInverseMapping &&other)=default
Move-assignment operator.
static bool try_unmap(const InverseMappingType &mapping, DomainPointType &domain_point, const ImagePointType &img_point, const Index cell, const bool ignore_failures=false)
Try to unmap a point.
typename InverseMappingType::DataType DataType
the datatype to be used
HierarchicalInverseMapping()=default
Constructor.
HierarchicalInverseMapping & operator=(const HierarchicalInverseMapping &other)=delete
Copy-assignment operator.
typename InverseMappingType::TrafoType TrafoType
the underlying trafo type
void push_level(const InverseMappingType &imapping, const CFMappingType_ &cf_mapping)
Push a fine level into the hierarchy.
std::deque< std::reference_wrapper< const InverseMappingType > > _mappings
deque of inverse mapping for each level
const TrafoType & get_trafo() const
Return a reference to the underlying trafo on the finest level.
typename InverseMappingType::ShapeType ShapeType
the shape type
InvMapDataType unmap_point(const ImagePointType &img_point, bool ignore_failures=false) const
Unmaps a given image point.
typename InverseMappingType::InvMapDataType InvMapDataType
the inverse mapping data type
CFMappingType_ CFMappingType
the type of mapping between mesh levels
HierarchicalInverseMapping(const HierarchicalInverseMapping &other)=delete
Copy constructor.
typename InvMapDataType::DomainPointType DomainPointType
the domain point type
Data structure for InverseMapping evaluations.
Tiny::Vector< DataType_, shape_dim_ > DomainPointType
the domain point type
InverseMappingData & operator=(InverseMappingData &&other)
move-assign operator
ImagePointType img_point
the image point that was unmapped
std::vector< Index > cells
the indices of the cells that intersect with the image point
InverseMappingData()
default constructor
InverseMappingData(const InverseMappingData &other)=default
use default copy constructor
std::vector< DomainPointType > dom_points
the domain points on each cell that map onto the image point
Tiny::Vector< DataType_, world_dim_ > ImagePointType
the image point type
InverseMappingData(InverseMappingData &&other)
move constructor
bool empty() const
Checks whether no cells were found.
Inverse Trafo Mapping Error class.
InverseMappingError(const Tiny::Vector< DT_, n_, s_ > &point, Index cell)
Constructor.
Inverse Trafo mapping class template.
std::vector< BBox > _bboxes
the array of cell bounding boxes
bool find_candidate_cells(std::vector< Index > &cells, const ImagePointType &img_point) const
Determines a set of candidate cells by a bounding-box test.
Index _newton_max_iter
maximum number of newton iterations for unmapping
void init_bounding_boxes(DataType bbox_tol)
Initializes the cell bounding boxes array.
Tiny::Matrix< DataType_, 2, world_dim > BBox
our bounding box type
static constexpr int shape_dim
the shape dimension
Trafo_ TrafoType
the underlying trafo type
bool unmap_point_by_newton(DomainPointType &dom_point, const ImagePointType &img_point, const Index cell) const
Unmaps a given point on a particular cell by Newton iteration.
DataType_ DataType
the datatype to be used
bool test_domain_point(const DomainPointType &dom_point) const
Tests whether a given domain point is on the reference element.
InverseMapping & operator=(InverseMapping &&other)=default
Move-assignment operator.
InverseMappingData< DataType, shape_dim, world_dim > InvMapDataType
the inverse mapping data type
InvMapDataType::DomainPointType DomainPointType
the domain point type
InverseMapping & operator=(const InverseMapping &other)=delete
Copy-assignment operator.
InverseMapping(const InverseMapping &other)=delete
Copy constructor.
InvMapDataType unmap_point(const ImagePointType &img_point, const std::vector< Index > &cells, bool ignore_failures=false) const
Unmaps a given image point.
InvMapDataType::ImagePointType ImagePointType
the image point type
InvMapDataType unmap_point(const ImagePointType &img_point, bool ignore_failures=false) const
Unmaps a given image point.
const TrafoType & get_trafo() const
Return a reference to the underlying trafo.
InverseMapping(const TrafoType &trafo, DataType bbox_tol=DataType(1E-2), DataType domain_tol=DataType(1E-4), bool init_boxes=true)
Constructor.
static constexpr int world_dim
the world dimension
InverseMapping(InverseMapping &&other)=default
Move constructor.
DataType _domain_tol
tolerance for unmapped domain coordinates
virtual ~InverseMapping()=default
virtual destructor
DataType _newton_tol
absolute tolerance for newton iteration
const TrafoType & _trafo
the trafo mapping
TrafoType::ShapeType ShapeType
the shape type
void minimax(T_ x, T_ &a, T_ &b)
Updates the minimum and maximum.
T_ sqr(T_ x)
Returns the square of a value.
String stringify(const T_ &item)
Converts an item into a String.
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
@ jac_inv
specifies whether the trafo should supply inverse jacobian matrices
Reference cell traits structure.