Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: boundary conditions #998

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 23 additions & 42 deletions include/BoundaryConditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <map>
#include <string>
#include <vector>
#include <memory>

namespace YAML {
class Node;
Expand All @@ -34,53 +35,33 @@ class BoundaryCondition {
BoundaryCondition(BoundaryConditions& bcs) : boundaryConditions_(bcs) {}

virtual ~BoundaryCondition() {}

BoundaryCondition * load(const YAML::Node & node) ;
Simulation *root();
BoundaryConditions *parent();

void breadboard()
{
// nothing
}


std::unique_ptr<BoundaryCondition> load(const YAML::Node& node);

std::string bcName_;
std::string targetName_;
BoundaryConditionType theBcType_;
BoundaryConditions& boundaryConditions_;
};

typedef std::vector<BoundaryCondition *> BoundaryConditionVector;

class BoundaryConditions {
public:

BoundaryConditions(Realm& realm)
: realm_(realm) {}
~BoundaryConditions() {
for ( size_t iboundary_condition = 0; iboundary_condition < boundaryConditionVector_.size(); ++iboundary_condition ) {
delete boundaryConditionVector_[iboundary_condition];
}
}

BoundaryConditions* load(const YAML::Node & node);

void breadboard()
{
for ( size_t iboundary_condition = 0; iboundary_condition < boundaryConditionVector_.size(); ++iboundary_condition ) {
boundaryConditionVector_[iboundary_condition]->breadboard();
}
}

Simulation *root();
Realm *parent();

// ease of access methods to particular boundary condition
size_t size() {return boundaryConditionVector_.size();}
BoundaryCondition *operator[](int i) { return boundaryConditionVector_[i];}

Realm &realm_;
BoundaryConditionVector boundaryConditionVector_;

typedef std::vector<std::unique_ptr<BoundaryCondition>> BoundaryConditionVector;

class BoundaryConditions
{
public:
BoundaryConditions(Realm& realm) : realm_(realm) {}
~BoundaryConditions() = default;

void load(const YAML::Node& node);

// ease of access methods to particular boundary condition
BoundaryCondition* operator[](int i)
{
return boundaryConditionVector_[i].get();
}

Realm& realm_;
BoundaryConditionVector boundaryConditionVector_;
};

} // namespace nalu
Expand Down
187 changes: 96 additions & 91 deletions src/BoundaryConditions.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// for more details.
//



#include <Realm.h>
#include <BoundaryConditions.h>
#include <NaluEnv.h>
Expand All @@ -17,8 +15,8 @@
#include <yaml-cpp/yaml.h>
#include <NaluParsing.h>

namespace sierra{
namespace nalu{
namespace sierra {
namespace nalu {

//==========================================================================
// Class Definition
Expand All @@ -28,7 +26,7 @@ namespace nalu{
//--------------------------------------------------------------------------
//-------- constructor -----------------------------------------------------
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//-------- destructor ------------------------------------------------------
//--------------------------------------------------------------------------
Expand All @@ -37,103 +35,110 @@ namespace nalu{
//-------- load -----------------------------------------------
//--------------------------------------------------------------------------


/// this is an example of a load() method with polymorphism - the type of
/// the node is determined from some information, then a particular type
/// of object is created and returned to the parent.

BoundaryCondition * BoundaryCondition::load(const YAML::Node & node)
template <typename T>
std::unique_ptr<BoundaryCondition>
register_bc(const YAML::Node& node, BoundaryConditions& bcs)
{
if ( node["wall_boundary_condition"] ){
WallBoundaryConditionData& wallBC = *new WallBoundaryConditionData(*parent());
node >> wallBC;
NaluEnv::self().naluOutputP0() << "Wall BC name: " << wallBC.bcName_
<< " on " << wallBC.targetName_ << std::endl;
return &wallBC;
}
else if (node["inflow_boundary_condition"]) {
InflowBoundaryConditionData& inflowBC = *new InflowBoundaryConditionData(*parent());
node >> inflowBC;
NaluEnv::self().naluOutputP0() << "Inflow BC name: " << inflowBC.bcName_
<< " on " << inflowBC.targetName_ << std::endl;
return &inflowBC;
}
else if (node["open_boundary_condition"]) {
OpenBoundaryConditionData& openBC = *new OpenBoundaryConditionData(*parent());
node >> openBC;
NaluEnv::self().naluOutputP0() << "Open BC name: " << openBC.bcName_
<< " on " << openBC.targetName_ << std::endl;
return &openBC;
}
else if (node["symmetry_boundary_condition"]) {
SymmetryBoundaryConditionData& symmetryBC = *new SymmetryBoundaryConditionData(*parent());
node >> symmetryBC;
NaluEnv::self().naluOutputP0() << "Symmetry BC name: " << symmetryBC.bcName_
<< " on " << symmetryBC.targetName_ << std::endl;
return &symmetryBC;
}
else if (node["abltop_boundary_condition"]) {
ABLTopBoundaryConditionData& abltopBC = *new ABLTopBoundaryConditionData(*parent());
node >> abltopBC;
NaluEnv::self().naluOutputP0() << "ABLTop BC name: " << abltopBC.bcName_
<< " on " << abltopBC.targetName_ << std::endl;
return &abltopBC;
}
else if (node["periodic_boundary_condition"]) {
PeriodicBoundaryConditionData& periodicBC = *new PeriodicBoundaryConditionData(*parent());
node >> periodicBC;
NaluEnv::self().naluOutputP0() << "Periodic BC name: " << periodicBC.bcName_
<< " between " << periodicBC.masterSlave_.master_
<< " and "<< periodicBC.masterSlave_.slave_ << std::endl;
return &periodicBC;
}
else if (node["non_conformal_boundary_condition"]) {
NonConformalBoundaryConditionData& nonConformalBC = *new NonConformalBoundaryConditionData(*parent());
node >> nonConformalBC;
NaluEnv::self().naluOutputP0() << "NonConformal BC name: " << nonConformalBC.bcName_
<< " using " << nonConformalBC.targetName_ << std::endl;
return &nonConformalBC;
}
else if (node["overset_boundary_condition"]) {
OversetBoundaryConditionData& oversetBC = *new OversetBoundaryConditionData(*parent());
node >> oversetBC;
NaluEnv::self().naluOutputP0() << "Overset BC name: " << oversetBC.bcName_ << std::endl;
return &oversetBC;
}
else {
throw std::runtime_error("parser error BoundaryConditions::load: no such bc type");
}
// Avoid nvcc unreachable statement warnings
#ifndef __CUDACC__
return 0;
#endif
std::unique_ptr<BoundaryCondition> this_bc = std::make_unique<T>(bcs);
auto* cast_bc = dynamic_cast<T*>(this_bc.get());
node >> *cast_bc;
return this_bc;
}

Simulation* BoundaryCondition::root() { return parent()->root(); }
BoundaryConditions *BoundaryCondition::parent() { return &boundaryConditions_; }
std::unique_ptr<BoundaryCondition>
BoundaryCondition::load(const YAML::Node& node)
{
std::unique_ptr<BoundaryCondition> this_bc;
if (node["wall_boundary_condition"]) {
this_bc = std::move(
register_bc<WallBoundaryConditionData>(node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "Wall BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

} else if (node["inflow_boundary_condition"]) {
this_bc = std::move(
register_bc<InflowBoundaryConditionData>(node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "Inflow BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

} else if (node["open_boundary_condition"]) {
this_bc = std::move(
register_bc<OpenBoundaryConditionData>(node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "Open BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

Simulation* BoundaryConditions::root() { return parent()->root(); }
Realm *BoundaryConditions::parent() { return &realm_; }
} else if (node["symmetry_boundary_condition"]) {
this_bc = std::move(
register_bc<SymmetryBoundaryConditionData>(node, boundaryConditions_));

BoundaryConditions* BoundaryConditions::load(const YAML::Node &node)
NaluEnv::self().naluOutputP0()
<< "Symmetry BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

} else if (node["abltop_boundary_condition"]) {
this_bc = std::move(
register_bc<ABLTopBoundaryConditionData>(node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "ABLTop BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

} else if (node["periodic_boundary_condition"]) {
this_bc = std::move(
register_bc<PeriodicBoundaryConditionData>(node, boundaryConditions_));

auto* periodicBC =
dynamic_cast<PeriodicBoundaryConditionData*>(this_bc.get());

NaluEnv::self().naluOutputP0()
<< "Periodic BC name: " << periodicBC->bcName_ << " between "
<< periodicBC->masterSlave_.master_ << " and "
<< periodicBC->masterSlave_.slave_ << std::endl;

} else if (node["non_conformal_boundary_condition"]) {
this_bc = std::move(register_bc<NonConformalBoundaryConditionData>(
node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "NonConformal BC name: " << this_bc->bcName_ << " using "
<< this_bc->targetName_ << std::endl;

} else if (node["overset_boundary_condition"]) {
this_bc = std::move(
register_bc<OversetBoundaryConditionData>(node, boundaryConditions_));

NaluEnv::self().naluOutputP0()
<< "Overset BC name: " << this_bc->bcName_ << std::endl;

} else {
throw std::runtime_error(
"parser error BoundaryConditions::load: no such bc type");
}
return this_bc;
}

void
BoundaryConditions::load(const YAML::Node& node)
{
BoundaryCondition tmp_boundary_condition(*this);
BoundaryCondition bc_factory(*this);

if(node["boundary_conditions"]) {
if (node["boundary_conditions"]) {
const YAML::Node boundary_conditions = node["boundary_conditions"];
for ( size_t iboundary_condition = 0; iboundary_condition < boundary_conditions.size(); ++iboundary_condition ) {
const YAML::Node boundary_condition_node = boundary_conditions[iboundary_condition];
BoundaryCondition* bc = tmp_boundary_condition.load(boundary_condition_node);
boundaryConditionVector_.push_back(bc);

for (auto&& bc_node : boundary_conditions) {
boundaryConditionVector_.emplace_back(bc_factory.load(bc_node));
}
}
else {

} else {
throw std::runtime_error("parser error BoundaryConditions::load");
}

return this;
}


} // namespace nalu
} // namespace Sierra
} // namespace sierra
12 changes: 5 additions & 7 deletions src/Realm.C
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,10 @@ void
Realm::setup_bc()
{
// loop over all bcs and register
for (size_t ibc = 0; ibc < boundaryConditions_.size(); ++ibc) {
BoundaryCondition& bc = *boundaryConditions_[ibc];
std::string name = physics_part_name(bc.targetName_);
for (auto&& bc : boundaryConditions_.boundaryConditionVector_) {
std::string name = physics_part_name(bc->targetName_);

switch(bc.theBcType_) {
switch(bc->theBcType_) {
case WALL_BC:
equationSystems_.register_wall_bc(name, *reinterpret_cast<const WallBoundaryConditionData *>(&bc));
break;
Expand Down Expand Up @@ -2314,9 +2313,8 @@ Realm::has_non_matching_boundary_face_alg() const
bool
Realm::query_for_overset()
{
for (size_t ibc = 0; ibc < boundaryConditions_.size(); ++ibc) {
BoundaryCondition& bc = *boundaryConditions_[ibc];
switch(bc.theBcType_) {
for (auto&& bc : boundaryConditions_.boundaryConditionVector_) {
switch(bc->theBcType_) {
case OVERSET_BC:
hasOverset_ = true;
break;
Expand Down