void volumeOptimizer::optimizeNodePosition(const scalar tol)
{
    point& p = points_[pointI_];

    if( !bb_.contains(p) )
        p = 0.5 * (bb_.max() + bb_.min());

    const scalar scale = 1.0 / bb_.mag();
    forAll(points_, pI)
        points_[pI] *= scale;
    bb_.min() *= scale;
    bb_.max() *= scale;

    //- find the optimum using divide and conquer
    const scalar func = optimiseDivideAndConquer(tol);
    const point copyP = p;

    //- check if the location can be improved using the steepest descent
    const scalar funcAfter = optimiseSteepestDescent(tol);

    if( funcAfter > func )
        p = copyP;

    //- scale back to the original size
    forAll(points_, pI)
        points_[pI] /= scale;
    bb_.min() /= scale;
    bb_.max() /= scale;
}
Exemple #2
0
void triSurf::readSurface(const fileName& fName)
{
    if( fName.ext() == "fms" || fName.ext() == "FMS" )
    {
        readFromFMS(fName);
    }
    else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
    {
        readFromFTR(fName);
    }
    else
    {
        triSurface copySurface(fName);

        //- copy the points
        triSurfPoints::points_.setSize(copySurface.points().size());
        forAll(copySurface.points(), pI)
            triSurfPoints::points_[pI] = copySurface.points()[pI];

        //- copy the triangles
        triSurfFacets::triangles_.setSize(copySurface.size());
        forAll(copySurface, tI)
            triSurfFacets::triangles_[tI] = copySurface[tI];

        //- copy patches
        triSurfFacets::patches_ = copySurface.patches();
    }
}
point surfaceOptimizer::optimizePoint(const scalar tol)
{
    const scalar scale = mag(pMax_ - pMin_);
    forAll(pts_, i)
        pts_[i] /= scale;
    pMin_ /= scale;
    pMax_ /= scale;

    point& pOpt = pts_[trias_[0][0]];

    const scalar funcDivide = optimiseDivideAndConquer(tol);
    const point newPoint = pOpt;

    const scalar funcSteepest = optimiseSteepestDescent(tol);

    if( funcSteepest > funcDivide )
        pOpt = newPoint;

    forAll(pts_, i)
        pts_[i] *= scale;
    pMin_ *= scale;
    pMax_ *= scale;

    return pOpt;
}
bool ODateBookAccessBackend_XML::save() {
    if (!m_changed) return true;

    int total_written;
    QString strFileNew = m_name + ".new";

    QFile f( strFileNew );
    if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;

    QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
    buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
    buf += "<events>\n";
    QCString str = buf.utf8();
    total_written = f.writeBlock( str.data(), str.length() );
    if ( total_written != int(str.length() ) ) {
        f.close();
        QFile::remove( strFileNew );
        return false;
    }

    if (!forAll( m_raw, f ) ) {
        f.close();
        QFile::remove( strFileNew );
        return false;
    }
    if (!forAll( m_rep, f ) ) {
        f.close();
        QFile::remove( strFileNew );
        return false;
    }

    buf = "</events>\n</DATEBOOK>\n";
    str = buf.utf8();
    total_written = f.writeBlock( str.data(), str.length() );
    if ( total_written != int(str.length() ) ) {
        f.close();
        QFile::remove( strFileNew );
        return false;
    }
    f.close();

    if ( ::rename( strFileNew, m_name ) < 0 ) {
        QFile::remove( strFileNew );
        return false;
    }

    m_changed = false;
    return true;
}
        forAll(facesInCell, faceI)
        {
            const face& f = facesInCell[faceI];

            const label pointI = f[0];

            label fLabel(-1);
            forAllRow(pointFaces, pointI, pfI)
            {
                const label faceI = pointFaces(pointI, pfI);

                if( faces[faceI] == f )
                {
                    fLabel = faceI;
                    break;
                }
            }

            if( fLabel == -1 )
            {
                faces.append(f);
                c[fI++] = nFaces;

                forAll(f, pI)
                    pointFaces.append(f[pI], nFaces);

                ++nFaces;
            }
            else
            {
                c[fI++] = fLabel;
            }
        }
void meshOptimizer::calculatePointLocations()
{
    vertexLocation_.setSize(mesh_.points().size());
    vertexLocation_ = INSIDE;

    const meshSurfaceEngine& mse = meshSurface();
    const labelList& bPoints = mse.boundaryPoints();

    //- mark boundary vertices
    forAll(bPoints, bpI)
        vertexLocation_[bPoints[bpI]] = BOUNDARY;

    //- mark edge vertices
    meshSurfacePartitioner mPart(mse);
    forAllConstIter(labelHashSet, mPart.edgePoints(), it)
        vertexLocation_[bPoints[it.key()]] = EDGE;

    //- mark corner vertices
    forAllConstIter(labelHashSet, mPart.corners(), it)
        vertexLocation_[bPoints[it.key()]] = CORNER;

    if( Pstream::parRun() )
    {
        const polyMeshGenAddressing& addresing = mesh_.addressingData();
        const VRWGraph& pointAtProcs = addresing.pointAtProcs();

        forAll(pointAtProcs, pointI)
            if( pointAtProcs.sizeOfRow(pointI) != 0 )
                vertexLocation_[pointI] |= PARALLELBOUNDARY;
    }
}
void triSurfaceCleanupDuplicates::mergeIdentities()
{
    if( Pstream::parRun() )
        FatalError << "Material detection does not run in parallel"
            << exit(FatalError);

    if( done_ )
    {
        WarningIn("void triSurfaceCleanupDuplicates::mergeIdentities()")
            << "Operation is already performed" << endl;
        return;
    }

    newTriangleLabel_.setSize(surf_.size());
    forAll(newTriangleLabel_, triI)
        newTriangleLabel_[triI] = triI;

    bool finished;
    do
    {
        finished = true;

        if( checkDuplicateTriangles() )
            finished = false;
        if( mergeDuplicatePoints() )
            finished = false;
    } while( !finished );

    done_ = true;
}
Exemple #8
0
vectorField fieldOperations::
getWallPointMotion
(
  const fvMesh& mesh,
  const volScalarField& C, 
  const label movingPatchID
)
{
  // interpolate the concentration from cells to wall faces
  coupledPatchInterpolation patchInterpolator
  (
    mesh.boundaryMesh()[movingPatchID], mesh 
  );

  // concentration and normals on the faces
  scalarField pointCface = -C.boundaryField()[movingPatchID].snGrad();
  vectorField pointNface = mesh.boundaryMesh()[movingPatchID].faceNormals();
  
  scalarField motionC = patchInterpolator.faceToPointInterpolate(pointCface);
  vectorField motionN = patchInterpolator.faceToPointInterpolate(pointNface);
  
  // normalize point normals to 1
  forAll(motionN, ii) motionN[ii]/=mag(motionN[ii]);
  
  return motionC*motionN;
}
void meshUntangler::optimizeNodePosition(const scalar tol)
{
    # ifdef DEBUGSmooth
    Info << "Untangling point " << pointI_ << endl;
    # endif

    cutRegion cr(bb_);

    forAll(tets_, tetI)
    {
        const partTet& tet = tets_[tetI];
        vector n
        (
            (points_[tet.b()] - points_[tet.a()]) ^
            (points_[tet.c()] - points_[tet.a()])
        );

        if( mag(n) < VSMALL ) continue;

        plane pl(points_[tet.a()], n);

        # ifdef DEBUGSmooth
        Info << "tet.a() " << tet.a() << endl;
        Info << "Cutting plane ref point " << pl.refPoint() << endl;
        Info << "Cutting plane normal " << pl.normal() << endl;
        # endif

        cr.planeCut(pl);
    }

    if( cr.points().size() )
    {
        point p(vector::zero);

        const DynList<point, 64>& pts = cr.points();
        forAll(pts, pI)
            p += pts[pI];

        p /= pts.size();

        # ifdef DEBUGSmooth
        Info << "Corners of the feasible region " << pts << endl;
        # endif

        for(direction i=0;i<vector::nComponents;++i)
        {
            const scalar& val = p[i];
            if( (val != val) || ((val - val) != (val - val)) )
                return;
        }

        points_[pointI_] = p;
    }
}
Exemple #10
0
triSurfFacets::triSurfFacets(const LongList<labelledTri>& triangles)
:
    triangles_(triangles),
    patches_(1),
    facetSubsets_()
{
    forAll(triangles_, triI)
        triangles_[triI].region() = 0;

    patches_[0].name() = "patch";
}
void triSurf::readFromFMS(const fileName& fName)
{
    IFstream fStream(fName);

    //- read the list of patches defined on the surface mesh
    fStream >> triSurfFacets::patches_;

    //- read points
    fStream >> triSurfPoints::points_;

    //- read surface triangles
    fStream >> triSurfFacets::triangles_;

    //- read feature edges
    fStream >> triSurfFeatureEdges::featureEdges_;

    List<meshSubset> subsets;

    //- read point subsets
    fStream >> subsets;
    forAll(subsets, subsetI)
        triSurfPoints::pointSubsets_.insert(subsetI, subsets[subsetI]);

    subsets.clear();

    //- read facet subsets
    fStream >> subsets;
    forAll(subsets, subsetI)
        triSurfFacets::facetSubsets_.insert(subsetI, subsets[subsetI]);

    subsets.clear();

    //- read subsets on feature edges
    fStream >> subsets;
    forAll(subsets, subsetI)
        triSurfFeatureEdges::featureEdgeSubsets_.insert
        (
            subsetI,
            subsets[subsetI]
        );
}
Exemple #12
0
 forAll(indices, indexI)
 {
     labelLongList nodesInSubset;
     mesh_.pointsInSubset(indices[indexI], nodesInSubset);
     
     fpmaGeometryFile << mesh_.pointSubsetName(indices[indexI]) << nl;
     fpmaGeometryFile << 1 << nl;
     fpmaGeometryFile << nodesInSubset.size() << nl;
     forAll(nodesInSubset, i)
         fpmaGeometryFile << nodesInSubset[i] << ' ';
     fpmaGeometryFile << nl;
 }
Exemple #13
0
 forAll(indices, indexI)
 {
     labelLongList facesInSubset;
     mesh_.facesInSubset(indices[indexI], facesInSubset);
     
     fpmaGeometryFile << mesh_.faceSubsetName(indices[indexI]) << nl;
     fpmaGeometryFile << 3 << nl;
     fpmaGeometryFile << facesInSubset.size() << nl;
     forAll(facesInSubset, i)
         fpmaGeometryFile << facesInSubset[i] << ' ';
     fpmaGeometryFile << nl;
 }
Exemple #14
0
 forAll(indices, indexI)
 {
     labelLongList cellsInSubset;
     mesh_.cellsInSubset(indices[indexI], cellsInSubset);
     
     fpmaGeometryFile << mesh_.cellSubsetName(indices[indexI]) << nl;
     fpmaGeometryFile << 2 << nl;
     fpmaGeometryFile << cellsInSubset.size() << nl;
     forAll(cellsInSubset, i)
         fpmaGeometryFile << cellsInSubset[i] << ' ';
     fpmaGeometryFile << nl;
 }
Exemple #15
0
void fpmaMesh::writeCells(OFstream& fpmaGeometryFile) const
{
    const cellListPMG& cells = mesh_.cells();
    
    fpmaGeometryFile << cells.size() << nl;
    forAll(cells, cellI)
    {
        const cell& c = cells[cellI];
        
        fpmaGeometryFile << c.size();
        forAll(c, fI)
            fpmaGeometryFile << ' ' << c[fI];
        fpmaGeometryFile << nl;
    }
}
void meshOctree::findBoundaryPatchesForLeaf
(
    const label leafI,
    DynList<label>& patches
) const
{
    if( leaves_[leafI]->hasContainedElements() )
    {
        patches.clear();
        const VRWGraph& ct = leaves_[leafI]->slotPtr()->containedTriangles_;
        const constRow ce =
            ct[leaves_[leafI]->containedElements()];
        forAll(ce, elI)
            patches.appendIfNotIn(surface_[ce[elI]].region());
    }
    else
    {
        patches.clear();
    }
}
label checkAngles
(
    triSurf& surf,
    const word subsetName,
    const scalar angleTol
)
{
    labelLongList badTriangles;

    if( checkAngles(surf, badTriangles, angleTol) )
    {
        label setId = surf.facetSubsetIndex(subsetName);
        if( setId >= 0 )
            surf.removeFacetSubset(setId);
        setId = surf.addFacetSubset(subsetName);

        forAll(badTriangles, i)
            surf.addFacetToSubset(setId, badTriangles[i]);
    }

    return badTriangles.size();
}
void polyMeshGenModifier::addCells(const VRWGraphList& cellFaces)
{
    Info << "Adding " << cellFaces.size() << " cells to the mesh" << endl;

    faceListPMG& faces = mesh_.faces_;
    cellListPMG& cells = mesh_.cells_;

    VRWGraph& pointFaces = this->pointFaces();

    //- start adding cells into the mesh
    label nFaces = faces.size();
    label nCells = cells.size();

    forAll(cellFaces, cI)
    {
        faceList facesInCell(cellFaces.sizeOfGraph(cI));
        forAll(facesInCell, fI)
        {
            facesInCell[fI].setSize(cellFaces.sizeOfRow(cI, fI));

            forAll(facesInCell[fI], pI)
                facesInCell[fI][pI] = cellFaces(cI, fI, pI);
        }
void triSurfacePatchManipulator::detectedSurfaceRegions
(
    VRWGraph& graph
) const
{
    graph.setSize(nPatches_);

    labelLongList nFacetsInPatch(nPatches_, 0);

    forAll(facetInPatch_, triI)
        ++nFacetsInPatch[facetInPatch_[triI]];

    graph.setSizeAndRowSize(nFacetsInPatch);

    nFacetsInPatch = 0;
    forAll(facetInPatch_, triI)
    {
        const label patchI = facetInPatch_[triI];

        graph(patchI, nFacetsInPatch[patchI]) = triI;
        ++nFacetsInPatch[patchI];
    }
}
Exemple #20
0
void triSurf::writeSurface(const fileName& fName) const
{
    if( fName.ext() == "fms" || fName.ext() == "FMS" )
    {
        writeToFMS(fName);
    }
    else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
    {
        writeToFTR(fName);
    }
    else
    {
        const pointField& pts = this->points();
        const LongList<labelledTri>& facets = this->facets();
        const geometricSurfacePatchList& patches = this->patches();

        List<labelledTri> newTrias(facets.size());
        forAll(facets, tI)
            newTrias[tI] = facets[tI];

        triSurface newSurf(newTrias, patches, pts);
        newSurf.write(fName);
    }
}
void decomposeFaces::decomposeMeshFaces(const boolList& decomposeFace)
{
    done_ = false;

    newFacesForFace_.setSize(mesh_.faces().size());
    forAll(newFacesForFace_, fI)
        newFacesForFace_.setRowSize(fI, 0);

    const label nIntFaces = mesh_.nInternalFaces();
    label nFaces(0), nPoints = mesh_.points().size();
    point p;

    pointFieldPMG& points = mesh_.points();
    forAll(decomposeFace, fI)
        if( decomposeFace[fI] )
            ++nFaces;

    points.setSize(nPoints + nFaces);

    polyMeshGenModifier meshModifier(mesh_);
    faceListPMG& faces = meshModifier.facesAccess();

    if( decomposeFace.size() != faces.size() )
        FatalErrorIn
        (
            "void decomposeFaces::decomposeMeshFaces(const boolList&)"
        ) << "Incorrect size of the decomposeFace list!" << abort(FatalError);

    nFaces = 0;
    VRWGraph newFaces;

    //- decompose internal faces
    for(label faceI=0;faceI<nIntFaces;++faceI)
    {
        const face& f = faces[faceI];

        if( decomposeFace[faceI] )
        {
            # ifdef DEBUGDec
            Info << "Decomposing internal face " << faceI << " with nodes "
                << f << endl;
            # endif

            FixedList<label, 3> newF;

            forAll(f, pI)
            {
                newF[0] = f[pI];
                newF[1] = f.nextLabel(pI);
                newF[2] = nPoints;

                # ifdef DEBUGDec
                Info << "Storing face " << newF << " with label "
                    << nFaces << endl;
                # endif

                newFaces.appendList(newF);
                newFacesForFace_.append(faceI, nFaces++);
            }

            p = f.centre(points);
            points[nPoints] = p;
            ++nPoints;
        }
        else
        {
// solve vegetation model
void modifiedVegetationModel::solve(volVectorField& U, volScalarField& T, volScalarField& w)
{
    // solve radiation within vegetation
    radiation();

    const double p_ = 101325;

    // Magnitude of velocity
    volScalarField magU("magU", mag(U));

    // Bounding velocity
    bound(magU, UMin_);

    // solve aerodynamic, stomatal resistance
    volScalarField new_Tl("new_Tl", Tl_);

    // info
    Info << "    max leaf temp tl=" << max(T.internalField())
         << "k, iteration i=0" << endl;

    scalar maxError, maxRelError;
    int i;

    // solve leaf temperature, iteratively.
    int maxIter = 500;
    for (i=1; i<=maxIter; i++)
    {
        // Solve aerodynamc, stomatal resistance
        resistance(magU, T, w, new_Tl);

        forAll(LAD_, cellI)
        {
            if (LAD_[cellI] > 10*SMALL)
            {
                // Initial leaf temperature
                if (i==1)
                    Tl_[cellI];// = T[cellI];//*0. + 300.;//T[cellI];

                // Calculate saturated density, specific humidity
                rhosat_[cellI] = calc_rhosat(Tl_[cellI]);
                evsat_[cellI] = calc_evsat(Tl_[cellI]);
                wsat_[cellI] = 0.621945*(evsat_[cellI]/(p_-evsat_[cellI])); // ASHRAE 1, eq.23

                // Calculate transpiration rate]);
                E_[cellI] = nEvapSides_.value()*LAD_[cellI]*rhoa_.value()*(wsat_[cellI]-w[cellI])/(ra_[cellI]+rs_[cellI]);
                //E_[cellI] = 0.0; // No evapotranspiration

                // Calculate latent heat flux
                Ql_[cellI] = lambda_.value()*E_[cellI];

                // Calculate new leaf temperature
                new_Tl[cellI] = T[cellI] + (Rn_[cellI] - Ql_[cellI])*(ra_[cellI]/(2.0*rhoa_.value()*cpa_.value()*LAD_[cellI]));

            }
        }

        // info
        Info << "    max leaf temp tl=" << gMax(new_Tl.internalField())
             << " K, iteration i="   << i << endl;

        // Check rel. L-infinity error
        maxError = gMax(mag(new_Tl.internalField()-Tl_.internalField()));
        maxRelError = maxError/gMax(mag(new_Tl.internalField()));

        // update leaf temp.
        forAll(Tl_, cellI)
            Tl_[cellI] = 0.5*Tl_[cellI]+0.5*new_Tl[cellI];

         // convergence check
         if (maxRelError < 1e-8)
             break;
    }
    Tl_.correctBoundaryConditions();

    // Iteration info
    Info << "Vegetation model:  Solving for Tl, Final residual = " << maxError
         << ", Final relative residual = " << maxRelError
         << ", No Iterations " << i << endl;

    Info << "temperature parameters: max Tl = " << gMax(Tl_)
         << ", min T = " << gMin(T) << ", max T = " << gMax(T) << endl;

    Info << "resistances: max rs = " << gMax(rs_)
         << ", max ra = " << gMax(ra_) << endl;

    // Final: Solve aerodynamc, stomatal resistance
    resistance(magU, T, w, Tl_);

    // Final: Update sensible and latent heat flux
    forAll(LAD_, cellI)
    {
        if (LAD_[cellI] > 10*SMALL)
        {
            // Calculate saturated density, specific humidity
            rhosat_[cellI] = calc_rhosat(Tl_[cellI]);
            evsat_[cellI] = calc_evsat(Tl_[cellI]);
            wsat_[cellI] = 0.621945*(evsat_[cellI]/(p_-evsat_[cellI])); // ASHRAE 1, eq.23

            // Calculate transpiration rate
            E_[cellI] = nEvapSides_.value()*LAD_[cellI]*rhoa_.value()*(wsat_[cellI]-w[cellI])/(ra_[cellI]+rs_[cellI]); // todo: implement switch for double or single side

            // Calculate latent heat flux
            Ql_[cellI] = lambda_.value()*E_[cellI];

            // Calculate sensible heat flux
            Qs_[cellI] = 2.0*rhoa_.value()*cpa_.value()*LAD_[cellI]*(Tl_[cellI]-T[cellI])/ra_[cellI];
        }
    }
    rhosat_.correctBoundaryConditions();
    wsat_.correctBoundaryConditions();
    E_.correctBoundaryConditions();
    Ql_.correctBoundaryConditions();
    Qs_.correctBoundaryConditions();


}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"

    regionProperties rp(runTime);

    #include "createFluidMeshes.H"
    #include "createSolidMeshes.H"

    #include "createFluidFields.H"
    #include "createSolidFields.H"

    #include "initContinuityErrs.H"

    #include "readTimeControls.H"
    #include "readSolidTimeControls.H"


    #include "compressibleMultiRegionCourantNo.H"
    #include "solidRegionDiffusionNo.H"
    #include "setInitialMultiRegionDeltaT.H"


    while (runTime.run())
    {
        #include "readTimeControls.H"
        #include "readSolidTimeControls.H"
        #include "readPIMPLEControls.H"


        #include "compressibleMultiRegionCourantNo.H"
        #include "solidRegionDiffusionNo.H"
        #include "setMultiRegionDeltaT.H"

        runTime++;

        Info<< "Time = " << runTime.timeName() << nl << endl;

        if (nOuterCorr != 1)
        {
            forAll(fluidRegions, i)
            {
                #include "setRegionFluidFields.H"
                #include "storeOldFluidFields.H"
            }
        }


        // --- PIMPLE loop
        for (int oCorr=0; oCorr<nOuterCorr; oCorr++)
        {
            forAll(fluidRegions, i)
            {
                Info<< "\nSolving for fluid region "
                    << fluidRegions[i].name() << endl;
                #include "setRegionFluidFields.H"
                #include "readFluidMultiRegionPIMPLEControls.H"
                #include "solveFluid.H"
            }

            forAll(solidRegions, i)
            {
                Info<< "\nSolving for solid region "
                    << solidRegions[i].name() << endl;
                #include "setRegionSolidFields.H"
                #include "readSolidMultiRegionPIMPLEControls.H"
                #include "solveSolid.H"
            }
        }

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info << "End\n" << endl;

    return 0;
}
scalar volumeOptimizer::optimiseSteepestDescent(const scalar tol)
{
    label iter(0);

    point& p = points_[pointI_];

    # ifdef DEBUGSmooth
    Info << nl << "Smoothing point " << pointI_
         << " with coordinates " << p << endl;
    scalar Vmina(VGREAT);
    forAll(tets_, tetI)
    Vmina = Foam::min(Vmina, tets_[tetI].mag(points_));
    Info << "Vmin before " << Vmina << endl;
    # endif

    vector gradF;
    vector disp(vector::zero);
    tensor gradGradF;
    point pOrig;

    scalar funcBefore, funcAfter(evaluateFunc());

    bool finished;
    do
    {
        finished = false;
        pOrig = p;
        funcBefore = funcAfter;

        evaluateGradientsExact(gradF, gradGradF);

        const scalar determinant = Foam::det(gradGradF);
        if( determinant > SMALL )
        {
            disp = (inv(gradGradF, determinant) & gradF);

            p -= disp;

            funcAfter = evaluateFunc();

            # ifdef DEBUGSmooth
            Info << nl << "gradF " << gradF << endl;
            Info << "gradGradF " << gradGradF << endl;
            Info << "det(gradGradF) " << determinant << endl;
            Info << "disp " << disp << endl;
            Info << "Func before " << funcBefore << endl;
            Info << "Func after " << funcAfter << endl;
            # endif

            scalar relax(0.8);
            label nLoops(0);

            while( funcAfter > funcBefore )
            {
                p = pOrig - relax * disp;
                relax *= 0.5;
                funcAfter = evaluateFunc();

                if( funcAfter < funcBefore )
                    continue;

                if( ++nLoops == 5 )
                {
                    //- it seems that this direction is wrong, stop the loop
                    p = pOrig;
                    disp = vector::zero;
                    finished = true;
                    funcAfter = funcBefore;
                }
            }

            if( mag(funcBefore - funcAfter) / funcBefore < tol )
                finished = true;
        }
        else
        {
            //- move in random direction
            //- this is usually needed to move the point off the zero volume
            disp = vector::zero;
            forAll(tets_, tetI)
            {
                const partTet& tet = tets_[tetI];
                const scalar Vtri = tet.mag(points_);

                if( Vtri < SMALL )
                {
                    triangle<point, point> tri
                    (
                        points_[tet.a()],
                        points_[tet.b()],
                        points_[tet.c()]
                    );

                    vector n = tri.normal();
                    const scalar d = mag(n);

                    if( d > VSMALL )
                        disp += 0.01 * (n / d);
                }
            }

            p += disp;
            funcAfter = evaluateFunc();
        }
    } while( (++iter < 100) && !finished );

    # ifdef DEBUGSmooth
    scalar Vmin(VGREAT);
    forAll(tets_, tetI)
        Vmin = Foam::min(Vmin, tets_[tetI].mag(points_));

    Info << nl << "New coordinates for point "
        << pointI_ << " are " << p << endl;
    Info << "Num iterations " << iter << " gradient " << gradF << endl;
    Info << "Vmin " << Vmin << endl;
    # endif

    return funcAfter;
}
void tetMeshExtractorOctree::createPolyMesh()
{
    polyMeshGenModifier meshModifier ( mesh_ );

    faceListPMG& faces = meshModifier.facesAccess();
    cellListPMG& cells = meshModifier.cellsAccess();
    meshModifier.boundariesAccess().setSize ( 0 );
    meshModifier.procBoundariesAccess().setSize ( 0 );

    const LongList<partTet>& tets = tetCreator_.tets();

    VRWGraph pTets;
    pTets.reverseAddressing(mesh_.points().size(), tets);

    //- set the number of cells
    cells.setSize(tets.size());

    //- all faces of tetrahedral cells
    faces.setSize(4*tets.size());
    boolList removeFace(faces.size());

    # ifdef USE_OMP
    # pragma omp parallel if( tets.size() > 1000 )
    # endif
    {
        //- set face labels
        # ifdef USE_OMP
        # pragma omp for
        # endif
        forAll(removeFace, faceI)
            removeFace[faceI] = false;

        //- set sizes of cells and create all faces
        # ifdef USE_OMP
        # pragma omp for schedule(dynamic, 20)
        # endif
        forAll(tets, elmtI)
        {
            cells[elmtI].setSize(4);

            const partTet& elmt = tets[elmtI];

            label faceI = 4 * elmtI;

            //- first face
            cells[elmtI][0] = faceI;

            face& f0 = faces[faceI];
            f0.setSize(3);

            f0[0] = elmt.a();
            f0[1] = elmt.c();
            f0[2] = elmt.b();

            ++faceI;

            //- second face
            cells[elmtI][1] = faceI;

            face& f1 = faces[faceI];
            f1.setSize(3);

            f1[0] = elmt.a();
            f1[1] = elmt.b();
            f1[2] = elmt.d();

            ++faceI;

            //- third face
            cells[elmtI][2] = faceI;

            face& f2 = faces[faceI];
            f2.setSize ( 3 );

            f2[0] = elmt.b();
            f2[1] = elmt.c();
            f2[2] = elmt.d();

            ++faceI;

            //- fourth face
            cells[elmtI][3] = faceI;

            face& f3 = faces[faceI];
            f3.setSize ( 3 );

            f3[0] = elmt.c();
            f3[1] = elmt.a();
            f3[2] = elmt.d();
        }

        # ifdef USE_OMP
        # pragma omp barrier
        # endif

        //- find duplicate faces
        # ifdef USE_OMP
        # pragma omp for schedule(dynamic, 20)
        # endif
        forAll(cells, cellI)
        {
            cell& c = cells[cellI];

            forAll(c, fI)
            {
                const face& f = faces[c[fI]];
                const label pointI = f[0];

                forAllRow(pTets, pointI, ptI)
                {
                    //- do not check cells with greater labels
                    //- they cannot be face owners
                    if( pTets(pointI, ptI) >= cellI )
                        continue;

                    const cell& otherTet = cells[pTets(pointI, ptI)];

                    //- check faces created from a tet
                    forAll(otherTet, ofI)
                    {
                        //- do not compare faces with greater labels
                        //- they shall not be removed here
                        if( otherTet[ofI] >= c[fI] )
                            continue;

                        //- check if the faces are equal
                        if( f == faces[otherTet[ofI]] )
                        {
                            removeFace[c[fI]] = true;
                            c[fI] = otherTet[ofI];
                        }
                    }
                }
            }
        }
Exemple #26
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"

    regionProperties rp(runTime);

    #include "createFluidMeshes.H"
    #include "createSolidMeshes.H"

    #include "createFluidFields.H"
    #include "createSolidFields.H"

    #include "initContinuityErrs.H"

    #include "readTimeControls.H"
    #include "readSolidTimeControls.H"


    #include "compressibleMultiRegionCourantNo.H"
    #include "solidRegionDiffusionNo.H"
    #include "setInitialMultiRegionDeltaT.H"
    ofstream resFile;
    int nIter=0;
    double resP, resU, resT;
    while (runTime.run())
    {
        #include "readTimeControls.H"
        #include "readSolidTimeControls.H"
        #include "readPIMPLEControls.H"
        lduMatrix::debug = dbgLvl;
        Info.level = dbgLvl;
        if((nIter==0)&&(Pstream::master())&&((onFile)||(onScreen)))
        {
            if(onFile){
                resFile.open("residuals.plt");
                resFile<<"Variables=\"Iterations\",\"Time\",\"Pressure\",\"Velocity\",\"Temperature\"";
                resFile.close();
            }
            if(onScreen)
                printResHeaders();
        }
        #include "compressibleMultiRegionCourantNo.H"
        #include "solidRegionDiffusionNo.H"
        #include "setMultiRegionDeltaT.H"

        runTime++;

        Info<< "Time = " << runTime.timeName() << nl << endl;

        if (nOuterCorr != 1)
        {
            forAll(fluidRegions, i)
            {
                #include "setRegionFluidFields.H"
                #include "storeOldFluidFields.H"
            }
        }


        // --- PIMPLE loop
        for (int oCorr=0; oCorr<nOuterCorr; oCorr++)
        {
            forAll(fluidRegions, i)
            {
                Info<< "\nSolving for fluid region "
                    << fluidRegions[i].name() << endl;
                #include "setRegionFluidFields.H"
                #include "readFluidMultiRegionPIMPLEControls.H"
                #include "solveFluid.H"
            }

            forAll(solidRegions, i)
            {
                Info<< "\nSolving for solid region "
                    << solidRegions[i].name() << endl;
                #include "setRegionSolidFields.H"
                #include "readSolidMultiRegionPIMPLEControls.H"
                #include "solveSolid.H"
            }
            nIter++;
            if(Pstream::master())
                printResiduals(onScreen, onFile, oCorr, runTime.value(), resP, resU, resT, resFile);
        }

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }
    Info<< "End\n" << endl;
    return 0;
}
int main(int argc, char *argv[])
{
    #define NO_CONTROL
    #define CREATE_MESH createMeshesPostProcess.H
    #include "postProcess.H"

    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMeshes.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"
    #include "createTimeControls.H"
    #include "readSolidTimeControls.H"
    #include "compressibleMultiRegionCourantNo.H"
    #include "solidRegionDiffusionNo.H"
    #include "setInitialMultiRegionDeltaT.H"

    while (runTime.run())
    {
        #include "readTimeControls.H"
        #include "readSolidTimeControls.H"
        #include "readPIMPLEControls.H"

        #include "compressibleMultiRegionCourantNo.H"
        #include "solidRegionDiffusionNo.H"
        #include "setMultiRegionDeltaT.H"

        runTime++;

        Info<< "Time = " << runTime.timeName() << nl << endl;

        if (nOuterCorr != 1)
        {
            forAll(fluidRegions, i)
            {
                #include "storeOldFluidFields.H"
            }
        }

        bool allRegionsConverged = false;
        bool finalIter = false;

        // --- PIMPLE loop
        for (int oCorr=0; oCorr<nOuterCorr; oCorr++)
        {
            Info<< "Pimple iteration " << oCorr << "\n";

            if (oCorr == nOuterCorr-1 || allRegionsConverged)
            {
                finalIter = true;
            }

            forAll(fluidRegions, i)
            {
                Info<< "\nSolving for fluid region "
                    << fluidRegions[i].name() << endl;
                #include "setRegionFluidFields.H"
                #include "readFluidMultiRegionPIMPLEControls.H"
                #include "readFluidMultiRegionResidualControls.H"
                #include "solveFluid.H"
                #include "residualControlsFluid.H"
            }

            forAll(solidRegions, i)
            {
                Info<< "\nSolving for solid region "
                    << solidRegions[i].name() << endl;
                #include "setRegionSolidFields.H"
                #include "readSolidMultiRegionPIMPLEControls.H"
                #include "readSolidMultiRegionResidualControls.H"
                #include "solveSolid.H"
                #include "residualControlsSolid.H"
            }

            #include "checkResidualControls.H"
        }

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}