CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Need help for interpolation (https://www.cfd-online.com/Forums/openfoam-programming-development/218772-need-help-interpolation.html)

frobaux July 3, 2019 10:24

Need help for interpolation
 
1 Attachment(s)
Good afternoon everyone and thank you for your time!

I have linked a figure to better understand my problem.



I've been struggling to devellop a domain coupling between two solvers.


- I have an external mesh, really coarse, with fields at points, obtained through an home made potential solver
- I have a small mesh, fine, on which I solve the equations of interFoam.


When I force both the velocity and p_rhg as fixed values at the boundary, the coupling run, even If I know that I can't supply both of them physically. And descent results are obtained, althought a little bit scattered.


When I supply zeroGradient on the outer boundaries of my small mesh and the velocity is supplied and forced, I obtain an error:
Code:

--> FOAM FATAL ERROR:
Continuity error cannot be removed by adjusting the outflow.
Please check the velocity boundary conditions and/or run potentialFoam to initialise the outflow.
Total flux              : 3.70382
Specified mass inflow  : 0.0365504
Specified mass outflow  : 0.0360725
Adjustable mass outflow : 0

I think that the problem of flow rate (when I compute it manually I obtain the same values) comes from the fact that a bad interpolation is done (see figure linked) when importing velocity values from the potential region.

I currently perform three steps to get this patch set up with fixedValue
- on potential Regions, from pointField -> volField
- from volField on potential -> volField on fineMesh (through meshToMesh, and I have tested all interpolation method)
- from volField on the fine mesh -> patch on the finemesh (patch.internalField(), but actually this is meshTomesh which does that directly.)


I there any better way to do this? Or an idea for where I could/should search. Is there any interpolation method which is more continuous (for example the interpolation used by paraFoam for plotOverLine is way cleaner)


Thank you in advance for any advice!


Fabien

mAlletto July 3, 2019 11:48

I did not undestand exactly what you are trying to do from your description but your mass imbalance comes from the Interpolation, i.e. you're trying to fix the velocity at all boundary of the inner domain. Since the interplolation scheme you're applying is not mass conservative this results in a mass increase or decreas in your innner domain. Usually OF tries to get rid of the global mass imbalance by applying some correction factors at the zeroGradiant boundaries. Since you fix all values it cannot get rid of the global mass imbalance.

I know that the cyclicAMI boundary conditions is mass convervative. Maybe you can have a look how this boundary condition is implemented.

frobaux July 4, 2019 04:04

Thank you for your answer, and sorry if I were unclear.



The velocity field I want to import from the outer region (coarser mesh) on the interFoam region (finer mesh) is divergence free (with of course a error from the computational method, but it should be lower than e-8, the hard coded value in adjustPhi.C)


The problem is when I import from the outer mesh to the fine mesh, degradation of the quality of the solution are at play. The worst part being the use of meshToMesh which does takes into account only one cell or 2 cells values of the source field.



I would like to implement or to find a better interpolation method.



For cyclicAMI, the boundaries are mass conservative but it easier as the mass going out is feeded in the other side, am I right?

mAlletto July 4, 2019 05:53

Just for clarification: Do the coarse and fine mesh share only the bounday or also some of the Volume?

I ask the question since meshToMesh can be used to perform an Interpolation between two meshes which share parts of their volume.


Can you describe a bit better you workflow in order that I can get a better Picture what you're doing.

frobaux July 4, 2019 06:11

The fine mesh is completely included in the coarse mesh. They are the same problems but with different sizes and discretisations.

So I think meshToMesh is suited in this case, but the interpolations methods are not well suited for a important difference in terms of discretisation.


My workflow is:
External solver:

- With an external solver, I solve for U and p for all times
- I convert those results into openFoam format -> external region


New coupled solver:
- I create a case with two regions
* the external mesh: results already available
* the "interFoam mesh".


I do it with that methodology because i would like to implement latter the outer solver in the openFoam framework, and solve both interFoam and outer solver as done in the multiRegions solvers (but with overlapping meshes).



and the runTime loop looks like, in pseudo code:
Code:

while (runTime.run())
{

    runTime++;


    - read External Fields;
    - convert PointFields to VolField on External;


    - interpolate InterFoam region Patches From External;


    pimple loop
    {
        - solve InterFoam Region;

    }

}


So later the "read external" will be replaced by "compute external" in theory.

mAlletto July 4, 2019 13:32

Just for clarification: what kind of boundary condition do you apply at the inner fine grid? fixed value or zero gradient

frobaux July 7, 2019 05:23

FixedValue, on both pressure (p_rgh) and velocity (U). Those values are interpolated from the outer coarse grid.


If I use ZeroGradient I wont be abble to set values from the outer grid, right?

mAlletto July 7, 2019 05:49

Yes. But if on patch you set zero gradient an on the other fixed value it is better for the convergence

frobaux July 8, 2019 05:40

Ok, I will try this, but the problem is my flow (waves) is mostly oscillatory, so there is no real physical reason for an inlet with fixedValue and outlet with zeroGradient.


And this does not change the fact that my values are not as correct as it could be on the inlet, due to the "bad" interpolation.

mAlletto July 8, 2019 07:09

There are inletOutlet boundary conditions available in OF: https://www.openfoam.com/documentati...conditions.php

So maybe one of this fits you Needs. But if not, you can derive of one of it and specify fixedValue if the flow goes into your Domain and zeroGradient if it goes out

frobaux July 8, 2019 10:11

I'm looking at this, and I should indeed be better to use this kind of boundaries.


So I need, at every time step to fill the valueInlet (from the value I got from the external region).


But when fill from a fixedValue patch the patch of U as:
Code:



    U.boundaryFieldRef()[patchId]=VfromExternal.boundaryField()[patchId];

Only the part "value" of the patch of U is filled and "inletValue" stays to

Code:

inletValue      uniform (0 0 0);

I have read that "value" is meaningless in the inletOutlet patch, is that correct?


looking at the code in inletOutletFvPatchField.H I read that "inletValue" is set inside "this->refValue()"
But calling "U.boundaryFieldRef()[patchId]->refValue()" does not compile.. Have you an idea as why?


Thanks again a lot for you help :)

mAlletto July 9, 2019 00:46

Can you post the whole code and the exact compiler error? From the message you sent it is unclear what you did and for this reason find the error.

mAlletto July 9, 2019 01:02

Maybe just a remark. What you are trying to do, I.e. embed a finer grid in a coarser in meteorology is common praxis since decades and the methodology is called nesting. You'll find plenty of literature on it.

frobaux July 9, 2019 03:10

Everything here is on the fine mesh:
- I have VfromExternal[i] which is a volVectorField (where the boundaries are "fixed value", and imported from the external regions
- I have U which I will solve. I just need to set its BC
Objective: set the value inside the inletOutlet patch of U:



Code:

forAll(mesh.boundaryMesh(), patchId)
{

    if(U.boundaryField()[patchId].type()== "inletOutlet")
    {
        Info << "inletOutletFound" << endl;
        U.boundaryFieldRef()[patchId].refValue()=VfromExternal[i].boundaryField()[patchId];
    }
}


The compiler error is pretty clear

Code:

    error: ‘class Foam::fvPatchField<Foam::Vector<double> >’ has no member named ‘refValue’
        U.boundaryFieldRef()[patchId].refValue()=VfromExternal[i].boundaryField()[patchId];

When I try

Code:

U.boundaryFieldRef()[patchId]->refValue()=VfromExternal[i].boundaryField()[patchId];
I obtain

Code:

./fluid/setRegionFluidFields.H:44:38: error: base operand of ‘->’ has non-pointer type ‘Foam::fvPatchField<Foam::Vector<double> >’

The problem is I cannot just equalize



Code:

U.boundaryFieldRef()[patchId]=VfromExternal[i].boundaryField()[patchId];
Otherwise the "value" field of the patch is filled, and not the "inletValue" field.



Thanks again. I will also check your recommandation about nested!

frobaux July 9, 2019 08:38

I have managed to use the inletOutlet for both p_rgh and the velocity U on every patch on the border of the fine mesh. The problem to set the pressure is I forgot to cast it into the correct type:
Code:

       
inletOutletFvPatchField<vector>& patchU = refCast<inletOutletFvPatchField<vector> >(U.boundaryFieldRef()[patchId]);


patchU.refValue()=VfromExternal[i].boundaryField()[patchId];
patchU.updateCoeffs();

but my results are not stable at all. I'm running a computation with outletInlet for the pressure instead of inletOutlet (as seen in another thread), but it seems it is not better.

mAlletto July 10, 2019 10:08

did you set the pressure to fixedValue where you have zeroGradient for U and vise versa?


All times are GMT -4. The time now is 08:56.