primitiveMeshCellCentresAndVols.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
00028
00029
00030
00031 #include "primitiveMesh.H"
00032
00033
00034
00035 void Foam::primitiveMesh::calcCellCentresAndVols() const
00036 {
00037 if (debug)
00038 {
00039 Pout<< "primitiveMesh::calcCellCentresAndVols() : "
00040 << "Calculating cell centres and cell volumes"
00041 << endl;
00042 }
00043
00044
00045
00046 if (cellCentresPtr_ || cellVolumesPtr_)
00047 {
00048 FatalErrorIn("primitiveMesh::calcCellCentresAndVols() const")
00049 << "Cell centres or cell volumes already calculated"
00050 << abort(FatalError);
00051 }
00052
00053
00054 cellCentresPtr_ = new vectorField(nCells());
00055 vectorField& cellCtrs = *cellCentresPtr_;
00056
00057
00058 cellVolumesPtr_ = new scalarField(nCells());
00059 scalarField& cellVols = *cellVolumesPtr_;
00060
00061
00062 makeCellCentresAndVols(faceCentres(), faceAreas(), cellCtrs, cellVols);
00063
00064 if (debug)
00065 {
00066 Pout<< "primitiveMesh::calcCellCentresAndVols() : "
00067 << "Finished calculating cell centres and cell volumes"
00068 << endl;
00069 }
00070 }
00071
00072
00073 void Foam::primitiveMesh::makeCellCentresAndVols
00074 (
00075 const vectorField& fCtrs,
00076 const vectorField& fAreas,
00077 vectorField& cellCtrs,
00078 scalarField& cellVols
00079 ) const
00080 {
00081
00082 cellCtrs = vector::zero;
00083 cellVols = 0.0;
00084
00085 const labelList& own = faceOwner();
00086 const labelList& nei = faceNeighbour();
00087
00088
00089
00090
00091 vectorField cEst(nCells(), vector::zero);
00092 labelField nCellFaces(nCells(), 0);
00093
00094 forAll (own, facei)
00095 {
00096 cEst[own[facei]] += fCtrs[facei];
00097 nCellFaces[own[facei]] += 1;
00098 }
00099
00100 forAll (nei, facei)
00101 {
00102 cEst[nei[facei]] += fCtrs[facei];
00103 nCellFaces[nei[facei]] += 1;
00104 }
00105
00106 forAll(cEst, celli)
00107 {
00108 cEst[celli] /= nCellFaces[celli];
00109 }
00110
00111 forAll (own, facei)
00112 {
00113
00114 scalar pyr3Vol =
00115 max(fAreas[facei] & (fCtrs[facei] - cEst[own[facei]]), VSMALL);
00116
00117
00118 vector pc = (3.0/4.0)*fCtrs[facei] + (1.0/4.0)*cEst[own[facei]];
00119
00120
00121 cellCtrs[own[facei]] += pyr3Vol*pc;
00122
00123
00124 cellVols[own[facei]] += pyr3Vol;
00125 }
00126
00127 forAll (nei, facei)
00128 {
00129
00130 scalar pyr3Vol =
00131 max(fAreas[facei] & (cEst[nei[facei]] - fCtrs[facei]), VSMALL);
00132
00133
00134 vector pc = (3.0/4.0)*fCtrs[facei] + (1.0/4.0)*cEst[nei[facei]];
00135
00136
00137 cellCtrs[nei[facei]] += pyr3Vol*pc;
00138
00139
00140 cellVols[nei[facei]] += pyr3Vol;
00141 }
00142
00143 cellCtrs /= cellVols;
00144 cellVols *= (1.0/3.0);
00145 }
00146
00147
00148
00149
00150 const Foam::vectorField& Foam::primitiveMesh::cellCentres() const
00151 {
00152 if (!cellCentresPtr_)
00153 {
00154 calcCellCentresAndVols();
00155 }
00156
00157 return *cellCentresPtr_;
00158 }
00159
00160
00161 const Foam::scalarField& Foam::primitiveMesh::cellVolumes() const
00162 {
00163 if (!cellVolumesPtr_)
00164 {
00165 calcCellCentresAndVols();
00166 }
00167
00168 return *cellVolumesPtr_;
00169 }
00170
00171
00172
Copyright © 2000-2009 OpenCFD Ltd