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/)
-   -   Time-varying boundary condition (https://www.cfd-online.com/Forums/openfoam-programming-development/121366-time-varying-boundary-condition.html)

yurifrey July 26, 2013 09:39

Time-varying boundary condition
 
Hello!

I am a new OpenFoam user and I am trying to set up a case with time-dependent boundary condition for velocity. In the tutorial I found something but it's not working.. :( In the "0" folder I wrote the file "U" for velocity specifying the inlet condition :

inlet

{type uniformFixedValue;
uniformValue table
(
(0 0)
(2.0 1.0)
)
}

I thought this was the way to say I have a uniform inlet profile which goes from 0 m/s to 1 m/s between time t=0 and t=2, but when I start icoFoam this is what I get:

--> FOAM FATAL IO ERROR:
Expected a '(' while reading VectorSpace<Form, Cmpt, nCmpt>, found on line 49 the label 0

file: /home/yurifrey/Scrivania/tesi/aorta/0/U.boundaryField.inlet.uniformValue at line 49.

From function Istream::readBegin(const char*)
in file db/IOstreams/IOstreams/Istream.C at line 94.

FOAM exiting

Wish someone can help me,
thank you very much,

Yuri

alexeym July 26, 2013 09:49

Velocity is a vector so table should contain vectors (1 0 0). You put there scalars, and it is the reason for OpenFOAM to complain.

Table should be something like:

{type uniformFixedValue;
uniformValue table
(
(0 (0 0 0))
(2.0 (1.0 0 0))
)
}

yurifrey July 26, 2013 10:00

Thank you very much! :)

yurifrey July 27, 2013 05:20

Just another little question.. What if I want the velocity to be directed normal to the boundary, instead of giving the components of the vector? I tried

{type surfaceNormalFixedValue;
refValue uniform table
(
(0 0)
(2 -1)
);
}

but it's not working..
Thank you again!

Yuri

alexeym July 27, 2013 07:51

AFAIK uniformFixedValue BCs are implemented only for limited types of boundary conditions (http://www.openfoam.org/version2.1.0...conditions.php).

Though it is rather simple to implement your own boundary condition. For example you can change surfaceNormalFixedValue. Instead of
Code:

class surfaceNormalFixedValueFvPatchVectorField
:
    public fixedValueFvPatchVectorField
{
    // Private data
   
        scalarField refValue_;

you put something like

Code:

class surfaceNormalUniformFixedValueFvPatchVectorField
:
    public fixedValueFvPatchVectorField
{
    // Private data
   
        autoPtr<DataEntry<Type> > refValue_;

and reimplement operator = to use new time dependent reference value.

maysmech October 5, 2014 21:28

Hello
I need varying BC for interstitialInletVelocity which can be found in DPMFoam/Goldschemidt. Using table for fixed value:
Code:

   
bottom
{
    type uniformFixedValue;
    uniformValue table
    (
        (0 (0 0 1))
        (0.001 (0 0 2))
        (0.002 (0 0 3))
        (0.003 (0 0 4))
    );
    }

the run starts without error. But for interstitialInletVelocity"
The default is:
Code:

    bottom
    {
        type            interstitialInletVelocity;
        inletVelocity  uniform (0 0 1);
        value          uniform (0 0 1);
        phi            phi.air;
        alpha          alpha.air;
    }

trying to time varying it by:
Code:

    bottomSB
    {
        type            interstitialInletVelocity;
        inletVelocity  uniformFixedValue;
    uniformValue table
(
        (0 (0 0 1))
        (0.001 (0 0 2))
        (0.002 (0 0 3))
        (0.003 (0 0 4))
);

        value          table
(
        (0 (0 0 1))
        (0.001 (0 0 2))
        (0.002 (0 0 3))
        (0.003 (0 0 4))
);
        phi            phi.air;
        alpha          alpha.air;
    }

gives this error:
Code:

--> FOAM FATAL IO ERROR:
expected keyword 'uniform' or 'nonuniform', found table

file: /home/user/OpenFOAM/user-2.3.0/run/tutorials/lagrangian/DPMFoam/test/0/U.air.boundaryField.bottom from line 52 to line 70.

    From function Field<Type>::Field(const word& keyword, const dictionary&, const label)
    in file /home/user/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/Field.C at line 304.

FOAM exiting

Change of second "table" to "nonuniform" also gives error:
Code:

--> FOAM FATAL IO ERROR:
wrong token type - expected Scalar, found on line 64 the punctuation token '('

file: /home/user/OpenFOAM/user-2.3.0/run/tutorials/lagrangian/DPMFoam/test/0/U.air.boundaryField.bottom.value at line 64.

    From function operator>>(Istream&, Scalar&)
    in file lnInclude/Scalar.C at line 93.

FOAM exiting

I checked other changes by "Banana" trick debugging ;) but it doesn't work. This boundary condition is suitable for two phase flows because It consider the inlet porosity so we will sure about fixed value of inlet flow rate. It is not possible to use simple fixed value BC and should use interstitialInletVelocity instead. If anyone know about time varying this BC please share here.
Best,

wyldckat October 12, 2014 12:47

Greetings to all!

@Maysam: Unfortunately I don't have enough time to give the whole solution, but I think I can still give information on why that didn't work and what can be done to fix the problem.

  1. "uniformFixedValue" is a special boundary condition, derived from "fixedValue". This is the reason why it's possible to use it to define values based on tables and polynomials and so on: http://www.openfoam.org/version2.1.0...conditions.php - and as explained on that page, this feature is possible thanks to another new feature they added in OpenFOAM 2.1.0, namely the "DataEntry" class.
  2. "interstitialInletVelocity" is similar to "fixedValue". Which is why it's not able to handle the time-based tables.
  3. The solution is to create a new boundary condition derived from "interstitialInletVelocity", almost the same way that "uniformFixedValue" is derived from "fixedValue". Online you can find the source code folders for these 3 BCs (in OpenFOAM 2.3.x):
  4. Instructions on how to create a new BC... there are several online... just Google:
    Code:

    openfoam create new boundary condition
    and you'll find several links.
Best regards,
Bruno

maysmech October 12, 2014 23:04

Thanks Bruno, Do you know what is the difference between "inletVelocity" and "value" in this BC?
fixedValue and uniformFixedValue value need one velocity but this on needs two.

wyldckat October 18, 2014 14:55

Hi Maysam,

Quote:

Originally Posted by maysmech (Post 513995)
Do you know what is the difference between "inletVelocity" and "value" in this BC?

If you learn a bit about C++ and reading OpenFOAM source code, you could easily see the following details:
  1. If you look at the file "src/finiteVolume/fields/fvPatchFields/derived/interstitialInletVelocity/interstitialInletVelocityFvPatchVectorField.C": https://github.com/OpenFOAM/OpenFOAM...hVectorField.C
  2. Then look at this part of the code in that file:
    Quote:

    Code:

    void Foam::interstitialInletVelocityFvPatchVectorField::updateCoeffs()
    {
        if (updated())
        {
            return;
        }

        const fvPatchField<scalar>& alphap =
            patch().lookupPatchField<volScalarField, scalar>(alphaName_);

        operator==(inletVelocity_/alphap);
        fixedValueFvPatchVectorField::updateCoeffs();
    }


  3. You'll see that the "value" field isn't directly used during the simulation. In fact, the value in "value" should be the result of "inletVelocity_/alphap"... therefore, "value" acts as the current representation of the velocity field for the current time instance or iteration.
  4. "inletVelocity" is the actual desired velocity for this inlet :)
Best regards,
Bruno

maysmech October 19, 2014 01:06

Hi Bruno,
I know the difference between u and U, the actual and superficial velocity with relation of U=alpha*u.
This is the main advantage of "interstitialInletVelocity" to "fixedValue" and "uniformFixedaValue". My question was about why there are two entries in 0/U.air
Quote:

bottom
{
type interstitialInletVelocity;
inletVelocity uniform (0 0 1.875);
value uniform (0 0 1.875);
phi phi.air;
alpha alpha.air;
}
However I found the answer. The second entry is a dummy value for 0 value reading in paraView. So I should try to use table for first entry "inletVelocity uniform (0 0 1.875);" and modify the source code. I have started to create the new boundary condition based on your comment but have faced to some problems because of C++ knowledge. I will bring the modifications to share with others to write the time varying interstitialInletVelocity BC.

maysmech October 21, 2014 17:26

We want use available boundary conditions of fixedValue (BC1), uniformFixedValue (BC2) and interstitialInletVelocity (BC3) to write own myInterstitialInletVelocity (BC4).
BC4 will have advantages of BC3 (which accounts alpha to have constant mass flow rate in multiphase flows) and BC2 (which accepts table to apply time varying air velocity).

The first step is compiling BC in user directory.

1- Copying BC3 from source to user directory and renaming it to my0InterstitialInletVelocity.
Code:

$FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/interstitialInletVelocity
to
$WM_PROJECT_USER_DIR/src/finiteVolume/fields/fvPatchFields/derived/my0interstitialInletVelocity

2- Modifying .H and .C files with new name.
3- Writing an appropriate Make/files and options and then compiling it in:
Code:

$WM_PROJECT_USER_DIR/src/finiteVolume/
4- Adding this dictionary to controlDict:
Code:

libs ("libmyFiniteVolume.so");
In these links the src folder and a test case are available. After extracting it in user directory it needs compile by wmake.
The link of GoldschemidtBC contains my0InterstitialInletVelocity BC in 0/U.air and dictionary in it is controlDict.
The src link contains BC1 to BC4. but is compiled for "my0InterstitialInletVelocity".
The BC4 doesn't work which will be discussed later.
Code:

https://www.dropbox.com/s/b54r786b167bmxw/src.tar.gz?dl=0
https://www.dropbox.com/s/8fpj3os65a8hnp9/GoldschmidtBC.tar.gz?dl=0



The next step is doing modification in
myInterstitialInletVelocity (BC4) to possible accepting table.

The difference of BC2 to BC1 are:
1- BC2 has a new parameter definition:
Code:

const Field<Type>& fld
which I think it is for the new variable:
Code:

uniformValue_()
I define uniformInletVelocity_ in BC4 too :p
2- BC1 uses mapper (which I don't know what does it do):

Code:

fixedValueFvPatchField<Type>::fixedValueFvPatchField
(
    const fixedValueFvPatchField<Type>& ptf,
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fvPatchField<Type>(ptf, p, iF, mapper)
{
    if (&iF && mapper.hasUnmapped())
    {
        WarningIn
        (
            "fixedValueFvPatchField<Type>::fixedValueFvPatchField\n"
            "(\n"
            "    const fixedValueFvPatchField<Type>&,\n"
            "    const fvPatch&,\n"
            "    const DimensionedField<Type, volMesh>&,\n"
            "    const fvPatchFieldMapper&\n"
            ")\n"
        )  << "On field " << iF.name() << " patch " << p.name()
            << " patchField " << this->type()
            << " : mapper does not map all values." << nl
            << "    To avoid this warning fully specify the mapping in derived"
            << " patch fields." << endl;
    }
}

but BC2 uses bypass mapper with the new variable of uniformValue_ :

Code:

template<class Type>
uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
(
    const uniformFixedValueFvPatchField<Type>& ptf,
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchField<Type>(p, iF),  // bypass mapper
    uniformValue_(ptf.uniformValue_().clone().ptr())
{
    // Evaluate since value not mapped
    const scalar t = this->db().time().timeOutputValue();
    fvPatchField<Type>::operator==(uniformValue_->value(t));
}

I think it uses bypass mapper of BC1 and doesn't rewrite it here. However what we are seeking is seen here (time).

3- we see time again in next class. In this one, it is looking for value or table:
Code:

template<class Type>
uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
(
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchField<Type>(p, iF),
    uniformValue_(DataEntry<Type>::New("uniformValue", dict))
{
    if (dict.found("value"))
    {
        fvPatchField<Type>::operator==(Field<Type>("value", dict, p.size()));
    }
    else
    {
        const scalar t = this->db().time().timeOutputValue();
        fvPatchField<Type>::operator==(uniformValue_->value(t));
    }
}

4- The last difference is "clone" which is added to BC2 and again I don't know what it is.

However, I tried many different tries and errors by adding classes to BC4 but not possible to compile it successfully.

Two possibles for errors are:
1- mistakes in defining parameters
2- two "operator== ..." in updateCoeff of BC4:
Code:

void Foam::myInterstitialInletVelocityFvPatchVectorField::updateCoeffs()
{

Info << "Banana1" <<endl;
    if (updated())
    {
        return;
    }
    const scalar t = this->db().time().timeOutputValue();            //
    fvPatchField<vector>::operator==(uniformInletVelocity_->value(t));  //

  // fixedValueFvPatchField<Type>::updateCoeffs();                    //

    const fvPatchField<scalar>& alphap =
        patch().lookupPatchField<volScalarField, scalar>(alphaName_);

    operator==(uniformInletVelocity_/alphap);
    fixedValueFvPatchVectorField::updateCoeffs();
}

It needs to check two things for update: alpha and uniformInletVelocity. Again I tried different configurations (separated, together, ...) but it doesn't compile at all :(

Sorry for this long post and thanks in advance for any suggestion.

maysmech November 3, 2014 18:24

Hi all,
I am trying to write a time varying boundary condition which accounts inlet porosity in applying inlet velocity but it hasn't lead to solution yet.
Is it possible to write a script which automatically do below procedure:
1- Run
2- After finishing run (reaching to endTime) do the following:
2-1- Iincrease endTime in system/controlDict (for example from 1 to 2)
2-2- Change inlet velocity in U.air file (with known line and column) in exist latest time folder.
3- Run again and do a loop from 1 to reach a desired time (for example 10sec).

For this purpose we should have a script to:
1- change a number in a file
2- understand when the run is finished
3- loop over time

I think the first one is possible but I don't know about 2 and 3.
Any idea will be appreciated.

ssss November 4, 2014 05:27

Why don't you use groovyBC for your custom boundary condition?

You seem to be making it a lot more complicated than what it really is, search for groovyBC I'm sure it will help you.

mechem November 5, 2014 16:31

Quote:

Originally Posted by maysmech (Post 515434)
We want use available boundary conditions of fixedValue (BC1), uniformFixedValue (BC2) and interstitialInletVelocity (BC3) to write own myInterstitialInletVelocity (BC4).
BC4 will have advantages of BC3 (which accounts alpha to have constant mass flow rate in multiphase flows) and BC2 (which accepts table to apply time varying air velocity).

Hi maysmech,
This is what exactly I need for finding minimum fluidization velocity.
I need a gradually increase in fluidization velocity.
I used table with fixed value but the results was mistake because of inlet porosity is not considered in fixedValue.
Did you find any solution? Please share it if you have found.
Best regards.

maysmech November 6, 2014 17:55

Quote:

Originally Posted by ssss (Post 517274)
Why don't you use groovyBC for your custom boundary condition?

You seem to be making it a lot more complicated than what it really is, search for groovyBC I'm sure it will help you.

Groovy boundary condition doesn't work with such boundary condition, as far as I know.
The type of boundary condition is interstitialInletVelocity which divide velocity over air volume fraction.
The groovy doesn't see volume fraction and is suitable for fixed value types.
If I'm wrong, please correct!


Quote:

Originally Posted by mechem (Post 517567)
Hi maysmech,
This is what exactly I need for finding minimum fluidization velocity.
I need a gradually increase in fluidization velocity.
I used table with fixed value but the results was mistake because of inlet porosity is not considered in fixedValue.
Did you find any solution? Please share it if you have found.
Best regards.

Hi Charlie,

As you mentioned, gradually increase of velocity is crucial for any fluidizeation velocity simulation.

But unfortunately I didn't find any solution yet
:(

maysmech November 23, 2014 14:35

Thanks Bruno for merging these threads.

If anyone has any Idea for first (BC4) or second (script) way it will be appreciated to share with others.

Regards,

ssss November 24, 2014 08:04

As far as I'm concerned, you can access volume fraction and all the variables you want from groovyBC.

wyldckat November 30, 2014 16:15

Greetings to all!

@Maysam: I didn't manage to have enough time to fully test this, so please test if everything is working OK. The new boundary condition, use/build instructions and tutorial cases are provided here: https://github.com/wyldckat/Unsuppor...OpenFOAM-2.3.x

Either use "git clone" or download as a ZIP file, as instructed on the right side of the page at that website.

By the way, the main detail was that the method "updateCoeffs()" should be like this:
Code:

void Foam::uniformInterstitialInletVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const fvPatchField<scalar>& alphap =
        patch().lookupPatchField<volScalarField, scalar>(alphaName_);
    const scalar t = this->db().time().timeOutputValue();
   
    inletVelocity_ = uniformInletVelocity_->value(t);
    operator==(inletVelocity_/alphap);
    fixedValueFvPatchVectorField::updateCoeffs();
}

By the way, if you're wondering how long it took me to develop this: around 2 hours.

Best regards,
Bruno

maysmech November 30, 2014 16:20

Hi Bruno,

Thank you very much for spending your valuable time on this issue.

I checked. it works perfect.

Best regards,

wyldckat December 8, 2014 13:25

Hi Maysam,

Just a side note: Sorry, I wasn't very clear on why I mentioned it took me 2 hours.
My estimate is that on average it takes me 20 minutes to answer each question here on the forum, although finding/developing the answer can sometimes take 6 to 8 hours or more... so the average comes down only because there are several posts where the answer ends up being a questions.
Therefore, the concept I had in mind when I said "2h" was that it was all of the time I had that day and that compared to the average it was 5 other posts I couldn't answer...

I wasn't trying to show off "how good I am", I was actually trying to state that I'm not good enough to answer as fast as I wanted to be able to :(
This to say: If you - and anyone reading this post - can find some time to help other newcomers on the forum, please do!

Best regards,
Bruno

PS: I'm very glad it's working!!


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