FRWGraphI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 template<class T, Foam::label width>
27 void Foam::FRWGraph<T, width>::checkIndex(const label i, const label j) const
28 {
29  if( (i < 0) || (i >= nRows_) )
30  {
32  (
33  "void Foam::FRWGraph<T,width>::"
34  "checkIndex(const label i, const label j) const"
35  ) << "Row index " << i
36  << " is not in range " << 0
37  << " and " << nRows_ << abort(FatalError);
38  }
39 
40  if( (j < 0) || (j >= width) )
42  (
43  "void Foam::FRWGraph<T,width>::"
44  "checkIndex(const label i, const label j) const"
45  ) << "Column index " << j
46  << " is not in range " << 0
47  << " and " << width << abort(FatalError);
48 }
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 //- Construct null
53 template<class T, Foam::label width>
55 :
56  data_(),
57  nRows_(0)
58 {}
59 
60 //- Construct given size
61 template<class T, Foam::label width>
63 (
64  const label s
65 )
66 :
67  data_(s * width),
68  nRows_(s)
69 {}
70 
71 
72 //- Construct given size
73 template<class T, Foam::label width>
75 (
76  const label s,
77  const T& t
78 )
79 :
80  data_(s * width, t),
81  nRows_(s)
82 {}
83 
84 template<class T, Foam::label width>
86 (
87  const FRWGraph<T,width>& ol
88 )
89 :
90  data_(ol.data_),
91  nRows_(ol.nRows_)
92 {}
93 
94 template<class T, Foam::label width>
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
101 template<class T, Foam::label width>
103 {
104  return nRows_;
105 }
106 
107 template<class T, Foam::label width>
109 {
110  return width;
111 }
112 
113 template<class T, Foam::label width>
115 {
116  data_.setSize(i * width);
117  nRows_ = i;
118 }
119 
120 template<class T, Foam::label width>
122 {
123  data_.clear();
124  nRows_ = 0;
125 }
126 
127 template<class T, Foam::label width>
129 (
130  const FixedList<T, width>& l
131 )
132 {
133  forAll(l, elI)
134  data_.append(l[elI]);
135  ++nRows_;
136 }
137 
138 template<class T, Foam::label width>
140 (
141  const label rowI,
142  const FixedList<T, width>& l
143 )
144 {
145  const label start = rowI * width;
146  forAll(l, elI)
147  data_[start+elI] = l[elI];
148 }
149 
150 template<class T, Foam::label width>
152 (
153  const label rowI,
154  const T& e
155 ) const
156 {
157  const label start = rowI * width;
158 
159  for(label i=0;i<width;++i)
160  if( data_[start+i] == e )
161  return true;
162 
163  return false;
164 }
165 
166 template<class T, Foam::label width>
168 (
169  const label rowI,
170  const T& e
171 ) const
172 {
173  const label start = rowI * width;
174 
175  for(label i=0;i<width;++i)
176  if( data_[start+i] == e )
177  return i;
178 
179  return -1;
180 }
181 
182 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
183 template<class T, Foam::label width>
184 inline const T& Foam::FRWGraph<T,width>::operator()
185 (
186  const label i,
187  const label j
188 ) const
189 {
190  #ifdef FULLDEBUG
191  checkIndex(i, j);
192  #endif
193 
194  return data_[i * width + j];
195 }
196 
197 template<class T, Foam::label width>
199 (
200  const label i, const label j
201 )
202 {
203  #ifdef FULLDEBUG
204  checkIndex(i, j);
205  #endif
206 
207  return data_[i * width + j];
208 }
209 
210 template<class T, Foam::label width>
212 (
213  const FRWGraph<T, width>& l
214 )
215 {
216  data_ = l.data_;
217  nRows_ = l.nRows_;
218 }
219 
220 
221 // ************************************************************************* //
Foam::FRWGraph::clear
void clear()
Clear the graph.
Definition: FRWGraphI.H:121
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::FRWGraph::setRow
void setRow(const label rowI, const FixedList< T, width > &l)
Set row with the list.
Definition: FRWGraphI.H:140
Foam::FRWGraph::size
label size() const
Returns the number of rows.
Definition: FRWGraphI.H:102
Foam::FRWGraph::~FRWGraph
~FRWGraph()
Definition: FRWGraphI.H:95
Foam::FRWGraph::setSize
void setSize(const label)
Reset the number of rows.
Definition: FRWGraphI.H:114
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:59
Foam::FRWGraph::contains
bool contains(const label rowI, const T &e) const
check if the element is in the given row (takes linear time)
Definition: FRWGraphI.H:152
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::FRWGraph::operator
friend Ostream & operator(Ostream &, const FRWGraph< T, width > &)
Foam::FRWGraph::nRows_
label nRows_
number of rows
Definition: FRWGraph.H:80
Foam::FRWGraph::containsAtPosition
label containsAtPosition(const label rowI, const T &e) const
Definition: FRWGraphI.H:168
Foam::FRWGraph::data_
LongList< T > data_
list containing the data
Definition: FRWGraph.H:77
T
const volScalarField & T
Definition: createFields.H:25
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::FRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the size of a given row (obsolete)
Definition: FRWGraphI.H:108
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:94
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::FRWGraph::checkIndex
void checkIndex(const label i, const label j) const
check index
Definition: FRWGraphI.H:27
Foam::FRWGraph::FRWGraph
FRWGraph()
Construct null.
Definition: FRWGraphI.H:54
Foam::FRWGraph
Definition: FRWGraph.H:53
Foam::FRWGraph::appendFixedList
void appendFixedList(const FixedList< T, width > &l)
Append a row at the end of the graph.
Definition: FRWGraphI.H:129