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

ignitionSite.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-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 "ignitionSite.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <finiteVolume/volFields.H>
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 void ignitionSite::findIgnitionCells(const fvMesh& mesh)
00038 {
00039     // Bit tricky: generate C and V before shortcutting if cannot find
00040     // cell locally. mesh.C generation uses parallel communication.
00041     const volVectorField& centres = mesh.C();
00042     const scalarField& vols = mesh.V();
00043 
00044     label ignCell = mesh.findCell(location_);
00045     if (ignCell == -1)
00046     {
00047         return;
00048     }
00049 
00050     scalar radius = diameter_/2.0;
00051 
00052     cells_.setSize(1);
00053     cellVolumes_.setSize(1);
00054 
00055     cells_[0] = ignCell;
00056     cellVolumes_[0] = vols[ignCell];
00057 
00058     scalar minDist = GREAT;
00059     label nearestCell = 0;
00060     label nIgnCells = 1;
00061 
00062     forAll(centres, celli)
00063     {
00064         scalar dist = mag(centres[celli] - location_);
00065 
00066         if (dist < minDist)
00067         {
00068             nearestCell = celli;
00069             minDist = dist;
00070         }
00071 
00072         if (dist < radius && celli != ignCell)
00073         {
00074             cells_.setSize(nIgnCells+1);
00075             cellVolumes_.setSize(nIgnCells+1);
00076 
00077             cells_[nIgnCells] = celli;
00078             cellVolumes_[nIgnCells] = vols[celli];
00079 
00080             nIgnCells++;
00081         }
00082     }
00083 
00084     if (cells_.size())
00085     {
00086         Pout<< "Found ignition cells:" << endl << cells_ << endl;
00087     }
00088 }
00089 
00090 
00091 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00092 
00093 const labelList& ignitionSite::cells() const
00094 {
00095     if (mesh_.changing() && timeIndex_ != db_.timeIndex())
00096     {
00097         const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
00098     }
00099     timeIndex_ = db_.timeIndex();
00100 
00101     return cells_;
00102 }
00103 
00104 
00105 bool ignitionSite::igniting() const
00106 {
00107     scalar curTime = db_.value();
00108     scalar deltaT = db_.deltaT().value();
00109 
00110     return
00111     (
00112         (curTime - deltaT >= time_)
00113         &&
00114         (curTime - deltaT < time_ + max(duration_, deltaT) + SMALL)
00115     );
00116 }
00117 
00118 
00119 bool ignitionSite::ignited() const
00120 {
00121     scalar curTime = db_.value();
00122     scalar deltaT = db_.deltaT().value();
00123 
00124     return(curTime - deltaT >= time_);
00125 }
00126 
00127 
00128 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00129 
00130 void ignitionSite::operator=(const ignitionSite& is)
00131 {
00132     location_ = is.location_;
00133     diameter_ = is.diameter_;
00134     time_ = is.time_;
00135     duration_ = is.duration_;
00136     strength_ = is.strength_;
00137     cells_ = is.cells_;
00138     cellVolumes_ = is.cellVolumes_;
00139 }
00140 
00141 
00142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00143 
00144 } // End namespace Foam
00145 
00146 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines