FreeFOAM The Cross-Platform CFD Toolkit
ensightPart.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 "ensightPart.H"
28 #include <OpenFOAM/dictionary.H>
29 #include <OpenFOAM/ListOps.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
33 {
34  defineTypeNameAndDebug(ensightPart, 0);
35  defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
36  defineRunTimeSelectionTable(ensightPart, istream);
37 }
38 
39 Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
44 {
45  forAll(elemLists_, elemI)
46  {
47  const labelList& idList = elemLists_[elemI];
48 
49  forAll(idList, i)
50  {
51  label id = idList[i];
52 
53  if (id >= field.size() || std::isnan(field[id]))
54  {
55  return false;
56  }
57  }
58  }
59  return true;
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 
66 ()
67 :
68  number_(0),
69  name_(""),
70  elemLists_(0),
71  offset_(0),
72  size_(0),
73  isCellData_(true),
74  matId_(0),
75  meshPtr_(0)
76 {}
77 
78 
80 (
81  label partNumber,
82  const string& partDescription
83 )
84 :
85  number_(partNumber),
86  name_(partDescription),
87  elemLists_(0),
88  offset_(0),
89  size_(0),
90  isCellData_(true),
91  matId_(0),
92  meshPtr_(0)
93 {}
94 
95 
97 (
98  label partNumber,
99  const string& partDescription,
100  const polyMesh& pMesh
101 )
102 :
103  number_(partNumber),
104  name_(partDescription),
105  elemLists_(0),
106  offset_(0),
107  size_(0),
108  isCellData_(true),
109  matId_(0),
110  meshPtr_(&pMesh)
111 {}
112 
113 
115 :
116  number_(part.number_),
117  name_(part.name_),
118  elemLists_(part.elemLists_),
119  offset_(part.offset_),
120  size_(part.size_),
121  isCellData_(part.isCellData_),
122  matId_(part.matId_),
123  meshPtr_(part.meshPtr_)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
128 
130 {
131  word partType(is);
132 
133  istreamConstructorTable::iterator cstrIter =
134  istreamConstructorTablePtr_->find(partType);
135 
136  if (cstrIter == istreamConstructorTablePtr_->end())
137  {
139  (
140  "ensightPart::New(Istream&)",
141  is
142  ) << "unknown ensightPart type " << partType << endl << endl
143  << "Valid ensightPart types are :" << endl
144  << istreamConstructorTablePtr_->sortedToc()
145  << exit(FatalIOError);
146  }
147 
148  return autoPtr<ensightPart>(cstrIter()(is));
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
162  dictionary dict(is);
163  dict.lookup("id") >> number_;
164  dict.lookup("name") >> name_;
165  dict.readIfPresent("offset", offset_);
166 
167  // populate elemLists_
168  elemLists_.setSize(elementTypes().size());
169 
170  forAll(elementTypes(), elemI)
171  {
172  word key(elementTypes()[elemI]);
173 
174  elemLists_[elemI].clear();
175  dict.readIfPresent(key, elemLists_[elemI]);
176 
177  size_ += elemLists_[elemI].size();
178  }
179 
180  is.check("ensightPart::reconstruct(Istream&)");
181 }
182 
183 
185 {
186  // transform to global values first
187  if (offset_)
188  {
189  forAll(elemLists_, elemI)
190  {
191  labelList& idList = elemLists_[elemI];
192  forAll(idList, i)
193  {
194  idList[i] += offset_;
195  }
196  }
197 
198  offset_ = 0;
199  }
200 
201  if (origId.size())
202  {
203  forAll(elemLists_, elemI)
204  {
205  inplaceRenumber(origId, elemLists_[elemI]);
206  }
207  }
208 }
209 
210 
211 // ************************ vim: set sw=4 sts=4 et: ************************ //