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

parabolic velocity for non-Newtonian fluid

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2019, 02:40
Default parabolic velocity for non-Newtonian fluid
  #1
Senior Member
 
Hojatollah Gholami
Join Date: Jan 2019
Posts: 171
Rep Power: 7
Hgholami is on a distinguished road
Dear All
I want to modify the boundary condition of OF4.0 for using parabolic velocity for non-Newtonian fluid
the equation is : U_mean*(3*n+1)/(n+1)*(1-pow(ABS(y/(0.5*H)),(n+1)/n))
where n is fluid index and H is height of channel.
I use this code for transitionalParabolicNonVelocityFvPatchVectorField .C
HTML Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | foam-extend: Open Source CFD
   \\    /   O peration     | Version:     4.0
    \\  /    A nd           | Web:         http://www.foam-extend.org
     \\/     M anipulation  | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
    This file is part of foam-extend.

    foam-extend 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.

    foam-extend 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 foam-extend.  If not, see <http://www.gnu.org/licenses/>.

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

#include "transitionalParabolicNonVelocityFvPatchVectorField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"

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

namespace Foam
{

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

transitionalParabolicNonVelocityFvPatchVectorField::
transitionalParabolicNonVelocityFvPatchVectorField
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchVectorField(p, iF),
    meanValue_(0),
    d_(1, 0, 0),
    y_(0, 1, 0),
    n_(0);
    transitionPeriod_(SMALL),
    boundBoxMin_(0, 0, 0),
    boundBoxMax_(0, 0, 0)
{}


transitionalParabolicNonVelocityFvPatchVectorField::
transitionalParabolicNonVelocityFvPatchVectorField
(
    const ParabolicNonVelocityFvPatchVectorField& ptf,
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchVectorField(ptf, p, iF, mapper),
    meanValue_(ptf.meanValue_),
    d_(ptf.d_),
    y_(ptf.y_),
    n_(ptf.n_),
    transitionPeriod_(ptf.transitionPeriod_),
    boundBoxMin_(ptf.boundBoxMin_),
    boundBoxMax_(ptf.boundBoxMax_)
{}


transitionalParabolicNonVelocityFvPatchVectorField::
transitionalParabolicNonVelocityFvPatchVectorField
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchVectorField(p, iF),
    meanValue_(readScalar(dict.lookup("meanValue"))),
    n_(readScalar(dict.lookup("n"))),
    d_(dict.lookup("d")),
    y_(dict.lookup("y")),
    transitionPeriod_(readScalar(dict.lookup("transitionPeriod"))),
    boundBoxMin_(dict.lookup("boundBoxMin")),
    boundBoxMax_(dict.lookup("boundBoxMax"))
{
    if (mag(d_) < SMALL || mag(y_) < SMALL)
    {
        FatalErrorIn("transitionalParabolicNonVelocityFvPatchVectorField(dict)")
            << "d or y given with zero size not correct"
            << abort(FatalError);
    }

    d_ /= mag(d_);
    y_ /= mag(y_);

    if (transitionPeriod_ < SMALL)
    {
        transitionPeriod_ = SMALL;
    }
    
    evaluate();
}


transitionalParabolicNonVelocityFvPatchVectorField::
transitionalParabolicNonVelocityFvPatchVectorField
(
    const transitionalParabolicNonVelocityFvPatchVectorField& fcvpvf,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchVectorField(fcvpvf, iF),
    meanValue_(fcvpvf.meanValue_),
    n_(fcvpvf.n_),
    d_(fcvpvf.d_),
    y_(fcvpvf.y_),
    transitionPeriod_(fcvpvf.transitionPeriod_),
    boundBoxMin_(fcvpvf.boundBoxMin_),
    boundBoxMax_(fcvpvf.boundBoxMax_)
{}


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

void transitionalParabolicNonVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    scalar curMeanValue = meanValue_;

    if (this->db().time().value() < transitionPeriod_)
    {
        scalar t = this->db().time().value();
        curMeanValue *= 0.5*(1.0-cos(M_PI*t/transitionPeriod_));
    }
    
    // Get range and orientation
//    boundBox bb(patch().patch().localPoints(), true);

    vector ctr = 0.5*(boundBoxMax_ + boundBoxMin_);

    const vectorField& c = patch().Cf();

    // Calculate local 1-D coordinate for the parabolic profile
    scalarField coord = 2*((c - ctr) & y_)/((boundBoxMax_ - boundBoxMin_) & y_);

    vectorField::operator=(d_*curMeanValue*(1.0+3.0*n_)/(1.0+n_)*(1.0 - pow (coord, (1+n_)/n_)));
}


// Write
void transitionalParabolicNonVelocityFvPatchVectorField::write(Ostream& os) const
{
    fvPatchVectorField::write(os);
    os.writeKeyword("meanValue")
        << meanValue_ << token::END_STATEMENT << nl;
    os.writeKeyword("n")
        << n_ << token::END_STATEMENT << nl;
    os.writeKeyword("d")
        << d_ << token::END_STATEMENT << nl;
    os.writeKeyword("y")
        << y_ << token::END_STATEMENT << nl;
    os.writeKeyword("transitionPeriod")
        << transitionPeriod_ << token::END_STATEMENT << nl;
    os.writeKeyword("boundBoxMin")
        << boundBoxMin_ << token::END_STATEMENT << nl;
    os.writeKeyword("boundBoxMax")
        << boundBoxMax_ << token::END_STATEMENT << nl;
    writeEntry("value", os);
}


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

makePatchTypeField(fvPatchVectorField,
          transitionalParabolicNonVelocityFvPatchVectorField
 );

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

} // End namespace Foam

// ************************************************************************* //
and for transitionalParabolicNonVelocityFvPatchVectorField .H

HTML Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | foam-extend: Open Source CFD
   \\    /   O peration     | Version:     4.0
    \\  /    A nd           | Web:         http://www.foam-extend.org
     \\/     M anipulation  | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
    This file is part of foam-extend.

    foam-extend 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.

    foam-extend 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 foam-extend.  If not, see <http://www.gnu.org/licenses/>.

Class
    ParabolicNonVelocityFvPatchVectorField

Description
    Boundary condition specifies a parabolic velocity inlet profile
    (fixed value), given maximum velocity value (peak of the parabola),
    flow direction n and direction of the parabolic coordinate y

SourceFiles
    transitionalParabolicNonVelocityFvPatchVectorField.C

Author
    Hrvoje Jasak, Wikki Ltd.  All rights reserved

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

#ifndef transitionalParabolicNonVelocityFvPatchVectorField_H
#define transitionalParabolicNonVelocityFvPatchVectorField_H

#include "fvPatchFields.H"
#include "fixedValueFvPatchFields.H"

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
              Class ParabolicNonVelocityFvPatchField Declaration
\*---------------------------------------------------------------------------*/

class transitionalParabolicNonVelocityFvPatchVectorField
:
    public fixedValueFvPatchVectorField
{
    // Private data

        //- mean velocity magnitude
        scalar meanValue_;

        //- Fluid index
        vector n_;
        
        //- Flow direction
        vector d_;

        //- Direction of the y-coordinate
        vector y_;

        //- Transition period
        scalar transitionPeriod_;

        //- Bound box min (must be specified duo to bug in parallel run)
        vector boundBoxMin_;

        //- Bound box max (must be specified duo to bug in parallel run)
        vector boundBoxMax_;

public:

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


    // Constructors

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

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

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

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

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

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


    // Member functions

        //- Return mean value
        scalar& meanValue()
        {
            return meanValue_;
        }

        //- Return fluid index
        scalar& n()
        {
            return n_;
        }
        
        //- Return flow direction
        vector& d()
        {
            return d_;
        }

        //- Return y direction
        vector& y()
        {
            return y_;
        }

        //- Update coefficients
        virtual void updateCoeffs();

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


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

} // End namespace Foam

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

#endif

// ************************************************************************* //
Hgholami is offline   Reply With Quote

Old   February 9, 2019, 02:44
Default
  #2
Senior Member
 
Hojatollah Gholami
Join Date: Jan 2019
Posts: 171
Rep Power: 7
Hgholami is on a distinguished road
I compile the code but have several error, anyone can help me with this problem?
Hgholami is offline   Reply With Quote

Reply

Tags
boundary condition, non-newtonian fluid, parabolic velocity


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
Wrong multiphase flow at rotating interface Sanyo CFX 14 February 7, 2017 18:19
Multiphase flow - incorrect velocity on inlet Mike_Tom CFX 6 September 29, 2016 02:27
Average Rising Velocity as boundary condition Floing CFX 11 August 21, 2016 06:47
Overflow Error in Multiphase Modelling with Two Continuous Fluids ashtonJ CFX 6 August 11, 2014 15:32
Terrible Mistake In Fluid Dynamics History Abhi Main CFD Forum 12 July 8, 2002 10:11


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