SPHinXsys  alpha version
level_set.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 * --------------------------------------------------------------------------*/
29 #ifndef LEVEL_SET_H
30 #define LEVEL_SET_H
31 
33 #include "adaptation.h"
34 #include "base_geometry.h"
35 
36 namespace SPH
37 {
38  class LevelSet;
39  class Kernel;
46  class LevelSetDataPackage : public GridDataPackage<4, 6>
47  {
48  public:
49  bool is_core_pkg_;
50  PackageData<Real> phi_;
51  PackageDataAddress<Real> phi_addrs_;
52  PackageData<Vecd> phi_gradient_;
53  PackageDataAddress<Vecd> phi_gradient_addrs_;
54  PackageData<Real> kernel_weight_;
55  PackageDataAddress<Real> kernel_weight_addrs_;
56  PackageData<Vecd> kernel_gradient_;
57  PackageDataAddress<Vecd> kernel_gradient_addrs_;
63  PackageData<int> near_interface_id_;
64  PackageDataAddress<int> near_interface_id_addrs_;
65 
68  virtual ~LevelSetDataPackage(){};
69 
70  void registerAllVariables();
71  void initializeSingularData(Real far_field_level_set);
72  void initializeBasicData(Shape &shape);
73  void computeKernelIntegrals(LevelSet &level_set);
74  void computeLevelSetGradient();
75  void stepReinitialization();
76  void markNearInterface(Real small_shift_factor);
77  };
78 
83  class BaseLevelSet : public BaseMeshField
84  {
85  public:
86  BaseLevelSet(Shape &shape, SPHAdaptation &sph_adaptation);
87  virtual ~BaseLevelSet(){};
88 
89  virtual void cleanInterface(Real small_shift_factor) = 0;
90  virtual bool probeIsWithinMeshBound(const Vecd &position) = 0;
91  virtual Real probeSignedDistance(const Vecd &position) = 0;
92  virtual Vecd probeNormalDirection(const Vecd &position) = 0;
93  virtual Vecd probeLevelSetGradient(const Vecd& position) = 0;
94  virtual Real probeKernelIntegral(const Vecd &position, Real h_ratio = 1.0) = 0;
95  virtual Vecd probeKernelGradientIntegral(const Vecd &position, Real h_ratio = 1.0) = 0;
96 
97  protected:
99  SPHAdaptation &sph_adaptation_;
100 
102  Real computeHeaviside(Real phi, Real half_width);
103  };
104 
112  class LevelSet
113  : public MeshWithGridDataPackages<BaseLevelSet, LevelSetDataPackage>
114  {
115  public:
117  Real global_h_ratio_;
118 
119  //this constructor only initialize far field
120  LevelSet(BoundingBox tentative_bounds, Real data_spacing, size_t buffer_size,
121  Shape &shape, SPHAdaptation &sph_adaptation);
122  //this constructor generate inner packages too
123  LevelSet(BoundingBox tentative_bounds, Real data_spacing,
124  Shape &shape, SPHAdaptation &sph_adaptation);
125  virtual ~LevelSet(){};
126 
127  virtual void cleanInterface(Real small_shift_factor) override;
128  virtual bool probeIsWithinMeshBound(const Vecd &position) override;
129  virtual Real probeSignedDistance(const Vecd &position) override;
130  virtual Vecd probeNormalDirection(const Vecd &position) override;
131  virtual Vecd probeLevelSetGradient(const Vecd& position) override;
132  virtual Real probeKernelIntegral(const Vecd &position, Real h_ratio = 1.0) override;
133  virtual Vecd probeKernelGradientIntegral(const Vecd &position, Real h_ratio = 1.0) override;
134  virtual void writeMeshFieldToPlt(std::ofstream &output_file) override;
135  bool isWithinCorePackage(Vecd position);
136  Real computeKernelIntegral(const Vecd &position);
137  Vecd computeKernelGradientIntegral(const Vecd &position);
138 
139  protected:
140  Kernel &kernel_;
141 
142  void finishDataPackages();
143  void reinitializeLevelSet();
144  void markNearInterface(Real small_shift_factor);
145  void redistanceInterface();
146  void updateLevelSetGradient();
147  void updateLevelSetGradientForAPackage(LevelSetDataPackage* inner_data_pkg, Real dt = 0.0);
148  void updateKernelIntegrals();
149  void updateKernelIntegralsForAPackage(LevelSetDataPackage *inner_data_pkg, Real dt = 0.0);
150  void stepReinitializationForAPackage(LevelSetDataPackage *inner_data_pkg, Real dt = 0.0);
151  void markNearInterfaceForAPackage(LevelSetDataPackage *core_data_pkg, Real dt = 0.0);
152  void redistanceInterfaceForAPackage(LevelSetDataPackage *core_data_pkg, Real dt = 0.0);
153  bool isInnerPackage(const Vecu &cell_index);
154  LevelSetDataPackage *createDataPackage(const Vecu &cell_index, const Vecd &cell_position);
155  void initializeDataInACell(const Vecu &cell_index, Real dt);
156  void initializeAddressesInACell(const Vecu &cell_index, Real dt);
157  void tagACellIsInnerPackage(const Vecu &cell_index, Real dt);
158  };
159 
164  class RefinedLevelSet : public RefinedMesh<LevelSet>
165  {
166  public:
167  RefinedLevelSet(BoundingBox tentative_bounds, LevelSet &coarse_level_set,
168  Shape &shape, SPHAdaptation &sph_adaptation);
169  virtual ~RefinedLevelSet(){};
170 
171  protected:
172  void initializeDataInACellFromCoarse(const Vecu &cell_index, Real dt);
173  };
174 
179  class MultilevelLevelSet : public MultilevelMesh<BaseLevelSet, LevelSet, RefinedLevelSet>
180  {
181  public:
182  MultilevelLevelSet(BoundingBox tentative_bounds, Real reference_data_spacing,
183  size_t total_levels, Shape &shape, SPHAdaptation &sph_adaptation);
184  virtual ~MultilevelLevelSet(){};
185 
186  virtual void cleanInterface(Real small_shift_factor) override;
187  virtual bool probeIsWithinMeshBound(const Vecd &position) override;
188  virtual Real probeSignedDistance(const Vecd &position) override;
189  virtual Vecd probeNormalDirection(const Vecd &position) override;
190  virtual Vecd probeLevelSetGradient(const Vecd &position) override;
191  virtual Real probeKernelIntegral(const Vecd &position, Real h_ratio = 1.0) override;
192  virtual Vecd probeKernelGradientIntegral(const Vecd &position, Real h_ratio = 1.0) override;
193 
194  protected:
195  inline size_t getProbeLevel(const Vecd &position);
196  inline size_t getMeshLevel(Real h_ratio);
197  };
198 }
199 #endif //LEVEL_SET_H
PackageDataAddress< Real > phi_addrs_
Definition: level_set.h:51
Base class for all adaptations. The base class defines essential global parameters. It is also used for single-resolution method. In the constructor parameter, system_refinement_ratio defines the relation between present resolution to the system reference resolution. The derived classes are defined for more complex adaptations.
Definition: adaptation.h:55
Definition: base_data_type.h:43
Base class for all volumetric geometries Note that checkContain and findClosest point are basic funct...
Definition: base_geometry.h:64
This class is designed to save memory and increase computational efficiency on mesh. //TODO: the connection between successive meshes in refined mesh should enhanced.
Adaptation defines the parameters for single or multi-resolution computations.
LevelSetDataPackage()
Definition: level_set.cpp:14
Fixed memory level set data packed in a package. Level set is the signed distance to an interface...
Definition: level_set.h:46
Abstract base class of a general SPH kernel function which is a smoothed Dirac delta function...
Definition: base_kernel.h:63
Abstract base class for the field data saved on a mesh.
Definition: base_mesh.h:128
Real computeHeaviside(Real phi, Real half_width)
Definition: level_set.cpp:42
Definition: level_set.h:179
PackageData< Real > phi_
Definition: level_set.h:50
A abstract describes a level set field defined on a mesh.
Definition: level_set.h:83
Multi-level Meshes with successively double the resolution.
Definition: base_mesh.h:166
ConcurrentVector< LevelSetDataPackage * > core_data_pkgs_
Definition: level_set.h:116
bool is_core_pkg_
Definition: level_set.h:49
Abstract class for mesh with data packages.
Definition: mesh_with_data_packages.h:236
Shape is the base class for all geometries.
Abstract base class derived from the coarse mesh but has double resolution. Currently, the design is simple but can be extending for more inter-mesh operations.
Definition: base_mesh.h:148
virtual void writeMeshFieldToPlt(std::ofstream &output_file) override
Definition: level_set_supplementary.cpp:246
Shape & shape_
Definition: level_set.h:98
Abstract base class for a data package whose data are defined on the grids of a small mesh patch...
Definition: mesh_with_data_packages.h:133
level set which has double resolution of a coarse level set.
Definition: level_set.h:164
PackageData< int > near_interface_id_
Definition: level_set.h:63
Mesh with level set data as packages. Note that the mesh containing the data packages are cell-based ...
Definition: level_set.h:112
Definition: solid_body_supplementary.cpp:9