FTRsurfaceFormat.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) 2011 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 "FTRsurfaceFormat.H"
27 #include "Keyed.H"
28 #include "IFstream.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Face>
34 (
35  const fileName& filename
36 )
37 {
38  read(filename);
39 }
40 
41 
42 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43 
44 template<class Face>
46 (
47  const fileName& filename
48 )
49 {
50  this->clear();
51 
52  IFstream is(filename);
53  if (!is.good())
54  {
56  (
57  "fileFormats::FTRsurfaceFormat::read(const fileName&)"
58  )
59  << "Cannot read file " << filename
60  << exit(FatalError);
61  }
62 
63  List<ftrPatch> ftrPatches(is);
64 
65  // points read directly
66  is >> this->storedPoints();
67 
68  // triFaces read with attached keys
69  List< Keyed<triFace> > facesRead(is);
70 
71  List<Face> faceLst(facesRead.size());
72  List<label> zoneIds(facesRead.size());
73 
74  // disentangle faces/keys - already triangulated
75  forAll(facesRead, faceI)
76  {
77  // unfortunately cannot transfer to save memory
78  faceLst[faceI] = facesRead[faceI];
79  zoneIds[faceI] = facesRead[faceI].key();
80  }
81 
82  this->storedFaces().transfer(faceLst);
83  this->storedZoneIds().transfer(zoneIds);
84  facesRead.clear();
85 
86  // change ftrPatch into surfZoneIdentifier
87  List<surfZoneIdentifier> newZones(ftrPatches.size());
88  forAll(newZones, zoneI)
89  {
90  newZones[zoneI] = surfZoneIdentifier
91  (
92  ftrPatches[zoneI].name(),
93  zoneI
94  );
95  }
96 
97  this->storedZoneToc().transfer(newZones);
98  return true;
99 }
100 
101 
102 // ************************************************************************* //
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Input from file stream.
Definition: IFstream.H:81
virtual bool read(const fileName &)
Read from file.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
An identifier for a surface zone on a meshed surface.
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
Reading of the (now deprecated and infrequently used) Foam Trisurface Format.
A class for handling file names.
Definition: fileName.H:69
bool read(const char *, int32_t &)
Definition: int32IO.C:87
UEqn clear()