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

runTime mapFields from fineMesh to coarseMesh

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 1 Post By Carlen
  • 2 Post By Carlen
  • 1 Post By Maff

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2015, 07:56
Default runTime mapFields from fineMesh to coarseMesh
  #1
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Hi Foamers,

I have recently successfully combined two solvers which solve different fields on two separate meshes(one fine and one coarse). Now I need to couple the fields of these two meshes every timestep. How can I achieve this? I read from this thread http://www.cfd-online.com/Forums/ope...-parallel.html #15 that I need to use a portion of the mapFields code. However, I have two questions, where do I put this code in my solver (eg.interFoam.C)? The second question is how can I read
Code:
HashTable<word> patchMap;
myDict.lookup("patchMap") >> patchMap;

wordList cuttingPatches;
myDict.lookup("cuttingPatches") >>  cuttingPatches;
How do I define parameters in myDict?
Also, my two meshes are of the same geometry, do you think the method I mentioned above is appropriate?

Thank you in advance
Carlen
Carlen is offline   Reply With Quote

Old   April 27, 2015, 03:45
Default
  #2
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Quote:
Originally Posted by Carlen View Post
Hi Foamers,

I have recently successfully combined two solvers which solve different fields on two separate meshes(one fine and one coarse). Now I need to couple the fields of these two meshes every timestep. How can I achieve this? I read from this thread http://www.cfd-online.com/Forums/ope...-parallel.html #15 that I need to use a portion of the mapFields code. However, I have two questions, where do I put this code in my solver (eg.interFoam.C)? The second question is how can I read
Code:
HashTable<word> patchMap;
myDict.lookup("patchMap") >> patchMap;

wordList cuttingPatches;
myDict.lookup("cuttingPatches") >>  cuttingPatches;
How do I define parameters in myDict?
Also, my two meshes are of the same geometry, do you think the method I mentioned above is appropriate?

Thank you in advance
Carlen
I managed to solver this problem by looking at the cavity case. Now my code for runTime mapFields looks like this:
Code:
IOdictionary carlenMapFieldsDict
          (
             IOobject
             (
              "carlenMapFieldsDict",
              runTime.constant(),
              mesh,
              IOobject::MUST_READ_IF_MODIFIED,
              IOobject::NO_WRITE     
            )
          );

          volVectorField U_L(U, mesh);
          volVectorField U_E(U_P, Primary);
          
          volScalarField p_L(p, mesh);
          volScalarField p_E(p_P, Primary);

          volScalarField T_L(T, mesh);
          volScalarField T_E(T_P, Primary);

          HashTable<word> patchMap;
          wordList cuttingPatches;
          carlenMapFieldsDict.lookup("patchMap") >> patchMap;
          carlenMapFieldsDict.lookup("cuttingPatches") >>  cuttingPatches;

          //set up an interpolation method
          meshToMesh::interpolationMethod mapMethod = meshToMesh::imCellVolumeWeight;
          
          // create the meshtomesh interpolator object
          Info << "Interpolating U,p,T Fields" << endl;
          meshToMesh InterpolatorObj
          (
            mesh,
            Primary,
            mapMethod,
            patchMap,
            addProcessorPatches(Primary, cuttingPatches)
          );

          //do the interpolation between U of the source mesh and Utgt of the target mesh
          InterpolatorObj.mapSrcToTgt
          (
            U,
            eqOp<vector>(),
            U_P
          );   

          InterpolatorObj.mapSrcToTgt
          (
            p,
            eqOp<scalar>(),
            p_P
          );

          InterpolatorObj.mapSrcToTgt
          (
            T,
            eqOp<scalar>(),
            T_P
          );

          Info << "Mapping complete" << endl;
The above code compiles and runs without problem. However, the fields are not mapped between two grids. I narrowed the problem to the way in which I define fields in two meshes. Cna anyone please tell me how to define the fields I want to map?

Thank you very much

carlen
Carlen is offline   Reply With Quote

Old   April 28, 2015, 15:21
Default
  #3
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 9
Sylv is on a distinguished road
What do you mean by "the fields are not mapped between two grid"? The solver crashes or the interpolation is wrong/incomplete?

Sylv
Sylv is offline   Reply With Quote

Old   April 28, 2015, 19:23
Default
  #4
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Quote:
Originally Posted by Sylv View Post
What do you mean by "the fields are not mapped between two grid"? The solver crashes or the interpolation is wrong/incomplete?

Sylv
Hi Marcel,
The interpolation is simply not carried out.

carlen
Carlen is offline   Reply With Quote

Old   April 29, 2015, 04:36
Default
  #5
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 9
Sylv is on a distinguished road
Quote:
Originally Posted by Carlen View Post
Hi Marcel,
The interpolation is simply not carried out.

carlen
So the solver just go through the interpolation without crashing and the target field remained unchanged, right? Are the mesh identical? Is one grid coarser? If yes, which one (target or source)?

Be more detailed in your answers. It is tough to understand the problem with just "not carried out" or "doesn't work"....

Sylv
Sylv is offline   Reply With Quote

Old   April 29, 2015, 20:28
Default
  #6
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Quote:
Originally Posted by Sylv View Post
So the solver just go through the interpolation without crashing and the target field remained unchanged, right? Are the mesh identical? Is one grid coarser? If yes, which one (target or source)?

Be more detailed in your answers. It is tough to understand the problem with just "not carried out" or "doesn't work"....

Sylv
Hi Marcel,
I managed to make the interpolation work from a fine mesh (mesh) to a coarse (Secondary) mesh (they are of the same geometry) using code below:
Code:
       
          IOdictionary carlenMapFieldsDict
          (
             IOobject
             (
              "carlenMapFieldsDict",
              runTime.constant(),
              mesh,
              IOobject::MUST_READ_IF_MODIFIED,
              IOobject::NO_WRITE     
            )
          );

          HashTable<word> patchMap;
          wordList cuttingPatches;
          carlenMapFieldsDict.lookup("patchMap") >> patchMap;
          carlenMapFieldsDict.lookup("cuttingPatches") >>  cuttingPatches;

          //set up an interpolation method
          meshToMesh::interpolationMethod mapMethod = meshToMesh::imCellVolumeWeight;
          
          // create the meshtomesh interpolator

          IOobject Utarget
          (
              "U",
              Secondary.time().timeName(),
              Secondary,
              IOobject::MUST_READ
          );
          volVectorField Utgt(Utarget, Secondary);

          meshToMesh Interp
          (
            mesh,
            Secondary,
            mapMethod,
            patchMap,
            addProcessorPatches(Secondary, cuttingPatches)
          );
         
          Info << "Interpolating U Field" << endl;
          Interp.mapSrcToTgt
          (
            U,
            eqOp<vector>(),
            Utgt
          ); 
          Utgt.write();

 
          Info << "Mapping complete" << endl;
However, the outcome is not ideal. You can see in the picture that the U field mapped on the coarse field is smeared. I wonder if I implement the mapping correctly.

Carlen
Attached Images
File Type: jpg 1.jpg (20.3 KB, 123 views)
ch1 likes this.
Carlen is offline   Reply With Quote

Old   May 1, 2015, 03:32
Default
  #7
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Anyone please help me with this problem. I am stuck.
carlen
Carlen is offline   Reply With Quote

Old   May 10, 2015, 15:20
Default
  #8
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,957
Blog Entries: 43
Rep Power: 122
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Carlen,

I have this thread of yours on my to-do list, but I won't be able to look into this any time soon

Nonetheless, please provide a test case and the code ready to be used/tested, so that it takes less time for someone to step in and help.

In addition, you might want to take a look into the source code for this library/toolkit: https://github.com/smenon/dynamicTopoFvMesh - it has the ability to re-mesh the whole domain on-the-fly, although last I saw, it could only handle tetrahedral meshes.

This issue also reminds me of a similar topic: http://www.cfd-online.com/Forums/ope...pdate-fsi.html - you might be able to find some additional helpful ideas on that thread!!

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   May 15, 2015, 07:10
Default
  #9
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 9
Carlen is on a distinguished road
Thank you bruno,
I solved the problem by applying the same initial boundary condition for both the fine and coarse meshes. Now the interpolations is working as intended.
wyldckat and Ebrahim like this.
Carlen is offline   Reply With Quote

Old   February 2, 2017, 09:07
Default
  #10
New Member
 
Join Date: Mar 2012
Posts: 20
Rep Power: 10
Maff is on a distinguished road
Hi Carlen,

I have been trying to implement mapField during runTime, in a similar way to the one you used (thank you for the useful posts btw).

I stumbled upon the same problem you had: the mapped field is smeared exactly as you posted.

You wrote that you solved the problem by applying the same initial boundary condition. It doesn't seem to work for me. Could you be more specific?
Maff is offline   Reply With Quote

Old   February 5, 2017, 11:09
Default
  #11
New Member
 
Join Date: Mar 2012
Posts: 20
Rep Power: 10
Maff is on a distinguished road
I solved my problem by replacing
Code:
eqOp<vector>()
with
Code:
plusEqOp<vector>()
I'm not sure why, but it seems to work.
Ebrahim likes this.
Maff is offline   Reply With Quote

Old   February 10, 2017, 03:58
Default
  #12
New Member
 
Ebrahim
Join Date: Mar 2010
Posts: 28
Rep Power: 12
Ebrahim is on a distinguished road
Quote:
Originally Posted by Maff View Post
I solved my problem by replacing
Code:
eqOp<vector>()
with
Code:
plusEqOp<vector>()
I'm not sure why, but it seems to work.
Hi Maff,

I have the same issue as yours and I solved it by replacing eqOp<vector>() with plusEqOp<vector>() as well.
Did you find the reason? Actually, I do not know what is changed by this replacement!

/Ebrahim
Ebrahim is offline   Reply With Quote

Old   February 23, 2017, 08:30
Default
  #13
New Member
 
Join Date: Mar 2012
Posts: 20
Rep Power: 10
Maff is on a distinguished road
Does anyone know how to save the meshToMesh addressing, so that it doesn't need to calculate it at every restart?
With some meshes it's a very time consuming process.

I found that with meshToMesh debug set to 1, it saves the srcToTgtCellAddr_, but I would need a way to write the whole result of
Code:
          meshToMesh Interp
          (
            mesh,
            Secondary,
            mapMethod,
            patchMap,
            addProcessorPatches(Secondary, cuttingPatches)
          );
so that it can read it if present.
I guess I would need to write my own meshToMesh.C.

Any idea?
Maff is offline   Reply With Quote

Old   April 5, 2017, 12:25
Default
  #14
New Member
 
Ehimen
Join Date: Jun 2016
Posts: 12
Rep Power: 5
Elliptic CFD is on a distinguished road
Quote:
Originally Posted by Maff View Post
Does anyone know how to save the meshToMesh addressing, so that it doesn't need to calculate it at every restart?
With some meshes it's a very time consuming process.

I found that with meshToMesh debug set to 1, it saves the srcToTgtCellAddr_, but I would need a way to write the whole result of
Code:
          meshToMesh Interp
          (
            mesh,
            Secondary,
            mapMethod,
            patchMap,
            addProcessorPatches(Secondary, cuttingPatches)
          );
so that it can read it if present.
I guess I would need to write my own meshToMesh.C.

Any idea?
Which of the meshToMesh libraries in OpenFOAM are you using?

I had the same problem of the cell addressing recalculating at every timestep when I used meshToMesh.H. I now use meshToMesh0.H and the interpolation between two regions is much faster, although, I am clueless on how to get it to work for parallel cases.

By the way, it seems that meshToMesh0.H is only available for the third and fourth versions of OpenFOAM.
Elliptic CFD is offline   Reply With Quote

Old   April 5, 2017, 12:33
Default
  #15
New Member
 
Ehimen
Join Date: Jun 2016
Posts: 12
Rep Power: 5
Elliptic CFD is on a distinguished road
Quote:
Originally Posted by Ebrahim View Post
Hi Maff,

I have the same issue as yours and I solved it by replacing eqOp<vector>() with plusEqOp<vector>() as well.
Did you find the reason? Actually, I do not know what is changed by this replacement!

/Ebrahim
In OpenFOAM 3+, mapFields.C (which uses meshToMesh0) has the eqOp in the code while mapFieldsPar (which uses meshToMesh) has the plusEqOp in the code.

The difference may depend on which of the mesh to mesh libraries that you use.

Cheers
Elliptic CFD is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with mapFields BlackBoatNavArch OpenFOAM Pre-Processing 33 April 25, 2018 05:32
Problem in3D model processing mebinitap OpenFOAM 2 December 12, 2014 04:40
Strange random behaviour of mapFields blaise OpenFOAM Pre-Processing 0 November 3, 2014 09:37
The -parallel parameter of mapFields utility in OpenFOAM v2.3.0 shuoxue OpenFOAM Pre-Processing 1 April 28, 2014 05:59
transientSimpleDyMFoam, mapFields and decomposePar pad OpenFOAM Running, Solving & CFD 0 December 3, 2010 05:22


All times are GMT -4. The time now is 01:17.