ENH: decomposePar.C: add shortcircuit to avoid allocating point mappers
[OpenFOAM-2.0.x.git] / applications / utilities / parallelProcessing / decomposePar / lagrangianFieldDecomposerDecomposeFields.C
blobf40de9a50ff79a63b2478686d246298abe7b6cfe
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.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "lagrangianFieldDecomposer.H"
27 #include "IOobjectList.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class Type>
32 void Foam::lagrangianFieldDecomposer::readFields
34     const label cloudI,
35     const IOobjectList& lagrangianObjects,
36     PtrList<PtrList<IOField<Type> > >& lagrangianFields
39     // Search list of objects for lagrangian fields
40     IOobjectList lagrangianTypeObjects
41     (
42         lagrangianObjects.lookupClass(IOField<Type>::typeName)
43     );
45     lagrangianFields.set
46     (
47         cloudI,
48         new PtrList<IOField<Type> >
49         (
50             lagrangianTypeObjects.size()
51         )
52     );
54     label lagrangianFieldi = 0;
55     forAllIter(IOobjectList, lagrangianTypeObjects, iter)
56     {
57         lagrangianFields[cloudI].set
58         (
59             lagrangianFieldi++,
60             new IOField<Type>(*iter())
61         );
62     }
66 template<class Type>
67 void Foam::lagrangianFieldDecomposer::readFieldFields
69     const label cloudI,
70     const IOobjectList& lagrangianObjects,
71     PtrList<PtrList<CompactIOField<Field<Type>, Type> > >& lagrangianFields
74     // Search list of objects for lagrangian fields
75     IOobjectList lagrangianTypeObjectsA
76     (
77         lagrangianObjects.lookupClass(IOField<Field<Type> >::typeName)
78     );
80     IOobjectList lagrangianTypeObjectsB
81     (
82         lagrangianObjects.lookupClass
83         (
84             CompactIOField<Field<Type>,
85             Type>::typeName
86         )
87     );
89     lagrangianFields.set
90     (
91         cloudI,
92         new PtrList<CompactIOField<Field<Type>, Type> >
93         (
94             lagrangianTypeObjectsA.size() + lagrangianTypeObjectsB.size()
95         )
96     );
98     label lagrangianFieldi = 0;
100     forAllIter(IOobjectList, lagrangianTypeObjectsA, iter)
101     {
102         lagrangianFields[cloudI].set
103         (
104             lagrangianFieldi++,
105             new CompactIOField<Field<Type>, Type>(*iter())
106         );
107     }
109     forAllIter(IOobjectList, lagrangianTypeObjectsB, iter)
110     {
111         lagrangianFields[cloudI].set
112         (
113             lagrangianFieldi++,
114             new CompactIOField<Field<Type>, Type>(*iter())
115         );
116     }
120 template<class Type>
121 Foam::tmp<Foam::IOField<Type> >
122 Foam::lagrangianFieldDecomposer::decomposeField
124     const word& cloudName,
125     const IOField<Type>& field
126 ) const
128     // Create and map the internal field values
129     Field<Type> procField(field, particleIndices_);
131     // Create the field for the processor
132     return tmp<IOField<Type> >
133     (
134         new IOField<Type>
135         (
136             IOobject
137             (
138                 field.name(),
139                 procMesh_.time().timeName(),
140                 cloud::prefix/cloudName,
141                 procMesh_,
142                 IOobject::NO_READ,
143                 IOobject::NO_WRITE
144             ),
145             procField
146         )
147     );
151 template<class Type>
152 Foam::tmp<Foam::CompactIOField<Foam::Field<Type>, Type> >
153 Foam::lagrangianFieldDecomposer::decomposeFieldField
155     const word& cloudName,
156     const CompactIOField<Field<Type>, Type>& field
157 ) const
159     // Create and map the internal field values
160     Field<Field<Type> > procField(field, particleIndices_);
162     // Create the field for the processor
163     return tmp<CompactIOField<Field<Type>, Type> >
164     (
165         new CompactIOField<Field<Type>, Type>
166         (
167             IOobject
168             (
169                 field.name(),
170                 procMesh_.time().timeName(),
171                 cloud::prefix/cloudName,
172                 procMesh_,
173                 IOobject::NO_READ,
174                 IOobject::NO_WRITE
175             ),
176             procField
177         )
178     );
182 template<class GeoField>
183 void Foam::lagrangianFieldDecomposer::decomposeFields
185     const word& cloudName,
186     const PtrList<GeoField>& fields
187 ) const
189     if (particleIndices_.size())
190     {
191         forAll(fields, fieldI)
192         {
193             decomposeField(cloudName, fields[fieldI])().write();
194         }
195     }
199 template<class GeoField>
200 void Foam::lagrangianFieldDecomposer::decomposeFieldFields
202     const word& cloudName,
203     const PtrList<GeoField>& fields
204 ) const
206     if (particleIndices_.size())
207     {
208         forAll(fields, fieldI)
209         {
210             decomposeFieldField(cloudName, fields[fieldI])().write();
211         }
212     }
216 // ************************************************************************* //