Loading...
Searching...
No Matches
foamGltfObjectTemplates.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) 2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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.
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
28template<class Type>
29void Foam::glTF::object::addData(const Type& fld)
30{
32
33 label count = data_.size();
34 data_.resize(data_.size() + fld.size()*nCmpts);
35
36 forAll(fld, fieldi)
37 {
38 for (direction d = 0; d < nCmpts; ++d)
39 {
40 data_[count++] = component(fld[fieldi], d);
41 }
42 }
43}
44
45
46template<class Type1, class Type2>
47void Foam::glTF::object::addData(const Type1& fld1, const Type2& fld2)
48{
49 if (fld1.size() != fld2.size())
50 {
52 << "Field lengths must be the same. Field1:"
53 << fld1.size() << " Field2:" << fld2.size()
54 << abort(FatalError);
55 }
56
57 const direction nCmpts1 = pTraits<typename Type1::value_type>::nComponents;
58 const direction nCmpts2 = pTraits<typename Type2::value_type>::nComponents;
59
60 label count = data_.size();
61 data_.resize(data_.size() + fld1.size()*(nCmpts1 + nCmpts2));
62
63 forAll(fld1, fieldi)
64 {
65 for (direction d = 0; d < nCmpts1; ++d)
66 {
67 data_[count++] = component(fld1[fieldi], d);
68 }
69
70 for (direction d = 0; d < nCmpts2; ++d)
71 {
72 data_[count++] = component(fld2[fieldi], d);
73 }
74 }
75}
76
77
78// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
void addData(const Type &fld)
Add data to the buffer.
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition BitOps.H:73
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
errorManip< error > abort(error &err)
Definition errorManip.H:139
uint8_t direction
Definition direction.H:49
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299