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

Time Varying BC

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 15, 2020, 07:25
Default Time Varying BC
  #1
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Hi,


I would like to have a time varying inlet BC for total pressure and total temperature.


It works fine with uniformTotalPressure for the total pressure.


Unfortunately I havent found a time varying BC for the total temperature.
The only think I have found is uniformFixedValue, but I dont want to fix
the static temperature, but the total temperature.


Does anyone know how to use time varying total temperature BC?






Kind regards,
shock77
shock77 is offline   Reply With Quote

Old   May 15, 2020, 17:29
Default
  #2
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
Hi,

- OF has totalTemperature BC, but I think you already know it.
- If you are comfortable with modifying the source code, and using a local library, you can modify `totalTemperature` BC's `scalarField``T0_` quantity (link) to be PatchFunction1 or `TimeFunction1`, so that you can use all time-varying condition capabilities of `Function1` class, e.g. CSV file, or time-value-pair table entry.
- An example of them can be found in atmBoundaryLayer boundary conditions.

Hope it helps.
HPE is offline   Reply With Quote

Old   May 17, 2020, 14:22
Default
  #3
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Hello HPE,


thank you very much for your detailed answer!


I have no experience with coding, but I am willing to try and to learn.


I will post my solution in case I succeed.




Kind regards,
shock77
shock77 is offline   Reply With Quote

Old   May 18, 2020, 11:41
Default
  #4
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Hello HPE,


I have tried to create a new BC named uniformTotalTemperature which shall be time varying. I have created a new folder in openfoam4/src/finiteVolume/fields/fvPatchFields/derived/totalPressure and copied totalTemperatureFvPatchScalarField.H and totalTemperatureFvPatchScalarField.C into my new BC-Folder and edited them. First I have just renamed every totalTemperature to uniformTotalTemperature to make sure my new BC works on this base lvl and it did without any trouble. I have included my BC files in the openfoam4/src/finiteVolume/Make/files and hit wmake. It worked fine.


Unfortunately I have some issues with the editing. I get a lot of "notes" during compiliing and the following message at the end:


Code:
openfoam4/wmake/rules/General/transform:8: recipe for target '/opt/openfoam4/platforms/linux64GccDPInt32Opt/src/finiteVolume/fields/fvPatchFields/derived/uniformTotalTemperature/uniformTotalTemperatureFvPatchScalarField.o' failed
I have tried to do it like you suggested and and did look into your sources and compared totalPressure with uniformTotalPressure and did some changes according to that.


In uniformTotalTemperatureFvPatchScalarField.H I did not many changes. I have included Function1 and tried to use it with "autoPtr<Function1<scalar>> T0_" so that I can use a table and I have deleted the Member Functions, like it has been done in uniformTotalPressure:


Code:
#ifndef uniformTotalTemperatureFvPatchScalarField_H
#define uniformTotalTemperatureFvPatchScalarField_H

#include "fixedValueFvPatchFields.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
             Class uniformTotalTemperatureFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/

class uniformTotalTemperatureFvPatchScalarField
:
    public fixedValueFvPatchScalarField
{
    // Private data

        //- Name of the velocity field
        word UName_;

        //- Name of the flux transporting the field
        word phiName_;

        //- Name of the compressibility field used to calculate the wave speed
        word psiName_;

        //- Heat capacity ratio
        scalar gamma_;

        //- Table of time vs total temperature
        autoPtr<Function1<scalar>> T0_;


public:

    //- Runtime type information
    TypeName("uniformTotalTemperature");


    // Constructors

        //- Construct from patch and internal field
        uniformTotalTemperatureFvPatchScalarField
        (
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&
        );

        //- Construct from patch, internal field and dictionary
        uniformTotalTemperatureFvPatchScalarField
        (
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&,
            const dictionary&
        );

        //- Construct by mapping given uniformTotalTemperatureFvPatchScalarField
        //  onto a new patch
        uniformTotalTemperatureFvPatchScalarField
        (
            const uniformTotalTemperatureFvPatchScalarField&,
            const fvPatch&,
            const DimensionedField<scalar, volMesh>&,
            const fvPatchFieldMapper&
        );

        //- Construct as copy
        uniformTotalTemperatureFvPatchScalarField
        (
            const uniformTotalTemperatureFvPatchScalarField&
        );

        //- Construct and return a clone
        virtual tmp<fvPatchScalarField> clone() const
        {
            return tmp<fvPatchScalarField>
            (
                new uniformTotalTemperatureFvPatchScalarField(*this)
            );
        }

        //- Construct as copy setting internal field reference
        uniformTotalTemperatureFvPatchScalarField
        (
            const uniformTotalTemperatureFvPatchScalarField&,
            const DimensionedField<scalar, volMesh>&
        );

        //- Construct and return a clone setting internal field reference
        virtual tmp<fvPatchScalarField> clone
        (
            const DimensionedField<scalar, volMesh>& iF
        ) const
        {
            return tmp<fvPatchScalarField>
            (
                new uniformTotalTemperatureFvPatchScalarField(*this, iF)
            );
        }


    // Member functions

        // Access


        // Mapping functions

            //- Map (and resize as needed) from self given a mapping object
            virtual void autoMap
            (
                const fvPatchFieldMapper&
            );

            //- Reverse map the given fvPatchField onto this fvPatchField
            virtual void rmap
            (
                const fvPatchScalarField&,
                const labelList&
            );


        // Evaluation functions

            //- Update the coefficients associated with the patch field
            virtual void updateCoeffs();


        //- Write
        virtual void write(Ostream&) const;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif
I have also modified uniformTotalTemperatureFvPatchScalarField.C according to uniformTotalPressureFvPatchScalarField.C:


Code:
#include "uniformTotalTemperatureFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::uniformTotalTemperatureFvPatchScalarField::uniformTotalTemperatureFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF
)
:
    fixedValueFvPatchScalarField(p, iF),
    UName_("U"),
    phiName_("phi"),
    psiName_("thermo:psi"),
    gamma_(0.0),
    T0_()
{}


Foam::uniformTotalTemperatureFvPatchScalarField::uniformTotalTemperatureFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchScalarField(p, iF),
    UName_(dict.lookupOrDefault<word>("U", "U")),
    phiName_(dict.lookupOrDefault<word>("phi", "phi")),
    psiName_(dict.lookupOrDefault<word>("psi", "thermo:psi")),
    gamma_(readScalar(dict.lookup("gamma"))),
    T0_(Function1<scalar>::New("T0", dict))
{
    if (dict.found("value"))
    {
        fvPatchField<scalar>::operator=
        (
            scalarField("value", dict, p.size())
        );
    }
    else
    {
       const scalar t = this->db().time().timeOutputValue();
       fvPatchScalarField::operator==(T0_->value(t));
    }
}

Foam::uniformTotalTemperatureFvPatchScalarField::uniformTotalTemperatureFvPatchScalarField
(
    const uniformTotalTemperatureFvPatchScalarField& ptf,
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchScalarField(p, iF),
    UName_(ptf.UName_),
    phiName_(ptf.phiName_),
    psiName_(ptf.psiName_),
    gamma_(ptf.gamma_),
    T0_(ptf.T0_, false)
{
    patchType() = ptf.patchType();
    const scalar t = this->db().time().timeOutputValue();
    fvPatchScalarField::operator==(T0_->value(t));

}





Foam::uniformTotalTemperatureFvPatchScalarField::uniformTotalTemperatureFvPatchScalarField
(
    const uniformTotalTemperatureFvPatchScalarField& ptf
)
:
    fixedValueFvPatchScalarField(ptf),
    UName_(ptf.UName_),
    phiName_(ptf.phiName_),
    psiName_(ptf.psiName_),
    gamma_(ptf.gamma_),
    T0_(ptf.T0_, false)
{}


Foam::uniformTotalTemperatureFvPatchScalarField::uniformTotalTemperatureFvPatchScalarField
(
    const uniformTotalTemperatureFvPatchScalarField& ptf,
    const DimensionedField<scalar, volMesh>& iF
)
:
    fixedValueFvPatchScalarField(ptf, iF),
    UName_(ptf.UName_),
    phiName_(ptf.phiName_),
    psiName_(ptf.psiName_),
    gamma_(ptf.gamma_),
    T0_(ptf.T0_, false)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::uniformTotalTemperatureFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }
    scalar T0 = T0_->value(this->db().time().timeOutputValue());

    const fvPatchVectorField& Up =
        patch().lookupPatchField<volVectorField, vector>(UName_);

    const fvsPatchField<scalar>& phip =
        patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);

    const fvPatchField<scalar>& psip =
        patch().lookupPatchField<volScalarField, scalar>(psiName_);

    scalar gM1ByG = (gamma_ - 1.0)/gamma_;

    operator==
    (
        T0_/(1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up))
    );

    fixedValueFvPatchScalarField::updateCoeffs();
}


void Foam::uniformTotalTemperatureFvPatchScalarField::write(Ostream& os) const
{
    fvPatchScalarField::write(os);
    writeEntryIfDifferent<word>(os, "U", "U", UName_);
    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
    writeEntryIfDifferent<word>(os, "psi", "thermo:psi", psiName_);
    os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
    T0_->writeData(os);
    writeEntry("value", os);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
    makePatchTypeField
    (
        fvPatchScalarField,
        uniformTotalTemperatureFvPatchScalarField
    );
}
Despite the error-message, I can still use this new BC, just not time varying with a table.


I have also attached both files in case someone likes it better that way.




I hope you HPE or someone else has some advice for me!




Thanks in advance,
shock77
shock77 is offline   Reply With Quote

Old   May 18, 2020, 16:39
Default
  #5
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
Hi,

- Please use PatchFunction1 instead of Function1 (Edit: OF4 certainly does not have that, but might OF7? Certainly OF1912 has).
- I can modify the code for you within two weeks when I can be a bit more free. If this does not help, I'm sorry. Otherwise, don't hesitate to poke me after two weeks if you still don't receive anything from my side.
- Till then might others kindly give a hand.
HPE is offline   Reply With Quote

Old   May 19, 2020, 04:21
Default
  #6
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Hi HPE,


thank you very much for your kind offer. I will try to make it run in the time beeing and hope I it will work. I will post again in case I make some progress or finish it.



In OpenFOAM 4 and OpenFOAM 7 there is only Function1. I could find PatchFunction1 only in the other openfoam version.






Kind regards,
shock77
shock77 is offline   Reply With Quote

Old   May 26, 2020, 05:27
Default
  #7
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Hi HPE,


so I finally managed to create my time varying BC for the total temperature.


I have atteched both files. It seems to work well, but if you could have a look at it, I would be glad, since this is my first time creating a custom BC.


Thanks again.




Kind regards,
shock77
shock77 is offline   Reply With Quote

Old   May 31, 2020, 15:36
Default
  #8
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
The code looks fine, and I think it should be considered in the official OF version. If it operates as you expect, you should have no worry. Good luck with this!
HPE is offline   Reply With Quote

Old   May 31, 2020, 16:47
Default
  #9
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Thank you very much!


I am very glad to hear that!




Kind regards,
shock77
shock77 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
bash script for pseudo-parallel usage of reconstructPar kwardle OpenFOAM Post-Processing 42 Yesterday 23:17
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 58 December 23, 2021 02:36
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 04:13
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 11:08
mixerVesselAMI2D's mass is not balancing sharonyue OpenFOAM Running, Solving & CFD 6 June 10, 2013 09:34


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