Snip calculating mass flow
From OpenFOAMWiki
Contents
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; }
buy vicodin online online lortab buy buy valium online soma buy online online tramadol buy buy cialis online viagra online buy levitra buy online buy xanax onine phentermine buy online replica swiss watch replica rolex swiss swiss rolex replica watch replica watch rolex band replica rolex watch watch replica designer replica rolex watch daytona the replica best rolex watch rolex fake watch watch replica rolex ambien buy online buy online adipex buy levitra online online buy viagra buy carisoprodol online phentermine online buy online xanax buy carisoprodol buy buy phentermine xanax online buy rolex daytona watch replica designer watch replica replica rolex swiss replica swiss watch rolex watch band replica replica rolex the replica rolex best watch watch replica rolex replica rolex watch swiss replica rolex rolex watch replica daytona replica designer watch replica rolex swiss swiss watch replica replica watch rolex band rolex replica watch replica the best rolex replica rolex watch rolex replica watch rolex swiss replica