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

Adding pressure-dependent heat source

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 10, 2021, 13:20
Default Adding pressure-dependent heat source
  #1
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
I'm working on a problem that requires me to modify the heat source in the flow field. For instance, I am wondering how to change the rho*r term in Eqn. 15 at this page:

http://https://cfd.direct/openfoam/energy-equation/

It says the term, rho*r, is a heat source, where r is any specific heat source. I'd like to make this heat source a function of pressure everywhere in the domain. Is this possible with a fvOptions code? I've seen fvOptions examples using a temperature hot spot, but never one that includes an actual term for the energy equation.

I would like to do this in rhoPimpleFoam if possible, where the energy equation is:

Code:
(	fvm::ddt(rho, he)+fvm::div(phi, he)+fvc::ddt(rho, K)+fvc::div(phi, K)+(he.name()=="e" ? fvc::div(fvc::absolute(phi/fvc::interpolate(rho), U), p, "div(phiv,p)") :-dpdt) - fvm::laplacian(turbulence->alphaEff(), he) 	= =fvOptions(rho, he)	)
I'm assuming the fvOptions portion at the end is the part that would allow me to do such a thing? Is anyone knowledgeable about this? I'm fairly new to OpenFOAM and this seems incredibly complicated.
jdw135 is offline   Reply With Quote

Old   February 10, 2021, 16:32
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: 931
Rep Power: 13
HPE is on a distinguished road
Yes, you can create your own fvOptions to affect this governing equation through the "fvOptions(rho, he)" term.

Please have a look at the available fvOptions here: https://develop.openfoam.com/Develop...ources/derived .

Find the most similar one to your case, and try to modify it accordingly.
HPE is offline   Reply With Quote

Old   February 10, 2021, 20:36
Default
  #3
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by HPE View Post
Yes, you can create your own fvOptions to affect this governing equation through the "fvOptions(rho, he)" term.

Please have a look at the available fvOptions here: https://develop.openfoam.com/Develop...ources/derived .

Find the most similar one to your case, and try to modify it accordingly.
Thanks for the link! That is what I was looking for. I think the buoyancyEnergy is closest to what I need, as it applies an equation to the entire domain, however, I'm not sure how to include other fields.

For instance, my equation is an isentropic relationship between pressure and heat, so how would I include the mach number and temperature? What about using the pressure from the current and previous time steps? Does anyone have experience with this?
jdw135 is offline   Reply With Quote

Old   February 11, 2021, 04:27
Default
  #4
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
Might help? There are a bit more involved fvOptions here, where temperature field has been used as well: https://develop.openfoam.com/Develop...dels/fvOptions
HPE is offline   Reply With Quote

Old   February 12, 2021, 16:39
Default
  #5
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by HPE View Post
Might help? There are a bit more involved fvOptions here, where temperature field has been used as well: https://develop.openfoam.com/Develop...dels/fvOptions

Those actually help quite a bit. I'm essentially using as many examples as I can to fill in the parts that I need. Having said that, I need to apply a minimum value to the field I compute. Is there some ability to do something like

if (field < 0.2)
{
field = 0.2;
}

to replace only values within the newly-computed field that meet the if statement? I know I can use a nested for loop, but I doubt that's the correct way to do it.
jdw135 is offline   Reply With Quote

Old   February 12, 2021, 16:46
Default
  #6
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
Hi,
- maybe `Foam::volScalarField& Foam::bound(volScalarField& vsf, const dimensionedScalar& lowerBound)`, like in `bound(k_, this->kMin_);` of `kEpsilon.C`?
- not the second parameter is not `scalar` but `dimensionedScalar`.
HPE is offline   Reply With Quote

Old   February 12, 2021, 17:11
Default
  #7
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Should it still be a dimensionedScalar if I'm computing a non-dimensional quantity? My thought is to do mach number like this. From looking at other files, it seems like this goes in the constructor in the .c file, so I was planning to implement it like this:

Code:
option(sourceName, modelType, dict, mesh),
    UName_(coeffs_.getOrDefault<word>("U", "U")),
    a0_
    (
        dimensionedScalar
        (
            dimLength/dimTime,
            coeffs_.getCheckOrDefault<scalar>
            (
                "a0",
                329.204,
                scalarMinMax::ge(SMALL)    // do I need this line?
            )
        )
    ),
    mach_
    (
        dimensionedScalar
        (
          coeffs_.getCheckOrDefault<scalar>
          (
                "mach",
                U/a0,    // can I put an eqn in the constructor?
                <bound mach number here?>
          )
        )
    )
I feel like I probably can't do the equation in the constructor, as that seems to be setting the default value. Would I create a member function to compute the mach number, or would that go in the system/fvOptions file?
jdw135 is offline   Reply With Quote

Old   February 13, 2021, 11:15
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: 931
Rep Power: 13
HPE is on a distinguished road
Quote:
Should it still be a dimensionedScalar if I'm computing a non-dimensional quantity?
Yes. e.g. `dimensionedScalar(dimless, Zero);` or `dimensionedScalar("someName", dimless, 1.0);`

I don't think you can compile the `mach_` like the above.

Could you please explain us (but like explaining to a person with a two-digit IQ) what you want to do as a pseudo-code, if possible?

Many thanks
HPE is offline   Reply With Quote

Old   February 13, 2021, 11:39
Default
  #9
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by HPE View Post
Yes. e.g. `dimensionedScalar(dimless, Zero);` or `dimensionedScalar("someName", dimless, 1.0);`

I don't think you can compile the `mach_` like the above.

Could you please explain us (but like explaining to a person with a two-digit IQ) what you want to do as a pseudo-code, if possible?

Many thanks

My goal is to add a source term to the rhoPimpleFoam energy equation using fvOptions. This source term is an isentropic relation between pressure and heat, in the form

\frac{dP_{s}}{P_{s}} = -\frac{\gamma M^{2}}{1 - M^{2}}\frac{dQ}{C_{p}T_{s}}

I was thinking that I would add this by doing the following:

1. compute speed of sound in the flow field
2. compute mach number in the flow field
3. compute the above equation

I'm unsure how to do this, because I have EXTREMELY little experience with OpenFOAM (I've run some tutorials and I have a rhoPimpleFoam case of my flow field that runs). After some reading online, I am sure that using fvOptions is the correct way forward, but I don't have the experience to modify existing options without asking a lot of questions. I'm using a lot of the existing fvOptions codes to help guide me, but the process is slow and painful. I'm still unsure if my approach is reasonable.
jdw135 is offline   Reply With Quote

Old   February 13, 2021, 13:46
Default
  #10
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Hello,


just out of interest, can you provide a reference for the equation.
mAlletto is offline   Reply With Quote

Old   February 13, 2021, 13:58
Default
  #11
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Hello,


just out of interest, can you provide a reference for the equation.
Shapiro, A. (1953) The Dynamics and Thermodynamics of Compressible Fluid Flow. McGraw-Hill, New York.

Specifically, this is a modified derivation from Table 8.1 in that book.
jdw135 is offline   Reply With Quote

Old   February 13, 2021, 15:15
Default
  #12
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
Let's see what we can do during the next week. (At least something for you to progress further rather than a complete solution.)
HPE is offline   Reply With Quote

Old   February 14, 2021, 12:03
Default
  #13
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
You can use a coded fvOption to include your source term. https://www.openfoam.com/documentati...ces-coded.html

And you also need to decide your equation by dt to insert it into the energy equation. Did you check the dimensions of the source term in the energy equation
mAlletto is offline   Reply With Quote

Old   February 14, 2021, 12:12
Default
  #14
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
You can use a coded fvOption to include your source term. https://www.openfoam.com/documentati...ces-coded.html

And you also need to decide your equation by dt to insert it into the energy equation. Did you check the dimensions of the source term in the energy equation
I've been looking at the units, yes. I just posted a generic version for the sake of discussion. I'm working on coding a custom fvOptions right now, but my experience in C++ and OpenFOAM is low, so it's quite a challenge so far. Also, there are a lot of fvOptions files, but many of them do the same task in different ways, so it's hard to figure out what commands are doing what. I have put together a starting point for what I think may work, if you or anyone else is interested in helping me debug it. I would be forever grateful for any help.
jdw135 is offline   Reply With Quote

Old   February 14, 2021, 12:32
Default
  #15
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Maybe it's better if you post the final equation you want to implement. This would lead you faster to your goal.
mAlletto is offline   Reply With Quote

Old   February 14, 2021, 13:05
Default
  #16
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Maybe it's better if you post the final equation you want to implement. This would lead you faster to your goal.
From a quick check of a single term in the energy equation,

\frac{\partial (\rho h)}{\partial t}

I see that the units are

h = e + \frac{p}{\rho} \equiv  \frac{J}{kg}

and

(\rho h) \equiv \frac{J}{m^{3}}

So, the units for the first term, and therefore all terms, is

\frac{\partial}{\partial t}(\frac{J}{m^{3}})

correct? My equation, modified using perfect gas assumption, is

Q = -\frac{P_{s}(1-M^{2})C_{p}}{\gamma M^{2}\rho R}

for which the units are

Q \equiv \frac{J}{kg}

So, if I were to insert my equation into the openfoam energy equation as

\frac{\partial}{\partial t}(\rho Q)

it looks like the units are correct, unless I've made a mistake somewhere.
jdw135 is offline   Reply With Quote

Old   February 15, 2021, 13:50
Default
  #17
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Here are my first attempts at modifying the variableHeatTransfer fvOptions files to do what I am trying to do. I'm sure there are mistakes, and probably a lot of places where I have misunderstood what the code is doing. To anyone willing to look it over and check it out, I'd be extremely thankful.

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2011-2015 OpenFOAM Foundation
    Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::fv::variableHeatTransfer

Group
    grpFvOptionsSources

Description
    Applies an additional source term to the rhoPimpleFoam energy equation via
    the fvOptions.  The source term is computed using Shapiro's influence
    coefficient table as an isentropic relationship between heat and Static
    Pressure, where

    \vartable
      a0      | Speed of Sound
      Cp0     | Specific Heat Capacity (constant pressure)
      mach    | Mach Number
    \endvartable

------------------- this section requires modification -------------------------
    Required fields:
    \verbatim

    \endverbatim

Usage
    Minimal example by using \c constant/fvOptions:
    \verbatim
    variableHeatTransfer1
    {
        // Mandatory entries (unmodifiable)
        type             variableHeatTransfer;

        // Optional entries (runtime modifiable)
        UNbr             U;
        PNbr             p;
        rhoNbr           rho;
        Cp               1005;
        R                287.058;
        a0               329.204;

        // Mandatory/Optional (inherited) entries
        ...
    }
    \endverbatim

    where the entries mean:
    \table
      Property  | Description                     | Type   | Reqd | Dflt
      type      | Type name: variableHeatTransfer | word   | yes  | -
      UNbr      | Name of velocity field          | word   | no   | U
      PNbr      | Name of pressure field          | word   | no   | p
      rhoNbr    | Name of density field           | word   | no   | rho
      Cp        | Specific Heat Capacity          | scalar | no   | 0
      R         | Universal Gas Constant          | scalar | no   | 0
      a0        | Speed of Sound                  | scalar | no   | 0
    \endtable

See also
  - Foam::fv::interRegionHeatTransferModel
  - Foam::fv::tabulatedHeatTransfer
  - Foam::fv::tabulatedNTUHeatTransfer
  - Foam::fv::constantHeatTransfer

SourceFiles
    variableHeatTransfer.C

\*---------------------------------------------------------------------------*/

#ifndef variableHeatTransfer_H
#define variableHeatTransfer_H

#include "fvOption.H"
#include "autoPtr.H"

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

namespace Foam
{
namespace fv
{

/*---------------------------------------------------------------------------*\
                    Class variableHeatTransfer Declaration
\*---------------------------------------------------------------------------*/

class variableHeatTransfer
:
    public option
{
    // Private Data

        //- Name of operand neighbour velocity field
        word UName_;

        //- Speed of Sound
        dimensionedScalar a0_;

        //- Specific Heat Capacity
        const dimensionedScalar Cp0_;

        //- Mach Number
        autoPtr<volScalarField> mach_;

        //- Universal Gas Constant
        const dimensionedScalar R_;


public:

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


    // Constructors

        //- Construct from dictionary
        variableHeatTransfer
        (
            const word& name,
            const word& modelType,
            const dictionary& dict,
            const fvMesh& mesh
        );

        //- No copy construct
        variableHeatTransfer(const variableHeatTransfer&) = delete;

        //- No copy assignment
        void operator=(const variableHeatTransfer&) = delete;


    //- Destructor
    virtual ~variableHeatTransfer() = default;

    // Member Functions

        //- Compute the Mach Number for the entire field
        virtual void heatCompute
        (
          const dimensionedScalar& a0,
          const dimensionedScalar& Cp0,
          const dimensionedScalar timeStepSize_,
          const volScalarField& rho,
          fvMatrix<scalar>& eqn,
          const label fieldi
        );

    // Public Functions

        //- Read dictionary
        virtual bool read(const dictionary& dict);
};


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

} // End namespace fv
} // End namespace Foam

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

#endif

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

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2011-2016 OpenFOAM Foundation
    Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "variableHeatTransfer.H"
#include "turbulentFluidThermoModel.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace fv
{
    defineTypeNameAndDebug(variableHeatTransfer, 0);
    addToRunTimeSelectionTable(option, variableHeatTransfer, dictionary);
}
}


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

Foam::fv::variableHeatTransfer::variableHeatTransfer
(
    const word& name,
    const word& modelType,
    const dictionary& dict,
    const fvMesh& mesh
)
:
    option(sourceName, modelType, dict, mesh),
    UName_(coeffs_.getOrDefault<word>("UNbr", "U")),
    PName_(coeffs_.getOrDefault<word>("PNbr","p")),
    rhoName_(coeffs_.getOrDefault<word>("rhoNbr","rho")),
    Cp0_
    (
        dimensionedScalar
        (
            sqr(dimLength)/sqr(dimTime)/dimTemperature,
            coeffs_.getCheckOrDefault<scalar>
            (
                "Cp0",
                1005.0,
                scalarMinMax::ge(SMALL)
            )
        )
    ),
    R_
    (
        dimensionedScalar
        (
            sqr(dimLength)/sqr(dimTime)/dimTemperature,
            coeffs_.getCheckOrDefault<scalar>
            (
                "R",
                287.058,
                scalarMinMax::ge(SMALL)
            )
        )
    ),
    a0_
    (
        dimensionedScalar
        (
            dimLength/dimTime,
            coeffs_.getCheckOrDefault<scalar>
            (
                "a0",
                329.204,
                scalarMinMax::ge(SMALL)
            )
        )
    ),
{

}


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

void Foam::fv::variableHeatTransfer::heatCompute()
{
    const auto& nbrMesh = mesh_.time().lookupObject<fvMesh>(nbrRegionName());

    const auto& UNbr = nbrMesh.lookupObject<volVectorField>(UName_);

    const auto& PNbr = nbrMesh.lookupObject<volScalarField>(PName_);

    const auto& rhoNbr = nbrMesh.lookupObject<volScalarField>(rhoName_);

    tmp<volScalarField> Mach(mag(UNbr)/a0_);

    // Need to bound the lower limit of mach number here...

    eqn += fvm::ddt(((PNbr*timeStepSize_)*(1-(Mach*Mach))*Cp0_)/(1.4*(Mach*Mach)*rho*R_));

}


bool Foam::fv::variableHeatTransfer::read(const dictionary& dict)
{
    if (interRegionHeatTransferModel::read(dict))
    {
        coeffs_.readIfPresent("UNbr", UName_);

        coeffs_.readIfPresent("a0", a0_);
        coeffs_.readIfPresent("Cp0", Cp0_);
        coeffs_.readIfPresent("M", mach_);
        coeffs_.readIfPresent("R", R_);

        return true;
    }

    return false;
}


// ************************************************************************* //
jdw135 is offline   Reply With Quote

Old   February 16, 2021, 07:20
Default
  #18
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Did you try to compile your fvOption and execute it within your solver?
mAlletto is offline   Reply With Quote

Old   February 16, 2021, 10:46
Default
  #19
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
I haven't yet, mostly because I was trying to find out how to properly bound the mach number before starting on that.

I also am not sure how to compile these, since I've never done it. Do I have to rebuild all of OpenFOAM or just the files I changed?
jdw135 is offline   Reply With Quote

Old   February 17, 2021, 02:56
Default
  #20
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Yes you need to compile only your fvOption. You'll find plenty of tutorials by googling how to write something new by Coping an existing file in OF
mAlletto 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
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 36 July 16, 2024 04:52
[OpenFOAM.com] swak4foam compiling issues on a cluster saj216 OpenFOAM Installation 5 January 17, 2023 17:05
Periodic flow using Cyclic - comparison with Fluent nusivares OpenFOAM Running, Solving & CFD 30 December 12, 2017 06:35
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 07:42
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28


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