FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

addSubtract.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "addSubtract.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     namespace calcTypes
00034     {
00035         defineTypeNameAndDebug(addSubtract, 0);
00036         addToRunTimeSelectionTable(calcType, addSubtract, dictionary);
00037     }
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 void Foam::calcTypes::addSubtract::writeAddSubtractFields
00044 (
00045     const Time& runTime,
00046     const fvMesh& mesh,
00047     const IOobject& baseFieldHeader
00048 )
00049 {
00050     bool processed = false;
00051 
00052     IOobject addSubtractFieldHeader
00053     (
00054         addSubtractFieldName_,
00055         runTime.timeName(),
00056         mesh,
00057         IOobject::MUST_READ
00058     );
00059 
00060     if (addSubtractFieldHeader.headerOk())
00061     {
00062         writeAddSubtractField<scalar>
00063         (
00064             baseFieldHeader,
00065             addSubtractFieldHeader,
00066             mesh,
00067             processed
00068         );
00069         writeAddSubtractField<vector>
00070         (
00071             baseFieldHeader,
00072             addSubtractFieldHeader,
00073             mesh,
00074             processed
00075         );
00076         writeAddSubtractField<sphericalTensor>
00077         (
00078             baseFieldHeader,
00079             addSubtractFieldHeader,
00080             mesh,
00081             processed
00082         );
00083         writeAddSubtractField<symmTensor>
00084         (
00085             baseFieldHeader,
00086             addSubtractFieldHeader,
00087             mesh,
00088             processed
00089         );
00090         writeAddSubtractField<tensor>
00091         (
00092             baseFieldHeader,
00093             addSubtractFieldHeader,
00094             mesh,
00095             processed
00096         );
00097 
00098         if (!processed)
00099         {
00100             FatalError
00101                 << "Unable to process " << baseFieldName_
00102                 << " + " << addSubtractFieldName_ << nl
00103                 << "No call to addSubtract for fields of type "
00104                 << baseFieldHeader.headerClassName() << " + "
00105                 << addSubtractFieldHeader.headerClassName() << nl << nl
00106                 << exit(FatalError);
00107         }
00108     }
00109     else
00110     {
00111         FatalErrorIn("calcTypes::addSubtract::writeAddSubtractFields()")
00112             << "Unable to read addSubtract field: " << addSubtractFieldName_
00113             << nl << exit(FatalError);
00114     }
00115 }
00116 
00117 
00118 void Foam::calcTypes::addSubtract::writeAddSubtractValues
00119 (
00120     const Time& runTime,
00121     const fvMesh& mesh,
00122     const IOobject& baseFieldHeader
00123 )
00124 {
00125     bool processed = false;
00126 
00127     writeAddSubtractValue<scalar>
00128     (
00129         baseFieldHeader,
00130         addSubtractValueStr_,
00131         mesh,
00132         processed
00133     );
00134     writeAddSubtractValue<vector>
00135     (
00136         baseFieldHeader,
00137         addSubtractValueStr_,
00138         mesh,
00139         processed
00140     );
00141     writeAddSubtractValue<sphericalTensor>
00142     (
00143         baseFieldHeader,
00144         addSubtractValueStr_,
00145         mesh,
00146         processed
00147     );
00148     writeAddSubtractValue<symmTensor>
00149     (
00150         baseFieldHeader,
00151         addSubtractValueStr_,
00152         mesh,
00153         processed
00154     );
00155     writeAddSubtractValue<tensor>
00156     (
00157         baseFieldHeader,
00158         addSubtractValueStr_,
00159         mesh,
00160         processed
00161     );
00162 
00163     if (!processed)
00164     {
00165         FatalErrorIn("calcTypes::addSubtract::writeAddSubtractValue()")
00166             << "Unable to process " << baseFieldName_
00167             << " + " << addSubtractValueStr_ << nl
00168             << "No call to addSubtract for fields of type "
00169             << baseFieldHeader.headerClassName() << nl << nl
00170             << exit(FatalError);
00171     }
00172 }
00173 
00174 
00175 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00176 
00177 Foam::calcTypes::addSubtract::addSubtract()
00178 :
00179     calcType(),
00180     baseFieldName_(""),
00181     calcType_(FIELD),
00182     addSubtractFieldName_(""),
00183     addSubtractValueStr_(""),
00184     resultName_(""),
00185     calcMode_(ADD)
00186 {}
00187 
00188 
00189 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00190 
00191 Foam::calcTypes::addSubtract::~addSubtract()
00192 {}
00193 
00194 
00195 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00196 
00197 void Foam::calcTypes::addSubtract::init()
00198 {
00199     argList::validArgs.append("add");
00200     argList::validArgs.append("baseField");
00201     argList::validArgs.append("calcMode");
00202     argList::validOptions.insert("field", "fieldName");
00203     argList::validOptions.insert("value", "valueString");
00204     argList::validOptions.insert("resultName", "fieldName");
00205 }
00206 
00207 
00208 void Foam::calcTypes::addSubtract::preCalc
00209 (
00210     const argList& args,
00211     const Time& runTime,
00212     const fvMesh& mesh
00213 )
00214 {
00215     baseFieldName_ = args.additionalArgs()[1];
00216     word calcModeName = args.additionalArgs()[2];
00217 
00218     if (calcModeName == "add")
00219     {
00220         calcMode_ = ADD;
00221     }
00222     else if (calcModeName == "subtract")
00223     {
00224         calcMode_ = SUBTRACT;
00225     }
00226     else
00227     {
00228         FatalErrorIn("calcTypes::addSubtract::preCalc")
00229             << "Invalid calcMode: " << calcModeName << nl
00230             << "    Valid calcModes are add and subtract" << nl
00231             << exit(FatalError);
00232     }
00233 
00234     if (args.optionFound("field"))
00235     {
00236         addSubtractFieldName_ = args.option("field");
00237         calcType_ = FIELD;
00238     }
00239     else if (args.optionFound("value"))
00240     {
00241         addSubtractValueStr_ = args.option("value");
00242         calcType_ = VALUE;
00243     }
00244     else
00245     {
00246         FatalErrorIn("calcTypes::addSubtract::preCalc")
00247             << "addSubtract requires either -field or -value option"
00248             << nl << exit(FatalError);
00249     }
00250 
00251     if (args.optionFound("resultName"))
00252     {
00253         resultName_ = args.option("resultName");
00254     }
00255 }
00256 
00257 
00258 void Foam::calcTypes::addSubtract::calc
00259 (
00260     const argList& args,
00261     const Time& runTime,
00262     const fvMesh& mesh
00263 )
00264 {
00265     IOobject baseFieldHeader
00266     (
00267         baseFieldName_,
00268         runTime.timeName(),
00269         mesh,
00270         IOobject::MUST_READ
00271     );
00272 
00273     if (baseFieldHeader.headerOk())
00274     {
00275         switch (calcType_)
00276         {
00277             case FIELD:
00278             {
00279                 writeAddSubtractFields(runTime, mesh, baseFieldHeader);
00280                 break;
00281             }
00282             case VALUE:
00283             {
00284                 writeAddSubtractValues(runTime, mesh, baseFieldHeader);
00285                 break;
00286             }
00287             default:
00288             {
00289                 FatalErrorIn("calcTypes::addSubtract::calc")
00290                     << "unknown calcType " << calcType_ << nl
00291                     << abort(FatalError);
00292             }
00293         }
00294     }
00295     else
00296     {
00297         FatalErrorIn("calcTypes::addSubtract::calc")
00298             << "Unable to read base field: " << baseFieldName_
00299             << nl << exit(FatalError);
00300     }
00301 }
00302 
00303 
00304 // ************************ vim: set sw=4 sts=4 et: ************************ //
00305 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines