1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "addSubtract.H"
27 #include "addToRunTimeSelectionTable.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(addSubtract, 0);
36 addToRunTimeSelectionTable(calcType, addSubtract, dictionary);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::calcTypes::addSubtract::writeAddSubtractFields
47 const IOobject& baseFieldHeader
50 bool processed = false;
52 IOobject addSubtractFieldHeader
54 addSubtractFieldName_,
60 if (addSubtractFieldHeader.headerOk())
62 writeAddSubtractField<scalar>
65 addSubtractFieldHeader,
69 writeAddSubtractField<vector>
72 addSubtractFieldHeader,
76 writeAddSubtractField<sphericalTensor>
79 addSubtractFieldHeader,
83 writeAddSubtractField<symmTensor>
86 addSubtractFieldHeader,
90 writeAddSubtractField<tensor>
93 addSubtractFieldHeader,
101 << "Unable to process " << baseFieldName_
102 << " + " << addSubtractFieldName_ << nl
103 << "No call to addSubtract for fields of type "
104 << baseFieldHeader.headerClassName() << " + "
105 << addSubtractFieldHeader.headerClassName() << nl << nl
111 FatalErrorIn("calcTypes::addSubtract::writeAddSubtractFields()")
112 << "Unable to read addSubtract field: " << addSubtractFieldName_
113 << nl << exit(FatalError);
118 void Foam::calcTypes::addSubtract::writeAddSubtractValues
122 const IOobject& baseFieldHeader
125 bool processed = false;
127 writeAddSubtractValue<scalar>
130 addSubtractValueStr_,
134 writeAddSubtractValue<vector>
137 addSubtractValueStr_,
141 writeAddSubtractValue<sphericalTensor>
144 addSubtractValueStr_,
148 writeAddSubtractValue<symmTensor>
151 addSubtractValueStr_,
155 writeAddSubtractValue<tensor>
158 addSubtractValueStr_,
165 FatalErrorIn("calcTypes::addSubtract::writeAddSubtractValue()")
166 << "Unable to process " << baseFieldName_
167 << " + " << addSubtractValueStr_ << nl
168 << "No call to addSubtract for fields of type "
169 << baseFieldHeader.headerClassName() << nl << nl
175 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
177 Foam::calcTypes::addSubtract::addSubtract()
182 addSubtractFieldName_(""),
183 addSubtractValueStr_(""),
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
191 Foam::calcTypes::addSubtract::~addSubtract()
195 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 void Foam::calcTypes::addSubtract::init()
199 argList::validArgs.append("add");
200 argList::validArgs.append("baseField");
201 argList::validArgs.append("calcMode");
202 argList::validOptions.insert("field", "fieldName");
203 argList::validOptions.insert("value", "valueString");
204 argList::validOptions.insert("resultName", "fieldName");
208 void Foam::calcTypes::addSubtract::preCalc
215 baseFieldName_ = args[2];
216 const word calcModeName = args[3];
218 if (calcModeName == "add")
222 else if (calcModeName == "subtract")
224 calcMode_ = SUBTRACT;
228 FatalErrorIn("calcTypes::addSubtract::preCalc")
229 << "Invalid calcMode: " << calcModeName << nl
230 << " Valid calcModes are add and subtract" << nl
234 if (args.optionReadIfPresent("field", addSubtractFieldName_))
238 else if (args.optionReadIfPresent("value", addSubtractValueStr_))
244 FatalErrorIn("calcTypes::addSubtract::preCalc")
245 << "addSubtract requires either -field or -value option"
246 << nl << exit(FatalError);
249 args.optionReadIfPresent("resultName", resultName_);
253 void Foam::calcTypes::addSubtract::calc
260 IOobject baseFieldHeader
268 if (baseFieldHeader.headerOk())
274 writeAddSubtractFields(runTime, mesh, baseFieldHeader);
279 writeAddSubtractValues(runTime, mesh, baseFieldHeader);
284 FatalErrorIn("calcTypes::addSubtract::calc")
285 << "unknown calcType " << calcType_ << nl
286 << abort(FatalError);
292 FatalErrorIn("calcTypes::addSubtract::calc")
293 << "Unable to read base field: " << baseFieldName_
294 << nl << exit(FatalError);
299 // ************************************************************************* //