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

A non-newtonian viscosity for thermophysicalModels - OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 28, 2020, 22:09
Default A non-newtonian viscosity for thermophysicalModels - OpenFOAM
  #1
New Member
 
Hamed
Join Date: Dec 2013
Location: Istanbul
Posts: 16
Rep Power: 12
Hamed1117 is on a distinguished road
Hello everyone,

Currently I am working on implementation of a non-Newtonian viscosity model in src/thermophysicalModel which requires some code modifications in src/thermophysicalMode/basic and src/thermophysicalMode/specie and I am using the following paper (https://doi.org/10.4236/ojfd.2020.102009) as the initial reference.

The new viscosity model needs to be modified inside specie/newNon-Newtonian.C and called by basic/rhoThermo/heRhoThermo.C where the shear rate (sr) and phase volume fraction (alpha.1) are the main variables.

The new model is compiled without any major problem, but some problems arises when it comes to the calling part using heRhoThermo.C.

According to the paper, I need to use the objectRegistery tool in order to get access to U1(for sr_) and alpha.1 fields.



heRhoThermo.C
Code:
#include "heRhoThermo.H"
#include "fvc.H"
//#include "fvCFD.H"
// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

template<class BasicPsiThermo, class MixtureType>
void Foam::heRhoThermo<BasicPsiThermo, MixtureType>::calculate()
{

    const scalarField& hCells = this->he();
    const scalarField& pCells = this->p_;

    scalarField& TCells = this->T_.primitiveFieldRef();
    scalarField& psiCells = this->psi_.primitiveFieldRef();
    scalarField& rhoCells = this->rho_.primitiveFieldRef();
    scalarField& muCells = this->mu_.primitiveFieldRef();
     scalarField& alphaCells = this->alpha_.primitiveFieldRef();


//register alpha.1_
    const volScalarField& alpha1 =  this->db().objectRegistry::lookupObject<volScalarField>("alpha.particles");
    volScalarField alpha1_ = alpha1;
    scalarField& alpha1Cells = alpha1_.primitiveFieldRef();

//register U1 for sr_ 
 const volVectorField& U1 = this->db().objectRegistry::lookupObject<volVectorField>("U.particles");    
 volScalarField sr_=sqrt(2.0)*mag(symm(fvc::grad(U1)));
  scalarField& srCells = sr_.primitiveFieldRef();
   
 forAll(TCells, celli)
    {
        const typename MixtureType::thermoType& mixture_ =
            this->cellMixture(celli);


        TCells[celli] = mixture_.THE
        (
            hCells[celli],
            pCells[celli],
            TCells[celli]
        );

        psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
        rhoCells[celli] = mixture_.rho(pCells[celli], TCells[celli]);
        muCells[celli] = mixture_.mu(pCells[celli], TCells[celli], alpha1Cells[celli], srCells[celli]);
        alphaCells[celli] = mixture_.alphah(pCells[celli], TCells[celli], alpha1Cells[celli], srCells[celli]);
    }

    volScalarField::Boundary& pBf =
        this->p_.boundaryFieldRef();

    volScalarField::Boundary& TBf =
        this->T_.boundaryFieldRef();
//
    volScalarField::Boundary& alpha1Bf =
             alpha1_.boundaryFieldRef();

    volScalarField::Boundary& srBf =
             sr_.boundaryFieldRef();
//
    volScalarField::Boundary& psiBf =
        this->psi_.boundaryFieldRef();
volScalarField::Boundary& psiBf =
        this->psi_.boundaryFieldRef();

    volScalarField::Boundary& rhoBf =
        this->rho_.boundaryFieldRef();

    volScalarField::Boundary& heBf =
        this->he().boundaryFieldRef();

    volScalarField::Boundary& muBf =
        this->mu_.boundaryFieldRef();

    volScalarField::Boundary& alphaBf =
        this->alpha_.boundaryFieldRef();

    forAll(this->T_.boundaryField(), patchi)
    {
        fvPatchScalarField& pp = pBf[patchi];
        fvPatchScalarField& pT = TBf[patchi];
//
        fvPatchScalarField& palpha1 = alpha1Bf[patchi];
        fvPatchScalarField& psr = srBf[patchi];
//
        fvPatchScalarField& ppsi = psiBf[patchi];
        fvPatchScalarField& prho = rhoBf[patchi];
        fvPatchScalarField& phe = heBf[patchi];
        fvPatchScalarField& pmu = muBf[patchi];
        fvPatchScalarField& palpha = alphaBf[patchi];
        if (pT.fixesValue())
        {

            forAll(pT, facei)
            {
                const typename MixtureType::thermoType& mixture_ =
                    this->patchFaceMixture(patchi, facei);
               phe[facei] = mixture_.HE(pp[facei], pT[facei]);
                ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
                prho[facei] = mixture_.rho(pp[facei], pT[facei]);
                pmu[facei] = mixture_.mu(pp[facei], pT[facei],palpha1[facei], psr[facei]);
                palpha[facei] = mixture_.alphah(pp[facei], pT[facei], palpha1[facei], psr[facei]);
            }
        }
        else
        {
            forAll(pT, facei)
            {
                const typename MixtureType::thermoType& mixture_ =
                    this->patchFaceMixture(patchi, facei);
                pT[facei] = mixture_.THE(phe[facei], pp[facei], pT[facei]);
                ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
                prho[facei] = mixture_.rho(pp[facei], pT[facei]);
//
                pmu[facei] = mixture_.mu(pp[facei], pT[facei], palpha1[facei], psr[facei]);
//
                palpha[facei] = mixture_.alphah(pp[facei], pT[facei], palpha1[facei], psr[facei]);
            }
        }
    }
}


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

template<class BasicPsiThermo, class MixtureType>
Foam::heRhoThermo<BasicPsiThermo, MixtureType>::heRhoThermo
(
    const fvMesh& mesh,
    const word& phaseName
)
:
    heThermo<BasicPsiThermo, MixtureType>(mesh, phaseName)
{
    calculate();
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

template<class BasicPsiThermo, class MixtureType>
Foam::heRhoThermo<BasicPsiThermo, MixtureType>::~heRhoThermo()
{}


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

template<class BasicPsiThermo, class MixtureType>
void Foam::heRhoThermo<BasicPsiThermo, MixtureType>::correct()
{
    if (debug)
    {
        InfoInFunction << endl;
    }

    calculate();

    if (debug)
    {
        Info<< "    Finished" << endl;
    }
}
And it compiles successfully. But when I run the solver in a simple case I got the following error as:

Code:
--> FOAM FATAL ERROR: 

    request for volVectorField U.particles from objectRegistry region0 failed
    available objects of type volVectorField are
0()

    From function const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>]
    in file /opt/openfoam5/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 193.

FOAM aborting
It is clear that I make a mistake during the U.particles registration process. The paper says that U (volVectorField) needs to be called in viscosity claculation loop (paper - listing.1), but I wonder where I should add it !! (inside basic/heRothermo.C, mySolver.C or specie/newNonNewtonianModel.C ?? )


Last edited by Hamed1117; August 6, 2020 at 14:32.
Hamed1117 is offline   Reply With Quote

Old   August 6, 2020, 14:50
Default
  #2
New Member
 
Hamed
Join Date: Dec 2013
Location: Istanbul
Posts: 16
Rep Power: 12
Hamed1117 is on a distinguished road
The above mentioned object registery is correct, and it works fine for different solvers (e.g. rhoPimpleFoam, compressibleInterFoam or ...) that are using the same thermoPhysical models. The twoPhaseEulerFoam solver, however, needs a little bit different procedure for accessing the U field.

I described it in the following post:

request fo volVectorField U.particles from objectRegistry regin0 failed-TwoPhaseEuler
Hamed1117 is offline   Reply With Quote

Old   February 18, 2021, 05:55
Default
  #3
New Member
 
Bruno Ramoa
Join Date: Jul 2019
Posts: 18
Rep Power: 6
brunomramoa is on a distinguished road
Hello,



I am also trying to implement a shear-rate dependent viscosity in the thermophysical models. However, I am getting troubles in the compilation. Would you mind sharing your experience?



Post: Debug help: Viscosity Model in compressibleInterFoam
brunomramoa is offline   Reply With Quote

Old   May 17, 2021, 03:47
Default Major steps
  #4
New Member
 
Bernhard
Join Date: Jun 2018
Posts: 15
Rep Power: 7
hebe03364 is on a distinguished road
Hello!


I am forcing the same problem. I would also like to implement a non-Newtonian transport model for the solver twoPhaseEulerFoam.



However, I am at the beginning of OpenFOAM programming an I want to generally ask what are the major implementation steps to solve this problem? Which files and folders have to be compiled?


Thanks in advance and best regards,
hebe
hebe03364 is offline   Reply With Quote

Reply

Tags
openfoam


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
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin cfd.direct OpenFOAM Announcements from Other Sources 0 September 21, 2016 11:50
coefficient of power-Law viscosity Model in OpenFOAM Daniel_Khazaei OpenFOAM Running, Solving & CFD 6 April 5, 2016 04:23
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 03:18
Molecular viscosity calculation in LES on OpenFOAM babakflame OpenFOAM 0 January 26, 2014 04:13


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