8#include <kernel/trafo/mapping_base.hpp>
20 template<
typename Shape_>
21 struct InverseMappingHelper;
46 template<
typename DT_,
int n_,
int s_>
70 template<
typename DataType_,
int shape_dim_,
int world_dim_ = shape_dim_>
110 cells = std::forward<std::vector<Index>>(other.cells);
111 dom_points = std::forward<std::vector<DomainPointType>>(other.dom_points);
121 return cells.empty();
155 template<
typename Trafo_,
typename DataType_>
213 bool init_boxes =
true
242 const auto& mesh =
_trafo.get_mesh();
244 const auto& vtx_set = mesh.get_vertex_set();
246 const auto& vert_idx = mesh.template get_index_set<shape_dim, 0>();
249 _bboxes.resize(std::size_t(mesh.get_num_elements()));
252 for(
Index cell(0); cell < vert_idx.get_num_entities(); ++cell)
255 const auto& vidx = vert_idx[cell];
261 bbox[0] = bbox[1] = vtx_set[vidx[0]];
262 for(
int i(1); i < vert_idx.get_num_indices(); ++i)
265 const auto& vtx = vtx_set[vidx[i]];
276 DataType bb_extra = bbox_tol * (bbox[1][j] - bbox[0][j]);
277 bbox[0][j] -= bb_extra;
278 bbox[1][j] += bb_extra;
326 std::vector<Index> cells;
331 for(
Index cell : cells)
353 inv_data.
cells.push_back(cell);
412 for(
Index cell : cells)
434 inv_data.
cells.push_back(cell);
467 XASSERTM(
_bboxes.size() ==
_trafo.get_mesh().get_num_elements(),
"Boundingbox are not initilialized correctly");
469 for(std::size_t cell(0); cell <
_bboxes.size(); ++cell)
486 cells.push_back(
Index(cell));
489 return !cells.empty();
511 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
512 TrafoEvaluator trafo_eval(
_trafo);
518 typename TrafoEvaluator::template ConfigTraits<trafo_tags>::EvalDataType trafo_data;
528 bool converged =
false;
531 trafo_eval.prepare(cell);
579 struct InverseMappingHelper<Shape::Simplex<dim_>>
582 template<
typename PT_,
typename DT_>
583 static bool is_on_ref(
const PT_& p,
const DT_ tol)
588 for(
int i(0); i < dim_; ++i)
591 if((p[i] < -tol) || (p[i] > DT_(1)+tol))
596 return (s <= DT_(1) + tol);
601 struct InverseMappingHelper<Shape::Hypercube<dim_>>
604 template<
typename PT_,
typename DT_>
605 static bool is_on_ref(
const PT_& p,
const DT_ tol)
608 for(
int i(0); i < dim_; ++i)
611 if((p[i] < -DT_(1)-tol) || (p[i] > DT_(1)+tol))
#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.
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.
InverseMappingData< DataType, shape_dim, world_dim > InvMapDataType
the inverse mapping data type
InvMapDataType::DomainPointType DomainPointType
the domain point type
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.
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
virtual ~InverseMapping()
virtual destructor
DataType _domain_tol
tolerance for unmapped domain coordinates
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.