Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
4b8e8e3e
Commit
4b8e8e3e
authored
Jan 13, 2009
by
Andrew Heather
Browse files
adding basic add functionality
parent
c1a32fa8
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/postProcessing/foamCalcFunctions/Make/files
View file @
4b8e8e3e
...
...
@@ -8,4 +8,6 @@ field/magGrad/magGrad.C
field/div/div.C
field/randomise/randomise.C
basic/add/add.C
LIB = $(FOAM_LIBBIN)/libfoamCalcFunctions
src/postProcessing/foamCalcFunctions/basic/add/add.C
0 → 100644
View file @
4b8e8e3e
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "add.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace
Foam
{
namespace
calcTypes
{
defineTypeNameAndDebug
(
add
,
0
);
addToRunTimeSelectionTable
(
calcType
,
add
,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void
Foam
::
calcTypes
::
add
::
writeAddFields
(
const
Time
&
runTime
,
const
fvMesh
&
mesh
,
const
IOobject
&
baseFieldHeader
)
{
bool
processed
=
false
;
IOobject
addFieldHeader
(
addFieldName_
,
runTime
.
timeName
(),
mesh
,
IOobject
::
MUST_READ
);
if
(
addFieldHeader
.
headerOk
())
{
writeAddField
<
scalar
>
(
baseFieldHeader
,
addFieldHeader
,
mesh
,
processed
);
writeAddField
<
vector
>
(
baseFieldHeader
,
addFieldHeader
,
mesh
,
processed
);
writeAddField
<
sphericalTensor
>
(
baseFieldHeader
,
addFieldHeader
,
mesh
,
processed
);
writeAddField
<
symmTensor
>
(
baseFieldHeader
,
addFieldHeader
,
mesh
,
processed
);
writeAddField
<
tensor
>
(
baseFieldHeader
,
addFieldHeader
,
mesh
,
processed
);
if
(
!
processed
)
{
FatalError
<<
"Unable to process "
<<
baseFieldName_
<<
" + "
<<
addFieldName_
<<
nl
<<
"No call to add for fields of type "
<<
baseFieldHeader
.
headerClassName
()
<<
" + "
<<
addFieldHeader
.
headerClassName
()
<<
nl
<<
nl
<<
exit
(
FatalError
);
}
}
else
{
FatalErrorIn
(
"calcTypes::add::writeAddFields()"
)
<<
"Unable to read add field: "
<<
addFieldName_
<<
nl
<<
exit
(
FatalError
);
}
}
void
Foam
::
calcTypes
::
add
::
writeAddValues
(
const
Time
&
runTime
,
const
fvMesh
&
mesh
,
const
IOobject
&
baseFieldHeader
)
{
bool
processed
=
false
;
writeAddValue
<
scalar
>
(
baseFieldHeader
,
addValueStr_
,
mesh
,
processed
);
writeAddValue
<
vector
>
(
baseFieldHeader
,
addValueStr_
,
mesh
,
processed
);
writeAddValue
<
sphericalTensor
>
(
baseFieldHeader
,
addValueStr_
,
mesh
,
processed
);
writeAddValue
<
symmTensor
>
(
baseFieldHeader
,
addValueStr_
,
mesh
,
processed
);
writeAddValue
<
tensor
>
(
baseFieldHeader
,
addValueStr_
,
mesh
,
processed
);
if
(
!
processed
)
{
FatalErrorIn
(
"calcTypes::add::writeAddValues()"
)
<<
"Unable to process "
<<
baseFieldName_
<<
" + "
<<
addValueStr_
<<
nl
<<
"No call to add for fields of type "
<<
baseFieldHeader
.
headerClassName
()
<<
nl
<<
nl
<<
exit
(
FatalError
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
calcTypes
::
add
::
add
()
:
calcType
(),
baseFieldName_
(
""
),
calcType_
(
FIELD
),
addFieldName_
(
""
),
addValueStr_
(
""
),
resultName_
(
""
)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam
::
calcTypes
::
add
::~
add
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void
Foam
::
calcTypes
::
add
::
init
()
{
argList
::
validArgs
.
append
(
"add"
);
argList
::
validArgs
.
append
(
"baseField"
);
argList
::
validOptions
.
insert
(
"field"
,
"fieldName"
);
argList
::
validOptions
.
insert
(
"value"
,
"valueString"
);
argList
::
validOptions
.
insert
(
"resultName"
,
"fieldName"
);
}
void
Foam
::
calcTypes
::
add
::
preCalc
(
const
argList
&
args
,
const
Time
&
runTime
,
const
fvMesh
&
mesh
)
{
baseFieldName_
=
args
.
additionalArgs
()[
1
];
if
(
args
.
options
().
found
(
"field"
))
{
addFieldName_
=
args
.
options
()[
"field"
];
calcType_
=
FIELD
;
}
else
if
(
args
.
options
().
found
(
"value"
))
{
addValueStr_
=
args
.
options
()[
"value"
];
calcType_
=
VALUE
;
}
else
{
FatalErrorIn
(
"calcTypes::add::preCalc"
)
<<
"add requires either -field or -value option"
<<
nl
<<
exit
(
FatalError
);
}
if
(
args
.
options
().
found
(
"resultName"
))
{
resultName_
=
args
.
options
()[
"resultName"
];
}
}
void
Foam
::
calcTypes
::
add
::
calc
(
const
argList
&
args
,
const
Time
&
runTime
,
const
fvMesh
&
mesh
)
{
IOobject
baseFieldHeader
(
baseFieldName_
,
runTime
.
timeName
(),
mesh
,
IOobject
::
MUST_READ
);
if
(
baseFieldHeader
.
headerOk
())
{
switch
(
calcType_
)
{
case
FIELD
:
{
writeAddFields
(
runTime
,
mesh
,
baseFieldHeader
);
break
;
}
case
VALUE
:
{
writeAddValues
(
runTime
,
mesh
,
baseFieldHeader
);
break
;
}
default:
{
FatalErrorIn
(
"calcTypes::add::calc"
)
<<
"unknown calcType "
<<
calcType_
<<
nl
<<
abort
(
FatalError
);
}
}
}
else
{
FatalErrorIn
(
"calcTypes::add::calc"
)
<<
"Unable to read base field: "
<<
baseFieldName_
<<
nl
<<
exit
(
FatalError
);
}
}
// ************************************************************************* //
src/postProcessing/foamCalcFunctions/basic/add/add.H
0 → 100644
View file @
4b8e8e3e
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::calcTypes::add
Description
Adds and field or value to base field.
New field name specified by -resultName option, or automatically as:
<baseFieldName>_plus_<addFieldName>
<baseFieldName>_plus_value
Example usage:
add p -value 100000 -resultName pAbs
add U -field U0
SourceFiles
add.C
writeAddField.C
writeAddValue.C
\*---------------------------------------------------------------------------*/
#ifndef add_H
#define add_H
#include "calcType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace
Foam
{
namespace
calcTypes
{
/*---------------------------------------------------------------------------*\
Class add Declaration
\*---------------------------------------------------------------------------*/
class
add
:
public
calcType
{
public:
enum
calcTypes
{
FIELD
,
VALUE
};
private:
// Private data
//- Name of base field (to add to)
word
baseFieldName_
;
//- Calc type as given by enumerations above
calcTypes
calcType_
;
//- Name of field to add
word
addFieldName_
;
//- String representation of value to add
string
addValueStr_
;
//- Name of result field
word
resultName_
;
// Private Member Functions
// Output
//- Calc and output field additions
void
writeAddFields
(
const
Time
&
runTime
,
const
fvMesh
&
mesh
,
const
IOobject
&
baseFieldHeader
);
//- Calc and output field and value additions
void
writeAddValues
(
const
Time
&
runTime
,
const
fvMesh
&
mesh
,
const
IOobject
&
baseFieldHeader
);
//- Disallow default bitwise copy construct
add
(
const
add
&
);
//- Disallow default bitwise assignment
void
operator
=
(
const
add
&
);
protected:
// Member Functions
// Calculation routines
//- Initialise - typically setting static variables,
// e.g. command line arguments
virtual
void
init
();
//- Pre-time loop calculations
virtual
void
preCalc
(
const
argList
&
args
,
const
Time
&
runTime
,
const
fvMesh
&
mesh
);
//- Time loop calculations
virtual
void
calc
(
const
argList
&
args
,
const
Time
&
runTime
,
const
fvMesh
&
mesh
);
// I-O
//- Write add field
template
<
class
Type
>
void
writeAddField
(
const
IOobject
&
baseHeader
,
const
IOobject
&
addHeader
,
const
fvMesh
&
mesh
,
bool
&
processed
);
//- Write add value
template
<
class
Type
>
void
writeAddValue
(
const
IOobject
&
baseHeader
,
const
string
&
valueStr
,
const
fvMesh
&
mesh
,
bool
&
processed
);
public:
//- Runtime type information
TypeName
(
"add"
);
// Constructors
//- Construct null
add
();
// Destructor
virtual
~
add
();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace calcTypes
}
// End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "writeAddField.C"
# include "writeAddValue.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
src/postProcessing/foamCalcFunctions/basic/add/writeAddField.C
0 → 100644
View file @
4b8e8e3e
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
template
<
class
Type
>
void
Foam
::
calcTypes
::
add
::
writeAddField
(
const
IOobject
&
baseHeader
,
const
IOobject
&
addHeader
,
const
fvMesh
&
mesh
,
bool
&
processed
)
{
if
(
resultName_
==
""
)
{
resultName_
=
baseHeader
.
name
()
+
"_plus_"
+
addHeader
.
name
();
}
typedef
GeometricField
<
Type
,
fvPatchField
,
volMesh
>
fieldType
;
if
(
baseHeader
.
headerClassName
()
==
fieldType
::
typeName
&&
baseHeader
.
headerClassName
()
==
addHeader
.
headerClassName
()
)
{
Info
<<
" Reading "
<<
baseHeader
.
name
()
<<
endl
;
fieldType
baseField
(
baseHeader
,
mesh
);
Info
<<
" Reading "
<<
addHeader
.
name
()
<<
endl
;
fieldType
addField
(
addHeader
,
mesh
);
if
(
baseField
.
dimensions
()
==
addField
.
dimensions
())
{
Info
<<
" Calculating "
<<
resultName_
<<
endl
;
fieldType
newField
(
IOobject
(
resultName_
,
mesh
.
time
().
timeName
(),
mesh
,
IOobject
::
NO_READ
),
baseField
+
addField
);
newField
.
write
();
}
else
{
Info
<<
" Cannot calculate "
<<
resultName_
<<
nl
<<
" - inconsistent dimensions: "
<<
baseField
.
dimensions
()
<<
" - "
<<
addField
.
dimensions
()
<<
endl
;
}
processed
=
true
;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
src/postProcessing/foamCalcFunctions/basic/add/writeAddValue.C
0 → 100644
View file @
4b8e8e3e
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
template
<
class
Type
>
void
Foam
::
calcTypes
::
add
::
writeAddValue