|
| 1 | +#ifndef __SurfaceTension_Jeske2023_Surface_Tension_h__ |
| 2 | +#define __SurfaceTension_Jeske2023_Surface_Tension_h__ |
| 3 | + |
| 4 | +#include "SPlisHSPlasH/Common.h" |
| 5 | +#include "SPlisHSPlasH/FluidModel.h" |
| 6 | +#include "SurfaceTensionBase.h" |
| 7 | +#include "SPlisHSPlasH/Utilities/MatrixFreeSolver.h" |
| 8 | +#include "Utilities/Logger.h" |
| 9 | + |
| 10 | +namespace SPH |
| 11 | +{ |
| 12 | + /** \brief This class implements the implicit surface tension method |
| 13 | + * by Jeske et al. 2023 [JWL+23]. |
| 14 | + * |
| 15 | + * References: |
| 16 | + * - [JWL+23] Jeske, Stefan Rhys, Lukas Westhofen, Fabian Löschner, José Antonio Fernández-Fernández, and Jan Bender. “Implicit Surface Tension for SPH Fluid Simulation.” ACM Transactions on Graphics, November 7, 2023. URL: https://doi.org/10.1145/3631936. |
| 17 | +
|
| 18 | + */ |
| 19 | + class SurfaceTension_Jeske2023 : public SurfaceTensionBase |
| 20 | + { |
| 21 | + protected: |
| 22 | + Real m_viscosity; |
| 23 | + Real m_boundaryViscosity; |
| 24 | + |
| 25 | + unsigned int m_maxIter; |
| 26 | + Real m_maxError; |
| 27 | + unsigned int m_iterations; |
| 28 | + std::vector<Vector3r> m_vDiff; |
| 29 | + std::vector<Real> m_gradRho; |
| 30 | + std::vector<Real> m_surfaceEnergy; |
| 31 | + std::vector<Real> m_color; |
| 32 | + std::vector<Vector3r> m_colorGrad; |
| 33 | + std::vector<Vector3r> m_nonlinearAcc; |
| 34 | + std::vector<Vector3r> m_nonlinearRes; |
| 35 | + std::vector<Vector3r> m_nonlinearGrad; |
| 36 | + |
| 37 | + Real m_tangentialDistanceFactor; |
| 38 | + bool m_weakPhaseCoupling; |
| 39 | + Real m_xsph; |
| 40 | + |
| 41 | + typedef Eigen::ConjugateGradient<MatrixReplacement, Eigen::Lower | Eigen::Upper, Eigen::IdentityPreconditioner> Solver; |
| 42 | + |
| 43 | + Solver m_solver; |
| 44 | + |
| 45 | + |
| 46 | + virtual void initParameters(); |
| 47 | + |
| 48 | + public: |
| 49 | + static int ITERATIONS; |
| 50 | + static int MAX_ITERATIONS; |
| 51 | + static int MAX_ERROR; |
| 52 | + static int VISCOSITY_COEFFICIENT; |
| 53 | + static int VISCOSITY_COEFFICIENT_BOUNDARY; |
| 54 | + static int XSPH; |
| 55 | + |
| 56 | + SurfaceTension_Jeske2023(FluidModel *model); |
| 57 | + virtual ~SurfaceTension_Jeske2023(void); |
| 58 | + |
| 59 | + static NonPressureForceBase* creator(FluidModel* model) { return new SurfaceTension_Jeske2023(model); } |
| 60 | + |
| 61 | + virtual void step(); |
| 62 | + virtual void reset(); |
| 63 | + |
| 64 | + virtual void performNeighborhoodSearchSort(); |
| 65 | + |
| 66 | + static void matrixVecProd(const Real* vec, Real *result, void *userData); |
| 67 | + |
| 68 | + FORCE_INLINE const Vector3r& getVDiff(const unsigned int i) const |
| 69 | + { |
| 70 | + return m_vDiff[i]; |
| 71 | + } |
| 72 | + |
| 73 | + FORCE_INLINE Vector3r& getVDiff(const unsigned int i) |
| 74 | + { |
| 75 | + return m_vDiff[i]; |
| 76 | + } |
| 77 | + |
| 78 | + FORCE_INLINE void setVDiff(const unsigned int i, const Vector3r& val) |
| 79 | + { |
| 80 | + m_vDiff[i] = val; |
| 81 | + } |
| 82 | + |
| 83 | + FORCE_INLINE const Real& getDensityGrad(const unsigned int i) const |
| 84 | + { |
| 85 | + return m_gradRho[i]; |
| 86 | + } |
| 87 | + |
| 88 | + FORCE_INLINE Real& getDensityGrad(const unsigned int i) |
| 89 | + { |
| 90 | + return m_gradRho[i]; |
| 91 | + } |
| 92 | + |
| 93 | + FORCE_INLINE void setDensityGrad(const unsigned int i, const Real& val) |
| 94 | + { |
| 95 | + m_gradRho[i] = val; |
| 96 | + } |
| 97 | + |
| 98 | + void computeRHS(VectorXr &b, VectorXr &g); |
| 99 | + |
| 100 | + void applyForces(const VectorXr &x); |
| 101 | + |
| 102 | + Real getMaxSolverError(){ return m_maxError; } |
| 103 | + void setMaxSolverError(Real error){ m_maxError = error; } |
| 104 | + |
| 105 | + bool getWeakCoupling(){ return m_weakPhaseCoupling; } |
| 106 | + void setWeakCoupling(bool val){ m_weakPhaseCoupling = val; } |
| 107 | + |
| 108 | + bool getViscosity(){ return m_viscosity; } |
| 109 | + void setViscosity(Real val){ m_viscosity = val; } |
| 110 | + |
| 111 | + void computeDensityGradient(); |
| 112 | + }; |
| 113 | +} |
| 114 | + |
| 115 | +#endif |
0 commit comments