FreeFOAM The Cross-Platform CFD Toolkit
ignitionSite.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ignitionSite.H"
27 #include <OpenFOAM/Time.H>
28 #include <finiteVolume/volFields.H>
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void ignitionSite::findIgnitionCells(const fvMesh& mesh)
38 {
39  // Bit tricky: generate C and V before shortcutting if cannot find
40  // cell locally. mesh.C generation uses parallel communication.
41  const volVectorField& centres = mesh.C();
42  const scalarField& vols = mesh.V();
43 
44  label ignCell = mesh.findCell(location_);
45  if (ignCell == -1)
46  {
47  return;
48  }
49 
50  scalar radius = diameter_/2.0;
51 
52  cells_.setSize(1);
53  cellVolumes_.setSize(1);
54 
55  cells_[0] = ignCell;
56  cellVolumes_[0] = vols[ignCell];
57 
58  scalar minDist = GREAT;
59  label nearestCell = 0;
60  label nIgnCells = 1;
61 
62  forAll(centres, celli)
63  {
64  scalar dist = mag(centres[celli] - location_);
65 
66  if (dist < minDist)
67  {
68  nearestCell = celli;
69  minDist = dist;
70  }
71 
72  if (dist < radius && celli != ignCell)
73  {
74  cells_.setSize(nIgnCells+1);
75  cellVolumes_.setSize(nIgnCells+1);
76 
77  cells_[nIgnCells] = celli;
78  cellVolumes_[nIgnCells] = vols[celli];
79 
80  nIgnCells++;
81  }
82  }
83 
84  if (cells_.size())
85  {
86  Pout<< "Found ignition cells:" << endl << cells_ << endl;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 {
95  if (mesh_.changing() && timeIndex_ != db_.timeIndex())
96  {
97  const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
98  }
99  timeIndex_ = db_.timeIndex();
100 
101  return cells_;
102 }
103 
104 
106 {
107  scalar curTime = db_.value();
108  scalar deltaT = db_.deltaT().value();
109 
110  return
111  (
112  (curTime - deltaT >= time_)
113  &&
114  (curTime - deltaT < time_ + max(duration_, deltaT) + SMALL)
115  );
116 }
117 
118 
120 {
121  scalar curTime = db_.value();
122  scalar deltaT = db_.deltaT().value();
123 
124  return(curTime - deltaT >= time_);
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
131 {
132  location_ = is.location_;
133  diameter_ = is.diameter_;
134  time_ = is.time_;
135  duration_ = is.duration_;
136  strength_ = is.strength_;
137  cells_ = is.cells_;
138  cellVolumes_ = is.cellVolumes_;
139 }
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace Foam
145 
146 // ************************ vim: set sw=4 sts=4 et: ************************ //