Skip to content
Snippets Groups Projects
Commit 48a0a363 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Plug boundary descriptor into the language

parent a753dc3f
No related branches found
No related tags found
1 merge request!37Feature/language
#include <language/modules/SchemeModule.hpp> #include <language/modules/SchemeModule.hpp>
#include <language/utils/BuiltinFunctionEmbedder.hpp> #include <language/utils/BuiltinFunctionEmbedder.hpp>
#include <language/utils/TypeDescriptor.hpp>
#include <mesh/Mesh.hpp> #include <mesh/Mesh.hpp>
#include <scheme/AcousticSolver.hpp> #include <scheme/AcousticSolver.hpp>
...@@ -36,8 +37,8 @@ struct MeshDimensionAdapter ...@@ -36,8 +37,8 @@ struct MeshDimensionAdapter
MeshDataType mesh_data(m_mesh); MeshDataType mesh_data(m_mesh);
std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list;
for (const 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<IBoundaryDescriptor> boudary_descriptor =
std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name));
SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = SymmetryBoundaryConditionDescriptor* sym_bc_descriptor =
new SymmetryBoundaryConditionDescriptor(boudary_descriptor); new SymmetryBoundaryConditionDescriptor(boudary_descriptor);
...@@ -132,6 +133,30 @@ struct MeshDimensionAdapter ...@@ -132,6 +133,30 @@ struct MeshDimensionAdapter
SchemeModule::SchemeModule() 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>>>( this->_addBuiltinFunction("glace", std::make_shared<BuiltinFunctionEmbedder<void, std::shared_ptr<IMesh>>>(
std::function<void(std::shared_ptr<IMesh>)>{ std::function<void(std::shared_ptr<IMesh>)>{
......
...@@ -2,8 +2,14 @@ ...@@ -2,8 +2,14 @@
#define SCHEME_MODULE_HPP #define SCHEME_MODULE_HPP
#include <language/modules/BuiltinModule.hpp> #include <language/modules/BuiltinModule.hpp>
#include <language/utils/ASTNodeDataTypeTraits.hpp>
#include <utils/PugsMacros.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 class SchemeModule : public BuiltinModule
{ {
public: public:
......
...@@ -65,8 +65,8 @@ main(int argc, char* argv[]) ...@@ -65,8 +65,8 @@ main(int argc, char* argv[])
std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX"}; std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX"};
std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list;
for (const 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<IBoundaryDescriptor> boudary_descriptor =
std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name));
SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = SymmetryBoundaryConditionDescriptor* sym_bc_descriptor =
new SymmetryBoundaryConditionDescriptor(boudary_descriptor); new SymmetryBoundaryConditionDescriptor(boudary_descriptor);
...@@ -184,8 +184,8 @@ main(int argc, char* argv[]) ...@@ -184,8 +184,8 @@ main(int argc, char* argv[])
std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX"}; std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX"};
std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list;
for (const 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<IBoundaryDescriptor> boudary_descriptor =
std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name));
SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = SymmetryBoundaryConditionDescriptor* sym_bc_descriptor =
new SymmetryBoundaryConditionDescriptor(boudary_descriptor); new SymmetryBoundaryConditionDescriptor(boudary_descriptor);
...@@ -290,8 +290,8 @@ main(int argc, char* argv[]) ...@@ -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::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX", "ZMIN", "ZMAX"};
std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list;
for (const 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<IBoundaryDescriptor> boudary_descriptor =
std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); std::shared_ptr<IBoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name));
SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = SymmetryBoundaryConditionDescriptor* sym_bc_descriptor =
new SymmetryBoundaryConditionDescriptor(boudary_descriptor); new SymmetryBoundaryConditionDescriptor(boudary_descriptor);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <memory> #include <memory>
class BoundaryDescriptor class IBoundaryDescriptor
{ {
public: public:
enum class Type enum class Type
...@@ -19,27 +19,27 @@ class BoundaryDescriptor ...@@ -19,27 +19,27 @@ class BoundaryDescriptor
public: public:
friend std::ostream& friend std::ostream&
operator<<(std::ostream& os, const BoundaryDescriptor& bd) operator<<(std::ostream& os, const IBoundaryDescriptor& bd)
{ {
return bd._write(os); return bd._write(os);
} }
virtual bool operator==(const RefId& ref_id) const = 0; virtual bool operator==(const RefId& ref_id) const = 0;
friend bool friend bool
operator==(const RefId& ref_id, const BoundaryDescriptor& bcd) operator==(const RefId& ref_id, const IBoundaryDescriptor& bcd)
{ {
return bcd == ref_id; return bcd == ref_id;
} }
virtual Type type() const = 0; virtual Type type() const = 0;
BoundaryDescriptor(const BoundaryDescriptor&) = delete; IBoundaryDescriptor(const IBoundaryDescriptor&) = delete;
BoundaryDescriptor(BoundaryDescriptor&&) = delete; IBoundaryDescriptor(IBoundaryDescriptor&&) = delete;
BoundaryDescriptor() = default; IBoundaryDescriptor() = default;
virtual ~BoundaryDescriptor() = default; virtual ~IBoundaryDescriptor() = default;
}; };
class NamedBoundaryDescriptor : public BoundaryDescriptor class NamedBoundaryDescriptor : public IBoundaryDescriptor
{ {
private: private:
std::string m_name; std::string m_name;
...@@ -73,7 +73,7 @@ class NamedBoundaryDescriptor : public BoundaryDescriptor ...@@ -73,7 +73,7 @@ class NamedBoundaryDescriptor : public BoundaryDescriptor
virtual ~NamedBoundaryDescriptor() = default; virtual ~NamedBoundaryDescriptor() = default;
}; };
class NumberedBoundaryDescriptor : public BoundaryDescriptor class NumberedBoundaryDescriptor : public IBoundaryDescriptor
{ {
private: private:
unsigned int m_number; unsigned int m_number;
...@@ -116,7 +116,7 @@ class BoundaryConditionDescriptor ...@@ -116,7 +116,7 @@ class BoundaryConditionDescriptor
}; };
protected: protected:
std::shared_ptr<BoundaryDescriptor> m_boundary_descriptor; std::shared_ptr<IBoundaryDescriptor> m_boundary_descriptor;
virtual std::ostream& _write(std::ostream& os) const = 0; virtual std::ostream& _write(std::ostream& os) const = 0;
...@@ -129,13 +129,13 @@ class BoundaryConditionDescriptor ...@@ -129,13 +129,13 @@ class BoundaryConditionDescriptor
virtual Type type() const = 0; virtual Type type() const = 0;
const BoundaryDescriptor& const IBoundaryDescriptor&
boundaryDescriptor() const boundaryDescriptor() const
{ {
return *m_boundary_descriptor; return *m_boundary_descriptor;
} }
BoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) BoundaryConditionDescriptor(std::shared_ptr<IBoundaryDescriptor> boundary_descriptor)
: m_boundary_descriptor(boundary_descriptor) : m_boundary_descriptor(boundary_descriptor)
{ {
; ;
...@@ -164,7 +164,7 @@ class SymmetryBoundaryConditionDescriptor : public BoundaryConditionDescriptor ...@@ -164,7 +164,7 @@ class SymmetryBoundaryConditionDescriptor : public BoundaryConditionDescriptor
return Type::symmetry; return Type::symmetry;
} }
SymmetryBoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) SymmetryBoundaryConditionDescriptor(std::shared_ptr<IBoundaryDescriptor> boundary_descriptor)
: BoundaryConditionDescriptor(boundary_descriptor) : BoundaryConditionDescriptor(boundary_descriptor)
{ {
; ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment