Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
Henry Weller
committed
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 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 "probes.H"
#include "volFields.H"
andy
committed
#include "interpolation.H"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class T>
class isNotEqOp
{
public:
void operator()(T& x, const T& y) const
{
const T unsetVal(-VGREAT*pTraits<T>::one);
if (x != unsetVal)
{
// Keep x.
// Note:chould check for y != unsetVal but multiple sample cells
// already handled in read().
}
else
{
// x is not set. y might be.
x = y;
}
}
};
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::probes::sampleAndWrite
(
const GeometricField<Type, fvPatchField, volMesh>& vField
)
{
Field<Type> values(sample(vField));
if (Pstream::master())
{
unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& os = *probeFilePtrs_[vField.name()];
Andrew Heather
committed
os << setw(w) << vField.time().timeOutputValue();
if (includeOutOfBounds_ || processor_[probei] != -1)
{
os << ' ' << setw(w) << values[probei];
}
void Foam::probes::sampleAndWrite
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
Field<Type> values(sample(sField));
if (Pstream::master())
{
unsigned int w = IOstream::defaultPrecision() + 7;
OFstream& os = *probeFilePtrs_[sField.name()];
Andrew Heather
committed
os << setw(w) << sField.time().timeOutputValue();
if (includeOutOfBounds_ || processor_[probei] != -1)
{
os << ' ' << setw(w) << values[probei];
}
}
os << endl;
}
}
void Foam::probes::sampleAndWrite(const fieldGroup<Type>& fields)
{
if (loadFromFiles_)
{
sampleAndWrite
(
GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
)
);
}
else
{
objectRegistry::const_iterator iter = mesh_.find(fields[fieldi]);
&& iter()->type()
== GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
sampleAndWrite
(
Henry Weller
committed
<GeometricField<Type, fvPatchField, volMesh>>
)
);
}
}
}
}
template<class Type>
void Foam::probes::sampleAndWriteSurfaceFields(const fieldGroup<Type>& fields)
{
{
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
Henry Weller
committed
<GeometricField<Type, fvsPatchField, surfaceMesh>>
)
);
}
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Henry Weller
committed
Foam::tmp<Foam::Field<Type>>
Foam::probes::sample
(
const GeometricField<Type, fvPatchField, volMesh>& vField
) const
{
const Type unsetVal(-VGREAT*pTraits<Type>::one);
Henry Weller
committed
tmp<Field<Type>> tValues
new Field<Type>(this->size(), unsetVal)
Field<Type>& values = tValues.ref();
andy
committed
if (fixedLocations_)
Henry Weller
committed
autoPtr<interpolation<Type>> interpolator
andy
committed
(
interpolation<Type>::New(interpolationScheme_, vField)
);
andy
committed
{
andy
committed
{
const vector& position = operator[](probei);
andy
committed
values[probei] = interpolator().interpolate
andy
committed
(
position,
andy
committed
-1
);
}
}
}
else
{
andy
committed
{
values[probei] = vField[elementList_[probei]];
andy
committed
}
}
}
Pstream::listCombineGather(values, isNotEqOp<Type>());
Pstream::listCombineScatter(values);
return tValues;
}
template<class Type>
Henry Weller
committed
Foam::tmp<Foam::Field<Type>>
Foam::probes::sample(const word& fieldName) const
{
return sample
(
Henry Weller
committed
mesh_.lookupObject<GeometricField<Type, fvPatchField, volMesh>>
(
fieldName
)
);
}
Henry Weller
committed
Foam::tmp<Foam::Field<Type>>
Foam::probes::sample
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& sField
) const
{
const Type unsetVal(-VGREAT*pTraits<Type>::one);
Henry Weller
committed
tmp<Field<Type>> tValues
(
new Field<Type>(this->size(), unsetVal)
);
Field<Type>& values = tValues.ref();
values[probei] = sField[faceList_[probei]];
}
}
Pstream::listCombineGather(values, isNotEqOp<Type>());
Pstream::listCombineScatter(values);
return tValues;
}
template<class Type>
Henry Weller
committed
Foam::tmp<Foam::Field<Type>>
Foam::probes::sampleSurfaceFields(const word& fieldName) const
{
return sample
(
Henry Weller
committed
mesh_.lookupObject<GeometricField<Type, fvsPatchField, surfaceMesh>>
(
fieldName
)
);
}
// ************************************************************************* //