【OpenFOAM】tutorials&src-01

skewness Cavity

openfoam2206/tutorials/verificationAndValidation/schemes/skewnessCavity

Allrun

#!/bin/sh
cd "${0%/*}" || exit                                # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions        # Tutorial run functions
#------------------------------------------------------------------------------

# settings

    # operand setups
    setups="
    Gauss-linear
    leastSquares
    Gauss-pointLinear
    iterativeGauss-linear-1
    cellLimited-Gauss-linear-1
    cellLimited-leastSquares-1
    cellLimited-Gauss-pointLinear-1
    cellLimited-iterativeGauss-linear-5-1
    faceLimited-Gauss-linear-1
    faceLimited-leastSquares-1
    faceLimited-Gauss-pointLinear-1
    faceLimited-iterativeGauss-linear-5-1
    cellMDLimited-Gauss-linear-1
    cellMDLimited-leastSquares-1
    cellMDLimited-Gauss-pointLinear-1
    cellMDLimited-iterativeGauss-linear-5-1
    faceMDLimited-Gauss-linear-1
    faceMDLimited-leastSquares-1
    faceMDLimited-Gauss-pointLinear-1
    faceMDLimited-iterativeGauss-linear-5-1
    iterativeGauss-linear-2
    iterativeGauss-linear-3
    iterativeGauss-linear-4
    iterativeGauss-linear-5
    iterativeGauss-linear-10
    iterativeGauss-linear-20
    "

    # flag to enable computations
    run=true

    # flag to enable computations in parallel mode
    parallel=false

    # flag to enable to use a common mesh
    common_mesh=true

    # flag to enable to use a common dynamic code
    common_dynamic_code=true


#------------------------------------------------------------------------------

#######################################
# Create the given setup
# Arguments:
#    $1 = Path to create the setup
# Outputs:
#    Writes info to stdout
#######################################
dry_run_setup() {

    [ $# -eq 0 ] && { echo "Usage error: $0"; exit 1; }

    setup="$1"
    dirSetup="setups/$setup"
    dirSetupOrig="setups.orig/$setup"
    dirOrig="$dirSetupOrig/0.orig"
    dirConstant="$dirSetupOrig/constant"
    dirSystem="$dirSetupOrig/system"

    printf "\n# Create the setup: %s\n" "$setup"

    if [ ! -d "$dirSetup" ]
    then
        mkdir -p "$dirSetup"

        cp -aRfL "setups.orig/common/." "$dirSetup"
        cp -afL "$dirSetupOrig"/All* "$dirSetup" 2>/dev/null || :
        [ -d "$dirOrig" ] && cp -aRfL "$dirOrig/." "$dirSetup/0.orig"
        [ -d "$dirConstant" ] && cp -aRfL "$dirConstant/." "$dirSetup/constant"
        [ -d "$dirSystem" ] && cp -aRfL "$dirSystem/." "$dirSetup/system"
    else
        printf "\n      # Directory %s already exists\n" "$dirSetup"
        printf "      # Skipping the creation of a new setup\n"
    fi
}


#######################################
# Run the given setup
# Arguments:
#    $1 = Path to the setup to run
# Outputs:
#    Writes info to stdout
#######################################
run_setup() {

    [ $# -eq 0 ] && { echo "Usage error: $0"; exit 1; }

    setup="$1"
    dirSetup="setups/$setup"
    dirResult="results/$setup"

    dry_run_setup "$setup"
    [ -d results ] || mkdir -p results

    printf "\n# Run the setup: %s\n\n" "$setup"

    if [ ! -d "$dirResult" ]
    then
        cp -Rf "$dirSetup" "$dirResult"

        if [ "$common_mesh" = true ]
        then
            if [ -d results/mesh ]
            then
                printf "## Copy the common mesh to the setup: %s\n\n" "$setup"
                cp -Rf results/mesh/polyMesh "$dirResult"/constant/.
            fi
        fi

        if [ "$common_dynamic_code" = true ]
        then
            if [ -d results/dynamicCode ]
            then
                printf "## Copy the common dynamic code to the setup: %s\n\n" "$setup"
                cp -Rf results/dynamicCode "$dirResult"/.
            fi
        fi


        if [ "$parallel" = true ]
        then
            ( cd "$dirResult" && ./Allrun-parallel )
        else
            ( cd "$dirResult" && ./Allrun )
        fi


        if [ "$common_mesh" = true ]
        then
            if [ ! -d results/mesh ]
            then
                printf "\n## Store the mesh of %s as the common mesh\n\n" "$setup"
                mkdir -p results/mesh
                cp -Rf "$dirResult"/constant/polyMesh results/mesh/.
            fi
        fi

        if [ "$common_dynamic_code" = true ]
        then
            if [ ! -d results/dynamicCode ]
            then
                printf "\n## Store the dynamic code of %s as the common dynamic code\n\n" "$setup"
                cp -Rf "$dirResult"/dynamicCode results/.
            fi
        fi


    else
        printf "      # Directory %s already exists\n" "$dirResult"
        printf "      # Skipping the computation of the given setup\n"
    fi
}在这里插入代码片



#------------------------------------------------------------------------------

for setup in $setups
do
    dirSetupOrig="setups.orig/$setup"

    if [ ! -d "$dirSetupOrig" ]
    then
        echo "Setup directory: $dirSetupOrig" \
             "could not be found - skipping execution" 1>&2
        continue
    fi

    if [ "$run" = true ]
    then
        run_setup "$setup"
    else
        dry_run_setup "$setup"
    fi
done


if notTest "$@" && [ "$run" = true ]
then
    ./plot
fi


#------------------------------------------------------------------------------

controlDict

functions
{
    coded1
    {
        name                calcGrad;
        type                coded;
        libs                (utilityFunctionObjects);
        writeControl        timeStep;

        codeInclude
        #{
            #include        "emptyFvPatchField.H"
        #};

        codeExecute
        #{
            const volVectorField& Cc = mesh().C();
            volVectorField Cc2
            (
                IOobject
                (
                    "Cc",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedVector(dimless/dimLength, Zero),
                calculatedFvPatchField<vector>::typeName
            );

            Cc2.primitiveFieldRef() = Cc.primitiveField();
            auto& bf = Cc2.boundaryFieldRef();

            forAll(bf, patchi)
            {
                fvPatchVectorField& pf = bf[patchi];

                if (!isA<emptyFvPatchField<vector>>(pf))
                {
                    pf == Cc.boundaryField()[patchi];
                }
            }

            tmp<volTensorField> gradC = fvc::grad(Cc2);
            const word gradCName(gradC.cref().name());
            gradC->write();

            volScalarField error
            (
                IOobject
                (
                    "error",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedScalar(dimless, Zero),
                calculatedFvPatchField<scalar>::typeName
            );

            volScalarField magError
            (
                IOobject
                (
                    "magError",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedScalar(dimless, Zero),
                calculatedFvPatchField<scalar>::typeName
            );

            const dimensionedScalar root2(dimless/sqr(dimLength), Foam::sqrt(2.0));

            error = scalar(100)*(mag(gradC) - root2)/root2;
            error.write();

            magError = mag(error);
            magError.write();
        #};
    }

    readFields1
    {
        type            readFields;
        libs            (fieldFunctionObjects);
        fields          ( error magError );
    }

    minMax1
    {
        type                fieldMinMax;
        libs                (fieldFunctionObjects);
        fields              ( error magError );
    }

    volFieldAverage
    {
        type            volFieldValue;
        libs            (fieldFunctionObjects);
        fields          ( error magError );
        operation       average;
        regionType      all;
        writeFields     false;
    }

    volFieldCoV
    {
        type            volFieldValue;
        libs            (fieldFunctionObjects);
        fields          ( error magError );
        operation       CoV;
        regionType      all;
        writeFields     false;
    }

functionObjectTemplate.C

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

bool
Foam::
calcGradFunctionObject::read(const dictionary& dict)
{
    if (false)
    {
        printMessage("read calcGrad");
    }

//{{{ begin code
    
//}}} end code

    return true;
}


bool
Foam::
calcGradFunctionObject::execute()
{
    if (false)
    {
        printMessage("execute calcGrad");
    }

//{{{ begin code
    #line 63 "/home/xx/xx/skewnessCavity/results/Gauss-linear/system/controlDict.functions.coded1"
const volVectorField& Cc = mesh().C();
            volVectorField Cc2
            (
                IOobject
                (
                    "Cc",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedVector(dimless/dimLength, Zero),
                calculatedFvPatchField<vector>::typeName
            );

            Cc2.primitiveFieldRef() = Cc.primitiveField();
            auto& bf = Cc2.boundaryFieldRef();

            forAll(bf, patchi)
            {
                fvPatchVectorField& pf = bf[patchi];

                if (!isA<emptyFvPatchField<vector>>(pf))
                {
                    pf == Cc.boundaryField()[patchi];
                }
            }

            tmp<volTensorField> gradC = fvc::grad(Cc2);
            const word gradCName(gradC.cref().name());
            gradC->write();

            volScalarField error
            (
                IOobject
                (
                    "error",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedScalar(dimless, Zero),
                calculatedFvPatchField<scalar>::typeName
            );

            volScalarField magError
            (
                IOobject
                (
                    "magError",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ
                ),
                mesh(),
                dimensionedScalar(dimless, Zero),
                calculatedFvPatchField<scalar>::typeName
            );

            const dimensionedScalar root2(dimless/sqr(dimLength), Foam::sqrt(2.0));

            error = scalar(100)*(mag(gradC) - root2)/root2;
            error.write();

            magError = mag(error);
            magError.write();
//}}} end code

    return true;
}


bool
Foam::
calcGradFunctionObject::write()
{
    if (false)
    {
        printMessage("write calcGrad");
    }

//{{{ begin code
    
//}}} end code

    return true;
}


bool
Foam::
calcGradFunctionObject::end()
{
    if (false)
    {
        printMessage("end calcGrad");
    }

//{{{ begin code
    
//}}} end code

    return true;
}

tutorials

.
├── Allclean
├── Allcollect
├── Allrun
├── Alltest
├── basic
├── combustion
├── compressible
├── discreteMethods
├── DNS
├── electromagnetics
├── financial
├── finiteArea
├── heatTransfer
├── incompressible
├── IO
├── lagrangian
├── mesh
├── modules
├── multiphase
├── preProcessing
├── resources
├── stressAnalysis
└── verificationAndValidation

19 directories, 4 files
/verificationAndValidation/atmosphericModels/atmDownstreamDevelopment

在这里插入图片描述

src

/openfoam2206/src  tree . -L 1                                                             
.
├── Allwmake
├── Allwmake-scan
├── atmosphericModels
├── combustionModels
├── conversion
├── dummyThirdParty
├── dynamicFaMesh
├── dynamicFvMesh
├── dynamicMesh
├── engine
├── faOptions
├── fileFormats
├── finiteArea
├── finiteVolume
├── functionObjects
├── fvAgglomerationMethods
├── fvMotionSolver
├── fvOptions
├── genericPatchFields
├── lagrangian
├── lumpedPointMotion
├── mesh
├── meshTools
├── ODE
├── OpenFOAM
├── optimisation
├── OSspecific
├── overset
├── parallel
├── phaseSystemModels
├── Pstream
├── randomProcesses
├── regionFaModels
├── regionModels
├── renumber
├── rigidBodyDynamics
├── rigidBodyMeshMotion
├── sampling
├── sixDoFRigidBodyMotion
├── sixDoFRigidBodyState
├── surfMesh
├── thermophysicalModels
├── thermoTools
├── topoChangerFvMesh
├── transportModels
├── TurbulenceModels
└── waveModels

45 directories, 2 files

以下文件夹很重要

finiteVolume

.
├── cfdTools
├── expressions
├── fields
├── finiteVolume
├── functionObjects
├── fvMatrices
├── fvMesh
├── interpolation
├── lduPrimitiveMeshAssembly
├── lnInclude
├── Make
├── surfaceMesh
└── volMesh
fields
/openfoam/openfoam2206/src/functionObjects/field/grad
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2012-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
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 "fvcGrad.H"

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

template<class Type>
bool Foam::functionObjects::grad::calcGrad()
{
    typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
    typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;

    if (foundObject<VolFieldType>(fieldName_, false))
    {
        return store
        (
            resultName_,
            fvc::grad(lookupObject<VolFieldType>(fieldName_)),
            mesh_.changing() && mesh_.cache(resultName_)
        );
    }
    else if (foundObject<SurfaceFieldType>(fieldName_, false))
    {
        return store
        (
            resultName_,
            fvc::grad(lookupObject<SurfaceFieldType>(fieldName_)),
            mesh_.changing() && mesh_.cache(resultName_)
        );
    }

    return false;
}


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

grad.H

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2012-2016 OpenFOAM Foundation
    Copyright (C) 2019-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::functionObjects::grad

Group
    grpFieldFunctionObjects

Description
    Computes the gradient of an input field.

    The operation is limited to scalar and vector volume or surface fields, and
    the output is a volume vector or tensor field.

    Operands:
    \table
      Operand       | Type                              | Location
      input         | {vol,surface}{Scalar,Vector}Field <!--
                --> | $FOAM_CASE/\<time\>/\<inpField\>
      output file   | -                                 | -
      output field  | vol{Vector,Tensor}Field           <!--
                --> | $FOAM_CASE/\<time\>/\<outField\>
    \endtable

Usage
    Minimal example by using \c system/controlDict.functions:
    \verbatim
    grad1
    {
        // Mandatory entries (unmodifiable)
        type            grad;
        libs            (fieldFunctionObjects);

        // Mandatory (inherited) entries (runtime modifiable)
        field           <field>;

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

    where the entries mean:
    \table
      Property     | Description                        | Type | Req'd | Dflt
      type         | Type name: grad                    | word |  yes  | -
      libs         | Library name: fieldFunctionObjects | word |  yes  | -
      field        | Name of the operand field          | word |  yes  | -
    \endtable

    The inherited entries are elaborated in:
     - \link functionObject.H \endlink
     - \link fieldExpression.H \endlink

    Minimal example by using the \c postProcess utility:
    \verbatim
        postProcess -func "grad(<field>)"
    \endverbatim

See also
    - Foam::functionObject
    - Foam::functionObjects::fvMeshFunctionObject
    - Foam::functionObjects::fieldExpression
    - ExtendedCodeGuide::functionObjects::field::grad

SourceFiles
    grad.C
    gradTemplates.C

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

#ifndef functionObjects_grad_H
#define functionObjects_grad_H

#include "fieldExpression.H"

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

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                         Class grad Declaration
\*---------------------------------------------------------------------------*/

class grad
:
    public fieldExpression
{
    // Private Member Functions

        //- Calculate the magnitude of the field and register the result
        template<class Type>
        bool calcGrad();

        //- Calculate the gradient field and return true if successful
        virtual bool calc();


public:

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


    // Constructors

        //- Construct from Time and dictionary
        grad
        (
            const word& name,
            const Time& runTime,
            const dictionary& dict
        );

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

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


    //- Destructor
    virtual ~grad() = default;
};


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

} // End namespace functionObjects
} // End namespace Foam

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

#ifdef NoRepository
    #include "gradTemplates.C"
#endif

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

#endif

// ************************************************************************* //
fvMesh
.
├── extendedStencil
├── fvBoundaryMesh
├── fvGeometryScheme
├── fvMesh.C
├── fvMeshGeometry.C
├── fvMesh.H
├── fvMeshLduAddressing.H
├── fvMeshMapper
├── fvMeshSubset
├── fvMeshTemplates.C
├── fvMeshTools
├── fvPatches
├── simplifiedFvMesh
├── singleCellFvMesh
├── wallDist
└── zoneDistribute
finiteVolume
.
├── convectionSchemes
├── d2dt2Schemes
├── ddtSchemes
├── divSchemes
├── doc
├── fv
├── fvc
├── fvm
├── fvSchemes
├── fvSolution
├── gradSchemes
├── laplacianSchemes
└── snGradSchemes

13 directories, 0 files
fvc
.
├── fvcAverage.C
├── fvcAverage.H
├── fvcCellReduce.C
├── fvcCellReduce.H
├── fvcCorrectAlpha.C
├── fvcCorrectAlpha.H
├── fvcCurl.C
├── fvcCurl.H
├── fvcD2dt2.C
├── fvcD2dt2.H
├── fvcDdt.C
├── fvcDDt.C
├── fvcDdt.H
├── fvcDDt.H
├── fvcDiv.C
├── fvcDiv.H
├── fvcFlux.C
├── fvcFlux.H
├── fvcFluxTemplates.C
├── fvcGrad.C
├── fvcGrad.H
├── fvc.H
├── fvcLaplacian.C
├── fvcLaplacian.H
├── fvcMagSqrGradGrad.C
├── fvcMagSqrGradGrad.H
├── fvcMeshPhi.C
├── fvcMeshPhi.H
├── fvcReconstruct.C
├── fvcReconstruct.H
├── fvcReconstructMag.C
├── fvcSimpleReconstruct.C
├── fvcSmooth
├── fvcSnGrad.C
├── fvcSnGrad.H
├── fvcSup.C
├── fvcSup.H
├── fvcSurfaceIntegrate.C
├── fvcSurfaceIntegrate.H
├── fvcVolumeIntegrate.C
└── fvcVolumeIntegrate.H

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

InNamespace
    Foam::fvc

Description
    Calculate the gradient of the given field.

SourceFiles
    fvcGrad.C

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


#ifndef fvcGrad_H
#define fvcGrad_H

#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
                     Namespace fvc functions Declaration
\*---------------------------------------------------------------------------*/

namespace fvc
{
    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const GeometricField<Type, fvsPatchField, surfaceMesh>&
    );

    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>&
    );

    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const GeometricField<Type, fvPatchField, volMesh>&,
        const word& name
    );

    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const tmp<GeometricField<Type, fvPatchField, volMesh>>&,
        const word& name
    );

    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const GeometricField<Type, fvPatchField, volMesh>&
    );

    template<class Type>
    tmp
    <
        GeometricField
        <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
    > grad
    (
        const tmp<GeometricField<Type, fvPatchField, volMesh>>&
    );
}


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

} // End namespace Foam

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

#ifdef NoRepository
    #include "fvcGrad.C"
#endif

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

#endif

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

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
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 "fvcGrad.H"
#include "fvcSurfaceIntegrate.H"
#include "fvMesh.H"
#include "gaussGrad.H"

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

namespace Foam
{

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

namespace fvc
{

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

template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector, Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
)
{
    return fv::gaussGrad<Type>::gradf(ssf, "grad(" + ssf.name() + ')');
}


template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector,Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>& tssf
)
{
    typedef typename outerProduct<vector, Type>::type GradType;
    tmp<GeometricField<GradType, fvPatchField, volMesh>> Grad
    (
        fvc::grad(tssf())
    );
    tssf.clear();
    return Grad;
}


template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector,Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const GeometricField<Type, fvPatchField, volMesh>& vf,
    const word& name
)
{
    return fv::gradScheme<Type>::New
    (
        vf.mesh(),
        vf.mesh().gradScheme(name)
    )().grad(vf, name);
}


template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector,Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const tmp<GeometricField<Type, fvPatchField, volMesh>>& tvf,
    const word& name
)
{
    tmp
    <
        GeometricField
        <
            typename outerProduct<vector, Type>::type, fvPatchField, volMesh
        >
    > tGrad
    (
        fvc::grad(tvf(), name)
    );
    tvf.clear();
    return tGrad;
}


template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector,Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const GeometricField<Type, fvPatchField, volMesh>& vf
)
{
    return fvc::grad(vf, "grad(" + vf.name() + ')');
}


template<class Type>
tmp
<
    GeometricField
    <
        typename outerProduct<vector,Type>::type, fvPatchField, volMesh
    >
>
grad
(
    const tmp<GeometricField<Type, fvPatchField, volMesh>>& tvf
)
{
    typedef typename outerProduct<vector, Type>::type GradType;
    tmp<GeometricField<GradType, fvPatchField, volMesh>> Grad
    (
        fvc::grad(tvf())
    );
    tvf.clear();
    return Grad;
}


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

} // End namespace fvc

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

} // End namespace Foam

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

fvm
gradSchemes
├── fourthGrad
├── gaussGrad
├── gradScheme
├── iterativeGaussGrad
├── leastSquaresGrad
├── LeastSquaresGrad
└── limitedGradSchemes
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  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) 2019-2021 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::fourthGrad

Group
    grpFvGradSchemes

Description
    Second-order gradient scheme using least-squares.

SourceFiles
    fourthGrad.C

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

#ifndef fourthGrad_H
#define fourthGrad_H

#include "gradScheme.H"

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

namespace Foam
{

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

namespace fv
{

/*---------------------------------------------------------------------------*\
                      Class fourthGrad Declaration
\*---------------------------------------------------------------------------*/

template<class Type>
class fourthGrad
:
    public fv::gradScheme<Type>
{
    // Private Member Functions

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

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


public:

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


    // Constructors

        //- Construct from Istream
        fourthGrad(const fvMesh& mesh, Istream&)
        :
            gradScheme<Type>(mesh)
        {}


    // Member Functions

        //- Return the gradient of the given field to the gradScheme::grad
        //- for optional caching
        virtual tmp
        <
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
        > calcGrad
        (
            const GeometricField<Type, fvPatchField, volMesh>& vsf,
            const word& name
        ) const;
};


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

} // End namespace fv

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

} // End namespace Foam

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

#ifdef NoRepository
    #include "fourthGrad.C"
#endif

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

#endif

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

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  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) 2018-2021 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 "gaussGrad.H"
#include "extrapolatedCalculatedFvPatchField.H"

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

template<class Type>
Foam::tmp
<
    Foam::GeometricField
    <
        typename Foam::outerProduct<Foam::vector, Type>::type,
        Foam::fvPatchField,
        Foam::volMesh
    >
>
Foam::fv::gaussGrad<Type>::gradf
(
    const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
    const word& name
)
{
    typedef typename outerProduct<vector, Type>::type GradType;
    typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;

    const fvMesh& mesh = ssf.mesh();

    tmp<GradFieldType> tgGrad
    (
        new GradFieldType
        (
            IOobject
            (
                name,
                ssf.instance(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensioned<GradType>(ssf.dimensions()/dimLength, Zero),
            extrapolatedCalculatedFvPatchField<GradType>::typeName
        )
    );
    GradFieldType& gGrad = tgGrad.ref();

    const labelUList& owner = mesh.owner();
    const labelUList& neighbour = mesh.neighbour();
    const vectorField& Sf = mesh.Sf();

    Field<GradType>& igGrad = gGrad;
    const Field<Type>& issf = ssf;

    forAll(owner, facei)
    {
        const GradType Sfssf = Sf[facei]*issf[facei];

        igGrad[owner[facei]] += Sfssf;
        igGrad[neighbour[facei]] -= Sfssf;
    }

    forAll(mesh.boundary(), patchi)
    {
        const labelUList& pFaceCells =
            mesh.boundary()[patchi].faceCells();

        const vectorField& pSf = mesh.Sf().boundaryField()[patchi];

        const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];

        forAll(mesh.boundary()[patchi], facei)
        {
            igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
        }
    }

    igGrad /= mesh.V();

    gGrad.correctBoundaryConditions();

    return tgGrad;
}


template<class Type>
Foam::tmp
<
    Foam::GeometricField
    <
        typename Foam::outerProduct<Foam::vector, Type>::type,
        Foam::fvPatchField,
        Foam::volMesh
    >
>
Foam::fv::gaussGrad<Type>::calcGrad
(
    const GeometricField<Type, fvPatchField, volMesh>& vsf,
    const word& name
) const
{
    typedef typename outerProduct<vector, Type>::type GradType;
    typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;

    tmp<GradFieldType> tgGrad
    (
        gradf(tinterpScheme_().interpolate(vsf), name)
    );
    GradFieldType& gGrad = tgGrad.ref();

    correctBoundaryConditions(vsf, gGrad);

    return tgGrad;
}


template<class Type>
void Foam::fv::gaussGrad<Type>::correctBoundaryConditions
(
    const GeometricField<Type, fvPatchField, volMesh>& vsf,
    GeometricField
    <
        typename outerProduct<vector, Type>::type, fvPatchField, volMesh
    >& gGrad
)
{
    auto& gGradbf = gGrad.boundaryFieldRef();

    forAll(vsf.boundaryField(), patchi)
    {
        if (!vsf.boundaryField()[patchi].coupled())
        {
            const vectorField n
            (
                vsf.mesh().Sf().boundaryField()[patchi]
              / vsf.mesh().magSf().boundaryField()[patchi]
            );

            gGradbf[patchi] += n *
            (
                vsf.boundaryField()[patchi].snGrad()
              - (n & gGradbf[patchi])
            );
        }
     }
}


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

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  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) 2018-2021 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::gaussGrad

Group
    grpFvGradSchemes

Description
    Basic second-order gradient scheme using face-interpolation
    and Gauss' theorem.

SourceFiles
    gaussGrad.C

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

#ifndef gaussGrad_H
#define gaussGrad_H

#include "gradScheme.H"
#include "surfaceInterpolationScheme.H"
#include "linear.H"

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

namespace Foam
{

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

namespace fv
{

/*---------------------------------------------------------------------------*\
                       Class gaussGrad Declaration
\*---------------------------------------------------------------------------*/

template<class Type>
class gaussGrad
:
    public fv::gradScheme<Type>
{
    // Private Data

        //- Interpolation scheme/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  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) 2018-2021 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::gaussGrad

Group
    grpFvGradSchemes

Description
    Basic second-order gradient scheme using face-interpolation
    and Gauss' theorem.

SourceFiles
    gaussGrad.C

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

#ifndef gaussGrad_H
#define gaussGrad_H

#include "gradScheme.H"
#include "surfaceInterpolationScheme.H"
#include "linear.H"

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

namespace Foam
{

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

namespace fv
{

/*---------------------------------------------------------------------------*\
                       Class gaussGrad Declaration
\*---------------------------------------------------------------------------*/

template<class Type>
class gaussGrad
:
    public fv::gradScheme<Type>
{
    // Private Data

        //- Interpolation scheme
        tmp<surfaceInterpolationScheme<Type>> tinterpScheme_;


    // Private Member Functions

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

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


public:

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


    // Constructors

        //- Construct from mesh
        gaussGrad(const fvMesh& mesh)
        :
            gradScheme<Type>(mesh),
            tinterpScheme_(new linear<Type>(mesh))
        {}

        //- Construct from mesh and Istream
        gaussGrad(const fvMesh& mesh, Istream& is)
        :
            gradScheme<Type>(mesh),
            tinterpScheme_(nullptr)
        {
            if (is.eof())
            {
                tinterpScheme_ =
                    tmp<surfaceInterpolationScheme<Type>>
                    (
                        new linear<Type>(mesh)
                    );
            }
            else
            {
                tinterpScheme_ =
                    tmp<surfaceInterpolationScheme<Type>>
                    (
                        surfaceInterpolationScheme<Type>::New(mesh, is)
                    );
            }
        }


    // Member Functions

        //- Return the gradient of the given field
        //- calculated using Gauss' theorem on the given surface field
        static
        tmp
        <
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
        > gradf
        (
            const GeometricField<Type, fvsPatchField, surfaceMesh>&,
            const word& name
        );

        //- Return the gradient of the given field to the gradScheme::grad
        //- for optional caching
        virtual tmp
        <
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
        > calcGrad
        (
            const GeometricField<Type, fvPatchField, volMesh>& vsf,
            const word& name
        ) const;

        //- Correct the boundary values of the gradient using the patchField
        //- snGrad functions
        static void correctBoundaryConditions
        (
            const GeometricField<Type, fvPatchField, volMesh>&,
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>&
        );
};


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

} // End namespace fv

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

} // End namespace Foam

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

#ifdef NoRepository
    #include "gaussGrad.C"
#endif

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

#endif

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

        tmp<surfaceInterpolationScheme<Type>> tinterpScheme_;


    // Private Member Functions

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

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


public:

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


    // Constructors

        //- Construct from mesh
        gaussGrad(const fvMesh& mesh)
        :
            gradScheme<Type>(mesh),
            tinterpScheme_(new linear<Type>(mesh))
        {}

        //- Construct from mesh and Istream
        gaussGrad(const fvMesh& mesh, Istream& is)
        :
            gradScheme<Type>(mesh),
            tinterpScheme_(nullptr)
        {
            if (is.eof())
            {
                tinterpScheme_ =
                    tmp<surfaceInterpolationScheme<Type>>
                    (
                        new linear<Type>(mesh)
                    );
            }
            else
            {
                tinterpScheme_ =
                    tmp<surfaceInterpolationScheme<Type>>
                    (
                        surfaceInterpolationScheme<Type>::New(mesh, is)
                    );
            }
        }


    // Member Functions

        //- Return the gradient of the given field
        //- calculated using Gauss' theorem on the given surface field
        static
        tmp
        <
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
        > gradf
        (
            const GeometricField<Type, fvsPatchField, surfaceMesh>&,
            const word& name
        );

        //- Return the gradient of the given field to the gradScheme::grad
        //- for optional caching
        virtual tmp
        <
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
        > calcGrad
        (
            const GeometricField<Type, fvPatchField, volMesh>& vsf,
            const word& name
        ) const;

        //- Correct the boundary values of the gradient using the patchField
        //- snGrad functions
        static void correctBoundaryConditions
        (
            const GeometricField<Type, fvPatchField, volMesh>&,
            GeometricField
            <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>&
        );
};


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

} // End namespace fv

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

} // End namespace Foam

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

#ifdef NoRepository
    #include "gaussGrad.C"
#endif

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

#endif

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

参考网址:

OpenFOAM

.
├── algorithms
├── Alltouch
├── containers
├── db
├── dimensionedTypes
├── dimensionSet
├── expressions
├── fields
├── global
├── include
├── interpolations
├── lnInclude
├── Make
├── matrices
├── memory
├── meshes
├── orientedType
├── parallel
└── primitives

18 directories, 1 file
openfoam/openfoam2206/src/OpenFOAM/matrices  tree . -L 1                                           
.
├── DiagonalMatrix
├── EigenMatrix
├── lduMatrix
├── LduMatrix
├── LLTMatrix
├── LUscalarMatrix
├── Matrix
├── MatrixBlock
├── QRMatrix
├── RectangularMatrix
├── scalarMatrices
├── schemes
├── simpleMatrix
├── solution
├── SquareMatrix
├── SymmetricSquareMatrix
└── tolerances
openfoam/openfoam2206/src/OpenFOAM/matrices/LduMatrix  tree . -L 1                                 
.
├── LduMatrix
├── Preconditioners
├── Smoothers
└── Solvers

4 directories, 0 files
openfoam2206/src/OpenFOAM/matrices/LduMatrix/Solvers   tree . -L 1                        
.
├── DiagonalSolver
├── lduSolvers.C
├── PBiCCCG
├── PBiCICG
├── PCICG
└── SmoothSolver

5 directories, 1 file
openfoam/openfoam2206/src/OpenFOAM/matrices/lduMatrix/solvers tree . -L 1                          
.
├── diagonalSolver
├── GAMG
├── PBiCG
├── PBiCGStab
├── PCG
├── PPCG
├── PPCR
└── smoothSolver

8 directories, 0 files

OSspecific

functionObjects

查询方法

补充学习资料

  • Hrvoje Jasak - Error Analysis and Estimation for the Finite Volume Method with Applications to Fluid Flows

  • Rusche, Henrik - Computational fluid dynamics of dispersed two-phase flows at high phase fractions

  • S. M. Damián - An extended mixture model for the simultaneous treatment of short and long scale interfaces

  • The OpenFOAM Technology Primer
    Listing 37 Looking up a geometric internal field from within a boundary mesh patch.
    P285

template<class GeometricField, class Type>
const typename GeometricField::PatchFieldType&
Foam::fvPatch::lookupPatchField
(
const word& name,
const GeometricField*,
const Type*
) const
{
return patchField<GeometricField, Type>
(
boundaryMesh().mesh().objectRegistry::template
lookupObject<GeometricField>(name)
);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值