Kmesh.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Kmesh.H"
00028 #include "polyMesh.H"
00029 #include "volFields.H"
00030 #include "mathematicalConstants.H"
00031
00032
00033
00034 namespace Foam
00035 {
00037 inline label rep
00038 (
00039 const label i,
00040 const label j,
00041 const label k,
00042 const labelList& nn
00043 )
00044 {
00045 return (k + j*nn[2] + i*nn[1]*nn[2]);
00046 }
00048
00049 }
00050
00051
00052
00053
00054
00055 Foam::Kmesh::Kmesh(const fvMesh& mesh)
00056 :
00057 vectorField(mesh.V().size()),
00058 NN(vector::dim)
00059 {
00060 const scalar pi = mathematicalConstant::pi;
00061 const scalar twoPi = 2.0*pi;
00062
00063 boundBox box = mesh.bounds();
00064 L = box.span();
00065
00066 vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
00067 vector cellL = 2 * (box.max() - cornerCellCentre);
00068
00069 vector rdeltaByL;
00070 label nTot = 1;
00071
00072 label i;
00073 forAll(NN, i)
00074 {
00075 NN[i] = label(L[i]/cellL[i] + 0.5);
00076 nTot *= NN[i];
00077
00078 if (NN[i] > 1)
00079 {
00080 L[i] -= cellL[i];
00081 }
00082
00083 rdeltaByL[i] = NN[i]/(L[i]*L[i]);
00084 }
00085
00086 if (nTot != mesh.nCells())
00087 {
00088 FatalErrorIn("Kmesh::Kmesh(const fvMesh& mesh)")
00089 << "calculated number of cells is incorrect"
00090 << abort(FatalError);
00091 }
00092
00093 for (i=0; i<NN[0]; i++)
00094 {
00095 scalar k1 = (i - NN[0]/2)*twoPi/L[0];
00096
00097 for (label j=0; j<NN[1]; j++)
00098 {
00099 scalar k2 = (j - NN[1]/2)*twoPi/L[1];
00100
00101 for (label k=0; k<NN[2]; k++)
00102 {
00103 scalar k3 = (k - NN[2]/2)*twoPi/L[2];
00104
00105 (*this)[rep(i, j, k, NN)] = vector(k1, k2, k3);
00106 }
00107 }
00108 }
00109
00110 Kmax = mag((*this)[rep(NN[0]-1, NN[1]-1, NN[2]-1, NN)]);
00111 }
00112
00113
00114
Copyright © 2000-2009 OpenCFD Ltd