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 >
K_Mesh< K_Simplex >::K_Mesh( const MeshInfo& meshInfo )
: _setupStorage( meshInfo, uint_c( walberla::mpi::MPIManager::instance()->numProcesses() ) )
{
// extract vertices
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() )
if ( walberla::mpi::MPIManager::instance()->rank() == 0 )
{
_vertices[idx] = vtx.getCoordinates();
// prepare element setup
conversion[id] = idx;
vtxIndices[idx] = idx;
++idx;
}
// extract vertices
_n_vertices = meshInfo.getVertices().size();
_vertices.resize( _n_vertices );
// [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 );
// simplex factory does not store cells
std::set< std::shared_ptr< Simplex3 > > cells;
SimplexFactory fac( nullptr, vtxIndices );
// simplex factory does not store cells
std::set< std::shared_ptr< Simplex3 > > cells;
for ( auto& p : meshInfo.getEdges() )
{
const auto& v = p.second.getVertices();
for ( auto& p : meshInfo.getEdges() )
{
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() )
{
const auto& v = p.second.getVertices();
for ( auto& p : meshInfo.getFaces() )
{
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() )
{
const auto& v = p.second.getVertices();
for ( auto& p : meshInfo.getCells() )
{
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 <>
......@@ -116,32 +122,42 @@ void K_Mesh< Simplex3 >::init_elements( const std::map< Idx< 3 >, std::shared_pt
template < class K_Simplex >
void K_Mesh< K_Simplex >::refineRG( const std::vector< PrimitiveID >& elements_to_refine )
{
auto R = init_R( elements_to_refine );
// remove green edges
remove_green_edges( R );
auto meshInfo = hyteg::MeshInfo::emptyMeshInfo();
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
green refinement steps
*/
std::set< std::shared_ptr< K_Simplex > > U = _T;
std::set< std::shared_ptr< K_Simplex > > refined;
while ( not R.empty() )
{
refined.merge( refine_red( R, U ) );
std::set< std::shared_ptr< K_Simplex > > U = _T;
std::set< std::shared_ptr< K_Simplex > > refined;
while ( not R.empty() )
{
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
refined.merge( refine_green( U ) );
// update current configuration
_T = U;
_T.merge( refined );
_n_vertices = _vertices.size();
_n_elements = _T.size();
// update setupStorage
meshInfo = export_meshInfo();
}
// update current configuration
_T = U;
_T.merge( refined );
// todo communication (meshInfo, _n_vertices, _n_elements)
// update setupStorage
auto meshInfo = export_meshInfo();
_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
{
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.second = std::max( mm.second, mm_el.second );
mm.first = std::min( mm.first, mm_el.first );
mm.second = std::max( mm.second, mm_el.second );
}
}
// todo communication (mm)
return mm;
}
......@@ -484,11 +505,16 @@ real_t K_Mesh< K_Simplex >::volume() const
{
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;
}
......
......@@ -53,10 +53,8 @@ class K_Mesh
// get SetupPrimitiveStorage corresponding to current refinement
inline SetupPrimitiveStorage& setupStorage() { return _setupStorage; };
inline const std::vector< Point3D >& vertices() const { return _vertices; }
inline const std::set< std::shared_ptr< K_Simplex > >& elements() const { return _T; }
inline uint_t n_elements() const { return _T.size(); }
inline uint_t n_vtx() const { return _vertices.size(); }
inline uint_t n_elements() const { return _n_elements; }
inline uint_t n_vtx() const { return _n_vertices; }
private:
/* remove green edges from _T and replace the corresponding faces in R with their parents
......@@ -111,6 +109,8 @@ class K_Mesh
/* generate MeshInfo corresponding to current refinement */
hyteg::MeshInfo export_meshInfo() const;
uint_t _n_vertices;
uint_t _n_elements;
std::vector< Point3D > _vertices;
std::set< std::shared_ptr< K_Simplex > > _T; // set of elements 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