OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

globalPointPatchField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "globalPointPatchField.H"
00028 #include "PstreamCombineReduceOps.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
00036 
00037 template<class Type>
00038 globalPointPatchField<Type>::globalPointPatchField
00039 (
00040     const pointPatch& p,
00041     const DimensionedField<Type, pointMesh>& iF
00042 )
00043 :
00044     coupledPointPatchField<Type>(p, iF),
00045     globalPointPatch_(refCast<const globalPointPatch>(p))
00046 {}
00047 
00048 
00049 template<class Type>
00050 globalPointPatchField<Type>::globalPointPatchField
00051 (
00052     const pointPatch& p,
00053     const DimensionedField<Type, pointMesh>& iF,
00054     const dictionary& dict
00055 )
00056 :
00057     coupledPointPatchField<Type>(p, iF, dict),
00058     globalPointPatch_(refCast<const globalPointPatch>(p))
00059 {
00060     if (!isType<globalPointPatch>(p))
00061     {
00062         FatalIOErrorIn
00063         (
00064             "globalPointPatchField<Type>::globalPointPatchField\n"
00065             "(\n"
00066             " const pointPatch& p,\n"
00067             " const Field<Type>& field,\n"
00068             " const dictionary& dict\n"
00069             ")\n",
00070             dict
00071         )   << "patch " << this->patch().index()
00072             << " not processorPoint type. "
00073             << "Patch type = " << p.type()
00074             << exit(FatalIOError);
00075     }
00076 }
00077 
00078 
00079 template<class Type>
00080 globalPointPatchField<Type>::globalPointPatchField
00081 (
00082     const globalPointPatchField<Type>& ptf,
00083     const pointPatch& p,
00084     const DimensionedField<Type, pointMesh>& iF,
00085     const pointPatchFieldMapper& mapper
00086 )
00087 :
00088     coupledPointPatchField<Type>(ptf, p, iF, mapper),
00089     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
00090 {
00091     if (!isType<globalPointPatch>(this->patch()))
00092     {
00093         FatalErrorIn
00094         (
00095             "globalPointPatchField<Type>::globalPointPatchField\n"
00096             "(\n"
00097             " const globalPointPatchField<Type>& ptf,\n"
00098             " const pointPatch& p,\n"
00099             " const DimensionedField<Type, pointMesh>& iF,\n"
00100             " const pointPatchFieldMapper& mapper\n"
00101             ")\n"
00102         )   << "Field type does not correspond to patch type for patch "
00103             << this->patch().index() << "." << endl
00104             << "Field type: " << typeName << endl
00105             << "Patch type: " << this->patch().type()
00106             << exit(FatalError);
00107     }
00108 }
00109 
00110 
00111 template<class Type>
00112 globalPointPatchField<Type>::globalPointPatchField
00113 (
00114     const globalPointPatchField<Type>& ptf,
00115     const DimensionedField<Type, pointMesh>& iF
00116 )
00117 :
00118     coupledPointPatchField<Type>(ptf, iF),
00119     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
00120 {}
00121 
00122 
00123 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
00124 
00125 template<class Type>
00126 globalPointPatchField<Type>::~globalPointPatchField()
00127 {}
00128 
00129 
00130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
00131 
00132 template<class Type>
00133 void globalPointPatchField<Type>::swapAdd(Field<Type>& pField) const
00134 {
00135     // Create the global list and insert local values
00136     if (globalPointPatch_.globalPointSize() > 0)
00137     {
00138         Field<Type> lpf = patchInternalField(pField);
00139         const labelList& addr = globalPointPatch_.sharedPointAddr();
00140 
00141         Field<Type> gpf
00142         (
00143             globalPointPatch_.globalPointSize(),
00144             pTraits<Type>::zero
00145         );
00146 
00147         forAll(addr, i)
00148         {
00149             gpf[addr[i]] += lpf[i];
00150         }
00151 
00152         combineReduce(gpf, plusEqOp<Field<Type> >());
00153 
00154         // Extract local data
00155         forAll (addr, i)
00156         {
00157             lpf[i] = gpf[addr[i]];
00158         }
00159 
00160         setInInternalField(pField, lpf);
00161     }
00162 }
00163 
00164 
00165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00166 
00167 } // End namespace Foam
00168 
00169 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd