Foam::tmp<Foam::scalarField> Foam::cellQuality::nonOrthogonality() const { tmp<scalarField> tresult ( new scalarField ( mesh_.nCells(), 0.0 ) ); scalarField& result = tresult.ref(); scalarField sumArea(mesh_.nCells(), 0.0); const vectorField& centres = mesh_.cellCentres(); const vectorField& areas = mesh_.faceAreas(); const labelList& own = mesh_.faceOwner(); const labelList& nei = mesh_.faceNeighbour(); forAll(nei, facei) { vector d = centres[nei[facei]] - centres[own[facei]]; vector s = areas[facei]; scalar magS = mag(s); scalar cosDDotS = radToDeg(Foam::acos(min(1.0, (d & s)/(mag(d)*magS + vSmall)))); result[own[facei]] = max(cosDDotS, result[own[facei]]); result[nei[facei]] = max(cosDDotS, result[nei[facei]]); }
Foam::tmp<Foam::scalarField> Foam::cellQuality::nonOrthogonality() const { tmp<scalarField> tresult ( new scalarField ( mesh_.nCells(), 0.0 ) ); scalarField& result = tresult(); scalarField sumArea(mesh_.nCells(), 0.0); const vectorField& centres = mesh_.cellCentres(); const vectorField& areas = mesh_.faceAreas(); const labelList& own = mesh_.faceOwner(); const labelList& nei = mesh_.faceNeighbour(); forAll (nei, faceI) { vector d = centres[nei[faceI]] - centres[own[faceI]]; vector s = areas[faceI]; scalar magS = mag(s); scalar cosDDotS = Foam::acos(min(1.0, (d & s)/(mag(d)*magS + VSMALL))) *180.0/mathematicalConstant::pi; result[own[faceI]] = max(cosDDotS, result[own[faceI]]); result[nei[faceI]] = max(cosDDotS, result[nei[faceI]]); }
void Map::mapgen() { // clear for(int i=0;i<c;i++) for(int j=0;j<r;j++) { if(i==0||j==0||i==c-1||j==r-1) m[i][j]=1; else m[i][j]=IMap::TileNone; } // DO: adjust the box // pandora box for(int i=c/2-3;i<=c/2;i++) for(int j=r/2-3;j<r/2+2;j++) { m[i][j]=IMap::TileBlock; } // random wall for(int t=0;t<1000;t++) { // get a random position int px=(rand()%(c/4))*2; int py=(rand()%(r/2))*2; // check if its ok to start if(sumArea(px,py)==0) { // set first pixel m[px][py]=IMap::TileBlock; int tries=2000; // random to continue while ((rand()%100<97)) { tries--; if(!tries) { m[px][py]=IMap::TileDebug; return; } int tx=px; int ty=py; // go to a new position switch(rand()%4) { case 0: ty-=1; break; case 1: tx+=1; break; case 2: ty+=1; break; default: tx-=1; } // if not in outside continue if(tx>=0) if(tx<=c/2) if(ty>=0) if(ty<r) { int tmax=1; if(px%2==0) if(py%2==0) tmax=2; // check new position if(sumArea(tx,ty)<=tmax) { // set pixel px=tx; py=ty; m[px][py]=IMap::TileBlock; } } } } } // fill corner for(int i=0;i<c;i++) for(int j=0;j<r;j++) { if(j%2==0&&i%2==0) m[i][j]=IMap::TileBlock; } // food for(int i=0;i<=c/2;i++) for(int j=0;j<r;j++) { if(m[i][j]==0) m[i][j]=IMap::TileFood; } // power m[1][1]=IMap::TilePower; // open pandora box for(int i=c/2-2;i<=c/2;i++) for(int j=r/2-2;j<r/2+1;j++) { m[i][j]=IMap::TileNone; } m[c/2][r/2-3]=IMap::TileGate; // mirror matrix for(int i=0;i<=c/2;i++) for(int j=0;j<r;j++) { m[c-i-1][j]=m[i][j]; } }