1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "addSubtract.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(addSubtract, 0);
37 addToRunTimeSelectionTable(calcType, addSubtract, dictionary);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 void Foam::calcTypes::addSubtract::writeAddSubtractFields
48 const IOobject& baseFieldHeader
51 bool processed = false;
53 IOobject addSubtractFieldHeader
55 addSubtractFieldName_,
61 if (addSubtractFieldHeader.headerOk())
63 writeAddSubtractField<scalar>
66 addSubtractFieldHeader,
70 writeAddSubtractField<vector>
73 addSubtractFieldHeader,
77 writeAddSubtractField<sphericalTensor>
80 addSubtractFieldHeader,
84 writeAddSubtractField<symmTensor>
87 addSubtractFieldHeader,
91 writeAddSubtractField<tensor>
94 addSubtractFieldHeader,
102 << "Unable to process " << baseFieldName_
103 << " + " << addSubtractFieldName_ << nl
104 << "No call to addSubtract for fields of type "
105 << baseFieldHeader.headerClassName() << " + "
106 << addSubtractFieldHeader.headerClassName() << nl << nl
112 FatalErrorIn("calcTypes::addSubtract::writeAddSubtractFields()")
113 << "Unable to read addSubtract field: " << addSubtractFieldName_
114 << nl << exit(FatalError);
119 void Foam::calcTypes::addSubtract::writeAddSubtractValues
123 const IOobject& baseFieldHeader
126 bool processed = false;
128 writeAddSubtractValue<scalar>
131 addSubtractValueStr_,
135 writeAddSubtractValue<vector>
138 addSubtractValueStr_,
142 writeAddSubtractValue<sphericalTensor>
145 addSubtractValueStr_,
149 writeAddSubtractValue<symmTensor>
152 addSubtractValueStr_,
156 writeAddSubtractValue<tensor>
159 addSubtractValueStr_,
166 FatalErrorIn("calcTypes::addSubtract::writeAddSubtractValue()")
167 << "Unable to process " << baseFieldName_
168 << " + " << addSubtractValueStr_ << nl
169 << "No call to addSubtract for fields of type "
170 << baseFieldHeader.headerClassName() << nl << nl
176 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 Foam::calcTypes::addSubtract::addSubtract()
183 addSubtractFieldName_(""),
184 addSubtractValueStr_(""),
190 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
192 Foam::calcTypes::addSubtract::~addSubtract()
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198 void Foam::calcTypes::addSubtract::init()
200 argList::validArgs.append("add");
201 argList::validArgs.append("baseField");
202 argList::validArgs.append("calcMode");
203 argList::validOptions.insert("field", "fieldName");
204 argList::validOptions.insert("value", "valueString");
205 argList::validOptions.insert("resultName", "fieldName");
209 void Foam::calcTypes::addSubtract::preCalc
216 baseFieldName_ = args.additionalArgs()[1];
217 word calcModeName = args.additionalArgs()[2];
219 if (calcModeName == "add")
223 else if (calcModeName == "subtract")
225 calcMode_ = SUBTRACT;
229 FatalErrorIn("calcTypes::addSubtract::preCalc")
230 << "Invalid calcMode: " << calcModeName << nl
231 << " Valid calcModes are add and subtract" << nl
235 if (args.optionFound("field"))
237 addSubtractFieldName_ = args.option("field");
240 else if (args.optionFound("value"))
242 addSubtractValueStr_ = args.option("value");
247 FatalErrorIn("calcTypes::addSubtract::preCalc")
248 << "addSubtract requires either -field or -value option"
249 << nl << exit(FatalError);
252 if (args.optionFound("resultName"))
254 resultName_ = args.option("resultName");
259 void Foam::calcTypes::addSubtract::calc
266 IOobject baseFieldHeader
274 if (baseFieldHeader.headerOk())
280 writeAddSubtractFields(runTime, mesh, baseFieldHeader);
285 writeAddSubtractValues(runTime, mesh, baseFieldHeader);
290 FatalErrorIn("calcTypes::addSubtract::calc")
291 << "unknown calcType " << calcType_ << nl
292 << abort(FatalError);
298 FatalErrorIn("calcTypes::addSubtract::calc")
299 << "Unable to read base field: " << baseFieldName_
300 << nl << exit(FatalError);
305 // ************************************************************************* //