FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "globalPointPatchField.H"
00027 #include <OpenFOAM/PstreamCombineReduceOps.H>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 globalPointPatchField<Type>::globalPointPatchField
00038 (
00039     const pointPatch& p,
00040     const DimensionedField<Type, pointMesh>& iF
00041 )
00042 :
00043     coupledPointPatchField<Type>(p, iF),
00044     globalPointPatch_(refCast<const globalPointPatch>(p))
00045 {}
00046 
00047 
00048 template<class Type>
00049 globalPointPatchField<Type>::globalPointPatchField
00050 (
00051     const pointPatch& p,
00052     const DimensionedField<Type, pointMesh>& iF,
00053     const dictionary& dict
00054 )
00055 :
00056     coupledPointPatchField<Type>(p, iF, dict),
00057     globalPointPatch_(refCast<const globalPointPatch>(p))
00058 {
00059     if (!isType<globalPointPatch>(p))
00060     {
00061         FatalIOErrorIn
00062         (
00063             "globalPointPatchField<Type>::globalPointPatchField\n"
00064             "(\n"
00065             " const pointPatch& p,\n"
00066             " const Field<Type>& field,\n"
00067             " const dictionary& dict\n"
00068             ")\n",
00069             dict
00070         )   << "patch " << this->patch().index()
00071             << " not processorPoint type. "
00072             << "Patch type = " << p.type()
00073             << exit(FatalIOError);
00074     }
00075 }
00076 
00077 
00078 template<class Type>
00079 globalPointPatchField<Type>::globalPointPatchField
00080 (
00081     const globalPointPatchField<Type>& ptf,
00082     const pointPatch& p,
00083     const DimensionedField<Type, pointMesh>& iF,
00084     const pointPatchFieldMapper& mapper
00085 )
00086 :
00087     coupledPointPatchField<Type>(ptf, p, iF, mapper),
00088     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
00089 {
00090     if (!isType<globalPointPatch>(this->patch()))
00091     {
00092         FatalErrorIn
00093         (
00094             "globalPointPatchField<Type>::globalPointPatchField\n"
00095             "(\n"
00096             " const globalPointPatchField<Type>& ptf,\n"
00097             " const pointPatch& p,\n"
00098             " const DimensionedField<Type, pointMesh>& iF,\n"
00099             " const pointPatchFieldMapper& mapper\n"
00100             ")\n"
00101         )   << "Field type does not correspond to patch type for patch "
00102             << this->patch().index() << "." << endl
00103             << "Field type: " << typeName << endl
00104             << "Patch type: " << this->patch().type()
00105             << exit(FatalError);
00106     }
00107 }
00108 
00109 
00110 template<class Type>
00111 globalPointPatchField<Type>::globalPointPatchField
00112 (
00113     const globalPointPatchField<Type>& ptf,
00114     const DimensionedField<Type, pointMesh>& iF
00115 )
00116 :
00117     coupledPointPatchField<Type>(ptf, iF),
00118     globalPointPatch_(refCast<const globalPointPatch>(ptf.patch()))
00119 {}
00120 
00121 
00122 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
00123 
00124 template<class Type>
00125 globalPointPatchField<Type>::~globalPointPatchField()
00126 {}
00127 
00128 
00129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
00130 
00131 template<class Type>
00132 void globalPointPatchField<Type>::swapAdd(Field<Type>& pField) const
00133 {
00134     // Create the global list and insert local values
00135     if (globalPointPatch_.globalPointSize() > 0)
00136     {
00137         Field<Type> lpf = this->patchInternalField(pField);
00138         const labelList& addr = globalPointPatch_.sharedPointAddr();
00139 
00140         Field<Type> gpf
00141         (
00142             globalPointPatch_.globalPointSize(),
00143             pTraits<Type>::zero
00144         );
00145 
00146         forAll(addr, i)
00147         {
00148             gpf[addr[i]] += lpf[i];
00149         }
00150 
00151         combineReduce(gpf, plusEqOp<Field<Type> >());
00152 
00153         // Extract local data
00154         forAll (addr, i)
00155         {
00156             lpf[i] = gpf[addr[i]];
00157         }
00158 
00159         this->setInInternalField(pField, lpf);
00160     }
00161 }
00162 
00163 
00164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00165 
00166 } // End namespace Foam
00167 
00168 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines