From 48a0a3633a8a480d9922452bfec65281cdef644e Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Tue, 19 May 2020 12:24:32 +0200 Subject: [PATCH] Plug boundary descriptor into the language --- src/language/modules/SchemeModule.cpp | 29 ++++++++++++++++++++-- src/language/modules/SchemeModule.hpp | 6 +++++ src/main.cpp | 12 ++++----- src/scheme/BoundaryConditionDescriptor.hpp | 26 +++++++++---------- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/language/modules/SchemeModule.cpp b/src/language/modules/SchemeModule.cpp index bc341bc98..7a41194c3 100644 --- a/src/language/modules/SchemeModule.cpp +++ b/src/language/modules/SchemeModule.cpp @@ -1,6 +1,7 @@ #include <language/modules/SchemeModule.hpp> #include <language/utils/BuiltinFunctionEmbedder.hpp> +#include <language/utils/TypeDescriptor.hpp> #include <mesh/Mesh.hpp> #include <scheme/AcousticSolver.hpp> @@ -36,8 +37,8 @@ struct MeshDimensionAdapter MeshDataType mesh_data(m_mesh); std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_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)); + std::shared_ptr<IBoundaryDescriptor> boudary_descriptor = + std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); @@ -132,6 +133,30 @@ struct MeshDimensionAdapter SchemeModule::SchemeModule() { + this->_addTypeDescriptor( + std::make_shared<TypeDescriptor>(ast_node_data_type_from<std::shared_ptr<IBoundaryDescriptor>>.typeName())); + + this + ->_addBuiltinFunction("boundaryName", + std::make_shared<BuiltinFunctionEmbedder<std::shared_ptr<IBoundaryDescriptor>, std::string>>( + std::function<std::shared_ptr<IBoundaryDescriptor>(std::string)>{ + + [](const std::string& boundary_name) -> std::shared_ptr<IBoundaryDescriptor> { + return std::make_shared<NamedBoundaryDescriptor>(boundary_name); + }} + + )); + + this->_addBuiltinFunction("boundaryTag", + std::make_shared<BuiltinFunctionEmbedder<std::shared_ptr<IBoundaryDescriptor>, int64_t>>( + std::function<std::shared_ptr<IBoundaryDescriptor>(int64_t)>{ + + [](int64_t boundary_tag) -> std::shared_ptr<IBoundaryDescriptor> { + return std::make_shared<NumberedBoundaryDescriptor>(boundary_tag); + }} + + )); + this->_addBuiltinFunction("glace", std::make_shared<BuiltinFunctionEmbedder<void, std::shared_ptr<IMesh>>>( std::function<void(std::shared_ptr<IMesh>)>{ diff --git a/src/language/modules/SchemeModule.hpp b/src/language/modules/SchemeModule.hpp index 73d675cda..942598624 100644 --- a/src/language/modules/SchemeModule.hpp +++ b/src/language/modules/SchemeModule.hpp @@ -2,8 +2,14 @@ #define SCHEME_MODULE_HPP #include <language/modules/BuiltinModule.hpp> +#include <language/utils/ASTNodeDataTypeTraits.hpp> #include <utils/PugsMacros.hpp> +class IBoundaryDescriptor; +template <> +inline ASTNodeDataType ast_node_data_type_from<std::shared_ptr<IBoundaryDescriptor>> = {ASTNodeDataType::type_id_t, + "boundary"}; + class SchemeModule : public BuiltinModule { public: diff --git a/src/main.cpp b/src/main.cpp index f6bec4d51..76f822d21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,8 +65,8 @@ main(int argc, char* argv[]) std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX"}; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_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)); + std::shared_ptr<IBoundaryDescriptor> boudary_descriptor = + std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); @@ -184,8 +184,8 @@ main(int argc, char* argv[]) std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX"}; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_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)); + std::shared_ptr<IBoundaryDescriptor> boudary_descriptor = + std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); @@ -290,8 +290,8 @@ main(int argc, char* argv[]) std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX", "ZMIN", "ZMAX"}; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_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)); + std::shared_ptr<IBoundaryDescriptor> boudary_descriptor = + std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); diff --git a/src/scheme/BoundaryConditionDescriptor.hpp b/src/scheme/BoundaryConditionDescriptor.hpp index 8f4911ad9..4fd5ae1d7 100644 --- a/src/scheme/BoundaryConditionDescriptor.hpp +++ b/src/scheme/BoundaryConditionDescriptor.hpp @@ -5,7 +5,7 @@ #include <memory> -class BoundaryDescriptor +class IBoundaryDescriptor { public: enum class Type @@ -19,27 +19,27 @@ class BoundaryDescriptor public: friend std::ostream& - operator<<(std::ostream& os, const BoundaryDescriptor& bd) + operator<<(std::ostream& os, const IBoundaryDescriptor& bd) { return bd._write(os); } virtual bool operator==(const RefId& ref_id) const = 0; friend bool - operator==(const RefId& ref_id, const BoundaryDescriptor& bcd) + operator==(const RefId& ref_id, const IBoundaryDescriptor& bcd) { return bcd == ref_id; } virtual Type type() const = 0; - BoundaryDescriptor(const BoundaryDescriptor&) = delete; - BoundaryDescriptor(BoundaryDescriptor&&) = delete; - BoundaryDescriptor() = default; + IBoundaryDescriptor(const IBoundaryDescriptor&) = delete; + IBoundaryDescriptor(IBoundaryDescriptor&&) = delete; + IBoundaryDescriptor() = default; - virtual ~BoundaryDescriptor() = default; + virtual ~IBoundaryDescriptor() = default; }; -class NamedBoundaryDescriptor : public BoundaryDescriptor +class NamedBoundaryDescriptor : public IBoundaryDescriptor { private: std::string m_name; @@ -73,7 +73,7 @@ class NamedBoundaryDescriptor : public BoundaryDescriptor virtual ~NamedBoundaryDescriptor() = default; }; -class NumberedBoundaryDescriptor : public BoundaryDescriptor +class NumberedBoundaryDescriptor : public IBoundaryDescriptor { private: unsigned int m_number; @@ -116,7 +116,7 @@ class BoundaryConditionDescriptor }; protected: - std::shared_ptr<BoundaryDescriptor> m_boundary_descriptor; + std::shared_ptr<IBoundaryDescriptor> m_boundary_descriptor; virtual std::ostream& _write(std::ostream& os) const = 0; @@ -129,13 +129,13 @@ class BoundaryConditionDescriptor virtual Type type() const = 0; - const BoundaryDescriptor& + const IBoundaryDescriptor& boundaryDescriptor() const { return *m_boundary_descriptor; } - BoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) + BoundaryConditionDescriptor(std::shared_ptr<IBoundaryDescriptor> boundary_descriptor) : m_boundary_descriptor(boundary_descriptor) { ; @@ -164,7 +164,7 @@ class SymmetryBoundaryConditionDescriptor : public BoundaryConditionDescriptor return Type::symmetry; } - SymmetryBoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) + SymmetryBoundaryConditionDescriptor(std::shared_ptr<IBoundaryDescriptor> boundary_descriptor) : BoundaryConditionDescriptor(boundary_descriptor) { ; -- GitLab