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

complexFields.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 Description
00025     Specialisation of Field<T> for complex and complexVector.
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "complexFields.H"
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 defineCompoundTypeName(List<complex>, complexList);
00040 addCompoundToRunTimeSelectionTable(List<complex>, complexList);
00041 
00042 complexField ComplexField(const UList<scalar>& re, const UList<scalar>& im)
00043 {
00044     complexField cf(re.size());
00045 
00046     forAll(cf, i)
00047     {
00048         cf[i].Re() = re[i];
00049         cf[i].Im() = im[i];
00050     }
00051 
00052     return cf;
00053 }
00054 
00055 
00056 complexField ReComplexField(const UList<scalar>& sf)
00057 {
00058     complexField cf(sf.size());
00059 
00060     forAll(cf, i)
00061     {
00062         cf[i].Re() = sf[i];
00063         cf[i].Im() = 0.0;
00064     }
00065 
00066     return cf;
00067 }
00068 
00069 
00070 complexField ImComplexField(const UList<scalar>& sf)
00071 {
00072     complexField cf(sf.size());
00073 
00074     forAll(cf, i)
00075     {
00076         cf[i].Re() = 0.0;
00077         cf[i].Im() = sf[i];
00078     }
00079 
00080     return cf;
00081 }
00082 
00083 
00084 scalarField ReImSum(const UList<complex>& cf)
00085 {
00086     scalarField sf(cf.size());
00087 
00088     forAll(sf, i)
00089     {
00090         sf[i] = cf[i].Re() + cf[i].Im();
00091     }
00092 
00093     return sf;
00094 }
00095 
00096 
00097 scalarField Re(const UList<complex>& cf)
00098 {
00099     scalarField sf(cf.size());
00100 
00101     forAll(sf, i)
00102     {
00103         sf[i] = cf[i].Re();
00104     }
00105 
00106     return sf;
00107 }
00108 
00109 
00110 scalarField Im(const UList<complex>& cf)
00111 {
00112     scalarField sf(cf.size());
00113 
00114     forAll(sf, i)
00115     {
00116         sf[i] = cf[i].Im();
00117     }
00118 
00119     return sf;
00120 }
00121 
00122 
00123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00124 
00125 defineCompoundTypeName(List<complexVector>, complexVectorList);
00126 addCompoundToRunTimeSelectionTable(List<complexVector>, complexVectorList);
00127 
00128 complexVectorField ComplexField(const UList<vector>& re, const UList<vector>& im)
00129 {
00130     complexVectorField cvf(re.size());
00131 
00132     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00133     {
00134         forAll(cvf, i)
00135         {
00136             cvf[i].component(cmpt).Re() = re[i].component(cmpt);
00137             cvf[i].component(cmpt).Im() = im[i].component(cmpt);
00138         }
00139     }
00140 
00141     return cvf;
00142 }
00143 
00144 
00145 complexVectorField ReComplexField(const UList<vector>& vf)
00146 {
00147     complexVectorField cvf(vf.size());
00148 
00149     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00150     {
00151         forAll(cvf, i)
00152         {
00153             cvf[i].component(cmpt).Re() = vf[i].component(cmpt);
00154             cvf[i].component(cmpt).Im() = 0.0;
00155         }
00156     }
00157 
00158     return cvf;
00159 }
00160 
00161 
00162 complexVectorField ImComplexField(const UList<vector>& vf)
00163 {
00164     complexVectorField cvf(vf.size());
00165 
00166     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00167     {
00168         forAll(cvf, i)
00169         {
00170             cvf[i].component(cmpt).Re() = 0.0;
00171             cvf[i].component(cmpt).Im() = vf[i].component(cmpt);
00172         }
00173     }
00174 
00175     return cvf;
00176 }
00177 
00178 
00179 vectorField ReImSum(const UList<complexVector>& cvf)
00180 {
00181     vectorField vf(cvf.size());
00182 
00183     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00184     {
00185         forAll(cvf, i)
00186         {
00187             vf[i].component(cmpt) =
00188                 cvf[i].component(cmpt).Re() + cvf[i].component(cmpt).Im();
00189         }
00190     }
00191 
00192     return vf;
00193 }
00194 
00195 
00196 vectorField Re(const UList<complexVector>& cvf)
00197 {
00198     vectorField vf(cvf.size());
00199 
00200     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00201     {
00202         forAll(cvf, i)
00203         {
00204             vf[i].component(cmpt) = cvf[i].component(cmpt).Re();
00205         }
00206     }
00207 
00208     return vf;
00209 }
00210 
00211 
00212 vectorField Im(const UList<complexVector>& cvf)
00213 {
00214     vectorField vf(cvf.size());
00215 
00216     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00217     {
00218         forAll(cvf, i)
00219         {
00220             vf[i].component(cmpt) = cvf[i].component(cmpt).Im();
00221         }
00222     }
00223 
00224     return vf;
00225 }
00226 
00227 
00228 complexVectorField operator^
00229 (
00230     const UList<vector>& vf,
00231     const UList<complexVector>& cvf
00232 )
00233 {
00234     return ComplexField(vf^Re(cvf), vf^Im(cvf));
00235 }
00236 
00237 
00238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00239 
00240 } // End namespace Foam
00241 
00242 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines