16 #include <LbmLib/include/Constants.hpp>
17 #include <LbmLib/include/GlobalSimulationParameters.hpp>
18 #include <LbmLib/include/nodes/PhysicalNode.hpp>
19 #include <LbmLib/include/solver/FluidSolver.hpp>
20 #include <UtilLib/include/Log.hpp>
32 constexpr
double W0 = 4.0 / 9.0;
36 constexpr
double W1 = 1.0 / 9.0;
40 constexpr
double W2 = 1.0 / 36.0;
52 distributions_[T] = 1.0;
57 void FluidSolver::initWithVelocity() {
58 const double rho = 1.0;
61 const double u = velocity_.
x;
62 const double v = velocity_.
y;
64 const double u2 = u * u;
65 const double v2 = v * v;
67 const double W1rho = W1 * rho;
68 const double W2rho = W2 * rho;
69 const double W3 = 9.0 / 2.0;
70 const double lastTerm = 3.0 / 2.0 * (u2 + v2);
74 temp[T] = W0 * rho * (1.0 - lastTerm);
75 temp[E] = W1rho * (1.0 + 3.0 * u + W3 * u2 - lastTerm);
76 temp[NE] = W2rho * (1.0 + 3.0 * (u + v) + W3 * (u + v) * (u + v) - lastTerm);
77 temp[N] = W1rho * (1.0 + 3.0 * v + W3 * v2 - lastTerm);
79 (1.0 + 3.0 * (-u + v) + W3 * (-u + v) * (-u + v) - lastTerm);
80 temp[W] = W1rho * (1.0 + 3.0 * (-u) + W3 * u2 - lastTerm);
82 (1.0 + 3.0 * (-u - v) + W3 * (-u - v) * (-u - v) - lastTerm);
83 temp[S] = W1rho * (1.0 + 3.0 * (-v) + W3 * v2 - lastTerm);
84 temp[SE] = W2rho * (1.0 + 3.0 * (u - v) + W3 * (u - v) * (u - v) - lastTerm);
86 for (
auto d : dirIter_) {
89 distributions_[d] = temp[d];
102 double rho = this->
getRho();
104 if (std::isfinite(this->rhoToAdd_)) {
105 rho += this->rhoToAdd_;
111 std::cout<<
"rhoToAdd="<<this->rhoToAdd_<<std::endl;
114 double rhoI = 1.0 / rho;
115 assert(std::isfinite(rhoI));
118 const double u = (distributions_[E] + distributions_[NE]
120 - (distributions_[NW] + distributions_[W]
121 + distributions_[SW])) * rhoI;
122 const double u2 = u * u;
124 const double v = (distributions_[NE] + distributions_[N]
126 - (distributions_[SW] + distributions_[S]
127 + distributions_[SE])) * rhoI;
129 const double v2 = v * v;
132 const double lastTerm = 3.0 / 2.0 * (u2 + v2);
133 const double tauI = 1.0 /
getTau();
137 const double W3 = 9.0 / 2.0;
138 const double W1rho = W1 * rho;
139 const double W2rho = W2 * rho;
143 temp[T] = W0 * rho * (1.0 - lastTerm) * tauI;
144 temp[E] = W1rho * (1.0 + 3.0 * u + W3 * u2 - lastTerm) * tauI + W1rho * 3 * force_.
x;
145 temp[NE] = W2rho * (1.0 + 3.0 * (u + v) + W3 * (u + v) * (u + v) - lastTerm) * tauI + W2rho * 3 * (force_.
x + force_.
y);
146 temp[N] = W1rho * (1.0 + 3.0 * v + W3 * v2 - lastTerm) * tauI + W1rho * 3 * force_.
y;
147 temp[NW] = W2rho * (1.0 + 3.0 * (-u + v) + W3 * (-u + v) * (-u + v) - lastTerm) * tauI + W2rho * 3 * (-force_.
x + force_.
y);
148 temp[W] = W1rho * (1.0 + 3.0 * (-u) + W3 * u2 - lastTerm) * tauI - W1rho * 3 * force_.
x;
149 temp[SW] = W2rho * (1.0 + 3.0 * (-u - v) + W3 * (-u - v) * (-u - v) - lastTerm) * tauI + W2rho * 3 * (-force_.
x - force_.
y);
150 temp[S] = W1rho * (1.0 + 3.0 * (-v) + W3 * v2 - lastTerm) * tauI - W1rho * 3 * force_.
y;
151 temp[SE] = W2rho * (1.0 + 3.0 * (u - v) + W3 * (u - v) * (u - v) - lastTerm) * tauI + W2rho * 3 * (force_.
x - force_.
y);
153 for (
auto d : dirIter_) {
154 const double tempD = distributions_[d];
156 distributions_[d] = tempD - tempD * tauI + temp[d];
160 const double un = (distributions_[E] + distributions_[NE]
162 - (distributions_[NW] + distributions_[W]
163 + distributions_[SW])) * rhoI;
164 const double vn = (distributions_[NE] + distributions_[N]
166 - (distributions_[SW] + distributions_[S]
167 + distributions_[SE])) * rhoI;
168 assert(std::isfinite(un));
169 assert(std::isfinite(vn));
195 (*stream) << physicalNode_.
getXPos() <<
'\t' << physicalNode_.
getYPos();
196 for (
auto d : distributions_) {
197 (*stream) <<
'\t' << d;
207 assert(physicalNode_.
getXPos() == x &&
"The position does not match");
208 assert(physicalNode_.
getYPos() == y &&
"The position does not match");
209 for (
auto d : dirIter_) {
210 (*stream) >> distributions_[d];
220 return distributions_[dir];
224 for (
auto &it: this->distributions_) {
230 velocity_ = velocity;
231 assert(std::isfinite(this->velocity_.
x));
232 assert(std::isfinite(this->velocity_.
y));
233 velocityInit_ =
true;
237 assert(std::isfinite(this->velocity_.
x));
238 assert(std::isfinite(this->velocity_.
y));
243 return std::accumulate(distributions_.begin(),
244 distributions_.end(), 0.0);
248 this->rhoToAdd_ = 0.0;
249 this->rhoToAdd_ += mass;
250 LOG(UtilLib::logDEBUG4) <<
"mass added to the fluid. " << mass;
253 void FluidSolver::localSwap() {
254 std::swap(distributions_[E], distributions_[W]);
255 std::swap(distributions_[NE], distributions_[SW]);
256 std::swap(distributions_[N], distributions_[S]);
257 std::swap(distributions_[NW], distributions_[SE]);
263 physicalNode_(physicalNode),
264 distributions_(std::array<double,
265 9> {{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
267 velocityInit_(
false),
271 DirectionIterator
const FluidSolver::dirIter_ = DirectionIterator();
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
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
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 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