mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: faceSource - corrections for oriented fields
This commit is contained in:
@ -99,11 +99,10 @@ void Foam::fieldValues::faceSource::setFaceZoneFaces()
|
||||
|
||||
const faceZone& fZone = mesh().faceZones()[zoneId];
|
||||
|
||||
faceId_.setSize(fZone.size());
|
||||
facePatchId_.setSize(fZone.size());
|
||||
faceSign_.setSize(fZone.size());
|
||||
DynamicList<label> faceIds(fZone.size());
|
||||
DynamicList<label> facePatchIds(fZone.size());
|
||||
DynamicList<label> faceSigns(fZone.size());
|
||||
|
||||
label count = 0;
|
||||
forAll(fZone, i)
|
||||
{
|
||||
label faceI = fZone[i];
|
||||
@ -145,27 +144,26 @@ void Foam::fieldValues::faceSource::setFaceZoneFaces()
|
||||
{
|
||||
if (fZone.flipMap()[i])
|
||||
{
|
||||
faceSign_[count] = -1;
|
||||
faceSigns.append(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
faceSign_[count] = 1;
|
||||
faceSigns.append(1);
|
||||
}
|
||||
faceId_[count] = faceId;
|
||||
facePatchId_[count] = facePatchId;
|
||||
count++;
|
||||
faceIds.append(faceId);
|
||||
facePatchIds.append(facePatchId);
|
||||
}
|
||||
}
|
||||
|
||||
faceId_.setSize(count);
|
||||
facePatchId_.setSize(count);
|
||||
faceSign_.setSize(count);
|
||||
faceId_.transfer(faceIds);
|
||||
facePatchId_.transfer(facePatchIds);
|
||||
faceSign_.transfer(faceSigns);
|
||||
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "Original face zone size = " << fZone.size()
|
||||
<< ", new size = " << count << endl;
|
||||
<< ", new size = " << faceId_.size() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,12 +443,43 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
|
||||
|
||||
if (dict.readIfPresent("weightField", weightFieldName_))
|
||||
{
|
||||
Info<< " weight field = " << weightFieldName_;
|
||||
Info<< " weight field = " << weightFieldName_ << nl;
|
||||
}
|
||||
|
||||
if (dict.found("orientedWeightField"))
|
||||
{
|
||||
if (weightFieldName_ == "none")
|
||||
{
|
||||
dict.lookup("orientedWeightField") >> weightFieldName_;
|
||||
Info<< " weight field = " << weightFieldName_ << nl;
|
||||
orientWeightField_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::fieldValues::faceSource::initialise"
|
||||
"("
|
||||
"const dictionary&"
|
||||
")",
|
||||
dict
|
||||
)
|
||||
<< "Either weightField or orientedWeightField can be supplied, "
|
||||
<< "but not both"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
List<word> orientedFields;
|
||||
if (dict.readIfPresent("orientedFields", orientedFields))
|
||||
{
|
||||
orientedFieldsStart_ = fields_.size();
|
||||
fields_.append(orientedFields);
|
||||
}
|
||||
|
||||
if (dict.readIfPresent("scaleFactor", scaleFactor_))
|
||||
{
|
||||
Info<< " scale factor = " << scaleFactor_;
|
||||
Info<< " scale factor = " << scaleFactor_ << nl;
|
||||
}
|
||||
|
||||
Info<< nl << endl;
|
||||
@ -581,6 +610,8 @@ Foam::fieldValues::faceSource::faceSource
|
||||
source_(sourceTypeNames_.read(dict.lookup("source"))),
|
||||
operation_(operationTypeNames_.read(dict.lookup("operation"))),
|
||||
weightFieldName_("none"),
|
||||
orientWeightField_(false),
|
||||
orientedFieldsStart_(labelMax),
|
||||
scaleFactor_(1.0),
|
||||
nFaces_(0),
|
||||
faceId_(),
|
||||
@ -628,24 +659,42 @@ void Foam::fieldValues::faceSource::write()
|
||||
totalArea = gSum(filterField(mesh().magSf(), false));
|
||||
}
|
||||
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
file() << obr_.time().value() << tab << totalArea;
|
||||
}
|
||||
|
||||
// construct weight field
|
||||
scalarField weightField(faceId_.size(), 1.0);
|
||||
if (weightFieldName_ != "none")
|
||||
{
|
||||
weightField =
|
||||
getFieldValues<scalar>
|
||||
(
|
||||
weightFieldName_,
|
||||
true,
|
||||
orientWeightField_
|
||||
);
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
combineFields(weightField);
|
||||
|
||||
// process the fields
|
||||
forAll(fields_, i)
|
||||
{
|
||||
const word& fieldName = fields_[i];
|
||||
bool processed = false;
|
||||
bool ok = false;
|
||||
|
||||
processed = processed || writeValues<scalar>(fieldName);
|
||||
processed = processed || writeValues<vector>(fieldName);
|
||||
processed = processed || writeValues<sphericalTensor>(fieldName);
|
||||
processed = processed || writeValues<symmTensor>(fieldName);
|
||||
processed = processed || writeValues<tensor>(fieldName);
|
||||
bool orient = i >= orientedFieldsStart_;
|
||||
ok = ok || writeValues<scalar>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<vector>(fieldName, weightField, orient);
|
||||
ok = ok
|
||||
|| writeValues<sphericalTensor>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<symmTensor>(fieldName, weightField, orient);
|
||||
ok = ok || writeValues<tensor>(fieldName, weightField, orient);
|
||||
|
||||
if (!processed)
|
||||
if (!ok)
|
||||
{
|
||||
WarningIn("void Foam::fieldValues::faceSource::write()")
|
||||
<< "Requested field " << fieldName
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -71,8 +71,10 @@ Description
|
||||
sourceName | name of face source if required | no |
|
||||
operation | operation to perform | yes |
|
||||
weightField | name of field to apply weighting | no |
|
||||
orientedWeightField | name of oriented field to apply weighting | no |
|
||||
scaleFactor | scale factor | no | 1
|
||||
fields | list of fields to operate on | yes |
|
||||
orientedFields | list of oriented fields to operate on | no |
|
||||
\endtable
|
||||
|
||||
\linebreak
|
||||
@ -109,8 +111,8 @@ Note
|
||||
- faces on empty patches get ignored
|
||||
- if the field is a volField the \c faceZone can only consist of boundary
|
||||
faces
|
||||
- all fields are oriented according to the \c faceZone (so you might
|
||||
e.g. see negative pressure)
|
||||
- the `oriented' entries relate to mesh-oriented fields, such as the
|
||||
flux, phi. These fields will be oriented according to the face normals.
|
||||
- using \c sampledSurfaces:
|
||||
- not available for surface fields
|
||||
- if interpolate=true they use \c interpolationCellPoint
|
||||
@ -128,6 +130,7 @@ SeeAlso
|
||||
|
||||
SourceFiles
|
||||
faceSource.C
|
||||
faceSourceTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -242,6 +245,12 @@ protected:
|
||||
//- Weight field name - optional
|
||||
word weightFieldName_;
|
||||
|
||||
//- Flag to indicate if flipMap should be applied to the weight field
|
||||
bool orientWeightField_;
|
||||
|
||||
//- Start index of fields that require application of flipMap
|
||||
label orientedFieldsStart_;
|
||||
|
||||
//- Scale factor - optional
|
||||
scalar scaleFactor_;
|
||||
|
||||
@ -282,7 +291,8 @@ protected:
|
||||
tmp<Field<Type> > getFieldValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const bool mustGet = false
|
||||
const bool mustGet = false,
|
||||
const bool applyOrientation = false
|
||||
) const;
|
||||
|
||||
//- Apply the 'operation' to the values. Operation has to
|
||||
@ -356,7 +366,12 @@ public:
|
||||
|
||||
//- Templated helper function to output field values
|
||||
template<class Type>
|
||||
bool writeValues(const word& fieldName);
|
||||
bool writeValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalarField& weightField,
|
||||
const bool orient
|
||||
);
|
||||
|
||||
//- Filter a surface field according to faceIds
|
||||
template<class Type>
|
||||
|
||||
@ -54,7 +54,8 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const bool mustGet
|
||||
const bool mustGet,
|
||||
const bool applyOrientation
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
|
||||
@ -62,7 +63,7 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
|
||||
|
||||
if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
|
||||
{
|
||||
return filterField(obr_.lookupObject<sf>(fieldName), true);
|
||||
return filterField(obr_.lookupObject<sf>(fieldName), applyOrientation);
|
||||
}
|
||||
else if (obr_.foundObject<vf>(fieldName))
|
||||
{
|
||||
@ -103,7 +104,7 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
|
||||
}
|
||||
else
|
||||
{
|
||||
return filterField(fld, true);
|
||||
return filterField(fld, applyOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +116,7 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
|
||||
"Foam::fieldValues::faceSource::getFieldValues"
|
||||
"("
|
||||
"const word&, "
|
||||
"const bool, "
|
||||
"const bool"
|
||||
") const"
|
||||
) << "Field " << fieldName << " not found in database"
|
||||
@ -267,22 +269,20 @@ Type Foam::fieldValues::faceSource::processValues
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
|
||||
bool Foam::fieldValues::faceSource::writeValues
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalarField& weightField,
|
||||
const bool orient
|
||||
)
|
||||
{
|
||||
const bool ok = validField<Type>(fieldName);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Field<Type> values(getFieldValues<Type>(fieldName));
|
||||
scalarField weightField(values.size(), 1.0);
|
||||
|
||||
if (weightFieldName_ != "none")
|
||||
{
|
||||
weightField = getFieldValues<scalar>(weightFieldName_, true);
|
||||
}
|
||||
Field<Type> values(getFieldValues<Type>(fieldName, true, orient));
|
||||
|
||||
vectorField Sf;
|
||||
|
||||
if (surfacePtr_.valid())
|
||||
{
|
||||
// Get oriented Sf
|
||||
@ -291,13 +291,12 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
|
||||
else
|
||||
{
|
||||
// Get oriented Sf
|
||||
Sf = filterField(mesh().Sf(), false);
|
||||
Sf = filterField(mesh().Sf(), true);
|
||||
}
|
||||
|
||||
// Combine onto master
|
||||
combineFields(values);
|
||||
combineFields(Sf);
|
||||
combineFields(weightField);
|
||||
|
||||
// Write raw values on surface if specified
|
||||
if (surfaceWriterPtr_.valid())
|
||||
@ -378,7 +377,8 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
|
||||
(
|
||||
"fieldValues::faceSource::filterField"
|
||||
"("
|
||||
"const GeometricField<Type, fvPatchField, volMesh>&"
|
||||
"const GeometricField<Type, fvPatchField, volMesh>&, "
|
||||
"const bool"
|
||||
") const"
|
||||
) << type() << " " << name_ << ": "
|
||||
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
|
||||
|
||||
Reference in New Issue
Block a user