Skip to content

Commit

Permalink
accelerated solver startup
Browse files Browse the repository at this point in the history
  • Loading branch information
ScSteffen committed Jun 13, 2024
1 parent 0fc96b5 commit 893c03c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 72 deletions.
18 changes: 15 additions & 3 deletions src/common/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,25 @@ double Mesh::GetDistanceToOrigin( unsigned idx_cell ) const {
}

unsigned Mesh::GetCellOfKoordinate( double x, double y ) const {
// Experimental parallel implementation
unsigned koordinate_cell_id = 0;
bool found = false;

#pragma omp parallel for
for( unsigned idx_cell = 0; idx_cell < _numCells; idx_cell++ ) {
if( IsPointInsideCell( idx_cell, x, y ) ) {
return idx_cell;
#pragma omp critical
{
koordinate_cell_id = idx_cell;
found = true;
}
}
// Check if cancellation has been requested
}
if( !found ) {
ErrorMessages::Error( "Probing point (" + std::to_string( x ) + "," + std::to_string( y ) + ") is not contained in mesh.", CURRENT_FUNCTION );
}
ErrorMessages::Error( "Probing point (" + std::to_string( x ) + "," + std::to_string( y ) + ") is not contained in mesh.", CURRENT_FUNCTION );
return 0;
return koordinate_cell_id;
}

bool Mesh::IsPointInsideCell( unsigned idx_cell, double x, double y ) const {
Expand Down
7 changes: 4 additions & 3 deletions src/problems/problembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,16 @@ void ProblemBase::SetGhostCells() {
std::map<int, Vector> ghostCellMap;

Vector dummyGhostCell( 1, 0.0 );

// #pragma omp parallel for
for( unsigned idx_cell = 0; idx_cell < _mesh->GetNumCells(); idx_cell++ ) {
if( cellBoundaries[idx_cell] == BOUNDARY_TYPE::NEUMANN || cellBoundaries[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
// TODO: Refactor Boundary Conditions: We only have Ghost Cells with
// Dirichlet conditions right now
ghostCellMap.insert( { idx_cell, dummyGhostCell } );
// #pragma omp critical
{ ghostCellMap.insert( { idx_cell, dummyGhostCell } ); }
}
_ghostCells = ghostCellMap;
}
_ghostCells = ghostCellMap;
}

const Vector& ProblemBase::GetGhostCellValue( int /*idx_cell*/, const Vector& cell_sol ) { return cell_sol; }
Expand Down
69 changes: 32 additions & 37 deletions src/problems/quarterhohlraum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ void QuarterHohlraum::SetGhostCells() {

double tol = 1e-12; // For distance to boundary

unsigned nGhostcells = 0;
for( unsigned idx_cell = 0; idx_cell < _mesh->GetNumCells(); idx_cell++ ) {
if( cellBoundaries[idx_cell] == BOUNDARY_TYPE::NEUMANN || cellBoundaries[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
nGhostcells++;
}
}

QuadratureBase* quad = QuadratureBase::Create( _settings );
VectorVector vq = quad->GetPoints();
unsigned nq = quad->GetNq();
Expand Down Expand Up @@ -165,39 +158,41 @@ void QuarterHohlraum::SetGhostCells() {
}

auto nodes = _mesh->GetNodes();

#pragma omp parallel for
for( unsigned idx_cell = 0; idx_cell < _mesh->GetNumCells(); idx_cell++ ) {
if( cellBoundaries[idx_cell] == BOUNDARY_TYPE::NEUMANN || cellBoundaries[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
#pragma omp critical
{
auto localCellNodes = _mesh->GetCells()[idx_cell];

_ghostCellsReflectingX[idx_cell] = false;
_ghostCellsReflectingY[idx_cell] = false;
for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) { // Check if corner node is in this cell
if( abs( nodes[localCellNodes[idx_node]][0] ) < tol ) { // close to 0 => left boundary
_ghostCellsReflectingY[idx_cell] = true;
ghostCellMap.insert( { idx_cell, vertical_flow } );
break;
}
else if( abs( nodes[localCellNodes[idx_node]][0] ) > 0.65 - tol ) { // right boundary
ghostCellMap.insert( { idx_cell, right_inflow } );
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) < tol ) { // lower boundary
_ghostCellsReflectingX[idx_cell] = true;
ghostCellMap.insert( { idx_cell, vertical_flow } );

auto localCellNodes = _mesh->GetCells()[idx_cell];

_ghostCellsReflectingX[idx_cell] = false;
_ghostCellsReflectingY[idx_cell] = false;
for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) { // Check if corner node is in this cell
if( abs( nodes[localCellNodes[idx_node]][0] ) < tol ) { // close to 0 => left boundary
_ghostCellsReflectingY[idx_cell] = true;
ghostCellMap.insert( { idx_cell, vertical_flow } );
break;
}
else if( abs( nodes[localCellNodes[idx_node]][0] ) > 0.65 - tol ) { // right boundary
ghostCellMap.insert( { idx_cell, right_inflow } );
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) < tol ) { // lower boundary
_ghostCellsReflectingX[idx_cell] = true;
ghostCellMap.insert( { idx_cell, vertical_flow } );

break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) > 0.65 - tol ) { // upper boundary
ghostCellMap.insert( { idx_cell, vertical_flow } );
break;
}
else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
ErrorMessages::Error( " Problem with ghost cell setup and boundary of this mesh at cell " + std::to_string( idx_cell ) +
" with node coordinates " + std::to_string( _mesh->GetNodes()[localCellNodes[idx_node]][0] ) + "," +
std::to_string( _mesh->GetNodes()[localCellNodes[idx_node]][1] ),
CURRENT_FUNCTION );
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) > 0.65 - tol ) { // upper boundary
ghostCellMap.insert( { idx_cell, vertical_flow } );
break;
}
else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
ErrorMessages::Error( " Problem with ghost cell setup and boundary of this mesh at cell " + std::to_string( idx_cell ) +
" with node coordinates " + std::to_string( _mesh->GetNodes()[localCellNodes[idx_node]][0] ) + "," +
std::to_string( _mesh->GetNodes()[localCellNodes[idx_node]][1] ),
CURRENT_FUNCTION );
}
}
}
}
Expand Down
59 changes: 30 additions & 29 deletions src/solvers/snsolver_hpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,39 +1370,40 @@ void SNSolverHPC::SetGhostCells() {

auto nodes = _mesh->GetNodes();

// #pragma omp parallel for
#pragma omp parallel for
for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {

if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN || _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {

auto localCellNodes = _mesh->GetCells()[idx_cell];

_ghostCellsReflectingX[idx_cell] = false;
_ghostCellsReflectingY[idx_cell] = false;
_ghostCells[idx_cell] = std::vector<double>( _nSys, 0.0 );

for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) { // Check if corner node is in this cell
if( abs( nodes[localCellNodes[idx_node]][0] ) < tol ) { // close to 0 => left boundary
_ghostCellsReflectingY[idx_cell] = true;
break;
}
else if( abs( nodes[localCellNodes[idx_node]][0] ) > 0.65 - tol ) { // right boundary
for( unsigned idx_q = 0; idx_q < _nSys; idx_q++ ) {
if( _quadPts[Idx2D( idx_q, 0, _nDim )] < 0.0 ) {
_ghostCells[idx_cell][idx_q] = 1.0;
#pragma omp critical
{
auto localCellNodes = _mesh->GetCells()[idx_cell];

_ghostCellsReflectingX[idx_cell] = false;
_ghostCellsReflectingY[idx_cell] = false;
_ghostCells[idx_cell] = std::vector<double>( _nSys, 0.0 );

for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) { // Check if corner node is in this cell
if( abs( nodes[localCellNodes[idx_node]][0] ) < tol ) { // close to 0 => left boundary
_ghostCellsReflectingY[idx_cell] = true;
break;
}
else if( abs( nodes[localCellNodes[idx_node]][0] ) > 0.65 - tol ) { // right boundary
for( unsigned idx_q = 0; idx_q < _nSys; idx_q++ ) {
if( _quadPts[Idx2D( idx_q, 0, _nDim )] < 0.0 ) {
_ghostCells[idx_cell][idx_q] = 1.0;
}
}
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) < tol ) { // lower boundary
_ghostCellsReflectingX[idx_cell] = true;
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) > 0.65 - tol ) { // upper boundary
break;
}
else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
ErrorMessages::Error( " Problem with ghost cell setup and boundary of this mesh ", CURRENT_FUNCTION );
}
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) < tol ) { // lower boundary
_ghostCellsReflectingX[idx_cell] = true;
break;
}
else if( abs( nodes[localCellNodes[idx_node]][1] ) > 0.65 - tol ) { // upper boundary
break;
}
else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
ErrorMessages::Error( " Problem with ghost cell setup and boundary of this mesh ", CURRENT_FUNCTION );
}
}
}
Expand Down

0 comments on commit 893c03c

Please sign in to comment.