initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / pointPatchFields / derived / global / globalPointPatchField.C
blobcce542b124da5df31eee48ef7547813c28e25128
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "globalPointPatchField.H"
28 #include "PstreamCombineReduceOps.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
37 template<class Type>
38 globalPointPatchField<Type>::globalPointPatchField
40     const pointPatch& p,
41     const DimensionedField<Type, pointMesh>& iF
44     coupledPointPatchField<Type>(p, iF),
45     globalPointPatch_(refCast<const globalPointPatch>(p))
49 template<class Type>
50 globalPointPatchField<Type>::globalPointPatchField
52     const pointPatch& p,
53     const DimensionedField<Type, pointMesh>& iF,
54     const dictionary& dict
57     coupledPointPatchField<Type>(p, iF, dict),
58     globalPointPatch_(refCast<const globalPointPatch>(p))
60     if (!isType<globalPointPatch>(p))
61     {
62         FatalIOErrorIn
63         (
64             "globalPointPatchField<Type>::globalPointPatchField\n"
65             "(\n"
66             " const pointPatch& p,\n"
67             " const Field<Type>& field,\n"
68             " const dictionary& dict\n"
69             ")\n",
70             dict
71         )   << "patch " << this->patch().index()
72             << " not processorPoint type. "
73             << "Patch type = " << p.type()
74             << exit(FatalIOError);
75     }
79 template<class Type>
80 globalPointPatchField<Type>::globalPointPatchField
82     const globalPointPatchField<Type>& ptf,
83     const pointPatch& p,
84     const DimensionedField<Type, pointMesh>& iF,
85     const pointPatchFieldMapper& mapper
88     coupledPointPatchField<Type>(ptf, p, iF, mapper),
89     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
91     if (!isType<globalPointPatch>(this->patch()))
92     {
93         FatalErrorIn
94         (
95             "globalPointPatchField<Type>::globalPointPatchField\n"
96             "(\n"
97             " const globalPointPatchField<Type>& ptf,\n"
98             " const pointPatch& p,\n"
99             " const DimensionedField<Type, pointMesh>& iF,\n"
100             " const pointPatchFieldMapper& mapper\n"
101             ")\n"
102         )   << "Field type does not correspond to patch type for patch "
103             << this->patch().index() << "." << endl
104             << "Field type: " << typeName << endl
105             << "Patch type: " << this->patch().type()
106             << exit(FatalError);
107     }
111 template<class Type>
112 globalPointPatchField<Type>::globalPointPatchField
114     const globalPointPatchField<Type>& ptf,
115     const DimensionedField<Type, pointMesh>& iF
118     coupledPointPatchField<Type>(ptf, iF),
119     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
123 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 template<class Type>
126 globalPointPatchField<Type>::~globalPointPatchField()
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
132 template<class Type>
133 void globalPointPatchField<Type>::swapAdd(Field<Type>& pField) const
135     // Create the global list and insert local values
136     if (globalPointPatch_.globalPointSize() > 0)
137     {
138         Field<Type> lpf = patchInternalField(pField);
139         const labelList& addr = globalPointPatch_.sharedPointAddr();
141         Field<Type> gpf
142         (
143             globalPointPatch_.globalPointSize(),
144             pTraits<Type>::zero
145         );
147         forAll(addr, i)
148         {
149             gpf[addr[i]] += lpf[i];
150         }
152         combineReduce(gpf, plusEqOp<Field<Type> >());
154         // Extract local data
155         forAll (addr, i)
156         {
157             lpf[i] = gpf[addr[i]];
158         }
160         setInInternalField(pField, lpf);
161     }
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 } // End namespace Foam
169 // ************************************************************************* //