Skip to content
Snippets Groups Projects
Commit 5c33df5d authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring MeshBuilder

parent 725a6d33
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
#pragma once
#include <TNL/Containers/Vector.h>
#include <TNL/Meshes/MeshDetails/traits/MeshTraits.h>
namespace TNL {
......@@ -24,50 +25,48 @@ namespace Meshes {
template< typename Mesh >
class MeshBuilder
{
//static constexpr const char *CLASS_NAME = "MeshBuilder";
public:
typedef Mesh MeshType;
typedef typename MeshType::MeshTraitsType MeshTraitsType;
typedef typename MeshTraitsType::GlobalIndexType GlobalIndexType;
typedef typename MeshTraitsType::LocalIndexType LocalIndexType;
typedef typename MeshTraitsType::PointType PointType;
typedef typename MeshTraitsType::CellTopology CellTopology;
typedef typename MeshTraitsType::CellSeedType CellSeedType;
public:
using MeshType = Mesh;
using MeshTraitsType = typename MeshType::MeshTraitsType;
using GlobalIndexType = typename MeshTraitsType::GlobalIndexType;
using LocalIndexType = typename MeshTraitsType::LocalIndexType;
using PointType = typename MeshTraitsType::PointType;
using CellTopology = typename MeshTraitsType::CellTopology;
using CellSeedType = typename MeshTraitsType::CellSeedType;
bool setPointsCount( const GlobalIndexType& points )
{
TNL_ASSERT( 0 <= points, std::cerr << "pointsCount = " << points );
this->points.setSize( points );
this->pointsSet.setSize( points );
if( ! this->points.setSize( points ) ||
! this->pointsSet.setSize( points ) )
return false;
pointsSet.setValue( false );
return true;
}
bool setCellsCount( const GlobalIndexType& cellsCount )
{
TNL_ASSERT( 0 <= cellsCount, std::cerr << "cellsCount = " << cellsCount );
this->cellSeeds.setSize( cellsCount );
return true;
return this->cellSeeds.setSize( cellsCount );
}
GlobalIndexType getPointsCount() const { return this->points.getSize(); }
GlobalIndexType getCellsCount() const { return this->cellSeeds.getSize(); }
void setPoint( GlobalIndexType index,
const PointType& point )
GlobalIndexType getPointsCount() const
{
return this->points.getSize();
}
GlobalIndexType getCellsCount() const
{
Assert( 0 <= index && index < getPointsCount(), std::cerr << "Index = " << index );
return this->cellSeeds.getSize();
}
void setPoint( GlobalIndexType index,
const PointType& point )
{
this->points[ index ] = point;
this->pointsSet[ index ] = true;
}
CellSeedType& getCellSeed( GlobalIndexType index )
{
TNL_ASSERT( 0 <= index && index < getCellsCount(), std::cerr << "Index = " << index );
return this->cellSeeds[ index ];
}
......@@ -80,56 +79,46 @@ class MeshBuilder
return true;
}
private:
typedef typename MeshTraitsType::PointArrayType PointArrayType;
typedef typename MeshTraitsType::CellSeedArrayType CellSeedArrayType;
private:
using PointArrayType = typename MeshTraitsType::PointArrayType;
using CellSeedArrayType = typename MeshTraitsType::CellSeedArrayType;
using BoolVector = Containers::Vector< bool, Devices::Host, GlobalIndexType >;
bool validate() const
{
if( ! allPointsSet() )
{
std::cerr << "Mesh builder error: Not all points were set." << std::endl;
return false;
}
bool validate() const
{
if( pointsSet.min() != true ) {
std::cerr << "Mesh builder error: Not all points were set." << std::endl;
return false;
}
std::unordered_set< GlobalIndexType > assignedPoints;
for( GlobalIndexType i = 0; i < getCellsCount(); i++ )
{
auto cornerIds = this->cellSeeds[ i ].getCornerIds();
for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ )
{
assignedPoints.insert( cornerIds[ j ] );
if( cornerIds[ j ] < 0 || getPointsCount() <= cornerIds[ j ] )
{
std::cerr << "Cell seed " << i << " is referencing unavailable point " << cornerIds[ j ] << std::endl;
return false;
}
BoolVector assignedPoints;
if( ! assignedPoints.setLike( pointsSet ) )
return false;
assignedPoints.setValue( false );
for( GlobalIndexType i = 0; i < getCellsCount(); i++ ) {
const auto cornerIds = this->cellSeeds[ i ].getCornerIds();
for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ ) {
assignedPoints[ cornerIds[ j ] ] = true;
if( cornerIds[ j ] < 0 || getPointsCount() <= cornerIds[ j ] ) {
std::cerr << "Cell seed " << i << " is referencing unavailable point " << cornerIds[ j ] << std::endl;
return false;
}
}
if( (GlobalIndexType) assignedPoints.size() != this->getPointsCount() )
{
std::cerr << "Mesh builder error: Some points were not used for cells." << std::endl;
return false;
}
return true;
}
bool allPointsSet() const
{
for( GlobalIndexType i = 0; i < this->points.getSize(); i++ )
if( ! this->pointsSet[ i ] )
return false;
return true;
if( assignedPoints.min() != true ) {
std::cerr << "Mesh builder error: Some points were not used for cells." << std::endl;
return false;
}
PointArrayType points;
CellSeedArrayType cellSeeds;
Containers::Array< bool, Devices::Host, GlobalIndexType > pointsSet;
return true;
}
PointArrayType points;
CellSeedArrayType cellSeeds;
BoolVector pointsSet;
};
} // namespace Meshes
} // namespace TNL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment