Skip to content
Snippets Groups Projects
patchProbesTemplates.C 7.02 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*---------------------------------------------------------------------------*\
      =========                 |
      \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
       \\    /   O peration     |
    
    OpenFOAM bot's avatar
    OpenFOAM bot committed
        \\  /    A nd           | www.openfoam.com
    
         \\/     M anipulation  |
    
    -------------------------------------------------------------------------------
    
    OpenFOAM bot's avatar
    OpenFOAM bot committed
        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 "patchProbes.H"
    #include "volFields.H"
    #include "IOmanip.H"
    
    
    // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
    
    template<class Type>
    void Foam::patchProbes::sampleAndWrite
    (
        const GeometricField<Type, fvPatchField, volMesh>& vField
    )
    {
    
        Field<Type> values(sample(vField));
    
    
        if (Pstream::master())
        {
            unsigned int w = IOstream::defaultPrecision() + 7;
            OFstream& probeStream = *probeFilePtrs_[vField.name()];
    
    
            probeStream
                << setw(w)
    
            forAll(values, probei)
    
                probeStream << ' ' << setw(w) << values[probei];
    
    template<class Type>
    void Foam::patchProbes::sampleAndWrite
    (
        const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
    )
    {
        Field<Type> values(sample(sField));
    
        if (Pstream::master())
        {
            unsigned int w = IOstream::defaultPrecision() + 7;
            OFstream& probeStream = *probeFilePtrs_[sField.name()];
    
    
            probeStream
                << setw(w)
    
            forAll(values, probei)
    
                probeStream << ' ' << setw(w) << values[probei];
    
    template<class Type>
    
    void Foam::patchProbes::sampleAndWrite
    (
        const fieldGroup<Type>& fields
    )
    {
    
        forAll(fields, fieldi)
    
        {
            if (loadFromFiles_)
            {
                sampleAndWrite
                (
                    GeometricField<Type, fvPatchField, volMesh>
                    (
                        IOobject
                        (
    
                            mesh_.time().timeName(),
                            mesh_,
                            IOobject::MUST_READ,
                            IOobject::NO_WRITE,
                            false
                        ),
                        mesh_
                    )
                );
            }
            else
            {
    
                objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
    
                 && iter()->type()
                 == GeometricField<Type, fvPatchField, volMesh>::typeName
                )
                {
                    sampleAndWrite
                    (
                        mesh_.lookupObject
    
    template<class Type>
    void Foam::patchProbes::sampleAndWriteSurfaceFields
    (
        const fieldGroup<Type>& fields
    )
    {
    
        forAll(fields, fieldi)
    
        {
            if (loadFromFiles_)
            {
                sampleAndWrite
                (
                    GeometricField<Type, fvsPatchField, surfaceMesh>
                    (
                        IOobject
                        (
    
                            mesh_.time().timeName(),
                            mesh_,
                            IOobject::MUST_READ,
                            IOobject::NO_WRITE,
                            false
                        ),
                        mesh_
                    )
                );
            }
            else
            {
    
                objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
    
                 && iter()->type()
                 == GeometricField<Type, fvsPatchField, surfaceMesh>::typeName
                )
                {
                    sampleAndWrite
                    (
                        mesh_.lookupObject
    
                        <GeometricField<Type, fvsPatchField, surfaceMesh>>
    
    // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
    
    template<class Type>
    
    Foam::patchProbes::sample
    (
        const GeometricField<Type, fvPatchField, volMesh>& vField
    ) const
    {
        const Type unsetVal(-VGREAT*pTraits<Type>::one);
    
    
        (
            new Field<Type>(this->size(), unsetVal)
        );
    
    
        Field<Type>& values = tValues.ref();
    
    
        const polyBoundaryMesh& patches = mesh_.boundaryMesh();
    
    
        forAll(*this, probei)
    
                label patchi = patches.whichPatch(facei);
    
                label localFacei = patches[patchi].whichFace(facei);
    
                values[probei] = vField.boundaryField()[patchi][localFacei];
    
            }
        }
    
        Pstream::listCombineGather(values, isNotEqOp<Type>());
        Pstream::listCombineScatter(values);
    
        return tValues;
    }
    
    
    template<class Type>
    
    Foam::patchProbes::sample(const word& fieldName) const
    {
        return sample
        (
    
            mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh>>
    
    template<class Type>
    
    Foam::patchProbes::sample
    (
        const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
    ) const
    {
        const Type unsetVal(-VGREAT*pTraits<Type>::one);
    
    
        (
            new Field<Type>(this->size(), unsetVal)
        );
    
    
        Field<Type>& values = tValues.ref();
    
    
        const polyBoundaryMesh& patches = mesh_.boundaryMesh();
    
    
        forAll(*this, probei)
    
                label patchi = patches.whichPatch(facei);
    
                label localFacei = patches[patchi].whichFace(facei);
    
                values[probei] = sField.boundaryField()[patchi][localFacei];
    
            }
        }
    
        Pstream::listCombineGather(values, isNotEqOp<Type>());
        Pstream::listCombineScatter(values);
    
        return tValues;
    }
    
    // ************************************************************************* //