Lagrangian Particle Code for The Simulation of 2D/3D Fluid Dynamics
 All Classes Files Functions Variables Typedefs Friends Pages
lp_solver.h
Go to the documentation of this file.
1 
22 #ifndef __LP_SOLVER_H__
23 #define __LP_SOLVER_H__
24 
25 #include <cstddef>
26 #include <vector>
27 #include <string>
28 #include <fstream>
29 
30 class Initializer;
31 class ParticleData;
32 class NeighbourSearcher;
33 class EOS;
34 
35 
53 class LPSolver {
54 
55 public:
57  virtual ~LPSolver() {}
58 
68  virtual int solve(double dt) = 0;
69 
75  virtual double getMinParticleSpacing() const {return m_fMinParticleSpacing;}
76 
82  virtual double getMaxSoundSpeed() const {return m_fMaxSoundSpeed;}
83 
89  virtual double getMaxFluidVelocity() const {return m_fMaxFluidVelocity;}
90 
91 protected:
92 
96  bool m_iIfDebug;
97  std::ofstream debug;
98 };
99 
100 
118 class HyperbolicLPSolver : public LPSolver {
119 
120 public:
131 
141  virtual int solve(double dt);
142 
143 private:
144 
145  //-----------------------------------------Data----------------------------------------
146 
147  //--------------------------Info got from input argument list---------------------------
148 
149  ParticleData* m_pParticleData;
150  NeighbourSearcher* m_pNeighbourSearcher;
151 
152  //--------------------------------------------------------------------------------------
153 
154  //--------------------------Info get from Initializer class------------------------------
155 
156  EOS* m_pEOS;
157  int m_iNumThreads;
158  bool m_iIfMultiThreads;
159  int m_iDimension;
160  bool m_iRandomDirSplitOrder;
161  int m_iLPFOrder;
162  std::size_t m_iNumRow2ndOrder;
163  std::size_t m_iNumRow1stOrder;
164  std::size_t m_iNumCol2ndOrder;
165  std::size_t m_iNumCol1stOrder;
166  bool m_iMovingBoxForGhostParticle;
167  double m_fInitParticleSpacing;
168  double m_fGravity;
169  double m_fInvalidPressure;
170  double m_fInvalidVolume;
171  double m_fNeiSearchRadius;
172  size_t m_iNumParticleWithinSearchRadius;
173  double m_fContactLength;
174 
175  //--------------------------------------------------------------------------------------
176 
177  //---------------------------------Other parameters-------------------------------------
178 
179  int m_iNumPhase;
180 
184  std::vector<std::vector<int> > m_vDirSplitTable;
185 
186  int m_iDirSplitOrder;
187 
188  double m_fDt;
189 
190  int m_iContactAlert;
191 
192  //std::ofstream debug;///< output information for debugging
193  //bool m_iIfDebug;///< if true then print debug info
194  //-------------------------------------------------------------------------------------
195 
196 
197 
198 
199  //-------------------------------------Methods-----------------------------------------
200 
219  void computeSetupsForNextIteration();
220 
221 
228  void updateFluidBoundingBox();
229 
237  void checkForContactAlert();
238 
244  void generateGhostParticle();
245 
252  bool isValidGhostParticle(double x, double y, double z, int* neiList, size_t numNei, int objectTag);
253 
261  void searchNeighbourForAllParticle();
262 
269  void setUpwindNeighbourList();
270 
278  void resetLPFOrder();
279 
286  void computeMinParticleSpacing();
287 
294  void computeMaxSoundSpeed();
295 
302  void computeMaxFluidVelocity();
303 
304 
312  void changeFluidObjectTagIfInContact(int index, size_t numNeiFound, const double* neiListDist);
313 
324  void changeNeighbourhoodToIncludeOnlyFluidNeiFromSameObject(int index, size_t numNeiFound);
325 
332  void changeNeighbourhoodToIncludeOnlyFluidNei(int index, size_t numNeiFound);
333 
334 
348  bool directionalSplitting(int phase);
349 
355  void setNeighbourListPointers(int dir, // input
356  const int **neighbourList0, const int **neighbourList1, // output
357  const int **neighbourListSize0, const int **neighbourListSize1);
358 
364  void setInAndOutDataPointers(int phase, int dir,
365  const double** inVelocity, const double** inPressure, const double** inVolume, const double** inSoundSpeed,
366  double** outVelocity, double** outPressure, double** outVolume, double** outSoundSpeed);
367 
373  void setLPFOrderPointers(int dir, // input
374  int** LPFOrder0, int** LPFOrder1, std::vector<int*>& LPFOrderOther); // output
375 
376 
382  void computeSpatialDer(int dir, size_t index, // input
383  int offset, void (HyperbolicLPSolver::*computeA) (size_t, const int *, const int*, size_t, size_t,double*),
384  const double* inPressure, const double* inVelocity,
385  const int *neighbourList, const int *neighbourListSize,
386  int* LPFOrder, double* vel_d, double* vel_dd, double* p_d, double* p_dd); // output
387 
388 
394  void timeIntegration(double real_dt, double multiplier1st, double multiplier2nd,
395  double gravity, double inVolume, double inVelocity, double inPressure,
396  double inSoundSpeed,
397  double vel_d_0, double vel_dd_0, double p_d_0, double p_dd_0,
398  double vel_d_1, double vel_dd_1, double p_d_1, double p_dd_1,
399  double* outVolume, double* outVelocity, double* outPressure); // output
400 
401 
407  void printInvalidState(int phase, int dir, int index, double positionX, double positionY, double positionZ,
408  double vel_d_0, double vel_dd_0, double p_d_0, double p_dd_0,
409  double vel_d_1, double vel_dd_1, double p_d_1, double p_dd_1);
410 
411 
412 
424  bool lowerLPFOrder(int index, const std::vector<int*>& LPFOrderOther, // input
425  int* LPFOrder0, int* LPFOrder1); // output
426 
433  void computeNumRowAndNumColAndLPFOrder(size_t index, // input
434  const int *neighbourList, const int *neighbourListSize, size_t numRow2nd, size_t numRow1st,
435  int* LPFOrder, size_t *numRow, size_t *numCol); // output
436 
437 
443  void computeA2D(size_t index, const int *neighbourList, const int* LPFOrder, size_t numRow, size_t numCol, // input
444  double *A); // output
445 
451  void computeA3D(size_t index, const int *neighbourList, const int* LPFOrder, size_t numRow, size_t numCol, // input
452  double *A); // output
453 
459  void computeB(size_t index, const int *neighbourList, size_t numRow, const double* inData,
460  double *b); // output
461 
462 
468  void setBoundaryPressureAndVelocity(int phase);
469 
475  void setGhostPressureAndVelocity(int phase);
476 
482  void computeOthOrderWeightedLPF(std::vector<const double*>& position,
483  std::size_t startIndex, std::size_t numParticle,
484  std::vector<double*>& data);
485 
491  void updateFluidState();
492 
498  void moveFluidParticle();
499 
505  void updateFluidVelocity();
506 
507 
513  void testNeighbourSearch();
514 
520  void searchNeighbourBruteForce(int, int* neighbourList, int* neighbourListSize);
521 
527  void searchNeighbourBruteForce(double x, double y, double z, int* neighbourList, size_t& numNeiFound);
528 
534  void generateGhostParticleByBruteForceNeighbourSearch();
535 
541  void searchNeighbourForAllParticleByBruteForceNeighbourSearch();
542 
548  bool checkUpwindNeighbourList();
549 
555  std::string rightFlush(size_t writeStep, size_t numDigits);
556 
562  int writeResult(double time, size_t writeStep, size_t startIndex, size_t numParticle);
563 };
564 
565 
566 
567 
568 
585 
586 public:
596  HyperbolicLPSolver1D(const Initializer& init, ParticleData* pData);
597 
607  virtual int solve(double dt);
608 
609 private:
610 
611  //-----------------------------------------Data----------------------------------------
612 
613  //--------------------------Info got from input argument list---------------------------
614 
615  ParticleData* m_pParticleData;
616 
617  //--------------------------------------------------------------------------------------
618 
619  //--------------------------Info get from Initializer class------------------------------
620 
621  EOS* m_pEOS;
622  int m_iDimension;
623  int m_iLPFOrder;
624  std::size_t m_iNumRow2ndOrder;
625  std::size_t m_iNumRow1stOrder;
626  std::size_t m_iNumCol2ndOrder;
627  std::size_t m_iNumCol1stOrder;
628  double m_fInitParticleSpacing;
629  double m_fInvalidPressure;
630  double m_fInvalidVolume;
631 
632  std::string m_sBoundaryType;
633  bool m_iUseLimiter;
634  double m_fThresholdP;
635  //--------------------------------------------------------------------------------------
636 
637  //---------------------------------Other parameters-------------------------------------
638 
639  double m_fPeriodicLeftBoundary;
640  double m_fPeriodicRightBoundary;
641  double m_fDisBetweenPeriodicBoundaries;
642 
643  double m_fDt;
644  //bool m_iIfDebug;///< if true then print debug info
645  //std::ofstream debug;///< output information for debugging
646  //-------------------------------------------------------------------------------------
647 
648 
649 
650  //-------------------------------------Methods-----------------------------------------
651 
666  void computeSetupsForNextIteration();
667 
668 
673  void updateFreeBoundaryLocation();
674 
675 
683  void updateFreeBoundaryPressureAndVelocity();
684 
685 
693  void updateSolidBoundaryPressureAndVelocity();
694 
695 
704  void computeMinParticleSpacing();
705 
706 
716  void computeMaxSoundSpeed();
717 
718 
725  void computeMaxFluidVelocity();
726 
727 
733  void updateLimiter();
734 
741  void computeLPFOrder(std::size_t index, int& left_order, int& right_order);
742 
743 
749  void computeSpatialDer(int order, int direction, int i,
750  const double *local_u, const double *local_x,
751  double& dudx, double& dudxx); //output
752 
762  void solveByQR(int order, int num_nei, const double *local_u, const double *local_x,
763  double &dudx, double &dudxx); //output
764 
765 
775  void solveByCramer(int order, int num_nei, const double *local_u, const double *local_x,
776  double &dudx, double &dudxx); //output
777 
778 
779  /*
780  * \brief returns a constant weight independent of the input
781  *
782  * \note A helper function for solveByCramer(), which always returns 1
783  */
784  double constantWeight(double h);
785 
791  void timeIntegration(int i, const double* V_old, const double* up_old,
792  const double* p_old, const double* cs_old,
793  double ux_left, double uxx_left,
794  double px_left, double pxx_left,
795  double ux_right, double uxx_right,
796  double px_right, double pxx_right,
797  double* V, double* up, double* p); // output
798 
799 
805  void printInvalidState(int i,
806  double ux_left, double uxx_left, double px_left, double pxx_left,
807  double ux_right, double uxx_right, double px_right, double pxx_right);
808 
809 
815  void updateFluidState();
816 
817 
823  void moveFluidParticle();
824 
825 
831  //void updateFluidVelocity(double*& up, double*& up_old);
832 
833 
845 // bool lowerLPFOrder(int index, const std::vector<int*>& LPFOrderOther, // input
846 // int* LPFOrder0, int* LPFOrder1); // output
847 
853 // std::string rightFlush(size_t writeStep, size_t numDigits);
854 
860 // int writeResult(double time, size_t writeStep, size_t startIndex, size_t numParticle);
861 
862 
863 };
864 
865 
866 
867 
868 
869 #endif // __LP_SOLVER_H__
virtual ~LPSolver()
Destructor.
Definition: lp_solver.h:57
virtual double getMaxFluidVelocity() const
Getter function of the maximum absolute value velocity among all fluid particles. ...
Definition: lp_solver.h:89
virtual double getMaxSoundSpeed() const
Getter function of the maximum sound speed among all fluid particles.
Definition: lp_solver.h:82
An abstract class for the family of classes that performs the task of nearest neighbour search for pa...
Definition: neighbour_searcher.h:64
virtual int solve(double dt)
The Lagrangian particle solver for the compressible Euler's equations for one iteration step...
Definition: lp_solver.cpp:145
double m_fMaxFluidVelocity
Maximum absolute value velocity of fluid particles at a time step.
Definition: lp_solver.h:95
virtual int solve(double dt)=0
The black box main Lagrangian particle solver for one iteration step.
double m_fMaxSoundSpeed
Maximum sound speed of fluid particles at a time step.
Definition: lp_solver.h:94
HyperbolicLPSolver(const Initializer &init, ParticleData *pData, NeighbourSearcher *ns)
Constructor.
Definition: lp_solver.cpp:25
The default Lagrangian Particle solver for the compressible Euler's equation in 2D and 3D...
Definition: lp_solver.h:118
An abstract class for the family of Lagrangian Particle solvers.
Definition: lp_solver.h:53
This class initializes the simulation.
Definition: initializer.h:227
An abstract class for the calculation of energy and sound speed based on different EOS models...
Definition: eos.h:42
double m_fMinParticleSpacing
Minimum inter-particle spacing among fluid particles at a time step.
Definition: lp_solver.h:93
The default Lagrangian Particle solver for the compressible Euler's equation in 1D.
Definition: lp_solver.h:584
HyperbolicLPSolver1D(const Initializer &init, ParticleData *pData)
Constructor.
Definition: lp_solver.cpp:3256
virtual double getMinParticleSpacing() const
Getter function of the minimum inter-particle distance among all fluid particles. ...
Definition: lp_solver.h:75
std::ofstream debug
output information for debugging
Definition: lp_solver.h:97
virtual int solve(double dt)
The 1D Lagrangian particle solver for the compressible Euler's equations for one iteration step...
Definition: lp_solver.cpp:3333
A class that stores all information and data of particles, such as x, y, and z coordinates, neighbour lists, and bounding boxes.
Definition: particle_data.h:51
bool m_iIfDebug
if true then print debug info
Definition: lp_solver.h:96