CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Need help for interpolation

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By mAlletto
  • 1 Post By mAlletto

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 3, 2019, 11:24
Default Need help for interpolation
  #1
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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
Attached Images
File Type: jpg Capture du 2019-07-03 16-11-41.jpg (119.3 KB, 54 views)
frobaux is offline   Reply With Quote

Old   July 3, 2019, 12:48
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
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.
mAlletto is offline   Reply With Quote

Old   July 4, 2019, 05:04
Default
  #3
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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?
frobaux is offline   Reply With Quote

Old   July 4, 2019, 06:53
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
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.
mAlletto is offline   Reply With Quote

Old   July 4, 2019, 07:11
Default
  #5
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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.
frobaux is offline   Reply With Quote

Old   July 4, 2019, 14:32
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Just for clarification: what kind of boundary condition do you apply at the inner fine grid? fixed value or zero gradient
mAlletto is offline   Reply With Quote

Old   July 7, 2019, 06:23
Default
  #7
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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?
frobaux is offline   Reply With Quote

Old   July 7, 2019, 06:49
Default
  #8
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Yes. But if on patch you set zero gradient an on the other fixed value it is better for the convergence
frobaux likes this.
mAlletto is offline   Reply With Quote

Old   July 8, 2019, 06:40
Default
  #9
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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.
frobaux is offline   Reply With Quote

Old   July 8, 2019, 08:09
Default
  #10
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
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 likes this.
mAlletto is offline   Reply With Quote

Old   July 8, 2019, 11:11
Default
  #11
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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
frobaux is offline   Reply With Quote

Old   July 9, 2019, 01:46
Default
  #12
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
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 is offline   Reply With Quote

Old   July 9, 2019, 02:02
Default
  #13
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
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.
mAlletto is offline   Reply With Quote

Old   July 9, 2019, 04:10
Default
  #14
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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 is offline   Reply With Quote

Old   July 9, 2019, 09:38
Default
  #15
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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.
frobaux is offline   Reply With Quote

Old   July 10, 2019, 11:08
Default
  #16
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
did you set the pressure to fixedValue where you have zeroGradient for U and vise versa?
mAlletto is offline   Reply With Quote

Reply

Tags
coupling, interpolation, meshtomesh, patch


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 14:00.