9#include <kernel/geometry/factory.hpp>
10#include <kernel/geometry/mesh_permutation.hpp>
11#include <kernel/geometry/mesh_node.hpp>
12#include <kernel/geometry/intern/facet_neighbors.hpp>
13#include <kernel/geometry/intern/standard_index_refiner.hpp>
14#include <kernel/geometry/intern/standard_vertex_refiner.hpp>
15#include <kernel/geometry/index_calculator.hpp>
16#include <kernel/util/dist.hpp>
18#include <kernel/util/random.hpp>
20#include <kernel/util/tiny_algebra.hpp>
40 template<
typename MeshType_>
44 typedef typename MeshType_::CoordType CoordType;
45 static constexpr int shape_dim = MeshType_::shape_dim;
46 static constexpr int world_dim = MeshType_::world_dim;
60 const CoordType
_pi_val = Math::pi<CoordType>();
115 auto& vtx =
_mesh.get_vertex_set();
119 for (
Index i(0); i < vtx.get_num_vertices(); ++i)
131 else if (world_dim == 3)
133 for (
Index i(0); i < vtx.get_num_vertices(); ++i)
137 CoordType theta(0), phi(0);
195 auto& vtx =
_mesh.get_vertex_set();
199 for (
Index i(0); i < vtx.get_num_vertices(); ++i)
212 else if (world_dim == 3)
214 for (
Index i(0); i < vtx.get_num_vertices(); ++i)
219 CoordType theta(0), phi(0);
239 const auto& vtx_neighbors =
_mesh.get_neighbors();
241 const auto& faces_at_elem =
_mesh.template get_index_set<shape_dim, shape_dim - 1>();
243 int num_faces = faces_at_elem.num_indices;
248 for (
Index i = 0; i < num_elements; ++i)
251 for (
int j = 0; j < num_faces; ++j)
254 if (vtx_neighbors[i][j] > num_elements)
267 const auto& verts_at_face =
_mesh.template get_index_set<shape_dim - 1, 0>();
269 int vert_per_face = verts_at_face.num_indices;
272 for (
Index i = 0; i <
_mesh.get_num_entities(shape_dim - 1); ++i)
278 for (
int j = 0; j < vert_per_face; ++j)
289 auto& vtx =
_mesh.get_vertex_set();
291 const auto& verts_at_edg =
_mesh.template get_index_set<1, 0>();
294 for (
Index i = 0; i < verts_at_edg.get_num_entities(); ++i)
296 Index ind_vert1 = verts_at_edg[i][0];
297 Index ind_vert2 = verts_at_edg[i][1];
298 CoordType edge_length = (vtx[ind_vert1] - vtx[ind_vert2]).norm_euclid();
330 template<
typename MeshType_>
336 typedef MeshType_ MeshType;
340 static constexpr int world_dim = MeshType::world_dim;
341 static constexpr int facet_dim = MeshType::shape_dim - 1;
343 typedef typename BaseClass::CoordType CoordType;
383 BaseClass(*root_mesh_node.get_mesh(), seed),
408 for(
const auto& v : halo_map)
411 const TargetSet& halo_facets = v.second->template get_target_set<facet_dim>();
413 this->_boundary_facets.at(halo_facets[i]) = 0;
430 const std::size_t num_halos = halo_map.size();
437 std::vector<int> ranks;
438 std::vector<std::vector<CoordType>> send_bufs, recv_bufs;
441 send_bufs.resize(num_halos);
442 recv_bufs.resize(num_halos);
447 for(
auto it = halo_map.begin(); it != halo_map.end(); ++it)
450 const int halo_rank = it->first;
451 const TargetSet& halo_vtx = it->second->template get_target_set<0>();
455 auto& sbuf = send_bufs.at(ranks.size());
456 auto& rbuf = recv_bufs.at(ranks.size());
457 sbuf.resize(halo_size);
458 rbuf.resize(halo_size);
459 ranks.push_back(halo_rank);
465 for(
Index k(0); k < halo_size; ++k)
466 sbuf.at(k) = this->_shortest_edge.at(halo_vtx[k]);
473 for(std::size_t idx(0u); recv_reqs.
wait_any(idx); )
476 const int halo_rank = ranks.at(idx);
479 auto it = halo_map.find(halo_rank);
483 const TargetSet& halo_vtx = it->second->template get_target_set<0>();
485 auto& rbuf = recv_bufs.at(idx);
488 for(
Index k(0); k < halo_size; ++k)
489 this->_shortest_edge.at(halo_vtx[k]) =
Math::min(this->_shortest_edge.at(halo_vtx[k]), rbuf.at(k));
507 for(
auto it = halo_map.begin(); it != halo_map.end(); ++it)
509 const int halo_rank = it->first;
510 const TargetSet& halo_vtx = it->second->template get_target_set<0>();
540 const std::size_t num_halos = halo_map.size();
554 std::vector<int> ranks;
555 std::vector<std::vector<CoordType>> buffers;
558 buffers.resize(num_halos);
562 for(
auto it = halo_map.begin(); it != halo_map.end(); ++it)
565 const int halo_rank = it->first;
566 const TargetSet& halo_vtx = it->second->template get_target_set<0>();
568 const std::size_t buf_size = halo_size *
Index(world_dim);
571 auto& buf = buffers.at(ranks.size());
572 buf.resize(buf_size);
573 ranks.push_back(halo_rank);
576 if(my_rank < halo_rank)
579 for(
Index i(0), j(0); i < halo_size; ++i)
581 const auto& vtx = vertex_set[halo_vtx[i]];
582 for(
int k(0); k < world_dim; ++j, ++k)
597 for(std::size_t idx(0u); requests.
wait_any(idx); )
600 const int halo_rank = ranks.at(idx);
603 if(my_rank < halo_rank)
607 auto it = halo_map.find(halo_rank);
611 const TargetSet& halo_vtx = it->second->template get_target_set<0>();
613 auto& buf = buffers.at(idx);
616 for(
Index i(0), j(0); i < halo_size; ++i, j += world_dim)
622 auto& vtx = vertex_set[halo_vtx[i]];
623 for(
int k(0); k < world_dim; ++k)
624 vtx[k] = buf[j+
Index(k)];
#define XASSERT(expr)
Assertion macro definition.
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
int rank() const
Returns the rank of this process in this communicator.
Communication Request vector class.
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
void wait_all()
Blocks until all active requests are fulfilled.
Distributed mesh distortion class template.
DistributedMeshDistortion(const Dist::Comm &comm, RootMeshNodeType &root_mesh_node, Random::SeedType seed)
Constructor.
virtual void _calc_vertex_owners()
determines for each vertex the length of the shortest adjacent edge
virtual ~DistributedMeshDistortion()
virtual destructor
virtual void _calc_boundary_facets() override
determines for each facet whether it is a boundary facet or an inner facet
const Dist::Comm & _comm
a reference to our communicator
std::vector< int > _vertex_owners
a vector of vertex owner ranks
RootMeshNodeType & _root_mesh_node
a reference to our root mesh node
virtual void _calc_shortest_edge() override
determines for each vertex whether it is a boundary vertex or an inner vertex
DistributedMeshDistortion(const Dist::Comm &comm, RootMeshNodeType &root_mesh_node)
Constructor.
virtual void _synchronize() override
synchronizes the distortion over all processes; is overridden in DistributedMeshDistortion
(Unpartitioned) mesh distortion class template
Random _rand
random number generator for random distortion
const CoordType _pi_val
have a guess...
virtual void _synchronize()
synchronizes the distortion over all processes; is overridden in DistributedMeshDistortion
MeshDistortion(MeshType_ &mesh, Random::SeedType seed)
Constructor.
std::vector< int > _boundary_vertices
vector to store which vertex is at the boundary
virtual void _calc_boundary_vertices()
determines for each vertex whether it is a boundary vertex or an inner vertex
MeshType_ & _mesh
the mesh we want to distort
void distort_uniform(CoordType rad)
Distorts the mesh uniformly.
std::vector< CoordType > _shortest_edge
vector to store the length of the shortest edge belonging to each vertex
virtual void _calc_boundary_facets()
determines for each facet whether it is a boundary facet or an inner facet
MeshDistortion(MeshType_ &mesh)
Constructor.
void distort_shortest_edge_local(CoordType scale=CoordType(0.1))
Distorts the mesh according to the shortest local edge.
void distort_shortest_edge_uniform(CoordType scale=CoordType(0.1))
Distorts the mesh according to the shortest edge.
std::vector< int > _boundary_facets
vector to story which facet is at the boundary
virtual void _calc_shortest_edge()
determines for each vertex the length of the shortest adjacent edge
MeshType * get_mesh()
Returns the mesh of this node.
Class template for partial meshes.
Root mesh node class template.
const std::map< int, std::unique_ptr< MeshPartType > > & get_halo_map() const
Index get_num_entities() const
Returns the number of entities.
Pseudo-Random Number Generator.
std::uint64_t SeedType
seed type
T_ sin(T_ x)
Returns the sine of a value.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
T_ cos(T_ x)
Returns the cosine of a value.
std::uint64_t Index
Index data type.