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

How to calculate area averaged velocity on a surface for a post-proccessing utility?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 13, 2017, 16:36
Default How to calculate area averaged velocity on a surface for a post-proccessing utility?
  #1
New Member
 
Lukas Lebovitz
Join Date: Mar 2017
Location: Zürich, Switzerland
Posts: 25
Rep Power: 9
lukas.lebo is on a distinguished road
Hello

I'm trying to make an utility that can calculate the mean and prime2mean of the pressure coefficient cp. My simulations already create the fields for pMean and pPrime2Mean during runtime.

I basically want to do this calculation:
cp = p/(0.5*U_ref^2)

where U_ref should be my reference velocity. Here I'd like to take the area averaged velocity from the inlet (patch is actually named "inlet").

How do I get a (scalar) value that is the area average of the inlet velocity?

And can I define my own variable? i.e. "double u_ref = ...;"

Thanks so much!



PS: I took another utility and modified it. You can take a look here:

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
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/>.

Application
    cpMean

Description
    Calculates and writes some mean fields from an LES calculation. The
    following fields are created:
        - cpMean: mean pressure coefficient
        - cpPrime2Mean: variance of the pressure coefficient
    Fields UMean, pPrime2Mean and pMean must exist.

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

#include "calc.H"
#include "fvc.H"
#include "fvCFD.H"

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

void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
    IOobject pMeanHeader
    (
        "pMean",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );


    IOobject pPrime2MeanHeader
    (
        "pPrime2Mean",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );


    IOobject UMeanHeader
    (
        "UMean",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ
    );
    
  
    if
    (
        pMeanHeader.headerOk()
     && pPrime2MeanHeader.headerOk()
     && UMeanHeader.headerOk()
    )
    {
        Info<< "    Reading average field pMean" << endl;
        const volScalarField pMean(pMeanHeader, mesh);

        Info<< "    Reading average field pPrime2Mean" << endl;
        const volScalarField pPrime2Mean(pPrim2MeanHeader, mesh);

        Info<< "    Reading average field UMean" << endl;
        const volVectorField UMean(UMeanHeader, mesh);


        volScalarField cpMean
        (
            IOobject
            (
                "cpMean",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh,
            dimensionedScalar("dimless",dimless,0)
        );


        volScalarField cpPrime2Mean
        (
            IOobject
            (
                "cpPrime2Mean",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh,
            dimensionedScalar("dimless",dimless,0)
        );

        // double u_ref = ... ; // is this allowed?

        Info<< "    Calculating cpMean" << endl;
	forAll(cpMean,i){
            cpMean[i] = pMean[i]/(0.5*...); // <-- Missing mean velocity at Inlet !!!
	}

        Info<< "    Calculating cpPrime2Mean" << endl;
	forAll(cpPrime2Mean,i){
	    cpPrime2Mean[i] = pPrime2Mean[i]/(0.5*...): // <-- Missing mean velocity at Inlet !!!
	}

        cpMean.write();
	cpPrime2Mean.write();
    }
    else
    {
        Info << "    No pPrime2Mean and/or pMean and/or UMean." << endl;
    }
    
    Info<< "End" << endl;
}


// ************************************************************************* //
lukas.lebo is offline   Reply With Quote

Old   April 19, 2017, 05:41
Default
  #2
Member
 
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11
sisetrun is on a distinguished road
Hey,
maybe the code from the patchIntegrate tool can help you:

Description
Calculates the integral of the specified field over the specified patch.

https://github.com/OpenFOAM/OpenFOAM...tchIntegrate.C
sisetrun 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
To calculate area averaged species mass fraction from PDF Bharadwaj B S Fluent UDF and Scheme Programming 3 March 8, 2016 02:22
Compare 2D axi-symmetric and 3D. Is OpenFOAM calculate the velocity wrong? RalphS OpenFOAM 6 November 13, 2010 20:51
how to plot out circumferentially mass averaged axial velocity in a rotor? wildli FLUENT 0 July 17, 2010 15:54
ATTENTION! Reliability problems in CFX 5.7 Joseph CFX 14 April 20, 2010 15:45
user surface in post xinzhangabc CFX 0 February 24, 2005 06:29


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