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

explicitSource.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 "explicitSource.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00030 #include <OpenFOAM/HashSet.H>
00031 
00032 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(explicitSource, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         basicSource,
00040         explicitSource,
00041         dictionary
00042     );
00043 }
00044 
00045 const Foam::wordList Foam::explicitSource::volumeModeTypeNames_
00046 (
00047     IStringStream("(absolute specific)")()
00048 );
00049 
00050 
00051 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00052 
00053 void Foam::explicitSource::setSelectedCellsFromPoints()
00054 {
00055     labelHashSet selectedCells;
00056 
00057     forAll(points_, i)
00058     {
00059         label cellI = this->mesh().findCell(points_[i]);
00060         if (cellI >= 0)
00061         {
00062             selectedCells.insert(cellI);
00063         }
00064 
00065         label globalCellI = returnReduce(cellI, maxOp<label>());
00066 
00067         if (globalCellI < 0)
00068         {
00069             WarningIn("explicitSource::setSelectedCellsFromPoints()")
00070                 << "Unable to find owner cell for point " << points_[i]
00071                 << endl;
00072         }
00073     }
00074 
00075     this->cells() = selectedCells.toc();
00076 }
00077 
00078 
00079 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00080 
00081 Foam::explicitSource::volumeModeType
00082 Foam::explicitSource::wordToVolumeModeType
00083 (
00084     const word& vmtName
00085 ) const
00086 {
00087     forAll(volumeModeTypeNames_, i)
00088     {
00089         if (vmtName == volumeModeTypeNames_[i])
00090         {
00091             return volumeModeType(i);
00092         }
00093     }
00094 
00095     FatalErrorIn
00096     (
00097         "explicitSource<Type>::volumeModeType"
00098         "explicitSource<Type>::wordToVolumeModeType(const word&)"
00099     )   << "Unknown volumeMode type " << vmtName
00100         << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
00101         << exit(FatalError);
00102 
00103     return volumeModeType(0);
00104 }
00105 
00106 
00107 Foam::word Foam::explicitSource::volumeModeTypeToWord
00108 (
00109     const volumeModeType& vmtType
00110 ) const
00111 {
00112     if (vmtType > volumeModeTypeNames_.size())
00113     {
00114         return "UNKNOWN";
00115     }
00116     else
00117     {
00118         return volumeModeTypeNames_[vmtType];
00119     }
00120 }
00121 
00122 
00123 void Foam::explicitSource::setFieldData(const dictionary& dict)
00124 {
00125     scalarFields_.clear();
00126     vectorFields_.clear();
00127 
00128     wordList fieldTypes(dict.toc().size());
00129     wordList fieldNames(dict.toc().size());
00130 
00131     forAll(dict.toc(), i)
00132     {
00133         const word& fieldName = dict.toc()[i];
00134         IOobject io
00135         (
00136             fieldName,
00137             this->mesh().time().timeName(0),
00138             this->mesh(),
00139             IOobject::NO_READ,
00140             IOobject::NO_WRITE,
00141             false
00142         );
00143         if (io.headerOk())
00144         {
00145             fieldTypes[i] = io.headerClassName();
00146             fieldNames[i] = dict.toc()[i];
00147         }
00148         else
00149         {
00150             FatalErrorIn
00151             (
00152                 "explicitSource::setFieldData"
00153             )   << "header not OK " << io.name()
00154                 << exit(FatalError);
00155         }
00156     }
00157 
00158     addField(scalarFields_, fieldTypes, fieldNames, dict);
00159     addField(vectorFields_, fieldTypes, fieldNames, dict);
00160 }
00161 
00162 
00163 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00164 
00165 Foam::explicitSource::explicitSource
00166 (
00167     const word& name,
00168     const dictionary& dict,
00169     const fvMesh& mesh
00170 )
00171 :
00172     basicSource(name, dict, mesh),
00173     scalarFields_(0, *this),
00174     vectorFields_(0, *this),
00175     dict_(dict.subDict(typeName + "Coeffs")),
00176     volumeMode_(wordToVolumeModeType(dict_.lookup("volumeMode"))),
00177     points_(),
00178     volSource_(this->cells().size(), 1.0)
00179 {
00180     setFieldData(dict_.subDict("fieldData"));
00181 
00182     // Set points if selectionMode is smPoints
00183     if (this->selectionMode() == smPoints)
00184     {
00185         dict_.lookup("points") >> points_;
00186         setSelectedCellsFromPoints();
00187         volSource_.setSize(points_.size(), 1.0);
00188     }
00189 
00190     const labelList& cellList = this->cells();
00191     scalar V = 0.0;
00192     if (volumeMode_ == vmAbsolute)
00193     {
00194         forAll(cellList, cellI)
00195         {
00196             volSource_[cellI] = mesh.V()[cellList[cellI]];
00197             V += volSource_[cellI];
00198         }
00199     }
00200     else
00201     {
00202         forAll(cellList, cellI)
00203         {
00204             V += mesh.V()[cellList[cellI]];
00205         }
00206     }
00207 
00208     reduce(V, sumOp<scalar>());
00209 
00210     Info<< "- selected " << returnReduce(cellList.size(), sumOp<label>())
00211         << " cell(s) with Volume: " << V << " in time activated sources "
00212         <<  endl;
00213 }
00214 
00215 
00216 void Foam::explicitSource::addSu(fvMatrix<scalar>& Eqn)
00217 {
00218     Field<scalar>& source = Eqn.source();
00219     scalar data = scalarFields_[Eqn.psi().name()];
00220     addSources<scalar>(source, data);
00221 }
00222 
00223 
00224 void Foam::explicitSource::addSu(fvMatrix<vector>& Eqn)
00225 {
00226     Field<vector>& source = Eqn.source();
00227     vector data = vectorFields_[Eqn.psi().name()];
00228     addSources<vector>(source, data);
00229 }
00230 
00231 
00232 void Foam::explicitSource::addSu(DimensionedField<scalar, volMesh>& field)
00233 {
00234     scalar data = scalarFields_[field.name()];
00235     addSources<scalar>(field, data);
00236 }
00237 
00238 
00239 void Foam::explicitSource::addSu(DimensionedField<vector, volMesh>& field)
00240 {
00241     vector data = vectorFields_[field.name()];
00242     addSources<vector>(field, data);
00243 }
00244 
00245 
00246 void Foam::explicitSource::addExplicitSources()
00247 {
00248     scalarFields_.applySources();
00249     vectorFields_.applySources();
00250 }
00251 
00252 
00253 // ************************************************************************* //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines