Skip to content

Mass flux calculation

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #6389

    Hi OpenLB community,

    I am trying to calculate the y-direction outflow mass flux using the SuperPlaneIntegralFluxMass2D. I can get a good value for the mass flux although it is negative (why is that?). However, the region size (e.g., output[1]) is a bit strange. My understanding is the region size should be the width of the outlet in a 2D simulation. In my case, I set nx = 200 but I keep getting output[1] = 279 or 280 even when I change nx. Does anyone have any ideas on this issue?

    Code snippet:

    const int nx = 200; // width of the channel
    const int ny = 200; // height of the channel

    SuperLatticeVelocity2D<T, NSDESCRIPTOR> velocity(NSlattice);
    SuperLatticeDensity2D<T, TDESCRIPTOR> concentration(ADlattice);

    Vector<T,2> normal(0,1); // normal vector in the y-direction

    SuperPlaneIntegralFluxMass2D<T> outflux(velocity, concentration, superGeometry, 1.0, 1.0, normal, 4, BlockDataReductionMode::Analytical); // material 4 is the outlet; conversion factor is 1 as I am using lattice units in the simulation

    [SuperPlaneIntegralFluxMass2D]regionName=outflux; regionSize[m]=279; massFlowRate[kg/s]=-7.89133



    The sign of the computed mass flux value depends on the orientation of the integration plane’s normal. In your case it is likely pointing in the opposite direction of where it should.

    For the region size: Can you post your whole example code / the geometry setup? (Just to make sure that there are no other issues, your setup of the plane integral functor looks correct).


    Hi Adrian,

    Thank you for your comments. I’ve attached the code snippet for setting the geometry as below.

    /// Stores geometry information in form of material numbers
    void prepareGeometry(SuperGeometry2D<T>& superGeometry)

    OstreamManager clout(std::cout,”prepareGeometry”);
    clout << “Prepare Geometry …” << std::endl;


    std::vector<T> extend( 2, T(0) );
    extend[0] = nx+2;
    extend[1] = 1;

    /// Set material number for bottom and top
    std::vector<T> origin( 2, T(0) );
    origin[0] = -1;
    IndicatorCuboid2D<T> bottom(extend, origin);

    origin[1] = ny-1;
    IndicatorCuboid2D<T> top(extend, origin);

    /// Set material number for right
    origin[0] = nx-1;
    extend[0] = 1;
    origin[1] = -1;
    extend[1] = ny+1;
    IndicatorCuboid2D<T> right(extend, origin);

    /// Removes all not needed boundary voxels outside the surface
    // superGeometry.clean();
    /// Removes all not needed boundary voxels inside the surface
    // superGeometry.innerClean();


    clout << “Prepare Geometry … OK” << std::endl;

    /// === 2nd Step: Prepare Geometry ===
    std::vector<T> extend(2,T());
    extend[0] = nx;
    extend[1] = ny;
    std::vector<T> origin(2,T());
    IndicatorCuboid2D<T> cuboid(extend, origin);

    /// Instantiation of a cuboidGeometry with weights
    const int noOfCuboids = singleton::mpi().getSize();
    const int noOfCuboids = 1;
    CuboidGeometry2D<T> cuboidGeometry(cuboid, 1, noOfCuboids);
    cuboidGeometry.setPeriodicity(false, false);

    /// Instantiation of a loadBalancer
    HeuristicLoadBalancer<T> loadBalancer(cuboidGeometry);

    /// Instantiation of a superGeometry
    SuperGeometry2D<T> superGeometry(cuboidGeometry, loadBalancer, 2);



    Hi Adrian,

    Just so you know. I changed my normal from (0,1) to (0,-1) but I am still getting negative mass flux…



    Sorry for the late response – our new release took up most of my time in the past weeks.

    I rechecked your instantiation of the mass flux functor: Which constructor did you actually want to use? (See Doxygen for reference).

    The arguments likely lead to selecting

    SuperPlaneIntegralFluxMass2D(FunctorPtr<SuperF2D<T>>&& velocityF,
                                   FunctorPtr<SuperF2D<T>>&& densityF,
                                   SuperGeometry<T,2>&       geometry,
                                   T conversationFactorMass,
                                   T conversationFactorTime,
                                   const Vector<T,2>& origin,
                                   const Vector<T,2>& u,
                                   BlockDataReductionMode mode);

    which is not we want here.


    Thank you so much for checking. Excited to hear the new version is out!

    You are right. I just realized SuperPlaneIntegralFluxMass2D doesn’t support using a normal. I am now setting the origin (0,ny) and u (1,0) instead. Just curious – is the direction vector u supposed to be along the outlet width? I get a negative flux when u is (1,0) and a positive one at (-1,0). Not quite sure why this happened.


    Good to hear that it works now.

    For the persisting dependency on u: This is an artifact of how the hyperplane (i.e. the line) is constructed in Hyperplane2D. u is passed to the parallelTo method which uses it to construct the normal vector. This normal vector is dependent on the sign of u and is also used to calculate the flow in SuperPlaneIntegralF2D::operator() (output[0] = (h * Vector<T,2>(flow)) * _normal;).

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.