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