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 -------------------------------------------------------------------------------
10 License
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.
22 
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 
28 template<class Type>
30 {
31  const label nComponents =
33 
34  label count = data_.size();
35  data_.setSize(data_.size() + fld.size()*nComponents);
36 
37  forAll(fld, fieldi)
38  {
39  for (direction d = 0; d < nComponents; ++d)
40  {
41  data_[count++] = component(fld[fieldi], d);
42  }
43  }
44 }
45 
46 
47 template<class Type1, class Type2>
48 void Foam::glTF::object::addData(const Type1& fld1, const Type2&fld2)
49 {
50  if (fld1.size() != fld2.size())
51  {
53  << "Field lengths must be the same. Field1:"
54  << fld1.size() << " Field2:" << fld2.size()
55  << abort(FatalError);
56  }
57 
58  const label nComponents1 =
60 
61  const label nComponents2 =
63 
64  label count = data_.size();
65  data_.setSize
66  (
67  data_.size() + fld1.size()*(nComponents1 + nComponents2)
68  );
69 
70  forAll(fld1, fieldi)
71  {
72  for (direction d = 0; d < nComponents1; ++d)
73  {
74  data_[count++] = component(fld1[fieldi], d);
75  }
76 
77  for (direction d = 0; d < nComponents2; ++d)
78  {
79  data_[count++] = component(fld2[fieldi], d);
80  }
81  }
82 }
83 
84 
85 // ************************************************************************* //
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::glTF::object::addData
void addData(const Type &fld)
Add data to the buffer.
Definition: foamGltfObjectTemplates.C:29