CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to know mesh size after dynamic refinement (http://www.cfd-online.com/Forums/openfoam/118064-how-know-mesh-size-after-dynamic-refinement.html)

tayo May 20, 2013 13:40

How to know mesh size after dynamic refinement
 
Hello all,

Do you know how to obtain the actual size of a mesh after refinement? I've been trying to get this for quite a while now. The only way that I've able to come up with something close is to try to replicate the dynamic mesh results with that of a fine static mesh and then I assume the static mesh size as the dynamic mesh size after refinement. Is it a ratio of the initial mesh size? Below is my dynamicRefineFvMesh setting. Thanks for your help/explanation.

dynamicRefineFvMeshCoeffs
{
// How often to refine
refineInterval 1;
// Field to be refinement on
field alpha1;
// Refine field inbetween lower..upper
lowerRefineLevel 0.001;
upperRefineLevel 0.999;
// If value < unrefineLevel unrefine
unrefineLevel 10;
// Have slower than 2:1 refinement
NBufferLayers 1;
// Refine cells only up to maxRefinement levels
maxRefinement 2;
// Stop refinement if maxCells reached
maxCells 1000000;
// Flux field and corresponding velocity field. Fluxes on changed
// faces get recalculated by interpolating the velocity. Use 'none'
// on surfaceScalarFields that do not need to be reinterpolated.

correctFluxes
(
(phi Urel)
(phiAbs U)
(phiAbs_0 U_0)
(nHatf none)
(rho*phi none)
(ghf none)
);
// Write the refinement level as a volScalarField
dumpLevel true;
}

kmooney May 20, 2013 21:13

If you're running in parallel you could do something like this:

Code:

label nCells = returnReduce(mesh.cells().size(), sumOp<label>());
Info<<"  Total number of cells in mesh:  "<<nCells<<endl;

If in serial you could do something like this:
Code:

label nCells = mesh.cells().size();
Info<<"  Total number of cells in mesh:  "<<nCells<<endl;

I'd imagine you could just throw this somewhere in the top level of your solver after the mesh.update() call.

tayo May 20, 2013 22:42

Hey Kyle, thanks for your response. I suppose this code would print in the log file, the number of cells in the alpha1 field after refinement at every time step. Assuming it gives me X cells in an alpha1 field with an initial size of Y, it will still be tough to obtain the average size/dimension of each cell after the refinement. Is there a way to obtain this average cell/grid size with a decent degree of accuracy?

kmooney May 20, 2013 22:50

I'm not sure if this is the exact code to make it happen but could could find the average cell volume exactly, no need for approximation:

Code:

scalar totalVol = gSum(mesh.cellVolumes());
scalar meanVol = totalVol / nCells;


tayo May 20, 2013 22:53

Thanks. I'll give it a try.

tayo May 21, 2013 13:03

Quote:

Originally Posted by kmooney (Post 428765)
Code:

label nCells = mesh.cells().size();
Info<<"  Total number of cells in mesh:  "<<nCells<<endl;

Code:

scalar totalVol = gSum(mesh.cellVolumes());
scalar meanVol = totalVol / nCells;


Hi Kyle, this code gives me the total number of cells in the entire domain after refinement. However, I'm trying to get the total number of cells in the alpha1 field alone. I tried "volScalarField nAlphaCells = alpha1.db().mesh.cells().size()" but it didn't work. Can you help with this? Thanks

kmooney May 21, 2013 19:14

After refinement, the alpha field would have been resized and mapped from the previous mesh. It will have the same number of internalField values as there are cells in the mesh.

If you still want to count the number of internalField values of the alpha field I think you could get an integer count like this:

Code:

Info<< Number of internalField values for alpha1: << alpha1.internalField().size() << endl;

kmooney May 21, 2013 19:15

After refinement, the alpha field would have been resized and mapped from the previous mesh. It will have the same number of internalField values as there are cells in the mesh.

If you still want to count the number of internalField values of the alpha field I think you could get an integer count like this:

Code:

Info<< Number of internalField values for alpha1: << alpha1.internalField().size() << endl;

tayo May 21, 2013 21:55

To get the total volume of cells in the alpha1 field, I tried this: "gSum(alpha1.internalFieldvolume())". It blew up:eek:. Please also provide this line of code. Thanks.

kmooney May 21, 2013 21:57

I'm going to be honest and say that at this point I really don't know what you're asking.

tayo May 21, 2013 22:06

Quote:

Originally Posted by kmooney (Post 428772)
Code:

scalar totalVol = gSum(mesh.cellVolumes());
scalar meanVol = totalVol / nCells;


I'm also trying to get the total volume of cells in the alpha1 field similar to the code above so that I will be able to estimate the volume of each cell.

kmooney May 21, 2013 22:10

The alpha1 field is stored on the mesh. It is one in the same as there is no alpha1 mesh, there is one domain mesh on which all of your flow fields are discretized onto. You should check out some introductory CFD texts, they will explain the basics better than I will.

You have a few conceptual gaps on your part which are causing communication issues between us.

tayo May 21, 2013 22:25

I clearly understand what you mean. What I'm saying is that the previous code seems to give the total volume of cells in the entire computation domain. But what I'm seeking the the total volume of cells in the alpha1 field alone. Remember it a 2-phase flow. Taking a 2nd look at the codes: "mesh.cells().size()" and "alpha1.internalField().size()" should give the same number of cells, just like you said. I guess I didn't explain clearly. What I wanted is the interfacial volume and number of cells (i.e. alpha1=0.5). Assuming the quasi bubble interface at alpha1=0.5, I will like to know its number of cells and volume after refinement at each time step.

tayo May 21, 2013 23:59

Alright, just got an idea. I can get the number of cells in the phase at alpha1 = 0.5 using the iso-contour plot in paraFoam. To get the volume, swakFunctionObjects be nicely used. Hence, vol. of each cell can be obtained. Assuming uniform grid length, I can therefore compute an average length/size of the refined mesh. While not the most accurate, I think it solves the problem:D. Case closed. Thanks for your comments.

Tobi May 22, 2013 08:44

Hi all,

just a damn question.

Is there a solver in Standard of solvers that is using that code for adaptive mesh refinement?

Tobi

tayo May 22, 2013 10:17

OF has a couple of solvers with dynamic mesh refinement, based on your interest: pimpleDyMFoam for incompressible single-phase flow, sonicDyMFoam for compressible flow, and interDymFoam for 2-phase. You might need to modify the solver if your problem is complex. Check out the link below.

http://www.openfoam.com/features/standard-solvers.php

Tobi May 22, 2013 13:39

Hi,

I thought that are "mesh moving solvers". So that a car or plane can go through a mesh not for adaptiv refinement! ?

Can I use that solvers for that problems too?


All times are GMT -4. The time now is 22:29.