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 all 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
68 changes: 15 additions & 53 deletions include/BoundaryConditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,34 @@
#include <map>
#include <string>
#include <vector>
#include <memory>

namespace YAML {
class Node;
}

namespace sierra{
namespace nalu{

class Realm;
class BoundaryConditions;
class Simulation;
namespace nalu {

class BoundaryCondition {
public:
BoundaryCondition(BoundaryConditions& bcs) : boundaryConditions_(bcs) {}

virtual ~BoundaryCondition() {}

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

void breadboard()
{
// nothing
}

std::string bcName_;
std::string targetName_;
BoundaryConditionType theBcType_;
BoundaryConditions& boundaryConditions_;
BoundaryCondition() {}
virtual ~BoundaryCondition() {}

std::string bcName_;
std::string targetName_;
BoundaryConditionType theBcType_;
};

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);
typedef std::vector<std::unique_ptr<BoundaryCondition>> BoundaryConditionVector;
struct BoundaryConditionCreator
{
public:
BoundaryConditionVector create_bc_vector(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_;
std::unique_ptr<BoundaryCondition>
load_single_bc_node(const YAML::Node& node);
};

} // namespace nalu
} // namespace Sierra

Expand Down
16 changes: 8 additions & 8 deletions include/NaluParsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,17 @@ struct NonConformalUserData : public UserData {
};

struct WallBoundaryConditionData : public BoundaryCondition {
WallBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
WallBoundaryConditionData(){};
WallUserData userData_;
};

struct InflowBoundaryConditionData : public BoundaryCondition {
InflowBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
InflowBoundaryConditionData(){};
InflowUserData userData_;
};

struct OpenBoundaryConditionData : public BoundaryCondition {
OpenBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
OpenBoundaryConditionData(){};
OpenUserData userData_;
};

Expand All @@ -258,30 +258,30 @@ struct OversetBoundaryConditionData : public BoundaryCondition {
OVERSET_NONE = 1 ///< Guard for error messages
};

OversetBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
OversetBoundaryConditionData(){};
OversetUserData userData_;
OversetAPI oversetConnectivityType_;
};

struct SymmetryBoundaryConditionData : public BoundaryCondition {
SymmetryBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
SymmetryBoundaryConditionData(){};
SymmetryUserData userData_;
};

struct ABLTopBoundaryConditionData : public BoundaryCondition {
ABLTopBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
ABLTopBoundaryConditionData(){};
ABLTopUserData userData_;
SymmetryUserData symmetryUserData_;
};

struct PeriodicBoundaryConditionData : public BoundaryCondition {
PeriodicBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
PeriodicBoundaryConditionData(){};
MasterSlave masterSlave_;
PeriodicUserData userData_;
};

struct NonConformalBoundaryConditionData : public BoundaryCondition {
NonConformalBoundaryConditionData(BoundaryConditions& bcs) : BoundaryCondition(bcs){};
NonConformalBoundaryConditionData(){};
std::vector<std::string> currentPartNameVec_;
std::vector<std::string> opposingPartNameVec_;
NonConformalUserData userData_;
Expand Down
2 changes: 1 addition & 1 deletion include/Realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class Realm {

TimeIntegrator *timeIntegrator_;

BoundaryConditions boundaryConditions_;
BoundaryConditionVector boundaryConditions_;
InitialConditions initialConditions_;
MaterialPropertys materialPropertys_;

Expand Down
196 changes: 90 additions & 106 deletions src/BoundaryConditions.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,133 +7,117 @@
// for more details.
//



#include <Realm.h>
#include <BoundaryConditions.h>
#include <NaluEnv.h>

// yaml for parsing..
#include <yaml-cpp/yaml.h>
#include <NaluParsing.h>

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

//==========================================================================
// Class Definition
//==========================================================================
// BoundaryCondition - do some stuff
//==========================================================================
//--------------------------------------------------------------------------
//-------- constructor -----------------------------------------------------
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//-------- destructor ------------------------------------------------------
//--------------------------------------------------------------------------
// helper function for reducing code duplication in the construction process
template <typename T>
std::unique_ptr<BoundaryCondition>
register_bc(const YAML::Node& node)
{
std::unique_ptr<BoundaryCondition> this_bc = std::make_unique<T>();
auto* cast_bc = dynamic_cast<T*>(this_bc.get());
node >> *cast_bc;
return this_bc;
}

//--------------------------------------------------------------------------
//-------- load -----------------------------------------------
//--------------------------------------------------------------------------
// factory method to create any supported bc
std::unique_ptr<BoundaryCondition>
BoundaryConditionCreator::load_single_bc_node(const YAML::Node& node)
{
std::unique_ptr<BoundaryCondition> this_bc;
if (node["wall_boundary_condition"]) {
this_bc = std::move(register_bc<WallBoundaryConditionData>(node));

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

/// 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.
} else if (node["inflow_boundary_condition"]) {
this_bc = std::move(register_bc<InflowBoundaryConditionData>(node));

BoundaryCondition * BoundaryCondition::load(const YAML::Node & node)
{
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
}
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));

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

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

Simulation* BoundaryConditions::root() { return parent()->root(); }
Realm *BoundaryConditions::parent() { return &realm_; }
NaluEnv::self().naluOutputP0()
<< "Symmetry BC name: " << this_bc->bcName_ << " on "
<< this_bc->targetName_ << std::endl;

BoundaryConditions* BoundaryConditions::load(const YAML::Node &node)
} else if (node["abltop_boundary_condition"]) {
this_bc = std::move(register_bc<ABLTopBoundaryConditionData>(node));

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));

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));

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));

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;
}

// convenience function to create a vector of bc's contianed in a single yaml
// node
BoundaryConditionVector
BoundaryConditionCreator::create_bc_vector(const YAML::Node& node)
{
BoundaryCondition tmp_boundary_condition(*this);
BoundaryConditionVector bc_vector;

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) {
bc_vector.emplace_back(load_single_bc_node(bc_node));
}
}
else {

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

return this;
return bc_vector;
}


} // namespace nalu
} // namespace Sierra
} // namespace sierra
2 changes: 1 addition & 1 deletion src/EquationSystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void EquationSystem::register_abltop_bc(
const stk::topology &theTopo,
const ABLTopBoundaryConditionData &abltopBCData)
{
SymmetryBoundaryConditionData simData(abltopBCData.boundaryConditions_);
SymmetryBoundaryConditionData simData;
register_symmetry_bc( part, theTopo, simData );
}

Expand Down
Loading