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

basicSource.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) 2010-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 "basicSource.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(basicSource, 0);
00036     defineRunTimeSelectionTable(basicSource, dictionary);
00037 }
00038 
00039 
00040 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
00041 
00042 const Foam::wordList Foam::basicSource::selectionModeTypeNames_
00043 (
00044     IStringStream("(points cellSet cellZone all)")()
00045 );
00046 
00047 
00048 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00049 
00050 Foam::basicSource::selectionModeType Foam::basicSource::wordToSelectionModeType
00051 (
00052     const word& smtName
00053 ) const
00054 {
00055     forAll(selectionModeTypeNames_, i)
00056     {
00057         if (smtName == selectionModeTypeNames_[i])
00058         {
00059             return selectionModeType(i);
00060         }
00061     }
00062 
00063     FatalErrorIn
00064     (
00065         "basicSource::selectionModeType"
00066         "basicSource::wordToSelectionModeType"
00067         "("
00068             "const word&"
00069         ")"
00070     )   << "Unknown selectionMode type " << smtName
00071         << ". Valid selectionMode types are:" << nl << selectionModeTypeNames_
00072         << exit(FatalError);
00073 
00074     return selectionModeType(0);
00075 }
00076 
00077 
00078 Foam::word Foam::basicSource::selectionModeTypeToWord
00079 (
00080     const selectionModeType& smtType
00081 ) const
00082 {
00083     if (smtType > selectionModeTypeNames_.size())
00084     {
00085         return "UNKNOWN";
00086     }
00087     else
00088     {
00089         return selectionModeTypeNames_[smtType];
00090     }
00091 }
00092 
00093 
00094 void Foam::basicSource::setSelection(const dictionary& dict)
00095 {
00096     switch (selectionMode_)
00097     {
00098         case smPoints:
00099         {
00100             // Do nothing. It should be sorted out by derived class
00101             break;
00102         }
00103         case smCellSet:
00104         {
00105             dict.lookup("cellSet") >> cellSetName_;
00106             break;
00107         }
00108         case smCellZone:
00109         {
00110             dict.lookup("cellZone") >> cellSetName_;
00111             break;
00112         }
00113         case smAll:
00114         {
00115             break;
00116         }
00117         default:
00118         {
00119             FatalErrorIn
00120             (
00121                 "basicSource::setSelection(const dictionary&)"
00122             )   << "Unknown selectionMode "
00123                 << selectionModeTypeNames_[selectionMode_]
00124                 << ". Valid selectionMode types are" << selectionModeTypeNames_
00125                 << exit(FatalError);
00126         }
00127     }
00128 }
00129 
00130 
00131 void Foam::basicSource::setCellSet()
00132 {
00133     Info<< incrIndent << indent << "Source: " << name_ << endl;
00134     switch (selectionMode_)
00135     {
00136         case smPoints:
00137         {
00138             break;
00139         }
00140         case smCellSet:
00141         {
00142             Info<< indent << "- selecting cells using cellSet "
00143                 << cellSetName_ << endl;
00144 
00145             cellSet selectedCells(mesh_, cellSetName_);
00146             cells_ = selectedCells.toc();
00147 
00148             break;
00149         }
00150         case smCellZone:
00151         {
00152             Info<< indent << "- selecting cells using cellZone "
00153                 << cellSetName_ << endl;
00154             label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
00155             if (zoneID == -1)
00156             {
00157                 FatalErrorIn("basicSource<Type>::setCellIds()")
00158                     << "Cannot find cellZone " << cellSetName_ << endl
00159                     << "Valid cellZones are " << mesh_.cellZones().names()
00160                     << exit(FatalError);
00161             }
00162             cells_ = mesh_.cellZones()[zoneID];
00163 
00164             break;
00165         }
00166         case smAll:
00167         {
00168             Info<< indent << "- selecting all cells" << endl;
00169             cells_ = identity(mesh_.nCells());
00170 
00171             break;
00172         }
00173         default:
00174         {
00175             FatalErrorIn("basicSource<Type>::setCellIds()")
00176                 << "Unknown selectionMode "
00177                 << selectionModeTypeNames_[selectionMode_]
00178                 << ". Valid selectionMode types are" << selectionModeTypeNames_
00179                 << exit(FatalError);
00180         }
00181     }
00182 
00183     // Set volume information
00184     if (selectionMode_ != smPoints)
00185     {
00186         V_ = 0.0;
00187         forAll(cells_, i)
00188         {
00189             V_ += mesh_.V()[cells_[i]];
00190         }
00191         reduce(V_, sumOp<scalar>());
00192 
00193         Info<< indent << "- selected "
00194             << returnReduce(cells_.size(), sumOp<label>())
00195             << " cell(s) with volume " << V_ << nl << decrIndent << endl;
00196     }
00197 }
00198 
00199 
00200 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00201 
00202 Foam::basicSource::basicSource
00203 (
00204     const word& name,
00205     const dictionary& dict,
00206     const fvMesh& mesh
00207 )
00208 :
00209     name_(name),
00210     mesh_(mesh),
00211     dict_(dict),
00212     active_(readBool(dict_.lookup("active"))),
00213     timeStart_(readScalar(dict_.lookup("timeStart"))),
00214     duration_(readScalar(dict_.lookup("duration"))),
00215     selectionMode_(wordToSelectionModeType(dict_.lookup("selectionMode"))),
00216     cellSetName_("none"),
00217     V_(1.0)
00218 {
00219     setSelection(dict_);
00220 
00221     setCellSet();
00222 }
00223 
00224 
00225 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
00226 
00227 Foam::autoPtr<Foam::basicSource> Foam::basicSource::New
00228 (
00229     const word& name,
00230     const dictionary& dict,
00231     const fvMesh& mesh
00232 )
00233 {
00234     word typeModel(dict.lookup("typeModel"));
00235 
00236     Info<< "Selecting model type " << typeModel << endl;
00237 
00238     dictionaryConstructorTable::iterator cstrIter =
00239         dictionaryConstructorTablePtr_->find(typeModel);
00240 
00241     if (cstrIter == dictionaryConstructorTablePtr_->end())
00242     {
00243         FatalErrorIn
00244         (
00245             "basicSource::New(const volVectorField&, "
00246             "const surfaceScalarField&, transportModel&)"
00247         )   << "Unknown Model type " << typeModel
00248             << nl << nl
00249             << "Valid model types are :" << nl
00250             << dictionaryConstructorTablePtr_->sortedToc()
00251             << exit(FatalError);
00252     }
00253 
00254     return autoPtr<basicSource>(cstrIter()(name, dict, mesh));
00255 }
00256 
00257 
00258 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00259 
00260 bool Foam::basicSource::isActive()
00261 {
00262     if
00263     (
00264         active_
00265      && (mesh_.time().value() >= timeStart_)
00266      && (mesh_.time().value() <= timeEnd())
00267     )
00268     {
00269         // Update the cell set if the mesh is changing
00270         if (mesh_.changing())
00271         {
00272             setCellSet();
00273         }
00274         return true;
00275     }
00276     else
00277     {
00278         return false;
00279     }
00280 }
00281 
00282 
00283 // ************************************************************************* //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines