OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

timeActivatedExplicitMulticomponentPointSource.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) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "timeActivatedExplicitMulticomponentPointSource.H"
00028 #include "volFields.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 Foam::label
00033 Foam::timeActivatedExplicitMulticomponentPointSource::carrierFieldId
00034 (
00035     const word& fieldName
00036 )
00037 {
00038     forAll(carrierFields_, fieldI)
00039     {
00040         if (carrierFields_[fieldI].name() == fieldName)
00041         {
00042             return fieldI;
00043         }
00044     }
00045 
00046     return -1;
00047 }
00048 
00049 
00050 void Foam::timeActivatedExplicitMulticomponentPointSource::updateAddressing()
00051 {
00052     forAll(pointSources_, sourceI)
00053     {
00054         const pointSourceProperties& psp = pointSources_[sourceI];
00055         bool foundCell = false;
00056         label cid = mesh_.findCell(psp.location());
00057         if (cid >= 0)
00058         {
00059             foundCell = mesh_.pointInCell(psp.location(), cid);
00060         }
00061         reduce(foundCell, orOp<bool>());
00062         if (!foundCell)
00063         {
00064             label cid = mesh_.findNearestCell(psp.location());
00065             if (cid >= 0)
00066             {
00067                 foundCell = mesh_.pointInCell(psp.location(), cid);
00068             }
00069         }
00070         reduce(foundCell, orOp<bool>());
00071 
00072         if (!foundCell)
00073         {
00074             FatalErrorIn
00075             (
00076                 "timeActivatedExplicitMulticomponentPointSource::"
00077                 "updateAddressing()"
00078             )   << "Unable to find location " << psp.location() << " in mesh "
00079                 << "for source " << psp.name() << nl
00080                 << exit(FatalError);
00081         }
00082         else
00083         {
00084             cellOwners_[sourceI] = cid;
00085         }
00086 
00087         fieldIds_[sourceI].setSize(psp.fieldData().size());
00088         forAll(psp.fieldData(), fieldI)
00089         {
00090             const word& fieldName = psp.fieldData()[fieldI].first();
00091             label cfid = carrierFieldId(fieldName);
00092             if (cfid < 0)
00093             {
00094                 FatalErrorIn
00095                 (
00096                     "timeActivatedExplicitMulticomponentPointSource::"
00097                     "updateAddressing()"
00098                 )   << "Unable to find field " << fieldName << " in carrier "
00099                     << "fields for source " << psp.name() << nl
00100                     << exit(FatalError);
00101             }
00102             else
00103             {
00104                 fieldIds_[sourceI][fieldI] = cfid;
00105             }
00106        }
00107     }
00108 }
00109 
00110 
00111 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00112 
00113 Foam::timeActivatedExplicitMulticomponentPointSource::
00114 timeActivatedExplicitMulticomponentPointSource
00115 (
00116     const word& name,
00117     const fvMesh& mesh,
00118     const PtrList<volScalarField>& carrierFields,
00119     const dimensionSet& dims
00120 )
00121 :
00122     IOdictionary
00123     (
00124         IOobject
00125         (
00126             name + "Properties",
00127             mesh.time().constant(),
00128             mesh,
00129             IOobject::MUST_READ,
00130             IOobject::NO_WRITE
00131         )
00132     ),
00133     name_(name),
00134     mesh_(mesh),
00135     runTime_(mesh.time()),
00136     dimensions_(dims),
00137     carrierFields_(carrierFields),
00138     active_(lookup("active")),
00139     pointSources_(lookup("pointSources")),
00140     cellOwners_(pointSources_.size()),
00141     fieldIds_(pointSources_.size())
00142 {
00143     // Initialise the field addressing
00144     updateAddressing();
00145 }
00146 
00147 
00148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00149 
00150 Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
00151 Foam::timeActivatedExplicitMulticomponentPointSource::Su
00152 (
00153     const label fieldI
00154 )
00155 {
00156     if (mesh_.changing())
00157     {
00158         updateAddressing();
00159     }
00160 
00161     tmp<DimensionedField<scalar, volMesh> > tSource
00162     (
00163         new DimensionedField<scalar, volMesh>
00164         (
00165             IOobject
00166             (
00167                 name_ + carrierFields_[fieldI].name() + "Su",
00168                 runTime_.timeName(),
00169                 mesh_,
00170                 IOobject::NO_READ,
00171                 IOobject::NO_WRITE
00172             ),
00173             mesh_,
00174             dimensionedScalar("zero", dimensions_, 0.0)
00175         )
00176     );
00177 
00178     if (active_)
00179     {
00180         DimensionedField<scalar, volMesh>& sourceField = tSource();
00181 
00182         const scalarField& V = mesh_.V();
00183         const scalar dt = runTime_.deltaT().value();
00184 
00185         forAll(pointSources_, sourceI)
00186         {
00187             const pointSourceProperties& psp = pointSources_[sourceI];
00188 
00189             forAll(fieldIds_[sourceI], i)
00190             {
00191                 if
00192                 (
00193                     fieldIds_[sourceI][i] == fieldI
00194                 && (runTime_.time().value() >= psp.timeStart())
00195                 && (runTime_.time().value() <= psp.timeEnd())
00196                 )
00197                 {
00198                     const label cid = cellOwners_[sourceI];
00199                     if (cid >= 0)
00200                     {
00201                         sourceField[cid] +=
00202                             dt*psp.fieldData()[i].second()/V[cid];
00203                     }
00204                 }
00205             }
00206         }
00207     }
00208 
00209     return tSource;
00210 }
00211 
00212 
00213 Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
00214 Foam::timeActivatedExplicitMulticomponentPointSource::Su()
00215 {
00216     if (mesh_.changing())
00217     {
00218         updateAddressing();
00219     }
00220 
00221     tmp<DimensionedField<scalar, volMesh> > tSource
00222     (
00223         new DimensionedField<scalar, volMesh>
00224         (
00225             IOobject
00226             (
00227                 name_ + "TotalSu",
00228                 runTime_.timeName(),
00229                 mesh_,
00230                 IOobject::NO_READ,
00231                 IOobject::NO_WRITE
00232             ),
00233             mesh_,
00234             dimensionedScalar("zero", dimensions_, 0.0)
00235         )
00236     );
00237 
00238     if (active_)
00239     {
00240         DimensionedField<scalar, volMesh>& sourceField = tSource();
00241 
00242         const scalarField& V = mesh_.V();
00243         const scalar dt = runTime_.deltaT().value();
00244 
00245         forAll(pointSources_, sourceI)
00246         {
00247             const pointSourceProperties& psp = pointSources_[sourceI];
00248 
00249             forAll(fieldIds_[sourceI], i)
00250             {
00251                 if
00252                 (
00253                    (runTime_.time().value() >= psp.timeStart())
00254                 && (runTime_.time().value() <= psp.timeEnd())
00255                 )
00256                 {
00257                     const label cid = cellOwners_[sourceI];
00258                     if (cid >= 0)
00259                     {
00260                         sourceField[cid] +=
00261                             dt*psp.fieldData()[i].second()/V[cid];
00262                     }
00263                 }
00264             }
00265         }
00266     }
00267 
00268     return tSource;
00269 }
00270 
00271 
00272 bool Foam::timeActivatedExplicitMulticomponentPointSource::read()
00273 {
00274     if (regIOobject::read())
00275     {
00276         lookup("active") >> active_;
00277         lookup("pointSources") >> pointSources_;
00278 
00279         cellOwners_.setSize(pointSources_.size());
00280 
00281         updateAddressing();
00282 
00283         return true;
00284     }
00285     else
00286     {
00287         return false;
00288     }
00289 }
00290 
00291 
00292 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd