MPS-Basic
Loading...
Searching...
No Matches
PressureCalculator::PressurePoissonEquation Class Reference

Class for setting up and solving pressure Poisson equation. More...

#include <pressure_poisson_equation.hpp>

Public Member Functions

 PressurePoissonEquation ()=default
 
 PressurePoissonEquation (int dimension, double dt, double relaxationCoefficient, double compressibility, double n0_forNumberDensity, double n0_forLaplacian, double lambda0, double reForLaplacian, double reForNumberDensity)
 
void setup (const Particles &particles, const DirichletBoundaryCondition &dirichletBoundaryCondition)
 Setup pressure Poisson equation.
 
std::vector< double > solve ()
 Solve pressure Poisson equation.
 

Private Member Functions

void resetEquation ()
 
void setSourceTerm (const Particles &particles, const DirichletBoundaryCondition &dirichletBoundaryCondition)
 Set the source term for the pressure Poisson equation.
 
void setMatrixTriplets (const Particles &particles, const DirichletBoundaryCondition &dirichletBoundaryCondition)
 Set the matrix triplets for the pressure Poisson equation.
 

Private Attributes

int dimension
 
double dt
 
double relaxationCoefficient
 
double compressibility
 
double n0_forNumberDensity
 
double n0_forLaplacian
 
double lambda0
 
double reForLaplacian
 
double reForNumberDensity
 
size_t particlesCount
 
std::vector< Eigen::Triplet< double > > matrixTriplets
 Triplets for coefficient matrix.
 
Eigen::SparseMatrix< double, Eigen::RowMajor > coefficientMatrix
 Coefficient matrix for pressure Poisson equation.
 
Eigen::VectorXd sourceTerm
 Source term for pressure Poisson equation.
 

Detailed Description

Class for setting up and solving pressure Poisson equation.

Definition at line 14 of file pressure_poisson_equation.hpp.

Constructor & Destructor Documentation

◆ PressurePoissonEquation() [1/2]

PressureCalculator::PressurePoissonEquation::PressurePoissonEquation ( )
default

◆ PressurePoissonEquation() [2/2]

PressurePoissonEquation::PressurePoissonEquation ( int dimension,
double dt,
double relaxationCoefficient,
double compressibility,
double n0_forNumberDensity,
double n0_forLaplacian,
double lambda0,
double reForLaplacian,
double reForNumberDensity )

Definition at line 9 of file pressure_poisson_equation.cpp.

Member Function Documentation

◆ setup()

void PressurePoissonEquation::setup ( const Particles & particles,
const DirichletBoundaryCondition & dirichletBoundaryCondition )

Setup pressure Poisson equation.

Parameters
particlesParticles
isPressureUpdateTargetFunction that gets a particle and returns true if the particle is a target for pressure update

Definition at line 31 of file pressure_poisson_equation.cpp.

33 {
34 this->particlesCount = particles.size();
35
37 setSourceTerm(particles, dirichletBoundaryCondition);
38 setMatrixTriplets(particles, dirichletBoundaryCondition);
39 coefficientMatrix.setFromTriplets(matrixTriplets.begin(), matrixTriplets.end());
40}
int size() const
Get the number of particles.
Definition particles.cpp:21
void setSourceTerm(const Particles &particles, const DirichletBoundaryCondition &dirichletBoundaryCondition)
Set the source term for the pressure Poisson equation.
Eigen::SparseMatrix< double, Eigen::RowMajor > coefficientMatrix
Coefficient matrix for pressure Poisson equation.
void setMatrixTriplets(const Particles &particles, const DirichletBoundaryCondition &dirichletBoundaryCondition)
Set the matrix triplets for the pressure Poisson equation.
std::vector< Eigen::Triplet< double > > matrixTriplets
Triplets for coefficient matrix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve()

std::vector< double > PressurePoissonEquation::solve ( )

Solve pressure Poisson equation.

Returns
Calculated pressure. The size of the vector is the same as the number of particles.

Definition at line 42 of file pressure_poisson_equation.cpp.

42 {
43 using std::cerr;
44 using std::endl;
45
46 Eigen::BiCGSTAB<Eigen::SparseMatrix<double, Eigen::RowMajor>> solver;
47 solver.compute(coefficientMatrix);
48 Eigen::VectorXd pressure = solver.solve(sourceTerm);
49 if (solver.info() != Eigen::Success) {
50 cerr << "Pressure calculation failed." << endl;
51 std::exit(-1);
52 }
53
54 // This conversion is done by giving std::vector the pointers to the first and the last elements of the
55 // Eigen::VectorXd. If this type of conversion appears frequently, consider defining a function to convert the
56 // vector type.
57 std::vector<double> pressureStdVec(pressure.data(), pressure.data() + pressure.size());
58 return pressureStdVec;
59}
Eigen::VectorXd sourceTerm
Source term for pressure Poisson equation.
Here is the caller graph for this function:

◆ resetEquation()

void PressurePoissonEquation::resetEquation ( )
private

Definition at line 61 of file pressure_poisson_equation.cpp.

Here is the caller graph for this function:

◆ setSourceTerm()

void PressurePoissonEquation::setSourceTerm ( const Particles & particles,
const DirichletBoundaryCondition & dirichletBoundaryCondition )
private

Set the source term for the pressure Poisson equation.

Parameters
particlesParticles
isPressureUpdateTargetFunction that gets a particle and returns true if the particle is a target for pressure update

Definition at line 73 of file pressure_poisson_equation.cpp.

75 {
76 double n0 = this->n0_forNumberDensity;
77 double gamma = this->relaxationCoefficient;
78
79#pragma omp parallel for
80 for (auto& pi : particles) {
81 if (dirichletBoundaryCondition.contains(pi.id)) {
82 // When dirichlet boundary condition is set, the source term is the boundary condition value.
83 sourceTerm[pi.id] = dirichletBoundaryCondition.value(pi.id);
84 } else {
85 sourceTerm[pi.id] = gamma * (1.0 / (dt * dt)) * ((pi.numberDensity - n0) / n0);
86 }
87 }
88}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMatrixTriplets()

void PressurePoissonEquation::setMatrixTriplets ( const Particles & particles,
const DirichletBoundaryCondition & dirichletBoundaryCondition )
private

Set the matrix triplets for the pressure Poisson equation.

Coefficient matrix is a sparse matrix and made by triplets. Triplets are the elements of the matrix that are not zero and represented by the row index, column index, and the value of the element. This function sets the triplets for the pressure Poisson equation.

Parameters
particlesParticles
isPressureUpdateTargetFunction that gets a particle and returns true if the particle is a target for pressure update

Definition at line 99 of file pressure_poisson_equation.cpp.

101 {
102 auto a = 2.0 * dimension / (n0_forLaplacian * lambda0);
103 auto re = reForLaplacian;
104
105 for (auto& pi : particles) {
106 if (dirichletBoundaryCondition.contains(pi.id)) {
107 // When Dirichlet boundary conditions are set, only the diagonal term is set to 1 so that the pressure is at
108 // the specified value.
109 matrixTriplets.emplace_back(pi.id, pi.id, 1.0);
110 continue;
111 }
112
113 double coefficient_ii = 0.0;
114 for (auto& neighbor : pi.neighbors) {
115 auto& pj = particles[neighbor.id];
116 if (pj.boundaryCondition == FluidState::Ignored) {
117 continue;
118 }
119
120 if (neighbor.distance < re) {
121 double coefficient_ij = a * weight(neighbor.distance, re) / pi.density;
122 matrixTriplets.emplace_back(pi.id, pj.id, -1.0 * coefficient_ij);
123 coefficient_ii += coefficient_ij;
124 }
125 }
126 coefficient_ii += (compressibility) / (dt * dt);
127 matrixTriplets.emplace_back(pi.id, pi.id, coefficient_ii);
128 }
129}
@ Ignored
Ghost or dummy.
double weight(double dis, double re)
Wight function for MPS method presented by Koshizuka and Oka, 1996
Definition weight.cpp:5
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dimension

int PressureCalculator::PressurePoissonEquation::dimension
private

Definition at line 45 of file pressure_poisson_equation.hpp.

◆ dt

double PressureCalculator::PressurePoissonEquation::dt
private

Definition at line 46 of file pressure_poisson_equation.hpp.

◆ relaxationCoefficient

double PressureCalculator::PressurePoissonEquation::relaxationCoefficient
private

Definition at line 47 of file pressure_poisson_equation.hpp.

◆ compressibility

double PressureCalculator::PressurePoissonEquation::compressibility
private

Definition at line 48 of file pressure_poisson_equation.hpp.

◆ n0_forNumberDensity

double PressureCalculator::PressurePoissonEquation::n0_forNumberDensity
private

Definition at line 49 of file pressure_poisson_equation.hpp.

◆ n0_forLaplacian

double PressureCalculator::PressurePoissonEquation::n0_forLaplacian
private

Definition at line 50 of file pressure_poisson_equation.hpp.

◆ lambda0

double PressureCalculator::PressurePoissonEquation::lambda0
private

Definition at line 51 of file pressure_poisson_equation.hpp.

◆ reForLaplacian

double PressureCalculator::PressurePoissonEquation::reForLaplacian
private

Definition at line 52 of file pressure_poisson_equation.hpp.

◆ reForNumberDensity

double PressureCalculator::PressurePoissonEquation::reForNumberDensity
private

Definition at line 53 of file pressure_poisson_equation.hpp.

◆ particlesCount

size_t PressureCalculator::PressurePoissonEquation::particlesCount
private

Definition at line 54 of file pressure_poisson_equation.hpp.

◆ matrixTriplets

std::vector<Eigen::Triplet<double> > PressureCalculator::PressurePoissonEquation::matrixTriplets
private

Triplets for coefficient matrix.

Definition at line 56 of file pressure_poisson_equation.hpp.

◆ coefficientMatrix

Eigen::SparseMatrix<double, Eigen::RowMajor> PressureCalculator::PressurePoissonEquation::coefficientMatrix
private

Coefficient matrix for pressure Poisson equation.

Definition at line 58 of file pressure_poisson_equation.hpp.

◆ sourceTerm

Eigen::VectorXd PressureCalculator::PressurePoissonEquation::sourceTerm
private

Source term for pressure Poisson equation.

Definition at line 59 of file pressure_poisson_equation.hpp.


The documentation for this class was generated from the following files: