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
77865d22
Commit
77865d22
authored
May 17, 2017
by
mattijs
Browse files
ENH: histogram: 1) if max is not provided use field max. 2) output count. Fixes
#467
.
parent
1889ea83
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/functionObjects/field/histogram/histogram.C
View file @
77865d22
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016
-2017
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -45,23 +45,31 @@ void Foam::functionObjects::histogram::writeGraph
(
const
coordSet
&
coords
,
const
word
&
fieldName
,
const
scalarField
&
values
const
scalarField
&
normalizedValues
,
const
scalarField
&
absoluteValues
)
const
{
const
wordList
fieldNames
(
1
,
fieldName
);
fileName
outputPath
=
baseTimeDir
();
mkDir
(
outputPath
);
OFstream
graphFile
(
outputPath
/
formatterPtr_
().
getFileName
(
coords
,
fieldNames
)
outputPath
/
formatterPtr_
().
getFileName
(
coords
,
wordList
(
1
,
fieldName
)
)
);
Log
<<
" Writing histogram of "
<<
fieldName
<<
" to "
<<
graphFile
.
name
()
<<
endl
;
List
<
const
scalarField
*>
yPtrs
(
1
);
yPtrs
[
0
]
=
&
values
;
wordList
fieldNames
(
2
);
fieldNames
[
0
]
=
fieldName
;
fieldNames
[
1
]
=
fieldName
+
"Count"
;
List
<
const
scalarField
*>
yPtrs
(
2
);
yPtrs
[
0
]
=
&
normalizedValues
;
yPtrs
[
1
]
=
&
absoluteValues
;
formatterPtr_
().
write
(
coords
,
fieldNames
,
yPtrs
,
graphFile
);
}
...
...
@@ -76,7 +84,9 @@ Foam::functionObjects::histogram::histogram
)
:
fvMeshFunctionObject
(
name
,
runTime
,
dict
),
writeFile
(
obr_
,
name
)
writeFile
(
obr_
,
name
),
max_
(
-
GREAT
),
min_
(
GREAT
)
{
read
(
dict
);
}
...
...
@@ -96,8 +106,9 @@ bool Foam::functionObjects::histogram::read(const dictionary& dict)
writeFile
::
read
(
dict
);
dict
.
lookup
(
"field"
)
>>
fieldName_
;
dict
.
lookup
(
"max"
)
>>
max_
;
min_
=
dict
.
lookupOrDefault
<
scalar
>
(
"min"
,
0
);
max_
=
dict
.
lookupOrDefault
<
scalar
>
(
"max"
,
-
GREAT
);
min_
=
dict
.
lookupOrDefault
<
scalar
>
(
"min"
,
GREAT
);
dict
.
lookup
(
"nBins"
)
>>
nBins_
;
word
format
(
dict
.
lookup
(
"setFormat"
));
...
...
@@ -149,38 +160,63 @@ bool Foam::functionObjects::histogram::write()
:
obr_
.
lookupObject
<
volScalarField
>
(
fieldName_
)
);
scalar
histMax
=
max_
;
scalar
histMin
=
min_
;
if
(
max_
==
-
GREAT
)
{
// Determine current min and max
histMax
=
max
(
field
).
value
();
if
(
min_
==
GREAT
)
{
histMin
=
min
(
field
).
value
();
}
Log
<<
" Determined histogram bounds from field"
<<
" min/max("
<<
fieldName_
<<
") = "
<<
histMin
<<
' '
<<
histMax
<<
endl
;
}
else
if
(
min_
==
GREAT
)
{
histMin
=
0
;
}
// Calculate the mid-points of bins for the graph axis
pointField
xBin
(
nBins_
);
const
scalar
delta
=
(
m
ax
_
-
m
in
_
)
/
nBins_
;
const
scalar
delta
=
(
histM
ax
-
histM
in
)
/
nBins_
;
scalar
x
=
m
in
_
+
0
.
5
*
delta
;
scalar
x
=
histM
in
+
0
.
5
*
delta
;
forAll
(
xBin
,
i
)
{
xBin
[
i
]
=
point
(
x
,
0
,
0
);
x
+=
delta
;
}
scalarField
data
(
nBins_
,
0
);
scalarField
dataNormalized
(
nBins_
,
0
);
labelField
dataCount
(
nBins_
,
0
);
const
scalarField
&
V
=
mesh_
.
V
();
forAll
(
field
,
celli
)
{
const
label
bini
=
(
field
[
celli
]
-
m
in
_
)
/
delta
;
const
label
bini
=
(
field
[
celli
]
-
histM
in
)
/
delta
;
if
(
bini
>=
0
&&
bini
<
nBins_
)
{
data
[
bini
]
+=
V
[
celli
];
dataNormalized
[
bini
]
+=
V
[
celli
];
dataCount
[
bini
]
++
;
}
}
Pstream
::
listCombineGather
(
data
,
plusEqOp
<
scalar
>
());
Pstream
::
listCombineGather
(
dataNormalized
,
plusEqOp
<
scalar
>
());
Pstream
::
listCombineGather
(
dataCount
,
plusEqOp
<
label
>
());
if
(
Pstream
::
master
())
{
const
scalar
sumData
=
sum
(
data
);
const
scalar
sumData
=
sum
(
data
Normalized
);
if
(
sumData
>
SMALL
)
{
data
/=
sumData
;
data
Normalized
/=
sumData
;
const
coordSet
coords
(
...
...
@@ -190,7 +226,15 @@ bool Foam::functionObjects::histogram::write()
mag
(
xBin
)
);
writeGraph
(
coords
,
fieldName_
,
data
);
// Convert count field from labelField to scalarField
scalarField
count
(
dataCount
.
size
());
forAll
(
count
,
i
)
{
count
[
i
]
=
1
.
0
*
dataCount
[
i
];
}
writeGraph
(
coords
,
fieldName_
,
dataNormalized
,
count
);
}
}
...
...
src/functionObjects/field/histogram/histogram.H
View file @
77865d22
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -53,7 +53,7 @@ Usage
type | type name: histogram | yes |
field | Field to analyse | yes |
nBins | Number of bins for the histogram | yes|
max | Maximum value sampled |
yes
|
max | Maximum value sampled |
no
|
field max
min | minimum value sampled | no | 0
setFormat | Output format | yes |
\endtable
...
...
@@ -115,7 +115,8 @@ class histogram
(
const
coordSet
&
coords
,
const
word
&
valueName
,
const
scalarField
&
values
const
scalarField
&
normalizedValues
,
const
scalarField
&
absoluteValues
)
const
;
//- Disallow default bitwise copy construct
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment