9#include <kernel/cubature/dynamic_factory.hpp>
10#include <kernel/cubature/rule.hpp>
11#include <kernel/trafo/standard/mapping.hpp>
12#include <kernel/trafo/standard/inverse_mapping.hpp>
13#include <kernel/util/tiny_algebra.hpp>
21 template<
typename DT_,
int dim_>
22 using BoundingBoxType = Tiny::Matrix<DT_, 2, dim_>;
26 template<
typename DT_,
int dim_,
typename VertexSet_,
typename IndexTuple_>
27 static inline BoundingBoxType<DT_, dim_> get_boundingbox(
const VertexSet_& vtx_set,
const IndexTuple_& vidx, DT_ tol)
30 BoundingBoxType<DT_, dim_> bbox;
33 bbox[0] = bbox[1] = vtx_set[vidx[0]];
34 for(
int i(1); i < vidx.num_indices; ++i)
37 const auto& vtx = vtx_set[vidx[i]];
38 for(
int j(0); j < dim_; ++j)
45 for(
int j(0); j < dim_; ++j)
48 DataType bb_extra = tol * (bbox[1][j] - bbox[0][j]);
49 bbox[0][j] -= bb_extra;
50 bbox[1][j] += bb_extra;
56 template<
typename DT_,
int dim_>
57 static inline bool check_point(
const Tiny::Vector<DT_, dim_>& pt,
const BoundingBoxType<DT_, dim_>& bb)
60 for(
int i = 0; i < dim_; ++i)
62 outside |= (pt[i] < bb[0][i]) || (pt[i] > bb[1][i]);
96 template<
typename Trafo_,
typename SurfaceShape_>
100 typedef Trafo_ TrafoType;
101 typedef typename TrafoType::MeshType MeshType;
102 typedef SurfaceShape_ SurfaceShapeType;
103 static constexpr int domain_dim = Trafo_::ShapeType::dimension;
104 static constexpr int sub_dim = SurfaceShapeType::dimension;
105 typedef typename TrafoType::CoordType DataType;
106 typedef Index IndexType;
120 const TrafoType& _trafo;
121 std::vector<Tiny::Vector<DataType, domain_dim>> _shape_vertices;
124 std::vector<Geometry::IndexTuple<verts_per_face>> _shape_index_tmp;
126 std::vector<IndexType> _cell_helper;
127 std::vector<IndexType> _cell_helper_offsets;
128 std::vector<IndexType> _active_surfaces;
129 std::vector<int> _cell_mask_vec;
139 bool no_intersect =
false;
140 for(
int d = 0; d < domain_dim; ++d)
142 no_intersect |= (bb_a[0][d] > bb_b[1][d]) || (bb_b[0][d] > bb_a[1][d]);
145 return !no_intersect;
150 void set_normal_view(
bool inside_view)
155 bool get_normal_view()
const
163 _shape_indices.set_indices(std::move(_shape_index_tmp));
165 const MeshType& mesh = _trafo.get_mesh();
166 const auto& vtx_set = mesh.get_vertex_set();
168 BoundingBoxType<DataType, domain_dim> mesh_bb;
169 for(
int k = 0; k < domain_dim; ++k)
171 mesh_bb[0][k] = Math::Limits<DataType>::max();
172 mesh_bb[1][k] = Math::Limits<DataType>::lowest();
175 for(
const auto* verts = vtx_set.begin(); verts != vtx_set.end(); ++verts)
177 for(
int k = 0; k < domain_dim; ++k)
183 _active_surfaces.clear();
186 const auto& loc_ind_tuple = _shape_indices[k];
188 auto shape_bb = Intern::get_boundingbox<DataType, domain_dim>(_shape_vertices, loc_ind_tuple, DataType(1E-2));
191 _active_surfaces.push_back(k);
195 _cell_helper.clear();
197 for(
auto& c : _cell_helper_offsets)
204 const auto& ele_to_vert = mesh.template get_index_set<domain_dim, 0>();
205 const Index num_elements = mesh.get_num_elements();
206 constexpr Index batch_size = 1 << 19;
207 std::vector<std::vector<IndexType>> gather_helper(std::min(batch_size,
Index(_active_surfaces.size())));
208 FEAT_PRAGMA_OMP(parallel
for)
209 for(std::size_t i = 0; i < gather_helper.size(); ++i)
212 gather_helper[i].reserve(128);
215 for(
Index num_batch = 0; num_batch*batch_size < _active_surfaces.size(); ++num_batch)
217 FEAT_PRAGMA_OMP(parallel
for)
218 for(
Index t = 0; t < gather_helper.size(); ++t)
220 gather_helper.at(t).clear();
223 const Index offset = num_batch*batch_size;
225 FEAT_PRAGMA_OMP(parallel
for)
226 for(
Index t = 0; t < num_elements; ++t)
229 if(!_cell_mask_vec.empty() && _cell_mask_vec.at(t) == 3)
235 auto cell_bb = Intern::get_boundingbox<DataType, domain_dim>(vtx_set, ele_to_vert[t], DataType(1E-4));
238 for(
Index k = 0; k+offset < std::min(_active_surfaces.size(), offset+batch_size); ++k)
240 const auto& loc_ind_tuple = _shape_indices[_active_surfaces.at(k+offset)];
242 auto shape_bb = Intern::get_boundingbox<DataType, domain_dim>(_shape_vertices, loc_ind_tuple, DataType(1E-4));
246 FEAT_PRAGMA_OMP(critical)
247 gather_helper.at(k).push_back(t);
252 for(std::size_t k = 0; k < gather_helper.size(); ++k)
254 const auto& v_info = gather_helper[k];
255 _cell_helper_offsets.at(_active_surfaces.at(k+offset)+1) = v_info.size();
256 for(
const auto& val : v_info)
257 _cell_helper.push_back(val);
262 std::partial_sum(_cell_helper_offsets.begin(), _cell_helper_offsets.end(), _cell_helper_offsets.begin());
264 XASSERTM(_cell_helper_offsets.back() == _cell_helper.size(),
"Offsets do not match size of cell helper array");
278 _cubature_rule(Cubature::ctor_factory, cubature_factory_),
286 template<
typename Vtxs_>
289 _shape_index_tmp.clear();
290 _shape_vertices.resize(vertices.size());
291 FEAT_PRAGMA_OMP(parallel
for)
292 for(std::size_t k = 0; k < std::size_t(vertices.size()); ++k)
294 _shape_vertices[k] = vertices[k];
301 template<
typename Vtxs_>
304 for(std::size_t i = 0; i < std::size_t(verts_per_face); ++i)
306 _shape_vertices.push_back(face_vertices[i]);
309 const IndexType num_indx = _shape_index_tmp.size();
310 _shape_index_tmp.emplace_back();
311 for(IndexType i = 0; i < IndexType(verts_per_face); ++i)
313 _shape_index_tmp.back()[int(i)] = num_indx*verts_per_face + IndexType(i);
320 template<
typename VertIdx_>
323 _shape_index_tmp.emplace_back();
324 for(
int i = 0; i < verts_per_face; ++i)
326 _shape_index_tmp.back()[i] = IndexType(vert_idx[std::size_t(i)]);
331 template<
typename Job_>
332 void assemble(Job_& job)
352 template<
typename MaskVec_>
355 _cell_mask_vec.resize(cell_mask_vec.size());
356 FEAT_PRAGMA_OMP(parallel
for)
357 for(
Index k = 0; k < cell_mask_vec.size(); ++k)
359 _cell_mask_vec[k] = int(cell_mask_vec[k]);
363 template<
typename Job_>
364 void assemble_omp(Job_& job)
366 typedef typename Job_::Task TaskType;
370 FEAT_PRAGMA_OMP(parallel)
373 std::unique_ptr<TaskType> task(
new TaskType(job));
376 for(IndexType k = 0; k < _active_surfaces.size(); ++k)
380 for(
int i = 0; i < verts_per_face; ++i)
382 surface_verts[i] = _shape_vertices[_shape_indices[_active_surfaces[k]][i]];
388 EvalHelper::set_coefficients(coefficients, _shape_vertices, _shape_indices, _active_surfaces[k]);
395 DataType
jac_det = DataType(0);
397 DataType face_volume = EvalHelper::volume(coefficients);
400 std::vector<CoordVecType> points(std::size_t(_cubature_rule.get_num_points()));
402 std::vector<DataType> weights(std::size_t(_cubature_rule.get_num_points()));
404 NormalVecType
normal(DataType(0));
407 for(
int pt = 0; pt < _cubature_rule.get_num_points(); ++pt)
409 RefCoordVecType domain_point = _cubature_rule.get_point(pt);
410 DataType weight = _cubature_rule.get_weight(pt);
412 EvalHelper::map_point(
img_point, domain_point, coefficients);
413 EvalHelper::calc_jac_mat(jac, domain_point, coefficients);
417 if constexpr(sub_dim+1==domain_dim)
427 DataType point_weight =
jac_det * weight;
429 weights[std::size_t(pt)] = point_weight;
433 task->prepare(_cell_helper, _cell_helper_offsets, points, weights,
normal, face_volume, _active_surfaces[k]);
439 FEAT_PRAGMA_OMP(critical)
444 FEAT_PRAGMA_OMP(critical)
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Assemble class Discrete Integrale of an FE function over a d-1 manifold.
void add_face_vertices(const Vtxs_ &face_vertices)
Simply pushes new vertices to the end of the current vertex array.
SurfaceIntegrator(const Trafo_ &trafo, const Cubature::DynamicFactory &cubature_factory_)
Initializes the integrator with a cell wise list of vertices.
bool _inside_view
Normal defined from the inside or outside?
void set_mask_vector(const MaskVec_ &cell_mask_vec)
Sets the cell mask vector, which sorts out any cells completelly outside the fluid domain.
void add_face(const VertIdx_ &vert_idx)
bool boundingbox_intersect_test(const BoundingBoxType< DataType, domain_dim > &bb_a, const BoundingBoxType< DataType, domain_dim > &bb_b)
tests whether two boundingboxes intersect in any way
void set_vertices(const std::vector< Vtxs_ > &vertices)
Cubature Rule class template.
Conformal Index-Set class template.
Index get_num_entities() const
Returns the number of entities.
Tiny Matrix class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the matrix.
Tiny Tensor3 class template.
Tiny Vector class template.
void minimax(T_ x, T_ &a, T_ &b)
Updates the minimum and maximum.
Vector< T_, m_ > orthogonal(const Matrix< T_, m_, m_-1, sm_, sn_ > &tau)
Computes the positively oriented orthogonal vector to the columns of a m_ x (m_-1) Matrix.
std::uint64_t Index
Index data type.
@ img_point
specifies whether the trafo should supply image point coordinates
@ jac_det
specifies whether the trafo should supply jacobian determinants
Face traits tag struct template.
Evalautator helper class for standard trafo.