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

PatchInjection.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) 2009-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 "PatchInjection.H"
00028 #include "DataEntry.H"
00029 #include "pdf.H"
00030 
00031 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00032 
00033 template<class CloudType>
00034 Foam::label Foam::PatchInjection<CloudType>::parcelsToInject
00035 (
00036     const scalar time0,
00037     const scalar time1
00038 ) const
00039 {
00040     if ((time0 >= 0.0) && (time0 < duration_))
00041     {
00042         return round(fraction_*(time1 - time0)*parcelsPerSecond_);
00043     }
00044     else
00045     {
00046         return 0;
00047     }
00048 }
00049 
00050 
00051 template<class CloudType>
00052 Foam::scalar Foam::PatchInjection<CloudType>::volumeToInject
00053 (
00054     const scalar time0,
00055     const scalar time1
00056 ) const
00057 {
00058     if ((time0 >= 0.0) && (time0 < duration_))
00059     {
00060         return fraction_*volumeFlowRate_().integrate(time0, time1);
00061     }
00062     else
00063     {
00064         return 0.0;
00065     }
00066 }
00067 
00068 
00069 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00070 
00071 template<class CloudType>
00072 Foam::PatchInjection<CloudType>::PatchInjection
00073 (
00074     const dictionary& dict,
00075     CloudType& owner
00076 )
00077 :
00078     InjectionModel<CloudType>(dict, owner, typeName),
00079     patchName_(this->coeffDict().lookup("patchName")),
00080     duration_(readScalar(this->coeffDict().lookup("duration"))),
00081     parcelsPerSecond_
00082     (
00083         readScalar(this->coeffDict().lookup("parcelsPerSecond"))
00084     ),
00085     U0_(this->coeffDict().lookup("U0")),
00086     volumeFlowRate_
00087     (
00088         DataEntry<scalar>::New
00089         (
00090             "volumeFlowRate",
00091             this->coeffDict()
00092         )
00093     ),
00094     parcelPDF_
00095     (
00096         pdf::New
00097         (
00098             this->coeffDict().subDict("parcelPDF"),
00099             owner.rndGen()
00100         )
00101     ),
00102     cellOwners_(),
00103     fraction_(1.0)
00104 {
00105     label patchId = owner.mesh().boundaryMesh().findPatchID(patchName_);
00106 
00107     if (patchId < 0)
00108     {
00109         FatalErrorIn
00110         (
00111             "PatchInjection<CloudType>::PatchInjection"
00112             "("
00113                 "const dictionary&, "
00114                 "CloudType&"
00115             ")"
00116         )   << "Requested patch " << patchName_ << " not found" << nl
00117             << "Available patches are: " << owner.mesh().boundaryMesh().names()
00118             << nl << exit(FatalError);
00119     }
00120 
00121     const polyPatch& patch = owner.mesh().boundaryMesh()[patchId];
00122 
00123     cellOwners_ = patch.faceCells();
00124 
00125     label patchSize = cellOwners_.size();
00126     label totalPatchSize = patchSize;
00127     reduce(totalPatchSize, sumOp<scalar>());
00128     fraction_ = patchSize/totalPatchSize;
00129 
00130     // Set total volume to inject
00131     this->volumeTotal_ = fraction_*volumeFlowRate_().integrate(0.0, duration_);
00132 }
00133 
00134 
00135 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00136 
00137 template<class CloudType>
00138 Foam::PatchInjection<CloudType>::~PatchInjection()
00139 {}
00140 
00141 
00142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00143 
00144 template<class CloudType>
00145 bool Foam::PatchInjection<CloudType>::active() const
00146 {
00147     return true;
00148 }
00149 
00150 
00151 template<class CloudType>
00152 Foam::scalar Foam::PatchInjection<CloudType>::timeEnd() const
00153 {
00154     return this->SOI_ + duration_;
00155 }
00156 
00157 
00158 template<class CloudType>
00159 void Foam::PatchInjection<CloudType>::setPositionAndCell
00160 (
00161     const label,
00162     const label,
00163     const scalar,
00164     vector& position,
00165     label& cellOwner
00166 )
00167 {
00168     label cellI = this->owner().rndGen().integer(0, cellOwners_.size() - 1);
00169 
00170     cellOwner = cellOwners_[cellI];
00171     position = this->owner().mesh().C()[cellOwner];
00172 }
00173 
00174 
00175 template<class CloudType>
00176 void Foam::PatchInjection<CloudType>::setProperties
00177 (
00178     const label,
00179     const label,
00180     const scalar,
00181     typename CloudType::parcelType& parcel
00182 )
00183 {
00184     // set particle velocity
00185     parcel.U() = U0_;
00186 
00187     // set particle diameter
00188     parcel.d() = parcelPDF_->sample();
00189 }
00190 
00191 
00192 template<class CloudType>
00193 bool Foam::PatchInjection<CloudType>::fullyDescribed() const
00194 {
00195     return false;
00196 }
00197 
00198 
00199 template<class CloudType>
00200 bool Foam::PatchInjection<CloudType>::validInjection(const label)
00201 {
00202     return true;
00203 }
00204 
00205 
00206 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd