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