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

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