22 #include <LbmLib/include/Constants.hpp>
23 #include <LbmLib/include/GlobalSimulationParameters.hpp>
24 #include <LbmLib/include/nodes/PhysicalNode.hpp>
25 #include <LbmLib/include/solver/FluidSolver/FluidSolver.hpp>
26 #include <LbmLib/include/solver/FluidSolver/FluidSolver.hpp>
27 #include <UtilLib/include/Log.hpp>
39 constexpr
double W0 = 4.0 / 9.0;
43 constexpr
double W1 = 1.0 / 9.0;
47 constexpr
double W2 = 1.0 / 36.0;
57 distributions_[T] = 1.0;
62 void FluidSolver::initWithVelocity() {
63 const double rho = 1.0;
66 const double u = velocity_.
x;
67 const double v = velocity_.
y;
69 const double u2 = u * u;
70 const double v2 = v * v;
72 const double W1rho = W1 * rho;
73 const double W2rho = W2 * rho;
74 const double W3 = 9.0 / 2.0;
75 const double lastTerm = 3.0 / 2.0 * (u2 + v2);
79 temp[T] = W0 * rho * (1.0 - lastTerm);
80 temp[E] = W1rho * (1.0 + 3.0 * u + W3 * u2 - lastTerm);
81 temp[NE] = W2rho * (1.0 + 3.0 * (u + v) + W3 * (u + v) * (u + v) - lastTerm);
82 temp[N] = W1rho * (1.0 + 3.0 * v + W3 * v2 - lastTerm);
84 (1.0 + 3.0 * (-u + v) + W3 * (-u + v) * (-u + v) - lastTerm);
85 temp[W] = W1rho * (1.0 + 3.0 * (-u) + W3 * u2 - lastTerm);
87 (1.0 + 3.0 * (-u - v) + W3 * (-u - v) * (-u - v) - lastTerm);
88 temp[S] = W1rho * (1.0 + 3.0 * (-v) + W3 * v2 - lastTerm);
89 temp[SE] = W2rho * (1.0 + 3.0 * (u - v) + W3 * (u - v) * (u - v) - lastTerm);
91 for (
auto d : dirIter_) {
94 distributions_[d] = temp[d];
106 double rho = this->
getRho();
108 if (std::isfinite(this->rhoToAdd_)) {
109 rho += this->rhoToAdd_;
115 std::cout<<
"rhoToAdd="<<this->rhoToAdd_<<std::endl;
118 double rhoI = 1.0 / rho;
119 assert(std::isfinite(rhoI));
124 const double ux2 = u.
x * u.
x;
125 const double uy2 = u.
y * u.
y;
128 const double lastTerm = 3.0 / 2.0 * (ux2 + uy2);
129 const double tauI = 1.0 /
getTau();
133 const double W3 = 9.0 / 2.0;
134 const double W1rho = W1 * rho;
135 const double W2rho = W2 * rho;
140 std::vector<double> forcecontribution;
147 temp[T] = W0 * rho * (1.0 - lastTerm) * tauI +
148 forcecontribution[T];
149 temp[E] = W1rho * (1.0 + 3.0 * u.
x + W3 * ux2 - lastTerm) * tauI +
150 forcecontribution[E];
151 temp[NE] = W2rho * (1.0 + 3.0 * (u.
x + u.
y) + W3 * (u.
x + u.
y) * (u.
x + u.
y) - lastTerm) * tauI +
152 forcecontribution[NE];
153 temp[N] = W1rho * (1.0 + 3.0 * u.
y + W3 * uy2 - lastTerm) * tauI +
154 forcecontribution[N];
155 temp[NW] = W2rho * (1.0 + 3.0 * (-u.
x + u.
y) + W3 * (-u.
x + u.
y) * (-u.
x + u.
y) - lastTerm) * tauI +
156 forcecontribution[NW];
157 temp[W] = W1rho * (1.0 + 3.0 * (-u.
x) + W3 * ux2 - lastTerm) * tauI +
158 forcecontribution[W];
159 temp[SW] = W2rho * (1.0 + 3.0 * (-u.
x - u.
y) + W3 * (-u.
x - u.
y) * (-u.
x - u.
y) - lastTerm) * tauI +
160 forcecontribution[SW];
161 temp[S] = W1rho * (1.0 + 3.0 * (-u.
y) + W3 * uy2 - lastTerm) * tauI +
162 forcecontribution[S];
163 temp[SE] = W2rho * (1.0 + 3.0 * (u.
x - u.
y) + W3 * (u.
x - u.
y) * (u.
x - u.
y) - lastTerm) * tauI +
164 forcecontribution[SE];
166 for (
auto d : dirIter_) {
167 const double tempD = distributions_[d];
169 distributions_[d] = tempD - tempD * tauI + temp[d];
174 assert(std::isfinite(u.
x));
175 assert(std::isfinite(u.
y));
201 (*stream) << physicalNode_.
getXPos() <<
'\t' << physicalNode_.
getYPos();
202 for (
auto d : distributions_) {
203 (*stream) <<
'\t' << d;
213 assert(physicalNode_.
getXPos() == x &&
"The position does not match");
214 assert(physicalNode_.
getYPos() == y &&
"The position does not match");
215 for (
auto d : dirIter_) {
216 (*stream) >> distributions_[d];
226 return distributions_[dir];
230 for (
auto &it: this->distributions_) {
236 velocity_ = velocity;
237 assert(std::isfinite(this->velocity_.
x));
238 assert(std::isfinite(this->velocity_.
y));
239 velocityInit_ =
true;
243 assert(std::isfinite(this->velocity_.
x));
244 assert(std::isfinite(this->velocity_.
y));
249 return std::accumulate(distributions_.begin(),
250 distributions_.end(), 0.0);
254 this->rhoToAdd_ = 0.0;
255 this->rhoToAdd_ += mass;
256 LOG(UtilLib::logDEBUG4) <<
"mass added to the fluid. " << mass;
259 void FluidSolver::localSwap() {
260 std::swap(distributions_[E], distributions_[W]);
261 std::swap(distributions_[NE], distributions_[SW]);
262 std::swap(distributions_[N], distributions_[S]);
263 std::swap(distributions_[NW], distributions_[SE]);
268 physicalNode_(physicalNode),
269 distributions_(std::array<double,
270 9> {{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
272 velocityInit_(
false),
the base class of the cde and fluid solvers
void setVelocity(Field< double > velocity)
setVelocity Sets the velocity of this fluid Algorithm. Should only be used for initialisation.
void addForce(Field< double > f)
adds f to the current force
virtual void writeSolver(std::ostream *const stream)
writes the solver to the file
virtual void computeVelocity(const double rho, const std::array< double, 9 > &fi, const Field< double > f, Field< double > &u)
computeVelocity since this operation depends on the force model.
FluidSolver(const nodes::PhysicalNode &physicalNode)
FluidSolver Initialises the fluid solver.
virtual double & accessDistribution(const Direction &dir)
accessDistribution Access to the distribution
PhysicalNode * getPhysicalNeighbour(const Direction &d) const
getPhysicalNeighbour Getter method to access the Physical Neighbour
void addMass(double mass)
addMass The mass which is added to this fluid solver
class representing a physical node
T x
x the value in x direction
virtual void initSolver()
initSolver Use this to initalise the solver
double getRho() const
getRho Calculates the Rho
void resetForce()
resets the force on this fluid solver to 0
virtual void computeForce(const double tau, const double rho, const Field< double > u, const Field< double > f, std::vector< double > &forcecontribution)
computeForce
virtual void rescaleDistributions(const double factor)
Rescales all distributions by a factor.
const Field< double > & getVelocity() const
getVelocity Returns the current velocity of the fluid
double getTau() const
getTau Getter method for the tau parameter
const solver::FluidSolver & getFluidSolver() const
getFluidSolver Const getter method for the fluid Solver
int getXPos() const
getXPos Getter for the X position
virtual void loadSolver(std::stringstream *const stream)
loads the solver from the file
int getYPos() const
getYPos Getter for the Y position
virtual void advect()
advect The advect step of the LBM
virtual void collide()
collide The collision step of the LBM
T y
y the value in y direction
The DirectionOperations_ class Provides methods to handle the Directions. Use the Function Directions...