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

modified version of timeVaryingMappedFixedValue BC for looping through data

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 5 Post By syavash
  • 1 Post By syavash

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 3, 2020, 10:06
Default modified version of timeVaryingMappedFixedValue BC for looping through data
  #1
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Hi Foamers,

I have created a modified version of timeVaryingMappedFixedValue BC which is useful when the inflow data are to be read using a loop-fashion.

Imagine there are 5 sampled time values:

0
0.001
0.002
0.003
0.004

Simulations typically start from 0 and proceed in time. In the original timeVaryingMappedFixedValue BC, if the physical time goes beyond the time 0.004, the inflow data thereafter would be read from the time instant of 0.004 alone. However, in many simulations, particularly in scale-resolved approaches such as LES or DNS, it is not good to have a constant inflow data.
An alternative would be to loop through the sampled times, which start from 0 in the example above. Of course, the original sampled data should provide a statistically converged solution in the first place.
The modified version of the original BC, entitled "loopedTimeVaryingMappedFixedValue" is developed to loop through the sampled time instants when past a user-provided threshold (timeLimit). It will be also useful for saving computational cost, as substantially fewer time instants would be required to be generated in the precursor calculations (half, 1/3, 1/4, ...).

The code has been written for OpenFOAM 2.3.0, but it will be straight forward to adapt it to the more recent versions of OpenFOAM.

Kiind regards,
syavash
Attached Files
File Type: zip loopedTimeVaryingMappedFixedValue.zip (13.4 KB, 66 views)
Farid, edsaac, mxa261 and 2 others like this.
syavash is offline   Reply With Quote

Old   December 17, 2020, 14:32
Default loopedTimeVaryingMappedFixedValue on OpenFOAM7
  #2
New Member
 
Join Date: Aug 2016
Location: USA
Posts: 5
Rep Power: 9
edsaac is on a distinguished road
Hi!
I tried to adapt this boundary condition to OpenFOAM 7 by modifying the original timeVaryingMappedFixedValue and adding the relevant pieces from this loopedTimeVaryingMappedFixedValue. It compiled and everything but when called from a case, it's not recognized.


Code:
FOAM FATAL IO ERROR: 
 Unknown patchField type loopedTimeVaryingMappedFixedValue for patch type patch

Valid patchField types are :

107
(
advective
...
timeVaryingMappedFixedValue
...
zeroGradient
)

file: /home/pathTocase/0/h.boundaryField.top from line 80 to line 80.

    From function static Foam::tmp<Foam::fvPatchField<Type> > Foam::fvPatchField<Type>::New(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
    in file /opt/openfoam7/src/finiteVolume/lnInclude/fvPatchFieldNew.C at line 131.

FOAM exiting
The corresponding library is added to the controlDict of the case:
Code:
libs ( 
  "libMyBoundaryCondition.so" 
  );
And it is defined in the field file as well
Code:
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      h;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 0 0 0 0 0];
internalField   uniform 0;
boundaryField
{

  top   

    {
      type            loopedTimeVaryingMappedFixedValue;
    }
...
}


I've attached the code for my loopedTimeVaryingMappedFixedValue version. Any idea what might be missing from this implementation?
(:
Attached Files
File Type: zip loopedTimeVaryingMappedFixedValue_OF7.zip (18.3 KB, 23 views)

Last edited by edsaac; December 18, 2020 at 09:47. Reason: Missed the attachment
edsaac is offline   Reply With Quote

Old   December 18, 2020, 15:24
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
I can't see that this is much different than using a table with "repeat" bounds.
olesen is offline   Reply With Quote

Old   December 19, 2020, 10:30
Default
  #4
New Member
 
Join Date: Aug 2016
Location: USA
Posts: 5
Rep Power: 9
edsaac is on a distinguished road
@olesen, I think you're probably referring to using repeated values in a table, right?, something like this:

Code:
{ 
  type           uniformFixedValue;
   uniformValue    table   
  (     
    (time1   value1)
     (time2   value2)
    (time3   value1)  // Loop starts
    (time4   value2)
     ...     
   ); 
}


Of course the same could be done with timeVaryingMappedFixedValue, just copy/paste the boundaryData over and over.

However, there are cases this is just not the best approach. For instance, I've got data for 0.05s time steps that loops every 2s (i.e., 40 boundaryData files for the 2s period). Each file is 3kB, hence, the 2s period just needs 120kB of input data. If I'd like to use this data for a 10 days simulation, I'd need to copy/paste that data 432000 times, requiring 51GB of storage! This is the kind of thing we'd like to avoid.

ps. I'm not aware of a "repeat" setting in uniformFixedValue{table} nor in timeVaryingMappedFixedValue - it'd be helpful though!
edsaac is offline   Reply With Quote

Old   January 11, 2021, 13:02
Default
  #5
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Quote:
Originally Posted by edsaac View Post
Hi!
I tried to adapt this boundary condition to OpenFOAM 7 by modifying the original timeVaryingMappedFixedValue and adding the relevant pieces from this loopedTimeVaryingMappedFixedValue. It compiled and everything but when called from a case, it's not recognized.


Code:
FOAM FATAL IO ERROR: 
 Unknown patchField type loopedTimeVaryingMappedFixedValue for patch type patch

Valid patchField types are :

107
(
advective
...
timeVaryingMappedFixedValue
...
zeroGradient
)

file: /home/pathTocase/0/h.boundaryField.top from line 80 to line 80.

    From function static Foam::tmp<Foam::fvPatchField<Type> > Foam::fvPatchField<Type>::New(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
    in file /opt/openfoam7/src/finiteVolume/lnInclude/fvPatchFieldNew.C at line 131.

FOAM exiting
The corresponding library is added to the controlDict of the case:
Code:
libs ( 
  "libMyBoundaryCondition.so" 
  );
And it is defined in the field file as well
Code:
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      h;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 0 0 0 0 0];
internalField   uniform 0;
boundaryField
{

  top   

    {
      type            loopedTimeVaryingMappedFixedValue;
    }
...
}


I've attached the code for my loopedTimeVaryingMappedFixedValue version. Any idea what might be missing from this implementation?
(:
Hi edsaac,

I guess this is more of a general issue with employing a new bc based on an older one. Unfortunately, I have no experience with doing this on ver. 7. However, I would try just to modify another bc (minor change) and compile to see if it works. Then, it might give you some idea on where you could be wrong.

And about the philosophy of developing this new bc, you were absolutely right. I had tried to explain the situation in the original post.

Kind regards,
syavash
syavash is offline   Reply With Quote

Old   January 13, 2021, 14:43
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
https://www.openfoam.com/documentati...0165456c2e9555
olesen is offline   Reply With Quote

Old   January 13, 2021, 14:48
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
I still cannot understand why you need to create a new boundary condition for this. If the regular "bounds" with repeat don't do it for you, then why not write your own Function1 with the file handling/table repetition instead and use that in the regular boundary condition?
olesen is offline   Reply With Quote

Old   January 14, 2021, 15:28
Default
  #8
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
In which version the "Function1" is implemented? Maybe in ESI versions?
I also looked for repeatableBounding but found no useful example for it...

Can you provide a simple example for this application?
syavash is offline   Reply With Quote

Old   July 7, 2021, 11:15
Default
  #9
New Member
 
Han
Join Date: Dec 2017
Location: USA
Posts: 9
Rep Power: 8
whhjken1 is on a distinguished road
Hi syavash,

Thank you for sharing your code. It is very helpful if one needs to perform LES or DNS because it really saves a lot of computational time.

BTW, is it possible for you to reform your code to adapt new version of OpenFOAM, for example OF6 or OF7? I have been trying to do it these days, but without any success. It is not that straight forward because OF2.3.0 is quite old.

Thank you again for your work!

Han

Quote:
Originally Posted by syavash View Post
Hi Foamers,

I have created a modified version of timeVaryingMappedFixedValue BC which is useful when the inflow data are to be read using a loop-fashion.

Imagine there are 5 sampled time values:

0
0.001
0.002
0.003
0.004

Simulations typically start from 0 and proceed in time. In the original timeVaryingMappedFixedValue BC, if the physical time goes beyond the time 0.004, the inflow data thereafter would be read from the time instant of 0.004 alone. However, in many simulations, particularly in scale-resolved approaches such as LES or DNS, it is not good to have a constant inflow data.
An alternative would be to loop through the sampled times, which start from 0 in the example above. Of course, the original sampled data should provide a statistically converged solution in the first place.
The modified version of the original BC, entitled "loopedTimeVaryingMappedFixedValue" is developed to loop through the sampled time instants when past a user-provided threshold (timeLimit). It will be also useful for saving computational cost, as substantially fewer time instants would be required to be generated in the precursor calculations (half, 1/3, 1/4, ...).

The code has been written for OpenFOAM 2.3.0, but it will be straight forward to adapt it to the more recent versions of OpenFOAM.

Kiind regards,
syavash
whhjken1 is offline   Reply With Quote

Old   July 7, 2021, 11:22
Default
  #10
New Member
 
Han
Join Date: Dec 2017
Location: USA
Posts: 9
Rep Power: 8
whhjken1 is on a distinguished road
Quote:
Originally Posted by edsaac View Post
Hi!
I tried to adapt this boundary condition to OpenFOAM 7 by modifying the original timeVaryingMappedFixedValue and adding the relevant pieces from this loopedTimeVaryingMappedFixedValue. It compiled and everything but when called from a case, it's not recognized.


Code:
FOAM FATAL IO ERROR: 
 Unknown patchField type loopedTimeVaryingMappedFixedValue for patch type patch

Valid patchField types are :

107
(
advective
...
timeVaryingMappedFixedValue
...
zeroGradient
)

file: /home/pathTocase/0/h.boundaryField.top from line 80 to line 80.

    From function static Foam::tmp<Foam::fvPatchField<Type> > Foam::fvPatchField<Type>::New(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
    in file /opt/openfoam7/src/finiteVolume/lnInclude/fvPatchFieldNew.C at line 131.

FOAM exiting
The corresponding library is added to the controlDict of the case:
Code:
libs ( 
  "libMyBoundaryCondition.so" 
  );
And it is defined in the field file as well
Code:
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      h;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 0 0 0 0 0];
internalField   uniform 0;
boundaryField
{

  top   

    {
      type            loopedTimeVaryingMappedFixedValue;
    }
...
}


I've attached the code for my loopedTimeVaryingMappedFixedValue version. Any idea what might be missing from this implementation?
(:
Hi edsaac,

Have you managed to solve the problem? I tried to implant your code to OpenFOAM 6.0, but end up with the same error.

Best wishes,

Han
whhjken1 is offline   Reply With Quote

Old   July 15, 2021, 03:24
Default
  #11
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Hi,

I have modified the code for version 3. Porting to higher versions would require some spare time. I hope you find it useful, hopefully adapt it for more recent versions.

Regards,
syavash

PS. The following lines must be added to controlDict

libs
(
"libLoopedTimeVaryingMappedFixedValueFvPatchFields .so"
...
);
Attached Files
File Type: zip loopedTimeVaryingMappedFixedValue_ver3.zip (13.6 KB, 25 views)
syavash is offline   Reply With Quote

Old   July 15, 2021, 11:32
Default
  #12
New Member
 
Han
Join Date: Dec 2017
Location: USA
Posts: 9
Rep Power: 8
whhjken1 is on a distinguished road
Quote:
Originally Posted by syavash View Post
Hi,

I have modified the code for version 3. Porting to higher versions would require some spare time. I hope you find it useful, hopefully adapt it for more recent versions.

Regards,
syavash

PS. The following lines must be added to controlDict

libs
(
"libLoopedTimeVaryingMappedFixedValueFvPatchFields .so"
...
);
Hi syavash,

Thank you again for sharing your code. I tested your first code to OF2.3, it worked fine for single core, but failed in parallel computation. Therefore, I have been trying to modify the original timeVaryingMappedFixedValue these days in OpenFOAM 6.0, and finally succeeded. Now I am checking whether the inlet velocity was loaded periodically.

Thank you for your help.

Han
whhjken1 is offline   Reply With Quote

Old   July 15, 2021, 14:21
Default
  #13
Senior Member
 
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Quote:
Originally Posted by whhjken1 View Post
Hi syavash,

Thank you again for sharing your code. I tested your first code to OF2.3, it worked fine for single core, but failed in parallel computation. Therefore, I have been trying to modify the original timeVaryingMappedFixedValue these days in OpenFOAM 6.0, and finally succeeded. Now I am checking whether the inlet velocity was loaded periodically.

Thank you for your help.

Han
Glad to hear that!

There was some minor mistake which prohibited restarting the simulation. It is fixed now in the last update. However, I run my code on several hundred of cores without any issues.
If you'd like, please share the code for future users who work on higher versions of OpenFOAM.

Regards,
syavash
syavash is offline   Reply With Quote

Old   November 3, 2023, 18:38
Default 0 folder request
  #14
New Member
 
Shusen
Join Date: Oct 2023
Posts: 1
Rep Power: 0
jichuan927@gmail.com is on a distinguished road
Quote:
Originally Posted by syavash View Post
Glad to hear that!

There was some minor mistake which prohibited restarting the simulation. It is fixed now in the last update. However, I run my code on several hundred of cores without any issues.
If you'd like, please share the code for future users who work on higher versions of OpenFOAM.

Regards,
syavash

Hello, I was able to access the code you provided successfully. However, when running my arithmetic example, it keeps reporting an error. The error is as follows:


I want to ask if you can provide or give me some advice on how to set up the 0 file? I greatly appreciate your help and your time.
Attached Images
File Type: jpg Screenshot from 2023-11-04 09-37-48.jpg (88.8 KB, 9 views)
jichuan927@gmail.com is offline   Reply With Quote

Reply


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
simpleFoam convergence issue Harnoor OpenFOAM Running, Solving & CFD 13 November 16, 2016 08:23
modified OF version on HPC federicabi OpenFOAM Running, Solving & CFD 3 October 10, 2016 19:18
strange problem with data seav OpenFOAM Running, Solving & CFD 0 April 11, 2014 05:01
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51
paraFoam reader for OpenFOAM 1.6 smart OpenFOAM Installation 13 November 16, 2009 21:41


All times are GMT -4. The time now is 05:12.