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/)
-   -   modified version of timeVaryingMappedFixedValue BC for looping through data (https://www.cfd-online.com/Forums/openfoam-programming-development/228505-modified-version-timevaryingmappedfixedvalue-bc-looping-through-data.html)

syavash July 3, 2020 10:06

modified version of timeVaryingMappedFixedValue BC for looping through data
 
1 Attachment(s)
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

edsaac December 17, 2020 14:32

loopedTimeVaryingMappedFixedValue on OpenFOAM7
 
1 Attachment(s)
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?
(:

olesen December 18, 2020 15:24

I can't see that this is much different than using a table with "repeat" bounds.

edsaac December 19, 2020 10:30

@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!

syavash January 11, 2021 13:02

Quote:

Originally Posted by edsaac (Post 790961)
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

olesen January 13, 2021 14:43

https://www.openfoam.com/documentati...0165456c2e9555

olesen January 13, 2021 14:48

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?

syavash January 14, 2021 15:28

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?

whhjken1 July 7, 2021 11:15

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 (Post 776803)
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 July 7, 2021 11:22

Quote:

Originally Posted by edsaac (Post 790961)
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

syavash July 15, 2021 03:24

1 Attachment(s)
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"
...
);

whhjken1 July 15, 2021 11:32

Quote:

Originally Posted by syavash (Post 808198)
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

syavash July 15, 2021 14:21

Quote:

Originally Posted by whhjken1 (Post 808224)
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

jichuan927@gmail.com November 3, 2023 18:38

0 folder request
 
1 Attachment(s)
Quote:

Originally Posted by syavash (Post 808238)
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.


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