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-2025 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 #include "meshSearch.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::ignitionSite::findIgnitionCells(const fvMesh& mesh)
34 {
35  // Bit tricky: generate C and V before shortcutting if cannot find
36  // cell locally. mesh.C generation uses parallel communication.
37  const volVectorField& centres = mesh.C();
38  const scalarField& vols = mesh.V();
39 
40  label ignCell = meshSearch::New(mesh).findCell(location_);
41  if (ignCell == -1)
42  {
43  return;
44  }
45 
46  scalar radius = diameter_/2.0;
47 
48  cells_.setSize(1);
49  cellVolumes_.setSize(1);
50 
51  cells_[0] = ignCell;
52  cellVolumes_[0] = vols[ignCell];
53 
54  scalar minDist = great;
55  label nIgnCells = 1;
56 
57  forAll(centres, celli)
58  {
59  scalar dist = mag(centres[celli] - location_);
60 
61  if (dist < minDist)
62  {
63  minDist = dist;
64  }
65 
66  if (dist < radius && celli != ignCell)
67  {
68  cells_.setSize(nIgnCells+1);
69  cellVolumes_.setSize(nIgnCells+1);
70 
71  cells_[nIgnCells] = celli;
72  cellVolumes_[nIgnCells] = vols[celli];
73 
74  nIgnCells++;
75  }
76  }
77 
78  if (cells_.size())
79  {
80  Pout<< "Found ignition cells:" << endl << cells_ << endl;
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
89  if (mesh_.changing() && timeIndex_ != db_.timeIndex())
90  {
91  const_cast<ignitionSite&>(*this).findIgnitionCells(mesh_);
92  }
93  timeIndex_ = db_.timeIndex();
94 
95  return cells_;
96 }
97 
98 
100 {
101  scalar curTime = db_.value();
102  scalar deltaT = db_.deltaTValue();
103 
104  return
105  (
106  (curTime - deltaT >= time_)
107  &&
108  (curTime - deltaT < time_ + max(duration_, deltaT) + small)
109  );
110 }
111 
112 
114 {
115  scalar curTime = db_.value();
116  scalar deltaT = db_.deltaTValue();
117 
118  return(curTime - deltaT >= time_);
119 }
120 
121 
122 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
123 
125 {
126  location_ = is.location_;
127  diameter_ = is.diameter_;
128  time_ = is.time_;
129  duration_ = is.duration_;
130  strength_ = is.strength_;
131  cells_ = is.cells_;
132  cellVolumes_ = is.cellVolumes_;
133 }
134 
135 
136 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
const volVectorField & C() const
Return cell centres.
const DimensionedField< scalar, fvMesh > & V() const
Return cell volumes.
Foam::ignitionSite.
Definition: ignitionSite.H:58
const labelList & cells() const
Return the ignition cells updated if the mesh moved.
Definition: ignitionSite.C:87
bool ignited() const
Definition: ignitionSite.C:113
void operator=(const ignitionSite &)
Definition: ignitionSite.C:124
bool igniting() const
Definition: ignitionSite.C:99
label findCell(const point &p, const pointInCellShapes=pointInCellShapes::tets) const
Find the cell containing the given point.
Definition: meshSearch.C:173
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
scalar minDist(const List< pointIndexHit > &hitList)
VolField< vector > volVectorField
Definition: volFieldsFwd.H:63
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)