initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / engine / ignition / ignitionSite.C
blob3c6529aef674bfcae62398bed5d678a0a0fac18e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "ignitionSite.H"
28 #include "Time.H"
29 #include "volFields.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
38 void ignitionSite::findIgnitionCells(const fvMesh& mesh)
40     // Bit tricky: generate C and V before shortcutting if cannot find
41     // cell locally. mesh.C generation uses parallel communication.
42     const volVectorField& centres = mesh.C();
43     const scalarField& vols = mesh.V();
45     label ignCell = mesh.findCell(location_);
46     if (ignCell == -1)
47     {
48         return;
49     }
51     scalar radius = diameter_/2.0;
53     cells_.setSize(1);
54     cellVolumes_.setSize(1);
56     cells_[0] = ignCell;
57     cellVolumes_[0] = vols[ignCell];
59     scalar minDist = GREAT;
60     label nearestCell = 0;
61     label nIgnCells = 1;
63     forAll(centres, celli)
64     {
65         scalar dist = mag(centres[celli] - location_);
67         if (dist < minDist)
68         {
69             nearestCell = celli;
70             minDist = dist;
71         }
73         if (dist < radius && celli != ignCell)
74         {
75             cells_.setSize(nIgnCells+1);
76             cellVolumes_.setSize(nIgnCells+1);
78             cells_[nIgnCells] = celli;
79             cellVolumes_[nIgnCells] = vols[celli];
81             nIgnCells++;
82         }
83     }
85     if (cells_.size())
86     {
87         Pout<< "Found ignition cells:" << endl << cells_ << endl;
88     }
92 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
94 const labelList& ignitionSite::cells() const
96     if (mesh_.changing() && timeIndex_ != db_.timeIndex())
97     {
98         const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
99     }
100     timeIndex_ = db_.timeIndex();
102     return cells_;
106 bool ignitionSite::igniting() const
108     scalar curTime = db_.value();
109     scalar deltaT = db_.deltaT().value();
111     return
112     (
113         (curTime - deltaT >= time_)
114         &&
115         (curTime - deltaT < time_ + max(duration_, deltaT) + SMALL)
116     );
120 bool ignitionSite::ignited() const
122     scalar curTime = db_.value();
123     scalar deltaT = db_.deltaT().value();
125     return(curTime - deltaT >= time_);
129 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
131 void ignitionSite::operator=(const ignitionSite& is)
133     location_ = is.location_;
134     diameter_ = is.diameter_;
135     time_ = is.time_;
136     duration_ = is.duration_;
137     strength_ = is.strength_;
138     cells_ = is.cells_;
139     cellVolumes_ = is.cellVolumes_;
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 } // End namespace Foam
147 // ************************************************************************* //