Added scalar multiplication
This commit is contained in:
parent
2fa97bf862
commit
1885f132dc
5 changed files with 525 additions and 0 deletions
|
@ -12,5 +12,6 @@ field/randomise/randomise.C
|
||||||
field/interpolate/interpolate.C
|
field/interpolate/interpolate.C
|
||||||
|
|
||||||
basic/addSubtract/addSubtract.C
|
basic/addSubtract/addSubtract.C
|
||||||
|
basic/scalarMult/scalarMult.C
|
||||||
|
|
||||||
LIB = $(FOAM_LIBBIN)/libfoamCalcFunctions
|
LIB = $(FOAM_LIBBIN)/libfoamCalcFunctions
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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 "scalarMult.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace calcTypes
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(scalarMult, 0);
|
||||||
|
addToRunTimeSelectionTable(calcType, scalarMult, dictionary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::calcTypes::scalarMult::writeScalarMultValues
|
||||||
|
(
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
const IOobject& baseFieldHeader
|
||||||
|
)
|
||||||
|
{
|
||||||
|
bool processed = false;
|
||||||
|
|
||||||
|
writeScalarMultValue<scalar>
|
||||||
|
(
|
||||||
|
baseFieldHeader,
|
||||||
|
scalarMultValueStr_,
|
||||||
|
mesh,
|
||||||
|
processed
|
||||||
|
);
|
||||||
|
writeScalarMultValue<vector>
|
||||||
|
(
|
||||||
|
baseFieldHeader,
|
||||||
|
scalarMultValueStr_,
|
||||||
|
mesh,
|
||||||
|
processed
|
||||||
|
);
|
||||||
|
writeScalarMultValue<sphericalTensor>
|
||||||
|
(
|
||||||
|
baseFieldHeader,
|
||||||
|
scalarMultValueStr_,
|
||||||
|
mesh,
|
||||||
|
processed
|
||||||
|
);
|
||||||
|
writeScalarMultValue<symmTensor>
|
||||||
|
(
|
||||||
|
baseFieldHeader,
|
||||||
|
scalarMultValueStr_,
|
||||||
|
mesh,
|
||||||
|
processed
|
||||||
|
);
|
||||||
|
writeScalarMultValue<tensor>
|
||||||
|
(
|
||||||
|
baseFieldHeader,
|
||||||
|
scalarMultValueStr_,
|
||||||
|
mesh,
|
||||||
|
processed
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!processed)
|
||||||
|
{
|
||||||
|
FatalErrorIn("calcTypes::scalarMult::writeScalarMultValue()")
|
||||||
|
<< "Unable to process " << baseFieldName_
|
||||||
|
<< " + " << scalarMultValueStr_ << nl
|
||||||
|
<< "No call to scalarMult for fields of type "
|
||||||
|
<< baseFieldHeader.headerClassName() << nl << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::calcTypes::scalarMult::scalarMult()
|
||||||
|
:
|
||||||
|
calcType(),
|
||||||
|
baseFieldName_(""),
|
||||||
|
scalarMultValueStr_(""),
|
||||||
|
resultName_("")
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::calcTypes::scalarMult::~scalarMult()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::calcTypes::scalarMult::init()
|
||||||
|
{
|
||||||
|
argList::validArgs.append("scalarMult");
|
||||||
|
argList::validArgs.append("baseField");
|
||||||
|
argList::validOptions.insert("value", "valueString");
|
||||||
|
argList::validOptions.insert("resultName", "fieldName");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::calcTypes::scalarMult::preCalc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
baseFieldName_ = args.additionalArgs()[1];
|
||||||
|
|
||||||
|
if (args.optionFound("value"))
|
||||||
|
{
|
||||||
|
scalarMultValueStr_ = args.option("value");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalErrorIn("calcTypes::scalarMult::preCalc")
|
||||||
|
<< "scalarMult requires -value option"
|
||||||
|
<< nl << exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.optionFound("resultName"))
|
||||||
|
{
|
||||||
|
resultName_ = args.option("resultName");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::calcTypes::scalarMult::calc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
IOobject baseFieldHeader
|
||||||
|
(
|
||||||
|
baseFieldName_,
|
||||||
|
runTime.timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::MUST_READ
|
||||||
|
);
|
||||||
|
|
||||||
|
if (baseFieldHeader.headerOk())
|
||||||
|
{
|
||||||
|
writeScalarMultValues(runTime, mesh, baseFieldHeader);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalErrorIn("calcTypes::scalarMult::calc")
|
||||||
|
<< "Unable to read base field: " << baseFieldName_
|
||||||
|
<< nl << exit(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
|
@ -0,0 +1,173 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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::scalarMult
|
||||||
|
|
||||||
|
Description
|
||||||
|
Multiplies base field with a scalar value.
|
||||||
|
|
||||||
|
New field name specified by -resultName option, or automatically as:
|
||||||
|
<baseFieldName>_scalarMult_value
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
scalarMult p scalarMult -value 100000 -resultName pAbs
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
scalarMult.C
|
||||||
|
writeScalarMultField.C
|
||||||
|
writeScalarMultValue.C
|
||||||
|
|
||||||
|
Author
|
||||||
|
Dominik Christ, Wikki Ltd. All right reserved.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef scalarMult_H
|
||||||
|
#define scalarMult_H
|
||||||
|
|
||||||
|
#include "calcType.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace calcTypes
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class scalarMult Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class scalarMult
|
||||||
|
:
|
||||||
|
public calcType
|
||||||
|
{
|
||||||
|
// Private data
|
||||||
|
|
||||||
|
//- Name of base field (to scalarMult to)
|
||||||
|
word baseFieldName_;
|
||||||
|
|
||||||
|
//- String representation of scalar value
|
||||||
|
string scalarMultValueStr_;
|
||||||
|
|
||||||
|
//- Name of result field
|
||||||
|
word resultName_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
// Output
|
||||||
|
|
||||||
|
//- Calc and output field and value scalarMult
|
||||||
|
void writeScalarMultValues
|
||||||
|
(
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
const IOobject& baseFieldHeader
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
scalarMult(const scalarMult&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const scalarMult&);
|
||||||
|
|
||||||
|
|
||||||
|
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 scalarMult value
|
||||||
|
template<class Type>
|
||||||
|
void writeScalarMultValue
|
||||||
|
(
|
||||||
|
const IOobject& baseHeader,
|
||||||
|
const string& valueStr,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
bool& processed
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("scalarMult");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
scalarMult();
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
|
||||||
|
virtual ~scalarMult();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace calcTypes
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "writeScalarMultValue.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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::scalarMult::writeAddSubtractField
|
||||||
|
(
|
||||||
|
const IOobject& baseHeader,
|
||||||
|
const IOobject& addHeader,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
bool& processed
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
baseHeader.headerClassName() == fieldType::typeName
|
||||||
|
&& baseHeader.headerClassName() == addHeader.headerClassName()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (resultName_ == "")
|
||||||
|
{
|
||||||
|
if (calcMode_ == ADD)
|
||||||
|
{
|
||||||
|
resultName_ = baseHeader.name() + "_add_" + addHeader.name();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultName_ = baseHeader.name() + "_subtract_"
|
||||||
|
+ addHeader.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
),
|
||||||
|
calcMode_ == ADD ? baseField + addField : baseField - addField
|
||||||
|
);
|
||||||
|
newField.write();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< " Cannot calculate " << resultName_ << nl
|
||||||
|
<< " - inconsistent dimensions: "
|
||||||
|
<< baseField.dimensions() << " - " << addField.dimensions()
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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::scalarMult::writeScalarMultValue
|
||||||
|
(
|
||||||
|
const IOobject& baseHeader,
|
||||||
|
const string& valueStr,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
bool& processed
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
|
if (baseHeader.headerClassName() == fieldType::typeName)
|
||||||
|
{
|
||||||
|
if (resultName_ == "")
|
||||||
|
{
|
||||||
|
resultName_ = baseHeader.name() + "_scalarMult";
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar value;
|
||||||
|
IStringStream(valueStr)() >> value;
|
||||||
|
|
||||||
|
Info<< " Reading " << baseHeader.name() << endl;
|
||||||
|
fieldType baseField(baseHeader, mesh);
|
||||||
|
|
||||||
|
fieldType newField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
resultName_,
|
||||||
|
mesh.time().timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::NO_READ
|
||||||
|
),
|
||||||
|
baseField
|
||||||
|
);
|
||||||
|
|
||||||
|
Info<< " Calculating " << resultName_ << endl;
|
||||||
|
|
||||||
|
newField == value*baseField;
|
||||||
|
newField.write();
|
||||||
|
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
Reference in a new issue