Commit 337e7d4d authored by Jannick Wolters's avatar Jannick Wolters
Browse files

everything working in serial

parent a202beb4
Pipeline #82232 passed with stages
in 7 minutes
......@@ -13,7 +13,6 @@ file( GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" "include/*.h" )
include_directories( ${CMAKE_SOURCE_DIR}/include )
add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} )
find_package( OpenMP REQUIRED )
if( OPENMP_FOUND )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
......
......@@ -41,6 +41,7 @@ using vtkPointDataToCellDataSP = vtkSmartPointer<vtkPointDataToCellData>;
void ExportVTK( const std::string fileName,
const std::vector<std::vector<std::vector<double>>>& results,
const std::vector<std::string> fieldNames,
const Settings* settings,
const Mesh* mesh );
void InitLogger( std::string logDir, spdlog::level::level_enum terminalLogLvl, spdlog::level::level_enum fileLogLvl );
Mesh* LoadSU2MeshFromFile( const Settings* settings );
......
......@@ -20,12 +20,12 @@ class Mesh
protected:
std::shared_ptr<spdlog::logger> _log;
unsigned _dim;
unsigned _numCells;
unsigned _numNodes;
unsigned _numNodesPerCell;
unsigned _numBoundaries;
unsigned _ghostCellID;
const unsigned _dim;
const unsigned _numCells;
const unsigned _numNodes;
const unsigned _numNodesPerCell;
const unsigned _numBoundaries;
const unsigned _ghostCellID;
std::vector<Vector> _nodes;
std::vector<std::vector<unsigned>> _cells;
......@@ -34,6 +34,8 @@ class Mesh
std::vector<double> _cellAreas;
std::vector<std::vector<unsigned>> _cellNeighbors;
std::vector<std::vector<Vector>> _cellNormals;
std::vector<bool> _isBoundaryCell;
blaze::CompressedMatrix<bool> _nodeNeighbors;
std::vector<unsigned> _colors;
void ComputeCellAreas();
......@@ -56,6 +58,7 @@ class Mesh
const std::vector<Vector>& GetNodes() const;
const std::vector<std::vector<unsigned>>& GetCells() const;
const std::vector<double>& GetCellAreas() const;
const std::vector<unsigned>& GetPartitionIDs() const;
};
#endif // MESH_H
......@@ -3,7 +3,9 @@
void ExportVTK( const std::string fileName,
const std::vector<std::vector<std::vector<double>>>& results,
const std::vector<std::string> fieldNames,
const Settings* settings,
const Mesh* mesh ) {
unsigned dim = mesh->GetDim();
unsigned numCells = mesh->GetNumCells();
unsigned numNodes = mesh->GetNumNodes();
auto nodes = mesh->GetNodes();
......@@ -15,14 +17,22 @@ void ExportVTK( const std::string fileName,
if( !fileNameWithExt.ends_with( ".vtk" ) ) {
fileNameWithExt.append( ".vtk" );
}
writer->SetFileName( fileNameWithExt.c_str() );
writer->SetFileName( ( settings->GetOutputDir() + fileNameWithExt ).c_str() );
auto grid = vtkUnstructuredGridSP::New();
auto pts = vtkPointsSP::New();
pts->SetDataTypeToDouble();
pts->SetNumberOfPoints( static_cast<int>( numNodes ) );
unsigned nodeID = 0;
for( const auto& node : nodes ) {
pts->SetPoint( nodeID++, node[0], node[1], node[2] );
if( dim == 2 ) {
pts->SetPoint( nodeID++, node[0], node[1], 0.0 );
}
else if( dim == 3 ) {
pts->SetPoint( nodeID++, node[0], node[1], node[2] );
}
else {
exit( EXIT_FAILURE );
}
}
vtkCellArraySP cellArray = vtkCellArraySP::New();
for( unsigned i = 0; i < numCells; ++i ) {
......@@ -246,6 +256,9 @@ Mesh* LoadSU2MeshFromFile( const Settings* settings ) {
exit( EXIT_FAILURE );
}
}
std::sort( bnodes.begin(), bnodes.end() );
auto last = std::unique( bnodes.begin(), bnodes.end() );
bnodes.erase( last, bnodes.end() );
boundaries[i] = std::make_pair( btype, bnodes );
}
break;
......
......@@ -11,8 +11,14 @@ int main( int argc, char** argv ) {
PrintLogHeader( settings->GetInputFile() );
#include "mesh.h"
Mesh* m = LoadSU2MeshFromFile( settings );
std::cout << &m << std::endl;
Mesh* m = LoadSU2MeshFromFile( settings );
auto colors = m->GetPartitionIDs();
std::vector<double> dcolors( colors.size() );
for( unsigned i = 0; i < colors.size(); ++i ) dcolors[i] = static_cast<double>( colors[i] );
std::vector<std::vector<double>> scalarField{dcolors};
std::vector<std::vector<std::vector<double>>> out{scalarField};
std::vector<std::string> fieldNames{"color"};
ExportVTK( "partitioning", out, fieldNames, settings, m );
return EXIT_SUCCESS;
}
......@@ -75,6 +75,12 @@ void Mesh::ComputeConnectivity() {
}
for( auto it = neighborsFlat.begin(); it != neighborsFlat.end(); it += _numNodesPerCell )
_cellNeighbors.push_back( std::vector<unsigned>( it, it + _numNodesPerCell ) );
_isBoundaryCell.resize( _numCells, false );
for( unsigned i = 0; i < _numCells; ++i ) {
if( std::any_of( _cellNeighbors[i].begin(), _cellNeighbors[i].end(), [this]( unsigned i ) { return i == this->_ghostCellID; } ) )
_isBoundaryCell[i] = true;
}
}
void Mesh::ComputeCellAreas() {
......@@ -150,25 +156,53 @@ void Mesh::ComputePartitioning() {
MPI_Comm_rank( comm, &comm_rank );
unsigned ompNThreads = omp_get_max_threads();
unsigned long nPoint = _numNodes;
if( ompNThreads > 1 ) {
blaze::CompressedMatrix<unsigned> adjMatrix( _numNodes, _numNodes );
unsigned long nPoint = _numNodes;
blaze::CompressedMatrix<bool> adjMatrix( _numNodes, _numNodes );
for( unsigned i = 0; i < _numNodes; ++i ) {
for( unsigned j = 0; j < _numCells; ++j ) {
for( unsigned k = 0; k < _numNodesPerCell; ++k ) {
if( i == _cells[j][k] ) {
if( k == 0 ) {
adjMatrix.set( i, _cells[j][_numNodesPerCell - 1], true );
adjMatrix.set( i, _cells[j][1], true );
}
else if( k == _numNodesPerCell - 1 ) {
adjMatrix.set( i, _cells[j][_numNodesPerCell - 2], true );
adjMatrix.set( i, _cells[j][0], true );
}
else {
adjMatrix.set( i, _cells[j][k - 1], true );
adjMatrix.set( i, _cells[j][k + 1], true );
}
}
}
}
}
int* xadj = new int[_nodes.size() + 1];
std::vector<int> tmp_adjncy;
std::vector<int> xadj( _numNodes + 1 );
std::vector<int> adjncy;
int ctr = 0;
for( unsigned i = 0; i < _numNodes; ++i ) {
xadj[i] = ctr;
for( unsigned j = 0; j < _numNodes; ++j ) {
if( adjMatrix( i, j ) == 1u ) {
tmp_adjncy.push_back( static_cast<int>( j ) );
if( adjMatrix( i, j ) ) {
adjncy.push_back( static_cast<int>( j ) );
ctr++;
}
}
}
int* adjncy = new int[static_cast<unsigned long>( xadj[_numNodes + 1] )];
std::copy( tmp_adjncy.begin(), tmp_adjncy.end(), adjncy );
xadj[_numNodes] = ctr;
real_t ubvec = static_cast<real_t>( 1.05 );
int* part;
int edgecut;
int ncon = 1;
int nparts = ompNThreads;
int options[METIS_NOPTIONS];
METIS_SetDefaultOptions( options );
if( comm_size > 1 ) { // use parmetis
std::vector<unsigned> npoint_procs( ompNThreads );
......@@ -186,50 +220,54 @@ void Mesh::ComputePartitioning() {
ending_node[i] = starting_node[i] + npoint_procs[i];
}
int numflag, nparts, edgecut, wgtflag, ncon;
int* vtxdist = new int[static_cast<unsigned>( ompNThreads ) + 1u];
int* part = new int[nPoint];
real_t ubvec;
real_t* tpwgts = new real_t[ompNThreads];
part = new int[nPoint];
wgtflag = 0;
numflag = 0;
ncon = 1;
ubvec = static_cast<real_t>( 1.05 );
nparts = ompNThreads;
int options[METIS_NOPTIONS];
METIS_SetDefaultOptions( options );
options[1] = 0;
for( unsigned i = 0; i < ompNThreads; i++ ) {
tpwgts[i] = static_cast<real_t>( 1.0 ) / static_cast<real_t>( ompNThreads );
}
int wgtflag = 0;
int numflag = 0;
vtxdist[0] = 0;
for( unsigned i = 0; i < ompNThreads; i++ ) {
vtxdist[i + 1] = static_cast<int>( ending_node[i] );
}
ParMETIS_V3_PartKway(
vtxdist, xadj, adjncy, nullptr, nullptr, &wgtflag, &numflag, &ncon, &nparts, tpwgts, &ubvec, options, &edgecut, part, &comm );
_colors.resize( nPoint );
for( unsigned i = 0; i < nPoint; ++i ) {
_colors[i] = static_cast<unsigned>( part[i] );
}
ParMETIS_V3_PartKway( vtxdist,
xadj.data(),
adjncy.data(),
nullptr,
nullptr,
&wgtflag,
&numflag,
&ncon,
&nparts,
nullptr,
&ubvec,
options,
&edgecut,
part,
&comm );
delete[] vtxdist;
delete[] part;
delete[] tpwgts;
}
else { // use metis
// METIS_PartGraphKway();
int nvtxs = _numNodes;
int vsize;
part = new int[_numNodes];
METIS_PartGraphKway(
&nvtxs, &ncon, xadj.data(), adjncy.data(), nullptr, &vsize, nullptr, &nparts, nullptr, &ubvec, options, &edgecut, part );
}
_colors.resize( _numCells );
for( unsigned i = 0; i < _numCells; ++i ) {
std::map<unsigned, int> occurances;
for( unsigned j = 0; j < _numNodesPerCell; ++j ) {
++occurances[part[_cells[i][j]]];
}
_colors[i] = occurances.rbegin()->first;
}
delete[] part;
}
else {
_colors.resize( nPoint, 0u );
_colors.resize( _numCells, 0u );
}
}
......@@ -240,4 +278,5 @@ unsigned Mesh::GetNumNodesPerCell() const { return _numNodesPerCell; }
const std::vector<Vector>& Mesh::GetNodes() const { return _nodes; }
const std::vector<std::vector<unsigned>>& Mesh::GetCells() const { return _cells; }
const std::vector<double>& Mesh::GetCellAreas() const { return _cellAreas; };
const std::vector<double>& Mesh::GetCellAreas() const { return _cellAreas; }
const std::vector<unsigned>& Mesh::GetPartitionIDs() const { return _colors; }
Supports Markdown
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