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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ignitionSite.H"
30 #include "Time.H"
31 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void Foam::ignitionSite::findIgnitionCells(const fvMesh& mesh)
36 {
37  // Bit tricky: generate C and V before shortcutting if cannot find
38  // cell locally. mesh.C generation uses parallel communication.
39  const volVectorField& centres = mesh.C();
40  const scalarField& vols = mesh.V();
41 
42  label ignCell = mesh.findCell(location_);
43  if (ignCell == -1)
44  {
45  return;
46  }
47 
48  scalar radius = diameter_/2.0;
49 
50  cells_.setSize(1);
51  cellVolumes_.setSize(1);
52 
53  cells_[0] = ignCell;
54  cellVolumes_[0] = vols[ignCell];
55 
56  scalar minDist = GREAT;
57  label nIgnCells = 1;
58 
59  forAll(centres, celli)
60  {
61  scalar dist = mag(centres[celli] - location_);
62 
63  if (dist < minDist)
64  {
65  minDist = dist;
66  }
67 
68  if (dist < radius && celli != ignCell)
69  {
70  cells_.setSize(nIgnCells+1);
71  cellVolumes_.setSize(nIgnCells+1);
72 
73  cells_[nIgnCells] = celli;
74  cellVolumes_[nIgnCells] = vols[celli];
75 
76  nIgnCells++;
77  }
78  }
79 
80  if (cells_.size())
81  {
82  Pout<< "Found ignition cells:" << endl << cells_ << endl;
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 {
91  if (mesh_.changing() && timeIndex_ != db_.timeIndex())
92  {
93  const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
94  }
95  timeIndex_ = db_.timeIndex();
96 
97  return cells_;
98 }
99 
100 
102 {
103  scalar curTime = db_.value();
104  scalar deltaT = db_.deltaTValue();
105 
106  return
107  (
108  (curTime - deltaT >= time_)
109  &&
110  (curTime - deltaT < time_ + max(duration_, deltaT) + SMALL)
111  );
112 }
113 
114 
116 {
117  scalar curTime = db_.value();
118  scalar deltaT = db_.deltaTValue();
119 
120  return(curTime - deltaT >= time_);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
125 
127 {
128  if (this == &is)
129  {
130  return;
131  }
132 
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_;
140 }
141 
142 
143 // ************************************************************************* //
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::ignitionSite::cells
const labelList & cells() const
Return the ignition cells updated if the mesh moved.
Definition: ignitionSite.C:89
ignitionSite.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::ignitionSite
Foam::ignitionSite.
Definition: ignitionSite.H:62
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::ignitionSite::ignited
bool ignited() const
Definition: ignitionSite.C:115
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:62
Time.H
Foam::List< label >
Foam::ignitionSite::operator=
void operator=(const ignitionSite &)
Definition: ignitionSite.C:126
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::ignitionSite::igniting
bool igniting() const
Definition: ignitionSite.C:101