Accessing dimensions (x, y, z) of cells
Hello everybody,
for a new hybrid turbulence model I want to implement I need the dimensions of each cell to calculate a new delta. I found a way of calculating the dimensions in each direction (x, y, z) in meter. See code attached: Code:
const faceList & ff = this->mesh().faces(); But my question is: Is there a more effective way of computing the cell dimensions in x, y and z than using a forAll loop? I have the impression that this is rather time-consuming when using a large mesh. Many thanks for your help! Daniel |
boundBox for the cell points?
BTW in your code example it appears that you are overwriting the entire fields each cell - probably not what you want. For efficiency, it would make sense to store/access the values as a DimensionedField of vectors and dump all of it into a class as a MeshObject. This would make it demand-driven and you could handle mesh changes seamlessly. |
Maybe I show the whole code so it becomes a bit more clear. I should also mention that I am a beginner with OpenFOAM coding and found this code in a other forum post and it seemed that this the thing I need: https://www.cfd-online.com/Forums/op...ize-x-y-z.html
My whole code for calculating the variable I need with the cell dimensions looks like this. For a non-moving mesh, the dimensions of each cell should only calculated at the beginning since they are not changing in time, but I am not sure yet how to solve this issue. Maybe write another file like the cubeRootVolDelta or the maxDelta. But what changes with each iteration is the vorticity, this should therefore be calculated at each time step. Code:
template<class BasicTurbulenceModel> Quote:
Many thanks for your help! Best regards, Daniel |
Quote:
If you examine the closing statements in your loop: Code:
forAll(this->mesh().C(), celli) After exiting the loop, the entire field will simply have the value of the last cell, which you will not notice if the mesh is uniform. |
You would need to verify, but my first idea was something like this (NOTE: quality not checked!!).
Code:
volScalarField deltax = this->y_; |
Many thanks for your help, now I understand! You are completely right. I just tested your piece of code and it seems to work also it seems much faster, I just have to check if the dimensions are right. I think for this the easiest way is to create IOobjects, what do you think?
But if I now want to calculate the deltaOmega for each cell, I don't have to use a forAll loop, right? I can just calculate like this: Code:
sqrt( sqr(vorticityUnit.component(0)) * deltay * deltaz + sqr(vorticityUnit.component(1)) * deltaz * deltax + sqr(vorticityUnit.component(2)) * deltax * deltay ); |
It's fine enough the way you now have it.
Since you have complete volfields after the loop, the rest should be OK. You will Probably want to store deltaxy, deltayz, deltazx instead. Cheap to calculate within the loop, and saves extra multiplications later. After that can revise how you create your fields. Probably want them with the class scope. For that, autoPtr is the usual container. |
Hi Daniel,
what does this->Y in your code mean?? Thanks in advance |
Quote:
That should be the wall distance if I remember correctly. It was just for initialization. |
I had written a loop similar to yours for finding deltaX and wrote return statement after the loop. But when I use deltaX in return statement it is throwing an error message that deltaX is undefined
|
Quote:
Did you define deltaX before the loop? |
Hi Daniel,
I didn't define it before loop. Because I don't know what I should assign to deltaX as u assigned this->Y. my cose looks like this Foam::tmp<Foam::volScalarField> Foam::phaseChangeTwoPhaseMixtures::myPhaseChange:: kappaGradT() const { const volScalarField limalpha1(min(max((alpha1()), scalar(0)), scalar(1))); const volVectorField& U = db().lookupObject<volVectorField>("U"); const fvMesh & mesh = U.mesh(); const unallocLabelList& neighbour = mesh.neighbour(); const unallocLabelList& owner = mesh.owner(); const volVectorField& C = mesh.C(); const volScalarField& T = alpha1().db().lookupObject<volScalarField>("T"); forAll(owner, facei) { vector delta = C[neighbour[facei]] - C[owner[facei]]; volScalarField gradAlpha = fvc::grad(limalpha1) & mesh.C(); volScalarField alphaPrim = mag(gradAlpha); const dimensionedScalar len("len",dimLength,mag(delta)); const dimensionedScalar small("small",dimensionSet(0, 0, 0, 0, 0, 0, 0),1e-5); } return ( (limalpha1*lambda1_+ (1-limalpha1)*lambda2_) * ((T-Tsat_)/(len))*(gradAlpha/max(alphaPrim,small)) ); } |
Quote:
you could try to define a vector before the loop like: Code:
|
Hi Daniel,
Thanks for your suggestion,I implemented it like this now I have no eroors or warnings,is it correct way?? Foam::tmp<Foam::volScalarField> Foam::phaseChangeTwoPhaseMixtures::myPhaseChange:: kappaGradT() const { const volScalarField limalpha1(min(max((alpha1()), scalar(0)), scalar(1))); const volVectorField& U = db().lookupObject<volVectorField>("U"); const fvMesh & mesh = U.mesh(); const unallocLabelList& neighbour = mesh.neighbour(); const unallocLabelList& owner = mesh.owner(); const volVectorField& C = mesh.C(); const volScalarField& T = alpha1().db().lookupObject<volScalarField>("T"); vector delta(0,0,0); const dimensionedScalar len("len",dimLength,0); forAll(owner, facei) { vector delta = C[neighbour[facei]] - C[owner[facei]]; volScalarField gradAlpha = fvc::grad(limalpha1) & mesh.C(); volScalarField alphaPrim = mag(gradAlpha); const dimensionedScalar len("len",dimLength,mag(delta)); const dimensionedScalar small("small",dimensionSet(0, 0, 0, 0, 0, 0, 0),1e-5); } return ( (limalpha1*lambda1_+ (1-limalpha1)*lambda2_) * ((T-Tsat_)/(len))*(gradAlpha/max(alphaPrim,small)) ); } is delta in loop getting used? Why I am doubting this is, I have set both delta and len to 0 before the loop ,will the get updated |
Quote:
Yes, that should be working. You are just defining delta and len beforehand so that it will be recognized for the loop. During the loop it will then get updated. You could print len or delta during your simulation so you can see if the results are meaningful. I am not sure how to print anymore but there are some posts related to this topic, just google for it. |
Hi daniel,
Thanks for helping me, And I am able to print them and I am getting correct results |
Quote:
|
Hi Daniel,
Can you look this post and suggest me what's wrong in it. https://www.cfd-online.com/Forums/op...ing-error.html Thanks in advance |
Hi Olesen,
If I want to write it as a post-processing program, is that possible? Regards. |
All times are GMT -4. The time now is 20:37. |