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

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