Question
Asked 29th Jul, 2021

Is it possible to extract the value of a variable from a template?

Dear all;
I am trying to simulate non-Newtonian fluid flow in porous media with the help of Palabos software. Palabos is a C+++ open-source library that solves flow problems with the lattice Boltzmann method. I am not familiar with object-oriented programming and I want to extract a value from a template that is used in every iteration. To be more precise; I want to print Omega (which is an (Nx-1)*(Ny-1) dimensional matrix) in every 250 iterations in the form of gif or data to validate my result. I added pcout to print variable in this function and it works but it is repeated every iteration which generates too much data ( imagine 200*200 lattice and 10000 iterations!).
I will be really glad if you could help me through this. the code is provided below. also, I uploaded
.h and .hh file to this message
Many thanks;
Elahe;
template<typename T, template<typename U> class Descriptor,int N>
T CarreauDynamics<T,Descriptor,N>::
getOmegaFromPiAndRhoBar(Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq, T rhoBar) const
{
T nu0_nuInfoverCs2 = (global::CarreauParameters().getNu0()-global::CarreauParameters().getNuInf())*Descriptor<T>::invCs2;
T nuInfoverCs2 = global::CarreauParameters().getNuInf()*Descriptor<T>::invCs2;
T nMinusOneOverTwo = (global::CarreauParameters().getExponent() - (T)1)/(T)2;
T lambdaOverCs2sqr = global::CarreauParameters().getLambda()*Descriptor<T>::invCs2;
lambdaOverCs2sqr *= lambdaOverCs2sqr;
T piNeqNormSqr = SymmetricTensor<T,Descriptor>::tensorNormSqr(PiNeq);
T alpha = lambdaOverCs2sqr * piNeqNormSqr *(T)0.5
*Descriptor<T>::invRho(rhoBar)*Descriptor<T>::invRho(rhoBar);
T omega = carreauDynamicsTemplates<T,N>::fromPiAndRhoToOmega(alpha, nu0_nuInfoverCs2, nuInfoverCs2, nMinusOneOverTwo, this->getOmega());
T tau=(T)1/ omega;
T visco=((T)2 * tau - (T)1)/(T)6;
pcout << "" << visco << std::endl;
return omega;
}

Most recent answer

29th Jul, 2021
Elahe Kamel
University of Tehran
Dear all;
I searched among some examples and I figured out that an output image for omega could be easily generated by adding these few lines to the writeGifs function in the CPP file.
imageWriter.writeScaledGif(createFileName("omega", iter, 6),*computeOmega(lattice , Box2D(0,nx-1, 0,ny-1)),
imSize, imSize );
Thank you for your contributions and precious answers.
Regards;
Elahe

All Answers (6)

29th Jul, 2021
Elahe Kamel
University of Tehran
Thank you for your reply.
I have asked some questions in the Palabos forum but unfortunately, my questions do not gain any views and replies.
I checked cavity3d.cpp examples and I think there was a mistake in the name of the file. This image belongs to vorticity, not omega. If you could take a look at line 111 it says:
,,,,
vtkOut.writeData<3,float>(*computeVorticity(*computeVelocity(lattice)), "vorticity", 1./dt);
,,,,
I also added the mentioned lines to my code with constant omega and the result is attached to this answer. I think it shows vorticity because it has higher values in corners.
Thank you for taking your time.
29th Jul, 2021
Elahe Kamel
University of Tehran
Thank you for your response. It was very useful and it will help me a lot for this project and future works.
Many thanks;
Elahe
29th Jul, 2021
Elahe Kamel
University of Tehran
Dear all;
I searched among some examples and I figured out that an output image for omega could be easily generated by adding these few lines to the writeGifs function in the CPP file.
imageWriter.writeScaledGif(createFileName("omega", iter, 6),*computeOmega(lattice , Box2D(0,nx-1, 0,ny-1)),
imSize, imSize );
Thank you for your contributions and precious answers.
Regards;
Elahe

Similar questions and discussions

Related Publications

Article
Until recently, fluid mechanics was largely outside of the expertise of materials engineers or metallurgists. However, with the major advances in computational hardware and software, fluid flow tools are becoming broadly accessible to the metallurgical/materials community.
Article
Full-text available
In the interdisciplinary field of data-driven models and computational fluid mechanics, the reduced-order model for flow field prediction is mainly constructed by a convolutional neural network (CNN) in recent years. However, the standard CNN is only applicable to data with Euclidean spatial structure, while data with non-Euclidean properties can o...
Article
The similarity between fluid mechanism and electromagnetics leads to the similarity between the governing equations of steady fluid flow, electrostatic field and static magnetic field, and there are some similar rules in numerical calculation. All these equations are expressed in terms of convection, diffusion and source, and the numerical method i...
Got a technical question?
Get high-quality answers from experts.