Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / conversion / ensight / part / ensightPartIO.C
blobb6f20da63d865d359e3f510295bc2604bee5c591
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Output for ensightPart
27 \*---------------------------------------------------------------------------*/
29 #include "ensightPart.H"
30 #include "dictionary.H"
31 #include "IOstreams.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 void Foam::ensightPart::writeHeader
37     ensightFile& os,
38     bool withDescription
39 ) const
41     os.write("part");
42     os.newline();
44     os.write(number() + 1);   // Ensight starts with 1
45     os.newline();
47     if (withDescription)
48     {
49         os.write(name());
50         os.newline();
51     }
55 void Foam::ensightPart::writeFieldList
57     ensightFile& os,
58     const List<scalar>& field,
59     const List<label>& idList
60 ) const
62     forAll(idList, i)
63     {
64 #       ifndef Intel
65         if (idList[i] >= field.size() || std::isnan(field[idList[i]]))
66 #       else
67         if (idList[i] >= field.size())
68 #       endif
69         {
70             os.writeUndef();
71         }
72         else
73         {
74             os.write(field[idList[i]]);
75         }
77         os.newline();
78     }
82 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
84 bool Foam::ensightPart::writeSummary(Ostream& os) const
86     os  << indent << type() << nl
87         << indent << token::BEGIN_BLOCK << incrIndent << nl;
89     // Ensight starts with 1
90     os.writeKeyword("id") << (number() + 1) << token::END_STATEMENT << nl;
91     os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
92     os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
93     os.writeKeyword("size") << size() << token::END_STATEMENT << nl;
95     os   << decrIndent << indent << token::END_BLOCK << nl << endl;
97     return true;
101 bool Foam::ensightPart::writeData(Ostream& os) const
103     os  << indent << type() << nl
104         << indent << token::BEGIN_BLOCK << incrIndent << nl;
106     os.writeKeyword("id") << number() << token::END_STATEMENT << nl;
107     os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
108     os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
110     forAll(elementTypes(), typeI)
111     {
112         word key(elementTypes()[typeI]);
113         if (elemLists_[typeI].size())
114         {
115             elemLists_[typeI].writeEntry(key, os);
116         }
117     }
119     os   << decrIndent << indent << token::END_BLOCK << nl << endl;
121     return true;
125 void Foam::ensightPart::writeGeometry(ensightGeoFile& os) const
127     if (size() && meshPtr_)
128     {
129         const polyMesh& mesh = *meshPtr_;
130         const pointField& meshPoints = mesh.points();
132         localPoints ptList = calcLocalPoints();
133         labelList& pointMap = ptList.list;
135         writeHeader(os, true);
137         // write points
138         os.writeKeyword("coordinates");
139         os.write(ptList.nPoints);
140         os.newline();
142         for (direction cmpt=0; cmpt < vector::nComponents; cmpt++)
143         {
144             forAll(pointMap, ptI)
145             {
146                 if (pointMap[ptI] > -1)
147                 {
148                     os.write( meshPoints[ptI].component(cmpt) );
149                     os.newline();
150                 }
151             }
152         }
154         // write parts
155         forAll(elementTypes(), elemI)
156         {
157             if (elemLists_[elemI].size())
158             {
159                 writeConnectivity
160                 (
161                     os,
162                     elementTypes()[elemI],
163                     elemLists_[elemI],
164                     pointMap
165                 );
166             }
167         }
168     }
172 void Foam::ensightPart::writeScalarField
174     ensightFile& os,
175     const List<scalar>& field
176 ) const
178     if (size() && field.size() && (os.allowUndef() || isFieldDefined(field)))
179     {
180         writeHeader(os);
182         forAll(elementTypes(), elemI)
183         {
184             const labelList& idList = elemLists_[elemI];
186             if (idList.size())
187             {
188                 os.writeKeyword( elementTypes()[elemI] );
189                 writeFieldList(os, field, idList);
190             }
191         }
192     }
196 void Foam::ensightPart::writeVectorField
198     ensightFile& os,
199     const List<scalar>& field0,
200     const List<scalar>& field1,
201     const List<scalar>& field2
202 ) const
204     if (size() && field0.size() && (os.allowUndef() || isFieldDefined(field0)))
205     {
206         writeHeader(os);
208         forAll(elementTypes(), elemI)
209         {
210             const labelList& idList = elemLists_[elemI];
212             if (idList.size())
213             {
214                 os.writeKeyword( elementTypes()[elemI] );
215                 writeFieldList(os, field0, idList);
216                 writeFieldList(os, field1, idList);
217                 writeFieldList(os, field2, idList);
218             }
219         }
220     }
224 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
226 Foam::Ostream& Foam::operator<<
228     Ostream& os,
229     const ensightPart& part
232     part.writeData(os);
233     return os;
237 Foam::ensightGeoFile& Foam::operator<<
239     ensightGeoFile& os,
240     const ensightPart& part
243     part.writeGeometry(os);
244     return os;
248 // ************************************************************************* //