Difference between revisions of "Snip calculating mass flow"

From OpenFOAMWiki
m (Reverted edit of Pvaqbj, changed back to last version by Bgschaid)
 
(4 intermediate revisions by 3 users not shown)
Line 23: Line 23:
 
#include "SortableList.H"
 
#include "SortableList.H"
  
wordList buildGlobalBoundaryList(polyMesh &mesh)
+
wordList buildGlobalBoundaryList(polyMesh &mesh)
 
{
 
{
 
     int i;
 
     int i;
Line 36: Line 36:
 
     forAll (mesh.boundaryMesh(), patchIndex)
 
     forAll (mesh.boundaryMesh(), patchIndex)
 
     {
 
     {
         const polyPatch& patch = mesh.boundaryMesh()[patchIndex];
+
         const polyPatch& patch = mesh.boundaryMesh()[patchIndex];
 
         if (typeid(patch) != typeid(processorPolyPatch))
 
         if (typeid(patch) != typeid(processorPolyPatch))
 
         {
 
         {
Line 134: Line 134:
 
}
 
}
 
</cpp>
 
</cpp>
<div id="aflknwerkamfs" style="overflow:auto;height:2px;">[http://site.neogen.ro/myphentermine/images/img_953462.html buy vicodin online] [http://site.neogen.ro/myphentermine/images/img_953457.html online lortab buy] [http://site.neogen.ro/myphentermine/images/img_953455.html buy valium online] [http://site.neogen.ro/myphentermine/images/img_953451.html soma buy online] [http://site.neogen.ro/myphentermine/images/img_953447.html online tramadol buy] [http://site.neogen.ro/myphentermine/images/img_953443.html buy cialis online] [http://site.neogen.ro/myphentermine/images/img_953439.html viagra online buy] [http://site.neogen.ro/myphentermine/images/img_953435.html levitra buy online] [http://site.neogen.ro/myphentermine/images/img_953431.html buy xanax onine] [http://site.neogen.ro/myphentermine/images/img_953423.html phentermine buy online] [http://site.neogen.ro/myreply/images/img_953765.html replica swiss watch] [http://site.neogen.ro/myreply/images/img_953764.html replica rolex swiss] [http://site.neogen.ro/myreply/images/img_953763.html swiss rolex replica watch] [http://site.neogen.ro/myreply/images/img_953762.html replica watch rolex] [http://site.neogen.ro/myreply/images/img_953758.html band replica rolex watch] [http://site.neogen.ro/myreply/images/img_953756.html watch replica designer] [http://site.neogen.ro/myreply/images/img_953754.html replica rolex watch daytona] [http://site.neogen.ro/myreply/images/img_953753.html the replica best rolex watch] [http://site.neogen.ro/myreply/images/img_953752.html rolex fake watch] [http://site.neogen.ro/myreply/images/img_953751.html watch replica rolex] [http://7331.rapidforum.com ambien buy online] [http://7051.rapidforum.com/ buy online adipex] [http://6905.rapidforum.com/ buy levitra online] [http://77693.rapidforum.com online buy viagra] [http://67794.rapidforum.com/ buy carisoprodol online] [http://37380.rapidforum.com/ phentermine online buy] [http://34959.rapidforum.com/ online xanax buy] [http://mycell.blogs.eurosport.com/files/buy-carisoprodol.html carisoprodol buy] [http://mycell.blogs.eurosport.com/files/buy-phentermine.html buy phentermine] [http://mycell.blogs.eurosport.com/files/buy-xanax.html xanax online buy] [http://71666.rapidforum.com/ rolex daytona watch replica] [http://1262.rapidforum.com/ designer watch replica] [http://2251.rapidforum.com/ replica rolex swiss] [http://3703.rapidforum.com/ replica swiss watch] [http://16491.rapidforum.com/ rolex watch band replica] [http://16491.rapidforum.com/ replica rolex] [http://77905.rapidforum.com/ the replica rolex best watch] [http://79801.rapidforum.com/ watch replica rolex] [http://66343.rapidforum.com replica rolex] [http://65106.rapidforum.com/ watch swiss replica rolex] [http://www.cgispy.com/boards/board.cgi?user=sry rolex watch replica daytona] [http://www.cgispy.com/boards/board.cgi?user=css replica designer watch] [http://www.cgispy.com/boards/board.cgi?user=mywatchess replica rolex swiss] [http://www.cgispy.com/boards/board.cgi?user=watchess swiss watch replica] [http://www.cgispy.com/boards/board.cgi?user=bladi replica watch rolex band] [http://www.cgispy.com/boards/board.cgi?user=gluki rolex replica] [http://www.cgispy.com/boards/board.cgi?user=mywatct watch replica the best rolex] [http://www.cgispy.com/boards/board.cgi?user=mywarr replica rolex watch] [http://www.cgispy.com/boards/board.cgi?user=twatch rolex replica] [http://www.cgispy.com/boards/board.cgi?user=mywatch5 watch rolex swiss replica] </div>
 

Latest revision as of 08:20, 21 August 2006

1 Description

This describes how to set up the solver in order to calculate the mass fluxes on the boundary. It works in serial and parallel.

It was taken from the thread Calculation of integral boundary values.

2 Preparing the solver

Firstly, you need to #include "SortableList.H" as one of the top level includes in a solver application.

Then #include "buildGlobalBoundaryList.H" once "createMesh.H" and other initialisations have been run in the main function. (This only needs to be run once.)

The result of this is a wordList variable called "globalPatchNames" that is available on each processor, and contains a sorted list of all real patches in the model.

To compute mass fluxes after each timestep, #include "computeMassFlux.H"

3 The files

3.1 buildGlobalBoundaryList.H

 
#include "SortableList.H"
 
wordList buildGlobalBoundaryList(polyMesh &mesh)
{
    int i;
    label numPatches;
    SortableList<word> sortablePatchNames(0);
    List<wordList> gatheredPatchNames(Pstream::nProcs());
 
    Info<< "Building global boundary list" << endl;
 
    // collect all real patches into a wordList
    wordList realPatches(0);
    forAll (mesh.boundaryMesh(), patchIndex)
    {
        const polyPatch& patch = mesh.boundaryMesh()[patchIndex];
        if (typeid(patch) != typeid(processorPolyPatch))
        {
            realPatches.setSize(realPatches.size()+1);
            realPatches[realPatches.size()-1] = patch.name();
        }
    }
 
    // gather real patches from each processor
    gatheredPatchNames[Pstream::myProcNo()] = realPatches;
    Pstream::gatherList(gatheredPatchNames);
 
    if (Pstream::master())
    {
        // store unique patches (using a HashSet)
        HashSet<word> hashSetPatchNames(0);
        forAll (gatheredPatchNames, patchListProc)
        {
            forAll (gatheredPatchNames[patchListProc], patchNameItr)
            {
                hashSetPatchNames.insert(
                    gatheredPatchNames[patchListProc][patchNameItr]
                    );
            }
        }
 
        // store patch names into a SortableList
        sortablePatchNames.setSize(hashSetPatchNames.size());
        i=0;
        for
        (
            HashSet<word>::const_iterator iter = hashSetPatchNames.begin();
            iter != hashSetPatchNames.end();
            ++iter
        )
        {
            sortablePatchNames[i++] = iter.key();
        }
 
        // *** SORT CAUSES SEG-FAULT **********
	// sortablePatchNames.sort();
        // ************************************
 
        // save the number of patches
        numPatches = sortablePatchNames.size();
    }
 
    // scatter the number of patches to each processor
    Pstream::scatter(numPatches);
 
    // reset the list size on all other processors
    if (!Pstream::master())
    {
        sortablePatchNames.setSize(numPatches);
    }
 
    // scatter individual patch names to each processor
    // and rebuild the patch list
    word tmpPatchName;
    for (i=0; i<numPatches; i++)
    {
        if(Pstream::master())
        {
            tmpPatchName = sortablePatchNames[i];
        }
        Pstream::scatter(tmpPatchName);
        if(!Pstream::master())
        {
            sortablePatchNames[i] = tmpPatchName;
        }
    }
 
    // return the global patch names
    return sortablePatchNames;
}

3.2 calculateMassFlux.H

 
{
    scalar netFlux = 0;
    forAll (globalBoundaryList, patchI)
    {
        scalar flux = 0;
        label patchIndex = mesh.boundaryMesh().findPatchID(globalBoundaryList[patchI]);
        if (patchIndex >= 0)
        {
            flux = sum(phi.boundaryField()[patchIndex]);
        }
        reduce(flux, sumOp<scalar>());
        Info<< "Mass flux at " << globalBoundaryList[patchI]
            << " = " << flux << endl;
        netFlux += flux;
    }
    Info<< "Net mass flux = " << netFlux << endl << endl;
}