ignitionSite.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "Time.H"
28 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::ignitionSite::findIgnitionCells(const fvMesh& mesh)
33 {
34  // Bit tricky: generate C and V before shortcutting if cannot find
35  // cell locally. mesh.C generation uses parallel communication.
36  const volVectorField& centres = mesh.C();
37  const scalarField& vols = mesh.V();
38 
39  label ignCell = mesh.findCell(location_);
40  if (ignCell == -1)
41  {
42  return;
43  }
44 
45  scalar radius = diameter_/2.0;
46 
47  cells_.setSize(1);
48  cellVolumes_.setSize(1);
49 
50  cells_[0] = ignCell;
51  cellVolumes_[0] = vols[ignCell];
52 
53  scalar minDist = great;
54  label nIgnCells = 1;
55 
56  forAll(centres, celli)
57  {
58  scalar dist = mag(centres[celli] - location_);
59 
60  if (dist < minDist)
61  {
62  minDist = dist;
63  }
64 
65  if (dist < radius && celli != ignCell)
66  {
67  cells_.setSize(nIgnCells+1);
68  cellVolumes_.setSize(nIgnCells+1);
69 
70  cells_[nIgnCells] = celli;
71  cellVolumes_[nIgnCells] = vols[celli];
72 
73  nIgnCells++;
74  }
75  }
76 
77  if (cells_.size())
78  {
79  Pout<< "Found ignition cells:" << endl << cells_ << endl;
80  }
81 }
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
87 {
88  if (mesh_.changing() && timeIndex_ != db_.timeIndex())
89  {
90  const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
91  }
92  timeIndex_ = db_.timeIndex();
93 
94  return cells_;
95 }
96 
97 
99 {
100  scalar curTime = db_.value();
101  scalar deltaT = db_.deltaTValue();
102 
103  return
104  (
105  (curTime - deltaT >= time_)
106  &&
107  (curTime - deltaT < time_ + max(duration_, deltaT) + small)
108  );
109 }
110 
111 
113 {
114  scalar curTime = db_.value();
115  scalar deltaT = db_.deltaTValue();
116 
117  return(curTime - deltaT >= time_);
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
122 
124 {
125  location_ = is.location_;
126  diameter_ = is.diameter_;
127  time_ = is.time_;
128  duration_ = is.duration_;
129  strength_ = is.strength_;
130  cells_ = is.cells_;
131  cellVolumes_ = is.cellVolumes_;
132 }
133 
134 
135 // ************************************************************************* //
bool changing() const
Is mesh changing (topology changing and/or moving)
Definition: polyMesh.H:530
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool ignited() const
Definition: ignitionSite.C:112
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:55
void operator=(const ignitionSite &)
Definition: ignitionSite.C:123
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const labelList & cells() const
Return the ignition cells updated if the mesh moved.
Definition: ignitionSite.C:86
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:41
const Type & value() const
Return const reference to value.
bool igniting() const
Definition: ignitionSite.C:98
Foam::ignitionSite.
Definition: ignitionSite.H:58
void setSize(const label)
Reset size of List.
Definition: List.C:281
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
dimensioned< scalar > mag(const dimensioned< Type > &)