SPHinXsys  alpha version
base_geometry.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------*
2  * SPHinXsys *
3  * --------------------------------------------------------------------------*
4  * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5  * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6  * physical accurate simulation and aims to model coupled industrial dynamic *
7  * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8  * (smoothed particle hydrodynamics), a meshless computational method using *
9  * particle discretization. *
10  * *
11  * SPHinXsys is partially funded by German Research Foundation *
12  * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13  * and HU1527/12-1. *
14  * *
15  * Portions copyright (c) 2017-2020 Technical University of Munich and *
16  * the authors' affiliations. *
17  * *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19  * not use this file except in compliance with the License. You may obtain a *
20  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21  * *
22  * --------------------------------------------------------------------------*/
32 #ifndef BASE_GEOMETRY_H
33 #define BASE_GEOMETRY_H
34 
35 #include "base_data_package.h"
36 #include "sph_data_containers.h"
37 
38 #include <string>
39 
40 namespace SPH
41 {
50  enum class ShapeBooleanOps
51  {
52  add,
53  sub,
54  sym_diff,
55  intersect
56  };
57 
64  class Shape
65  {
66  public:
67  explicit Shape(const std::string &shape_name)
68  : name_(shape_name), is_bounds_found_(false){};
69  virtual ~Shape(){};
70 
71  std::string getName() { return name_; };
72  void setName(const std::string &name) { name_ = name; };
73  BoundingBox getBounds();
74  virtual bool isValid() { return true; };
75  virtual bool checkContain(const Vecd &pnt, bool BOUNDARY_INCLUDED = true) = 0;
76  virtual Vecd findClosestPoint(const Vecd &input_pnt) = 0;
77 
78  bool checkNotFar(const Vecd &input_pnt, Real threshold);
79  bool checkNearSurface(const Vecd &input_pnt, Real threshold);
81  Real findSignedDistance(const Vecd &input_pnt);
83  Vecd findNormalDirection(const Vecd &input_pnt);
84 
85  protected:
86  std::string name_;
87  BoundingBox bounding_box_;
88  bool is_bounds_found_;
89 
90  virtual BoundingBox findBounds() = 0;
91  };
92 
93  using ShapeAndOp = std::pair<Shape *, ShapeBooleanOps>;
101  class BinaryShapes : public Shape
102  {
103  public:
104  BinaryShapes() : Shape("BinaryShapes"){};
105  explicit BinaryShapes(const std::string &shapes_name) : Shape(shapes_name){};
106  virtual ~BinaryShapes(){};
107 
108  template <class ShapeType, typename... Args>
109  void add(Args &&...args)
110  {
111  Shape *shape = shapes_ptr_keeper_.createPtr<ShapeType>(std::forward<Args>(args)...);
112  ShapeAndOp shape_and_op(shape, ShapeBooleanOps::add);
113  shapes_and_ops_.push_back(shape_and_op);
114  };
115 
116  template <class ShapeType, typename... Args>
117  void subtract(Args &&...args)
118  {
119  Shape *shape = shapes_ptr_keeper_.createPtr<ShapeType>(std::forward<Args>(args)...);
120  ShapeAndOp shape_and_op(shape, ShapeBooleanOps::sub);
121  shapes_and_ops_.push_back(shape_and_op);
122  };
123 
124  virtual bool isValid() override;
125  virtual bool checkContain(const Vecd &pnt, bool BOUNDARY_INCLUDED = true) override;
126  virtual Vecd findClosestPoint(const Vecd &input_pnt) override;
127  Shape *getShapeByName(const std::string &shape_name);
128  ShapeAndOp *getShapeAndOpByName(const std::string &shape_name);
129  size_t getShapeIndexByName(const std::string &shape_name);
130 
131  protected:
132  UniquePtrKeepers<Shape> shapes_ptr_keeper_;
133  StdVec<ShapeAndOp> shapes_and_ops_;
134 
135  virtual BoundingBox findBounds() override;
136  };
137 
145  template <typename InEdgeType, typename OutEdgeType>
146  class Edge
147  {
148  public:
150  template <class EdgeStructureType>
151  explicit Edge(EdgeStructureType *structure)
152  : id_(structure->ContainerSize()), in_edge_(MaxSize_t){};
154  template <class EdgeStructureType>
155  Edge(InEdgeType in_edge, EdgeStructureType *structure)
156  : id_(structure->ContainerSize()), in_edge_(in_edge){};
157  virtual ~Edge(){};
158 
159  size_t id_;
160  InEdgeType in_edge_;
161  OutEdgeType out_edge_;
162  };
163 }
164 #endif // BASE_GEOMETRY_H
template base class of linear structure only with topology information. Note that a edge is defined t...
Definition: base_geometry.h:146
size_t id_
Definition: base_geometry.h:157
Base class for all volumetric geometries Note that checkContain and findClosest point are basic funct...
Definition: base_geometry.h:64
Vecd findNormalDirection(const Vecd &input_pnt)
Definition: base_geometry.cpp:36
Edge(EdgeStructureType *structure)
Definition: base_geometry.h:151
Real findSignedDistance(const Vecd &input_pnt)
Definition: base_geometry.cpp:30
OutEdgeType out_edge_
Definition: base_geometry.h:161
A wrapper to provide an ownership for a vector of base class pointers which point to derived objects...
Definition: ownership.h:127
a collections of shapes with binary operations This class so that it has ownership of all shapes by u...
Definition: base_geometry.h:101
Set up of basic data structure.
Boolean operation for generate complex shapes.
Edge(InEdgeType in_edge, EdgeStructureType *structure)
Definition: base_geometry.h:155
InEdgeType in_edge_
Definition: base_geometry.h:160
Definition: solid_body_supplementary.cpp:9