Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
d26b4ee4
Commit
d26b4ee4
authored
Nov 11, 2015
by
Andrew Heather
Browse files
ENH: fieldValues FOs updated following update to use functionObjectState
parent
40680a43
Changes
14
Hide whitespace changes
Inline
Side-by-side
src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
View file @
d26b4ee4
...
...
@@ -79,8 +79,6 @@ void Foam::fieldValues::cellSource::setCellZoneCells()
{
case
stCellZone
:
{
dict
().
lookup
(
"sourceName"
)
>>
sourceName_
;
label
zoneId
=
mesh
().
cellZones
().
findZoneID
(
sourceName_
);
if
(
zoneId
<
0
)
...
...
@@ -135,7 +133,8 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
WarningIn
(
"Foam::fieldValues::cellSource::initialise(const dictionary&)"
)
<<
type
()
<<
" "
<<
name_
<<
": "
)
<<
type
()
<<
" "
<<
name_
<<
": "
<<
sourceTypeNames_
[
source_
]
<<
"("
<<
sourceName_
<<
"):"
<<
nl
<<
" Source has no cells - deactivating"
<<
endl
;
...
...
@@ -145,44 +144,46 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
volume_
=
volume
();
Info
<<
type
()
<<
" "
<<
name_
<<
":"
<<
sourceTypeNames_
[
source_
]
<<
"("
<<
sourceName_
<<
"):"
<<
nl
<<
" total cells = "
<<
nCells_
<<
nl
<<
" total volume = "
<<
volume_
<<
nl
<<
endl
;
if
(
log_
)
{
Info
<<
type
()
<<
" "
<<
name_
<<
":"
<<
sourceTypeNames_
[
source_
]
<<
"("
<<
sourceName_
<<
"):"
<<
nl
<<
" total cells = "
<<
nCells_
<<
nl
<<
" total volume = "
<<
volume_
<<
nl
<<
endl
;
}
if
(
dict
.
readIfPresent
(
"weightField"
,
weightFieldName_
))
{
Info
<<
" weight field = "
<<
weightFieldName_
;
if
(
log_
)
Info
<<
" weight field = "
<<
weightFieldName_
;
}
Info
<<
nl
<<
endl
;
if
(
log_
)
Info
<<
nl
<<
endl
;
}
void
Foam
::
fieldValues
::
cellSource
::
writeFileHeader
(
const
label
i
)
void
Foam
::
fieldValues
::
cellSource
::
writeFileHeader
(
Ostream
&
os
)
const
{
write
Commented
(
file
(),
"Source : "
);
file
()
<<
sourceTypeNames_
[
source_
]
<<
" "
<<
sourceName_
<<
endl
;
write
Commented
(
file
(),
"Cells : "
);
file
()
<<
nCells_
<<
endl
;
write
Commented
(
file
(),
"Volume : "
);
file
()
<<
volume_
<<
endl
;
writeCommented
(
file
()
,
"Time"
);
write
HeaderValue
(
os
,
"Source"
,
sourceTypeNames_
[
source_
]
);
writeHeaderValue
(
os
,
"Name"
,
sourceName_
)
;
write
HeaderValue
(
os
,
"Cells"
,
nCells_
);
writeHeaderValue
(
os
,
"Volume"
,
volume_
)
;
write
HeaderValue
(
os
,
"Scale factor"
,
scaleFactor_
);
writeCommented
(
os
,
"Time"
);
if
(
writeVolume_
)
{
file
()
<<
tab
<<
"Volume"
;
os
<<
tab
<<
"Volume"
;
}
forAll
(
fields_
,
i
)
{
file
()
<<
tab
<<
operationTypeNames_
[
operation_
]
os
<<
tab
<<
operationTypeNames_
[
operation_
]
<<
"("
<<
fields_
[
i
]
<<
")"
;
}
file
()
<<
endl
;
os
<<
endl
;
}
...
...
@@ -204,7 +205,11 @@ Foam::fieldValues::cellSource::cellSource
weightFieldName_
(
"none"
),
writeVolume_
(
dict
.
lookupOrDefault
(
"writeVolume"
,
false
))
{
read
(
dict
);
if
(
active_
)
{
read
(
dict
);
writeFileHeader
(
file
());
}
}
...
...
@@ -218,11 +223,11 @@ Foam::fieldValues::cellSource::~cellSource()
void
Foam
::
fieldValues
::
cellSource
::
read
(
const
dictionary
&
dict
)
{
fieldValue
::
read
(
dict
);
if
(
active_
)
{
// no additional info to read
fieldValue
::
read
(
dict
);
// No additional info to read
initialise
(
dict
);
}
}
...
...
@@ -234,33 +239,34 @@ void Foam::fieldValues::cellSource::write()
if
(
active_
)
{
if
(
Pstream
::
master
())
file
()
<<
obr_
.
time
().
value
();
// Construct weight field. Note: zero size indicates unweighted
scalarField
weightField
;
if
(
weightFieldName_
!=
"none"
)
{
file
()
<<
obr_
.
time
().
value
(
);
weightField
=
setFieldValues
<
scalar
>
(
weightFieldName_
,
true
);
}
if
(
writeVolume_
)
{
volume_
=
volume
();
if
(
Pstream
::
master
())
{
file
()
<<
tab
<<
volume_
;
}
file
()
<<
tab
<<
volume_
;
if
(
log_
)
Info
<<
" total volume = "
<<
volume_
<<
endl
;
}
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
);
ok
=
ok
||
writeValues
<
scalar
>
(
fieldName
,
weightField
);
ok
=
ok
||
writeValues
<
vector
>
(
fieldName
,
weightField
);
ok
=
ok
||
writeValues
<
sphericalTensor
>
(
fieldName
,
weightField
);
ok
=
ok
||
writeValues
<
symmTensor
>
(
fieldName
,
weightField
);
ok
=
ok
||
writeValues
<
tensor
>
(
fieldName
,
weightField
);
if
(
!
processed
)
if
(
!
ok
)
{
WarningIn
(
"void Foam::fieldValues::cellSource::write()"
)
<<
"Requested field "
<<
fieldName
...
...
@@ -269,10 +275,7 @@ void Foam::fieldValues::cellSource::write()
}
}
if
(
Pstream
::
master
())
{
file
()
<<
endl
;
}
file
()
<<
endl
;
if
(
log_
)
Info
<<
endl
;
}
...
...
src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H
View file @
d26b4ee4
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -62,11 +62,11 @@ Description
log | Write data to standard output | no | no
valueOutput | Write the raw output values | yes |
writeVolume | Write the volume of the cellSource | no |
source |
c
ell source: see below | yes |
sourceName |
n
ame of cell source if required | no |
operation |
o
peration to perform | yes |
weightField |
n
ame of field to apply weighting | no |
fields |
l
ist of fields to operate on | yes |
source |
C
ell source: see below | yes |
sourceName |
N
ame of cell source if required | no |
operation |
O
peration to perform | yes |
weightField |
N
ame of field to apply weighting | no |
fields |
L
ist of fields to operate on | yes |
\endtable
\linebreak
...
...
@@ -228,7 +228,7 @@ protected:
)
const
;
//- Output file header information
virtual
void
writeFileHeader
(
const
label
i
)
;
virtual
void
writeFileHeader
(
Ostream
&
os
)
const
;
public:
...
...
@@ -272,7 +272,11 @@ public:
//- Templated helper function to output field values
template
<
class
Type
>
bool
writeValues
(
const
word
&
fieldName
);
bool
writeValues
(
const
word
&
fieldName
,
const
scalarField
&
weightField
);
//- Filter a field according to cellIds
template
<
class
Type
>
...
...
src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C
View file @
d26b4ee4
...
...
@@ -87,52 +87,65 @@ Type Foam::fieldValues::cellSource::processValues
{
case
opSum
:
{
result
=
s
um
(
values
);
result
=
gS
um
(
values
);
break
;
}
case
opSumMag
:
{
result
=
s
um
(
cmptMag
(
values
));
result
=
gS
um
(
cmptMag
(
values
));
break
;
}
case
opAverage
:
{
result
=
sum
(
values
)
/
values
.
size
();
label
n
=
returnReduce
(
values
.
size
(),
sumOp
<
label
>
());
result
=
gSum
(
values
)
/
(
scalar
(
n
)
+
ROOTVSMALL
);
break
;
}
case
opWeightedAverage
:
{
result
=
sum
(
weightField
*
values
)
/
sum
(
weightField
);
label
wSize
=
returnReduce
(
weightField
.
size
(),
sumOp
<
label
>
());
if
(
wSize
>
0
)
{
result
=
gSum
(
weightField
*
values
)
/
(
gSum
(
weightField
)
+
ROOTVSMALL
);
}
else
{
label
n
=
returnReduce
(
values
.
size
(),
sumOp
<
label
>
());
result
=
gSum
(
values
)
/
(
scalar
(
n
)
+
ROOTVSMALL
);
}
break
;
}
case
opVolAverage
:
{
result
=
s
um
(
V
*
values
)
/
sum
(
V
);
result
=
gS
um
(
values
*
V
)
/
(
gSum
(
V
)
+
ROOTVSMALL
);
break
;
}
case
opWeightedVolAverage
:
{
result
=
s
um
(
weightField
*
V
*
values
)
/
s
um
(
weightField
*
V
);
result
=
gS
um
(
weightField
*
V
*
values
)
/
gS
um
(
weightField
*
V
);
break
;
}
case
opVolIntegrate
:
{
result
=
s
um
(
V
*
values
);
result
=
gS
um
(
V
*
values
);
break
;
}
case
opMin
:
{
result
=
m
in
(
values
);
result
=
gM
in
(
values
);
break
;
}
case
opMax
:
{
result
=
m
ax
(
values
);
result
=
gM
ax
(
values
);
break
;
}
case
opCoV
:
{
Type
meanValue
=
sum
(
values
*
V
)
/
sum
(
V
);
const
scalar
sumV
=
gSum
(
V
);
Type
meanValue
=
gSum
(
V
*
values
)
/
sumV
;
const
label
nComp
=
pTraits
<
Type
>::
nComponents
;
...
...
@@ -142,7 +155,7 @@ Type Foam::fieldValues::cellSource::processValues
scalar
mean
=
component
(
meanValue
,
d
);
scalar
&
res
=
setComponent
(
result
,
d
);
res
=
sqrt
(
s
um
(
V
*
sqr
(
vals
-
mean
))
/
sum
(
V
)
)
/
mean
;
res
=
sqrt
(
gS
um
(
V
*
sqr
(
vals
-
mean
))
/
sum
V
)
/
(
mean
+
ROOTVSMALL
)
;
}
break
;
...
...
@@ -160,7 +173,11 @@ Type Foam::fieldValues::cellSource::processValues
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class
Type
>
bool
Foam
::
fieldValues
::
cellSource
::
writeValues
(
const
word
&
fieldName
)
bool
Foam
::
fieldValues
::
cellSource
::
writeValues
(
const
word
&
fieldName
,
const
scalarField
&
weightField
)
{
const
bool
ok
=
validField
<
Type
>
(
fieldName
);
...
...
@@ -168,26 +185,13 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
{
Field
<
Type
>
values
(
setFieldValues
<
Type
>
(
fieldName
));
scalarField
V
(
filterField
(
mesh
().
V
()));
scalarField
weightField
(
values
.
size
(),
1
.
0
);
if
(
weightFieldName_
!=
"none"
)
if
(
valueOutput_
)
{
weightField
=
setFieldValues
<
scalar
>
(
weightFieldName_
,
true
);
}
// Combine onto master
combineFields
(
values
);
combineFields
(
V
);
combineFields
(
weightField
);
if
(
Pstream
::
master
())
{
Type
result
=
processValues
(
values
,
V
,
weightField
);
// Add to result dictionary, over-writing any previous entry
resultDict_
.
add
(
fieldName
,
result
,
true
);
Field
<
Type
>
allValues
(
values
);
combineFields
(
allValues
);
if
(
valueOutput_
)
if
(
Pstream
::
master
()
)
{
IOField
<
Type
>
(
...
...
@@ -200,17 +204,29 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
IOobject
::
NO_READ
,
IOobject
::
NO_WRITE
),
weightField
*
v
alues
allV
alues
).
write
();
}
}
// Apply scale factor
values
*=
scaleFactor_
;
Type
result
=
processValues
(
values
,
V
,
weightField
);
file
()
<<
tab
<<
result
;
file
()
<<
tab
<<
result
;
if
(
log_
)
Info
<<
" "
<<
operationTypeNames_
[
operation_
]
if
(
log_
)
{
Info
<<
" "
<<
operationTypeNames_
[
operation_
]
<<
"("
<<
sourceName_
<<
") of "
<<
fieldName
<<
" = "
<<
result
<<
endl
;
}
// write state/results information
const
word
&
opName
=
operationTypeNames_
[
operation_
];
word
resultName
=
opName
+
'('
+
sourceName_
+
','
+
fieldName
+
')'
;
this
->
setResult
(
resultName
,
result
);
}
return
ok
;
...
...
src/postProcessing/functionObjects/field/fieldValues/controlDict
View file @
d26b4ee4
...
...
@@ -60,10 +60,13 @@ functions
// Output field values as well
valueOutput true;
// Output format for field values
surfaceFormat vtk;
// Type of source: patch/faceZone/sampledSurface
source patch;
//
i
f patch or faceZone: name of patch or faceZone
//
I
f patch or faceZone: name of patch or faceZone
sourceName movingWall;
//// if sampledSurface: dictionary with a sampledSurface
...
...
@@ -96,6 +99,7 @@ functions
outputControl outputTime;
log true;
valueOutput true;
surfaceFormat vtk;
source faceZone;
sourceName f0;
operation sum;
...
...
src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C
View file @
d26b4ee4
...
...
@@ -352,7 +352,7 @@ void Foam::fieldValues::faceSource::combineSurfaceGeometry
if
(
Pstream
::
parRun
())
{
//
d
imension as fraction of mesh bounding box
//
D
imension as fraction of mesh bounding box
scalar
mergeDim
=
1e-10
*
mesh
().
bounds
().
mag
();
labelList
pointsMap
;
...
...
@@ -400,8 +400,6 @@ Foam::scalar Foam::fieldValues::faceSource::totalArea() const
void
Foam
::
fieldValues
::
faceSource
::
initialise
(
const
dictionary
&
dict
)
{
dict
.
lookup
(
"sourceName"
)
>>
sourceName_
;
switch
(
source_
)
{
case
stFaceZone
:
...
...
@@ -450,15 +448,14 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
totalArea_
=
totalArea
();
Info
<<
type
()
<<
" "
<<
name_
<<
":"
<<
nl
<<
" total faces = "
<<
nFaces_
<<
nl
<<
" total area = "
<<
totalArea_
<<
nl
;
if
(
log_
)
Info
<<
type
()
<<
" "
<<
name_
<<
":"
<<
nl
<<
" total faces = "
<<
nFaces_
<<
nl
<<
" total area = "
<<
totalArea_
<<
nl
;
if
(
dict
.
readIfPresent
(
"weightField"
,
weightFieldName_
))
{
Info
<<
" weight field = "
<<
weightFieldName_
<<
nl
;
if
(
log_
)
Info
<<
" weight field = "
<<
weightFieldName_
<<
nl
;
if
(
source_
==
stSampledSurface
)
{
...
...
@@ -480,7 +477,7 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
if
(
weightFieldName_
==
"none"
)
{
dict
.
lookup
(
"orientedWeightField"
)
>>
weightFieldName_
;
Info
<<
" weight field = "
<<
weightFieldName_
<<
nl
;
if
(
log_
)
Info
<<
" weight field = "
<<
weightFieldName_
<<
nl
;
orientWeightField_
=
true
;
}
else
...
...
@@ -506,12 +503,7 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
fields_
.
append
(
orientedFields
);
}
if
(
dict
.
readIfPresent
(
"scaleFactor"
,
scaleFactor_
))
{
Info
<<
" scale factor = "
<<
scaleFactor_
<<
nl
;
}
Info
<<
nl
<<
endl
;
if
(
log_
)
Info
<<
nl
<<
endl
;
if
(
valueOutput_
)
{
...
...
@@ -530,29 +522,27 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
}
void
Foam
::
fieldValues
::
faceSource
::
writeFileHeader
(
const
label
i
)
void
Foam
::
fieldValues
::
faceSource
::
writeFileHeader
(
Ostream
&
os
)
const
{
writeCommented
(
file
(),
"Source : "
);
file
()
<<
sourceTypeNames_
[
source_
]
<<
" "
<<
sourceName_
<<
endl
;
writeCommented
(
file
(),
"Faces : "
);
file
()
<<
nFaces_
<<
endl
;
writeCommented
(
file
(),
"Area : "
);
file
()
<<
totalArea_
<<
endl
;
writeCommented
(
file
(),
"Time"
);
writeHeaderValue
(
os
,
"Source"
,
sourceTypeNames_
[
source_
]);
writeHeaderValue
(
os
,
"Name"
,
sourceName_
);
writeHeaderValue
(
os
,
"Faces"
,
nFaces_
);
writeHeaderValue
(
os
,
"Total area"
,
totalArea_
);
writeHeaderValue
(
os
,
"Scale factor"
,
scaleFactor_
);
writeCommented
(
os
,
"Time"
);
if
(
writeArea_
)
{
file
()
<<
tab
<<
"Area"
;
os
<<
tab
<<
"Area"
;
}
forAll
(
fields_
,
i
)
{
file
()
<<
tab
<<
operationTypeNames_
[
operation_
]
os
<<
tab
<<
operationTypeNames_
[
operation_
]
<<
"("
<<
fields_
[
i
]
<<
")"
;
}
file
()
<<
endl
;
os
<<
endl
;
}
...
...
@@ -569,14 +559,14 @@ Foam::scalar Foam::fieldValues::faceSource::processValues
case
opSumDirection
:
{
vector
n
(
dict_
.
lookup
(
"direction"
));
return
s
um
(
pos
(
values
*
(
Sf
&
n
))
*
mag
(
values
));
return
gS
um
(
pos
(
values
*
(
Sf
&
n
))
*
mag
(
values
));
}
case
opSumDirectionBalance
:
{
vector
n
(
dict_
.
lookup
(
"direction"
));
const
scalarField
nv
(
values
*
(
Sf
&
n
));
return
s
um
(
pos
(
nv
)
*
mag
(
values
)
-
neg
(
nv
)
*
mag
(
values
));
return
gS
um
(
pos
(
nv
)
*
mag
(
values
)
-
neg
(
nv
)
*
mag
(
values
));
}
default:
{
...
...
@@ -603,7 +593,7 @@ Foam::vector Foam::fieldValues::faceSource::processValues
n
/=
mag
(
n
)
+
ROOTVSMALL
;
const
scalarField
nv
(
n
&
values
);
return
s
um
(
pos
(
nv
)
*
n
*
(
nv
));
return
gS
um
(
pos
(
nv
)
*
n
*
(
nv
));
}
case
opSumDirectionBalance
:
{
...
...
@@ -611,16 +601,16 @@ Foam::vector Foam::fieldValues::faceSource::processValues
n
/=
mag
(
n
)
+
ROOTVSMALL
;
const
scalarField
nv
(
n
&
values
);
return
s
um
(
pos
(
nv
)
*
n
*
(
nv
));
return
gS
um
(
pos
(
nv
)
*
n
*
(
nv
));
}
case
opAreaNormalAverage
:
{
scalar
result
=
s
um
(
values
&
Sf
)
/
s
um
(
mag
(
Sf
));
scalar
result
=
gS
um
(
values
&
Sf
)
/
gS
um
(
mag
(
Sf
));
return
vector
(
result
,
0
.
0
,
0
.
0
);
}
case
opAreaNormalIntegrate
:
{
scalar
result
=
s
um
(
values
&
Sf
);
scalar
result
=
gS
um
(
values
&
Sf
);
return
vector
(
result
,
0
.
0
,
0
.
0
);
}
default:
...
...
@@ -649,14 +639,17 @@ Foam::fieldValues::faceSource::faceSource
weightFieldName_
(
"none"
),
orientWeightField_
(
false
),
orientedFieldsStart_
(
labelMax
),
scaleFactor_
(
1
.
0
),
writeArea_
(
dict
.
lookupOrDefault
(
"writeArea"
,
false
)),
nFaces_
(
0
),
faceId_
(),
facePatchId_
(),
faceSign_
()
{
read
(
dict
);
if
(
active_
)
{
read
(
dict
);
writeFileHeader
(
file
());
}
}
...
...
@@ -670,10 +663,11 @@ Foam::fieldValues::faceSource::~faceSource()
void
Foam
::
fieldValues
::
faceSource
::
read
(
const
dictionary
&
dict
)
{
fieldValue
::
read
(
dict
);
if
(
active_
)
{
fieldValue
::
read
(
dict
);