From 824589258e14933c0d9032b1ff2f1cb397a5a59a Mon Sep 17 00:00:00 2001 From: zy69guqi <richard.angersbach@fau.de> Date: Thu, 28 Sep 2023 19:30:20 +0200 Subject: [PATCH] Add type checker functions to BoundaryCondition class --- .../ApplyPotentialValidationBoundaryConditions.h | 4 ++-- .../ChargedParticles/poisson_solver/BoundaryCondition.h | 4 ++++ .../ChargedParticles/poisson_solver/DirichletDomainBoundary.h | 2 +- apps/showcases/ChargedParticles/poisson_solver/Neumann.h | 2 +- .../poisson_solver/PotentialValidationCustomBoundary.h | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/showcases/ChargedParticles/poisson_solver/ApplyPotentialValidationBoundaryConditions.h b/apps/showcases/ChargedParticles/poisson_solver/ApplyPotentialValidationBoundaryConditions.h index 0fe32b43e..5eb2be600 100644 --- a/apps/showcases/ChargedParticles/poisson_solver/ApplyPotentialValidationBoundaryConditions.h +++ b/apps/showcases/ChargedParticles/poisson_solver/ApplyPotentialValidationBoundaryConditions.h @@ -52,14 +52,14 @@ void applyPotentialBoundaryValue(IBlock* block, PdeField* p, const CellInterval& } funcVal = real_c(0); - if (e.getType() == "Dirichlet") { + if (e.isDirichletType()) { real_t distance = real_c(std::sqrt(pow((boundaryCoord_x - domainAABB.center()[0]), 2) + pow((boundaryCoord_y - domainAABB.center()[1]), 2) + pow((boundaryCoord_z - domainAABB.center()[2]), 2))); funcVal = (charge / (4 * math::pi * epsilon * distance)); p->get(x, y, z) = real_c(2) * funcVal - p->get(x + cx, y + cy, z + cz); - } else if (e.getType() == "Neumann") { + } else if (e.isNeumannType()) { funcVal = e.getValue(); if (isIdentical(funcVal, real_t(0))) diff --git a/apps/showcases/ChargedParticles/poisson_solver/BoundaryCondition.h b/apps/showcases/ChargedParticles/poisson_solver/BoundaryCondition.h index 29bd9f25f..77df9ec03 100644 --- a/apps/showcases/ChargedParticles/poisson_solver/BoundaryCondition.h +++ b/apps/showcases/ChargedParticles/poisson_solver/BoundaryCondition.h @@ -10,6 +10,10 @@ public: std::string getType() { return type_; } + bool isDirichletType() { return getType() == "Dirichlet"; } + + bool isNeumannType() { return getType() == "Neumann"; } + real_t getValue() { return value_; } BoundaryCondition(stencil::Direction direction, std::string type, real_t value) diff --git a/apps/showcases/ChargedParticles/poisson_solver/DirichletDomainBoundary.h b/apps/showcases/ChargedParticles/poisson_solver/DirichletDomainBoundary.h index 9156d6c1b..3ab73bf8a 100644 --- a/apps/showcases/ChargedParticles/poisson_solver/DirichletDomainBoundary.h +++ b/apps/showcases/ChargedParticles/poisson_solver/DirichletDomainBoundary.h @@ -18,7 +18,7 @@ class DirichletDomainBoundary for (auto e : boundaryConditions) { - if (e.getType() == "Neumann") { this->excludeBoundary(e.getDirection()); } // swap conditions + if (e.isNeumannType()) { this->excludeBoundary(e.getDirection()); } // swap conditions else { this->includeBoundary(e.getDirection()); diff --git a/apps/showcases/ChargedParticles/poisson_solver/Neumann.h b/apps/showcases/ChargedParticles/poisson_solver/Neumann.h index d102aad87..b441c35fa 100644 --- a/apps/showcases/ChargedParticles/poisson_solver/Neumann.h +++ b/apps/showcases/ChargedParticles/poisson_solver/Neumann.h @@ -72,7 +72,7 @@ class NeumannDomainBoundary for (auto e : boundaryConditions) { - if (e.getType() == "Dirichlet") { this->excludeBoundary(e.getDirection()); } // swap condtions + if (e.isDirichletType()) { this->excludeBoundary(e.getDirection()); } // swap condtions else { this->includeBoundary(e.getDirection()); diff --git a/apps/showcases/ChargedParticles/poisson_solver/PotentialValidationCustomBoundary.h b/apps/showcases/ChargedParticles/poisson_solver/PotentialValidationCustomBoundary.h index bdec79a05..b0eee9fff 100644 --- a/apps/showcases/ChargedParticles/poisson_solver/PotentialValidationCustomBoundary.h +++ b/apps/showcases/ChargedParticles/poisson_solver/PotentialValidationCustomBoundary.h @@ -23,7 +23,7 @@ class PotentialCustomBoundary this->includeBoundary(e.getDirection()); this->setValue(e.getDirection(), e.getValue()); - if (e.getType() == "Neumann") + if (e.isNeumannType()) { if (e.getDirection() == stencil::E) { dx_[stencil::D3Q6::idx[stencil::E]] = blocks.dx(); } else if (e.getDirection() == stencil::W) { dx_[stencil::D3Q6::idx[stencil::W]] = blocks.dx(); } @@ -81,7 +81,7 @@ class PotentialCustomBoundary const cell_idx_t cy, const cell_idx_t cz, BoundaryCondition& e, StructuredBlockStorage& blocks, const math::AABB& domainAABB, const real_t charge, const real_t epsilon) { - if (e.getType() == "Neumann") + if (e.isNeumannType()) { dx_[stencil::D3Q6::idx[stencil::E]] = blocks.dx(); dx_[stencil::D3Q6::idx[stencil::W]] = blocks.dx(); -- GitLab