diff --git a/src/main.cpp b/src/main.cpp index c12e2c9773d131547a54dd60ed0a6ffc39323f94..58166eda7fd3b7c1ffa33a7079d937991372c7d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) // test case boundary condition description std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX"}; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; - for (auto sym_boundary_name : sym_boundary_name_list){ + for (const auto& sym_boundary_name : sym_boundary_name_list){ std::shared_ptr<BoundaryDescriptor> boudary_descriptor = std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); SymmetryBoundaryConditionDescriptor* sym_bc_descriptor @@ -239,7 +239,20 @@ int main(int argc, char *argv[]) std::vector<BoundaryConditionHandler> bc_list; { - + for (const auto& bc_descriptor : bc_descriptor_list) { + switch (bc_descriptor->type()) { + case BoundaryConditionDescriptor::Type::symmetry: { + const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor + = dynamic_cast<const SymmetryBoundaryConditionDescriptor&>(*bc_descriptor); + std::cout << sym_bc_descriptor << '\n'; + break; + } + default: { + std::cerr << "Unknown BCDescription\n"; + std::exit(1); + } + } + } for (size_t i_ref_face_list=0; i_ref_face_list<mesh.connectivity().numberOfRefFaceList(); ++i_ref_face_list) { const RefFaceList& ref_face_list = mesh.connectivity().refFaceList(i_ref_face_list); diff --git a/src/scheme/BoundaryConditionDescriptor.hpp b/src/scheme/BoundaryConditionDescriptor.hpp index 3e69e13d6a9c5c28bcfb175eeb0072e27d1a69e7..f6027b246691797833f8bc78f5f48ac09ae77ecb 100644 --- a/src/scheme/BoundaryConditionDescriptor.hpp +++ b/src/scheme/BoundaryConditionDescriptor.hpp @@ -13,6 +13,16 @@ class BoundaryDescriptor numbered }; + protected: + virtual std::ostream& _write(std::ostream& os) const = 0; + + public: + friend std::ostream& operator<<(std::ostream& os, + const BoundaryDescriptor& bd) + { + return bd._write(os); + } + virtual Type type() const = 0; BoundaryDescriptor(const BoundaryDescriptor&) = default; BoundaryDescriptor() = default; @@ -25,8 +35,14 @@ class NamedBoundaryDescriptor private: std::string m_name; + std::ostream& _write(std::ostream& os) const final + { + os << '"' << m_name << '"'; + return os; + } + public: - Type type() const + Type type() const final { return Type::named; } @@ -43,14 +59,27 @@ class NamedBoundaryDescriptor class NumberedBoundaryDescriptor : public BoundaryDescriptor { + private: + int m_number; + + std::ostream& _write(std::ostream& os) const final + { + os << '"' << m_number << '"'; + return os; + } + public: - Type type() const + Type type() const final { return Type::numbered; } NumberedBoundaryDescriptor(const NumberedBoundaryDescriptor&) = default; - NumberedBoundaryDescriptor() = default; + NumberedBoundaryDescriptor(const int& number) + : m_number(number) + { + ; + } virtual ~NumberedBoundaryDescriptor() = default; }; @@ -62,9 +91,17 @@ class BoundaryConditionDescriptor { symmetry }; - private: + protected: std::shared_ptr<BoundaryDescriptor> m_boundary_descriptor; + + virtual std::ostream& _write(std::ostream& os) const = 0; + public: + friend std::ostream& operator<<(std::ostream& os, const BoundaryConditionDescriptor& bcd) + { + return bcd._write(os); + } + virtual Type type() const = 0; const BoundaryDescriptor& boundaryDescriptor() const @@ -85,8 +122,14 @@ class BoundaryConditionDescriptor class SymmetryBoundaryConditionDescriptor : public BoundaryConditionDescriptor { + private: + std::ostream& _write(std::ostream& os) const final + { + os << "symmetry(" << *m_boundary_descriptor << ")"; + return os; + } public: - Type type() const + Type type() const final { return Type::symmetry; }