This post was written in English because my workstation(contains source codes) was not installed with any Chinese input method. In the next few days I’ll install one.
Cell Location
By the code below you can reach to the cell of the location you want as “cell”. Then it will be easier to make other operations.
Cell<T,Descriptor>& cell = lattice.get(ix,iy,iz);
For parallelism
If you would like to run the code in parallel, the below operation is a necessity.
for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
Cell<T,Descriptor>& cell = lattice.get(iX,iY,iZ);
......
}}}
If you would like to get the global coordinates, you can refer to the code below
Dot3D absoluteOffset = lattice.getLocation();
for (plint iX=domain.x0; iX<=domain.x1; ++iX)
{
plint absoluteX = absoluteOffset.x + iX;
for (plint iY=domain.y0; iY<=domain.y1; ++iY)
{
plint absoluteY = absoluteOffset.y + iY;
for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ)
{
plint absoluteZ = absoluteOffset.z + iZ;
Cell<T, Descriptor>& cell = lattice.get(iX,iY,iZ);
......
......
}
}
}
Code source: https://palabos-forum.unige.ch/t/data-processor-for-non-local-operation/1075/2
iniCellAtEquilibrium(cell, density, velocity)
T density = cell.computeDensity();
Array<T, 3> velocity;
cell.computeVelocity(velocity);
cell.defineDensity(density);
cell.defineVelocity(velocity);
iniCellAtEquilibrium(cell, density, velocity);
By using function inicellAtEquilibrium
, you will need density and velocity to assign the Feq to that cell. By cell.computeDensity()
you will get the density and by cell.computeVelocity(velocity)
you will calculate that cell’s velocity and assign it to the variable you defined, for example, here is the “velocity”.
So you want to change the properties of the fluid node during simulation, you can add codes to modify the density and velocity before defineDensity
and defineVelocity
.
computeEquilibria(fEq, rhoBar, j, jSqr)
template<typename T, template<typename U> class Descriptor> void Dynamics<T,Descriptor>::computeEquilibria (
Array<T,Descriptor<T>::q>& fEq, T rhoBar, Array<T,Descriptor<T>::d> const& j, T jSqr, T thetaBar ) const {
for (int iPop=0; iPop<Descriptor<T>::q; ++iPop) {
fEq[iPop] = computeEquilibrium(iPop, rhoBar, j, jSqr, thetaBar);
} }
Before I introduce the computeEquilibria, the above code of function should be demonstrated. It shows that the variable fEq
is calculated by function computeEquilibrium
with inputs iPop, rhoBar, j, and jSqr, where iPop depends on the lattice structure you chose. For example if you use D3Q19, then the ::q term
here will be 19.
Then we look at the main codes to see how this way can perform.
Cell<T,Descriptor>& cell = lattice.get(iX,iY,iZ);
T rhoBar; Array<T,3> j; Array<T,D::q> fEq;
cell.getDynamics().computeRhoBarJ(cell, rhoBar, j);
T jSqr = normSqr(j);
cell.getDynamics().computeEquilibria(fEq, rhoBar, j, jSqr);
The idea is simple, firstly calculate the rho, j, and jsqr, and then we will gather everything we need to get the Feq. The computeEquilibria
only does the favor of looping for us.
If we want to change the properties of that cell, we can modify rhoBar, j to assign the new Feq to fEq
and implement the code below.
for (plint iPop=0; iPop<D::q; ++iPop) {
cell[iPop] = fEq[iPop];
}
computeEquilibrium(iPop, rhoBar, j, jSqr)
This way is similar to the method above, I think I don’t need to make further explanation.
for(plint iPop=0;iPop<D::q;++iPop){
cell[iPop] = cell.computeEquilibrium(iPop, rhoBar, j, jSqr);
}