diff --git a/include/simulation/geometry.h b/include/simulation/geometry.h index a5e639f..b6119c3 100755 --- a/include/simulation/geometry.h +++ b/include/simulation/geometry.h @@ -26,4 +26,37 @@ class Cylinder : public Geometry { const double height_; }; +/* + /|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\ ‾‾‾ + / | | \ ^ + / | | \ | + / | | \ | R_cylinder + / | | \ ⌄ + |<-->|<------------------>|<------------------><---> --- + z=0 ^ ^ | + | | | + H_cone H_cylinder symmetry axis + + The geometry will only know 3 regions, "inside", "hull", "top". Meaning the + cone will always have the same boundary condition as the cylinder boundary. +*/ + +/* + Geometry of a cylinder with a cone as the end at z=0. +*/ +class HalfCylinderWithCone : public Geometry { + public: + HalfCylinderWithCone(double radiusCylinder, double heightCylinder, + double heightCone); + bool isInside(const Coordinate& position) const; + GeometryPositioning isWhere(const Coordinate& position) const; + + private: + const double cylinder_radius_; + const double cylinder_height_; + const double cone_height_; + + double localRadius(double z) const; +}; + #endif /* GEOMETRY_H */ diff --git a/src/generators/geometry_generator.cpp b/src/generators/geometry_generator.cpp index 40d7531..66c01d4 100755 --- a/src/generators/geometry_generator.cpp +++ b/src/generators/geometry_generator.cpp @@ -23,6 +23,32 @@ std::shared_ptr buildGeometry(Parameter& parameter, DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m"); #endif return std::shared_ptr(new Cylinder(radius, height)); + } else if(parameter.jsonObjectFromBase( + json_path_append(path_to_geometry, {"HalfCylinderWithCone"}))) { + +#ifdef debug + DEBUG("Creating geometry: half cylinder with cone."); +#endif + double radius = + json_read_length(parameter.jsonObjectFromBase(json_path_append( + path_to_geometry, {"HalfCylinderWithCone", "Radius"})), + "m"); + double heightcylinder = + json_read_length(parameter.jsonObjectFromBase(json_path_append( + path_to_geometry, {"HalfCylinderWithCone", "HeightCylinder"})), + "m"); + double heightcone = + json_read_length(parameter.jsonObjectFromBase(json_path_append( + path_to_geometry, {"HalfCylinderWithCone", "HeightCone"})), + "m"); + +#ifdef debug + std::stringstream out; + out << "height cyl: " << heightcylinder << ", height cone: " << heightcone << ", radius: " << radius << "\n"; + DEBUG(out.str()); +#endif + return std::shared_ptr( + new HalfCylinderWithCone(radius, heightcylinder, heightcone)); } else { ERROR("This geometry is not implemented."); return nullptr; diff --git a/src/simulation/geometry.cpp b/src/simulation/geometry.cpp index 58e99fd..b140fb6 100755 --- a/src/simulation/geometry.cpp +++ b/src/simulation/geometry.cpp @@ -23,3 +23,38 @@ GeometryPositioning Cylinder::isWhere(const Coordinate& position) const { return GeometryPositioning::inside; } } + +HalfCylinderWithCone::HalfCylinderWithCone(double radiusCylinder, double heightCylinder, + double heightCone) : + cylinder_height_(heightCylinder), + cylinder_radius_(radiusCylinder), + cone_height_(heightCone) {} + +bool HalfCylinderWithCone::isInside(const Coordinate& coordinate) const { + const blitz::TinyVector cylinder_position = coordinate.cylinderEntries(); + return (cylinder_position(2) > 0) && + (cylinder_position(2) < (cylinder_height_ + cone_height_)) && + (cylinder_position(0) < localRadius(cylinder_position(2))); +} + +GeometryPositioning HalfCylinderWithCone::isWhere(const Coordinate& coordinate) const { + const blitz::TinyVector cylinder_position = coordinate.cylinderEntries(); + if(cylinder_position(0) >= localRadius(cylinder_position(2))) { + return GeometryPositioning::hull; + } else if (cylinder_position(2) >= (cone_height_ + cylinder_height_)) { + return GeometryPositioning::top; + } else { + return GeometryPositioning::inside; + } +} + +double HalfCylinderWithCone::localRadius(double z) const { + if(z >= cone_height_) { + return cylinder_radius_; + } else { + // can potentially be negative, but that should be fine for a check if + // the position is inside the geometry + return z/cone_height_*cylinder_radius_; + } +} +