Commit 72da656f authored by Benjamin Mann's avatar Benjamin Mann
Browse files

restrict RG-refinement to rank=0

parent 243b0b08
Pipeline #36018 failed with stages
in 105 minutes and 55 seconds
...@@ -36,54 +36,60 @@ template < class K_Simplex > ...@@ -36,54 +36,60 @@ template < class K_Simplex >
K_Mesh< K_Simplex >::K_Mesh( const MeshInfo& meshInfo ) K_Mesh< K_Simplex >::K_Mesh( const MeshInfo& meshInfo )
: _setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) ) : _setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) )
{ {
// extract vertices if ( walberla::mpi::MPIManager::instance()->rank() == 0 )
const uint_t n_vtxs = meshInfo.getVertices().size();
_vertices.resize( n_vtxs );
// [0,1,...,n-1]
std::vector< uint_t > vtxIndices( n_vtxs );
// convert MeshInfo::vertexID to Mesh::vertexID
std::map< MeshInfo::IDType, uint_t > conversion;
// initialize vertices
uint_t idx = 0;
for ( auto& [id, vtx] : meshInfo.getVertices() )
{ {
_vertices[idx] = vtx.getCoordinates(); // extract vertices
// prepare element setup _n_vertices = meshInfo.getVertices().size();
conversion[id] = idx; _vertices.resize( _n_vertices );
vtxIndices[idx] = idx;
++idx; // [0,1,...,n-1]
} std::vector< uint_t > vtxIndices( _n_vertices );
// convert MeshInfo::vertexID to Mesh::vertexID
std::map< MeshInfo::IDType, uint_t > conversion;
// initialize vertices
uint_t idx = 0;
for ( auto& [id, vtx] : meshInfo.getVertices() )
{
_vertices[idx] = vtx.getCoordinates();
// prepare element setup
conversion[id] = idx;
vtxIndices[idx] = idx;
++idx;
}
// initialize all edges, faces and cells // initialize all edges, faces and cells
SimplexFactory fac( nullptr, vtxIndices ); SimplexFactory fac( nullptr, vtxIndices );
// simplex factory does not store cells // simplex factory does not store cells
std::set< std::shared_ptr< Simplex3 > > cells; std::set< std::shared_ptr< Simplex3 > > cells;
for ( auto& p : meshInfo.getEdges() ) for ( auto& p : meshInfo.getEdges() )
{ {
const auto& v = p.second.getVertices(); const auto& v = p.second.getVertices();
fac.make_edge( conversion[v[0]], conversion[v[1]] ); fac.make_edge( conversion[v[0]], conversion[v[1]] );
} }
for ( auto& p : meshInfo.getFaces() ) for ( auto& p : meshInfo.getFaces() )
{ {
const auto& v = p.second.getVertices(); const auto& v = p.second.getVertices();
fac.make_face( conversion[v[0]], conversion[v[1]], conversion[v[2]] ); fac.make_face( conversion[v[0]], conversion[v[1]], conversion[v[2]] );
} }
for ( auto& p : meshInfo.getCells() ) for ( auto& p : meshInfo.getCells() )
{ {
const auto& v = p.second.getVertices(); const auto& v = p.second.getVertices();
cells.insert( fac.make_cell( conversion[v[0]], conversion[v[1]], conversion[v[2]], conversion[v[3]] ) ); cells.insert( fac.make_cell( conversion[v[0]], conversion[v[1]], conversion[v[2]], conversion[v[3]] ) );
}
init_elements( fac.faces(), cells );
_n_elements = _T.size();
} }
init_elements( fac.faces(), cells ); // todo communication (_n_vertices, _n_elements)
} }
template <> template <>
...@@ -116,32 +122,42 @@ void K_Mesh< Simplex3 >::init_elements( const std::map< Idx< 3 >, std::shared_pt ...@@ -116,32 +122,42 @@ void K_Mesh< Simplex3 >::init_elements( const std::map< Idx< 3 >, std::shared_pt
template < class K_Simplex > template < class K_Simplex >
void K_Mesh< K_Simplex >::refineRG( const std::vector< PrimitiveID >& elements_to_refine ) void K_Mesh< K_Simplex >::refineRG( const std::vector< PrimitiveID >& elements_to_refine )
{ {
auto R = init_R( elements_to_refine ); auto meshInfo = hyteg::MeshInfo::emptyMeshInfo();
// remove green edges
remove_green_edges( R ); if ( walberla::mpi::MPIManager::instance()->rank() == 0 )
{
auto R = init_R( elements_to_refine );
// remove green edges
remove_green_edges( R );
/* recursively apply red refinement for elements /* recursively apply red refinement for elements
that otherwise would be subject to multiple that otherwise would be subject to multiple
green refinement steps green refinement steps
*/ */
std::set< std::shared_ptr< K_Simplex > > U = _T; std::set< std::shared_ptr< K_Simplex > > U = _T;
std::set< std::shared_ptr< K_Simplex > > refined; std::set< std::shared_ptr< K_Simplex > > refined;
while ( not R.empty() ) while ( not R.empty() )
{ {
refined.merge( refine_red( R, U ) ); refined.merge( refine_red( R, U ) );
R = find_elements_for_red_refinement( U ); R = find_elements_for_red_refinement( U );
} }
// apply green refinement
refined.merge( refine_green( U ) );
// apply green refinement // update current configuration
refined.merge( refine_green( U ) ); _T = U;
_T.merge( refined );
_n_vertices = _vertices.size();
_n_elements = _T.size();
// update setupStorage
meshInfo = export_meshInfo();
}
// update current configuration // todo communication (meshInfo, _n_vertices, _n_elements)
_T = U;
_T.merge( refined );
// update setupStorage
auto meshInfo = export_meshInfo();
_setupStorage = SetupPrimitiveStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) ); _setupStorage = SetupPrimitiveStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) );
} }
...@@ -468,14 +484,19 @@ std::pair< real_t, real_t > K_Mesh< K_Simplex >::min_max_angle() const ...@@ -468,14 +484,19 @@ std::pair< real_t, real_t > K_Mesh< K_Simplex >::min_max_angle() const
{ {
std::pair< real_t, real_t > mm{ 10, 0 }; std::pair< real_t, real_t > mm{ 10, 0 };
for ( auto& el : _T ) if ( walberla::mpi::MPIManager::instance()->rank() == 0 )
{ {
auto mm_el = el->min_max_angle( _vertices ); for ( auto& el : _T )
{
auto mm_el = el->min_max_angle( _vertices );
mm.first = std::min( mm.first, mm_el.first ); mm.first = std::min( mm.first, mm_el.first );
mm.second = std::max( mm.second, mm_el.second ); mm.second = std::max( mm.second, mm_el.second );
}
} }
// todo communication (mm)
return mm; return mm;
} }
...@@ -484,11 +505,16 @@ real_t K_Mesh< K_Simplex >::volume() const ...@@ -484,11 +505,16 @@ real_t K_Mesh< K_Simplex >::volume() const
{ {
real_t v_tot = 0; real_t v_tot = 0;
for ( auto& el : _T ) if ( walberla::mpi::MPIManager::instance()->rank() == 0 )
{ {
v_tot += el->volume( _vertices ); for ( auto& el : _T )
{
v_tot += el->volume( _vertices );
}
} }
// todo communication (v_tot)
return v_tot; return v_tot;
} }
......
...@@ -53,10 +53,8 @@ class K_Mesh ...@@ -53,10 +53,8 @@ class K_Mesh
// get SetupPrimitiveStorage corresponding to current refinement // get SetupPrimitiveStorage corresponding to current refinement
inline SetupPrimitiveStorage& setupStorage() { return _setupStorage; }; inline SetupPrimitiveStorage& setupStorage() { return _setupStorage; };
inline const std::vector< Point3D >& vertices() const { return _vertices; } inline uint_t n_elements() const { return _n_elements; }
inline const std::set< std::shared_ptr< K_Simplex > >& elements() const { return _T; } inline uint_t n_vtx() const { return _n_vertices; }
inline uint_t n_elements() const { return _T.size(); }
inline uint_t n_vtx() const { return _vertices.size(); }
private: private:
/* remove green edges from _T and replace the corresponding faces in R with their parents /* remove green edges from _T and replace the corresponding faces in R with their parents
...@@ -111,6 +109,8 @@ class K_Mesh ...@@ -111,6 +109,8 @@ class K_Mesh
/* generate MeshInfo corresponding to current refinement */ /* generate MeshInfo corresponding to current refinement */
hyteg::MeshInfo export_meshInfo() const; hyteg::MeshInfo export_meshInfo() const;
uint_t _n_vertices;
uint_t _n_elements;
std::vector< Point3D > _vertices; std::vector< Point3D > _vertices;
std::set< std::shared_ptr< K_Simplex > > _T; // set of elements of current refinement level std::set< std::shared_ptr< K_Simplex > > _T; // set of elements of current refinement level
SetupPrimitiveStorage _setupStorage; // primitive storage of current refinement level SetupPrimitiveStorage _setupStorage; // primitive storage of current refinement level
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment