void dynLagrangianCsBound::correct(const tmp<volTensorField>& gradU) { LESModel::correct(gradU); volSymmTensorField S(dev(symm(gradU()))); volScalarField magS(mag(S)); volVectorField Uf(filter_(U())); volSymmTensorField Sf(dev(symm(fvc::grad(Uf)))); volScalarField magSf(mag(Sf)); volSymmTensorField L(dev(filter_(sqr(U())) - (sqr(filter_(U()))))); volSymmTensorField M(2.0*sqr(delta())*(filter_(magS*S) - 4.0*magSf*Sf)); volScalarField invT ( (1.0/(theta_.value()*delta()))*pow(flm_*fmm_, 1.0/8.0) ); volScalarField LM(L && M); fvScalarMatrix flmEqn ( fvm::ddt(flm_) + fvm::div(phi(), flm_) == invT*LM - fvm::Sp(invT, flm_) ); flmEqn.relax(); flmEqn.solve(); bound(flm_, flm0_); volScalarField MM(M && M); fvScalarMatrix fmmEqn ( fvm::ddt(fmm_) + fvm::div(phi(), fmm_) == invT*MM - fvm::Sp(invT, fmm_) ); fmmEqn.relax(); fmmEqn.solve(); bound(fmm_, fmm0_); updateSubGridScaleFields(gradU); }
void Foam::sampledSurface::project ( Field<ReturnType>& res, const Field<Type>& field ) const { if (checkFieldSize(field)) { const vectorField& norm = Sf(); forAll(norm, faceI) { res[faceI] = field[faceI] & (norm[faceI] / mag(norm[faceI])); } }
void Foam::cyclicACMIFvPatch::updateAreas() const { if (cyclicACMIPolyPatch_.updated()) { if (debug) { Pout<< "cyclicACMIFvPatch::updateAreas() : updating fv areas for " << name() << " and " << this->nonOverlapPatch().name() << endl; } // owner couple const_cast<vectorField&>(Sf()) = patch().faceAreas(); const_cast<scalarField&>(magSf()) = mag(patch().faceAreas()); // owner non-overlapping const fvPatch& nonOverlapPatch = this->nonOverlapPatch(); const_cast<vectorField&>(nonOverlapPatch.Sf()) = nonOverlapPatch.patch().faceAreas(); const_cast<scalarField&>(nonOverlapPatch.magSf()) = mag(nonOverlapPatch.patch().faceAreas()); // neighbour couple const cyclicACMIFvPatch& nbrACMI = neighbPatch(); const_cast<vectorField&>(nbrACMI.Sf()) = nbrACMI.patch().faceAreas(); const_cast<scalarField&>(nbrACMI.magSf()) = mag(nbrACMI.patch().faceAreas()); // neighbour non-overlapping const fvPatch& nbrNonOverlapPatch = nbrACMI.nonOverlapPatch(); const_cast<vectorField&>(nbrNonOverlapPatch.Sf()) = nbrNonOverlapPatch.patch().faceAreas(); const_cast<scalarField&>(nbrNonOverlapPatch.magSf()) = mag(nbrNonOverlapPatch.patch().faceAreas()); // set the updated flag cyclicACMIPolyPatch_.setUpdated(false); } }
bool Foam::rawTopoChangerFvMesh::update() { // Do mesh changes (use inflation - put new points in topoChangeMap) Info<< "rawTopoChangerFvMesh : Checking for topology changes..." << endl; // Mesh not moved/changed yet moving(false); topoChanging(false); // Do any topology changes. Sets topoChanging (through polyTopoChange) autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true); bool hasChanged = topoChangeMap.valid(); if (hasChanged) { Info<< "rawTopoChangerFvMesh : Done topology changes..." << endl; // Temporary: fix fields on patch faces created out of nothing // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Two situations: // - internal faces inflated out of nothing // - patch faces created out of previously internal faces // Is face mapped in any way? PackedBoolList mappedFace(nFaces()); const label nOldInternal = topoChangeMap().oldPatchStarts()[0]; const labelList& faceMap = topoChangeMap().faceMap(); for (label facei = 0; facei < nInternalFaces(); facei++) { if (faceMap[facei] >= 0) { mappedFace[facei] = 1; } } for (label facei = nInternalFaces(); facei < nFaces(); facei++) { if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal) { mappedFace[facei] = 1; } } const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap(); forAll(fromFaces, i) { mappedFace[fromFaces[i].index()] = 1; } const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap(); forAll(fromEdges, i) { mappedFace[fromEdges[i].index()] = 1; } const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap(); forAll(fromPts, i) { mappedFace[fromPts[i].index()] = 1; } // Set unmapped faces to zero Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values." << endl; zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace); // Special handling for phi: set unmapped faces to recreated phi Info<< "rawTopoChangerFvMesh :" << " recreating phi for unmapped boundary values." << endl; const volVectorField& U = lookupObject<volVectorField>("U"); surfaceScalarField& phi = const_cast<surfaceScalarField&> ( lookupObject<surfaceScalarField>("phi") ); setUnmappedValues ( phi, mappedFace, (linearInterpolate(U) & Sf())() ); if (topoChangeMap().hasMotionPoints()) { pointField newPoints = topoChangeMap().preMotionPoints(); // Give the meshModifiers opportunity to modify points Info<< "rawTopoChangerFvMesh :" << " calling modifyMotionPoints." << endl; topoChanger_.modifyMotionPoints(newPoints); // Actually move points Info<< "rawTopoChangerFvMesh :" << " calling movePoints." << endl; movePoints(newPoints); } } else { //Pout<< "rawTopoChangerFvMesh :" // << " no topology changes..." << endl; } return hasChanged;
void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers() { // Add the zones and mesh modifiers to operate piston and valve motion if ( pointZones().size() > 0 || faceZones().size() > 0 || cellZones().size() > 0 ) { Info<< "void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers() : " << "Zones and modifiers already present. Skipping." << endl; if (topoChanger_.size() == 0) { FatalErrorIn ( "void simpleEngineTopoFvMesh::addZonesAndModifiers()" ) << "Mesh modifiers not read properly" << abort(FatalError); } return; } Info<< "Time = " << engineTime_.theta() << endl << "Adding zones to the engine mesh" << endl; List<pointZone*> pz(nValves()); List<faceZone*> fz(6*nValves() + 1); List<cellZone*> cz(0); label nPointZones = 0; label nFaceZones = 0; for (label valveI = 0; valveI < nValves(); valveI++) { // If both sides of the interface exist, add sliding interface // for a valve if ( valves_[valveI].curtainInCylinderPatchID().active() && valves_[valveI].curtainInPortPatchID().active() ) { Info<< "Adding sliding interface zones for curtain of valve " << valveI + 1 << endl; pz[nPointZones] = new pointZone ( "cutPointsV" + Foam::name(valveI + 1), labelList(0), nPointZones, pointZones() ); nPointZones++; const polyPatch& cylCurtain = boundaryMesh() [valves_[valveI].curtainInCylinderPatchID().index()]; labelList cylCurtainLabels(cylCurtain.size(), cylCurtain.start()); forAll (cylCurtainLabels, i) { cylCurtainLabels[i] += i; } fz[nFaceZones] = new faceZone ( "curtainCylZoneV" + Foam::name(valveI + 1), cylCurtainLabels, boolList(cylCurtainLabels.size(), false), nFaceZones, faceZones() ); nFaceZones++; const polyPatch& portCurtain = boundaryMesh() [valves_[valveI].curtainInPortPatchID().index()]; labelList portCurtainLabels ( portCurtain.size(), portCurtain.start() ); forAll (portCurtainLabels, i) { portCurtainLabels[i] += i; } fz[nFaceZones] = new faceZone ( "curtainPortZoneV" + Foam::name(valveI + 1), portCurtainLabels, boolList(portCurtainLabels.size(), false), nFaceZones, faceZones() ); nFaceZones++; // Add empty zone for cut faces fz[nFaceZones] = new faceZone ( "cutFaceZoneV" + Foam::name(valveI + 1), labelList(0), boolList(0, false), nFaceZones, faceZones() ); nFaceZones++; // Create a detach zone if ( valves_[valveI].detachInCylinderPatchID().active() && valves_[valveI].detachInPortPatchID().active() && valves_[valveI].detachFaces().size() > 0 ) { Info<< "Adding detach boundary for valve " << valveI + 1 << endl; const vectorField& areas = Sf().internalField(); const labelList& df = valves_[valveI].detachFaces(); boolList flip(df.size(), false); const vector& pistonAxis = piston().cs().axis(); forAll (df, dfI) { if (isInternalFace(df[dfI])) { if ((areas[df[dfI]] & pistonAxis) > 0) { flip[dfI] = true; } } else { FatalErrorIn ( "void simpleEngineTopoFvMesh::" "addZonesAndModifiers()" ) << "found boundary face in valve detach definition" << " for valve " << valveI + 1 << ". This is not allowed. Detach faces: " << df << " nInternalFaces: " << nInternalFaces() << abort(FatalError); } } // Add detach face zone fz[nFaceZones] = new faceZone ( "detachFaceZoneV" + Foam::name(valveI + 1), df, flip, nFaceZones, faceZones() ); nFaceZones++; } }
inline double Qf() const { return Sf().imag(); };
// some functions that return manipulated forms of the data inline double Pf() const { return Sf().real(); };
bool invert(const Mat_<_Tp, chs>&src, Mat_<_Tp, chs>& dst, int method = DECOMP_LU) { FBC_Assert(src.data != NULL && dst.data != NULL); FBC_Assert(src.cols > 0 && src.rows > 0 && dst.cols > 0 && dst.rows > 0); FBC_Assert(typeid(double).name() == typeid(_Tp).name() || typeid(float).name() == typeid(_Tp).name()); FBC_Assert(src.cols == dst.rows && src.rows == dst.cols); bool result = false; size_t esz = sizeof(_Tp) * chs; // size_t esz = CV_ELEM_SIZE(type); int m = src.rows, n = src.cols; if (method == DECOMP_SVD) { // TODO FBC_Assert(0); } FBC_Assert(m == n); if (method == DECOMP_EIG) { // TODO FBC_Assert(0); } FBC_Assert(method == DECOMP_LU || method == DECOMP_CHOLESKY); if (n <= 3) { const uchar* srcdata = src.ptr(); uchar* dstdata = const_cast<uchar*>(dst.ptr()); size_t srcstep = src.step; size_t dststep = dst.step; if (n == 2) { // TODO FBC_Assert(0); } else if (n == 3) { if (typeid(float).name() == typeid(_Tp).name() && chs == 1) { double d = det3(Sf); if (d != 0.) { double t[12]; result = true; d = 1./d; t[0] = (((double)Sf(1,1) * Sf(2,2) - (double)Sf(1,2) * Sf(2,1)) * d); t[1] = (((double)Sf(0,2) * Sf(2,1) - (double)Sf(0,1) * Sf(2,2)) * d); t[2] = (((double)Sf(0,1) * Sf(1,2) - (double)Sf(0,2) * Sf(1,1)) * d); t[3] = (((double)Sf(1,2) * Sf(2,0) - (double)Sf(1,0) * Sf(2,2)) * d); t[4] = (((double)Sf(0,0) * Sf(2,2) - (double)Sf(0,2) * Sf(2,0)) * d); t[5] = (((double)Sf(0,2) * Sf(1,0) - (double)Sf(0,0) * Sf(1,2)) * d); t[6] = (((double)Sf(1,0) * Sf(2,1) - (double)Sf(1,1) * Sf(2,0)) * d); t[7] = (((double)Sf(0,1) * Sf(2,0) - (double)Sf(0,0) * Sf(2,1)) * d); t[8] = (((double)Sf(0,0) * Sf(1,1) - (double)Sf(0,1) * Sf(1,0)) * d); Df(0,0) = (float)t[0]; Df(0,1) = (float)t[1]; Df(0,2) = (float)t[2]; Df(1,0) = (float)t[3]; Df(1,1) = (float)t[4]; Df(1,2) = (float)t[5]; Df(2, 0) = (float)t[6]; Df(2, 1) = (float)t[7]; Df(2, 2) = (float)t[8]; } } else { double d = det3(Sd); if (d != 0.) { result = true; d = 1. / d; double t[9]; t[0] = (Sd(1, 1) * Sd(2, 2) - Sd(1, 2) * Sd(2, 1)) * d; t[1] = (Sd(0, 2) * Sd(2, 1) - Sd(0, 1) * Sd(2, 2)) * d; t[2] = (Sd(0, 1) * Sd(1, 2) - Sd(0, 2) * Sd(1, 1)) * d; t[3] = (Sd(1, 2) * Sd(2, 0) - Sd(1, 0) * Sd(2, 2)) * d; t[4] = (Sd(0, 0) * Sd(2, 2) - Sd(0, 2) * Sd(2, 0)) * d; t[5] = (Sd(0, 2) * Sd(1, 0) - Sd(0, 0) * Sd(1, 2)) * d; t[6] = (Sd(1, 0) * Sd(2, 1) - Sd(1, 1) * Sd(2, 0)) * d; t[7] = (Sd(0, 1) * Sd(2, 0) - Sd(0, 0) * Sd(2, 1)) * d; t[8] = (Sd(0, 0) * Sd(1, 1) - Sd(0, 1) * Sd(1, 0)) * d; Dd(0, 0) = t[0]; Dd(0, 1) = t[1]; Dd(0, 2) = t[2]; Dd(1, 0) = t[3]; Dd(1, 1) = t[4]; Dd(1, 2) = t[5]; Dd(2, 0) = t[6]; Dd(2, 1) = t[7]; Dd(2, 2) = t[8]; } } } else { assert(n == 1); if (typeid(float).name() == typeid(_Tp).name() && chs == 1) { double d = Sf(0, 0); if (d != 0.) { result = true; Df(0, 0) = (float)(1. / d); } } else { double d = Sd(0, 0); if (d != 0.) { result = true; Dd(0, 0) = 1. / d; } } } if (!result) dst.setTo(Scalar(0)); return result; } FBC_Assert(0); // TODO return result; }
void dynamicLagrangian<BasicTurbulenceModel>::correct() { if (!this->turbulence_) { return; } // Local references const surfaceScalarField& phi = this->phi_; const volVectorField& U = this->U_; LESeddyViscosity<BasicTurbulenceModel>::correct(); tmp<volTensorField> tgradU(fvc::grad(U)); const volTensorField& gradU = tgradU(); volSymmTensorField S(dev(symm(gradU))); volScalarField magS(mag(S)); volVectorField Uf(filter_(U)); volSymmTensorField Sf(dev(symm(fvc::grad(Uf)))); volScalarField magSf(mag(Sf)); volSymmTensorField L(dev(filter_(sqr(U)) - (sqr(filter_(U))))); volSymmTensorField M ( 2.0*sqr(this->delta())*(filter_(magS*S) - 4.0*magSf*Sf) ); volScalarField invT ( (1.0/(theta_.value()*this->delta()))*pow(flm_*fmm_, 1.0/8.0) ); volScalarField LM(L && M); fvScalarMatrix flmEqn ( fvm::ddt(flm_) + fvm::div(phi, flm_) == invT*LM - fvm::Sp(invT, flm_) ); flmEqn.relax(); flmEqn.solve(); bound(flm_, flm0_); volScalarField MM(M && M); fvScalarMatrix fmmEqn ( fvm::ddt(fmm_) + fvm::div(phi, fmm_) == invT*MM - fvm::Sp(invT, fmm_) ); fmmEqn.relax(); fmmEqn.solve(); bound(fmm_, fmm0_); correctNut(gradU); }