Skip to content

How to create complex 2D geometry stucture

OpenLB – Open Source Lattice Boltzmann Code Forums on OpenLB General Topics How to create complex 2D geometry stucture

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #5752

    Dear everyone,

    As mentioned in the title , because my coding ability is not sufficient,I wonder whether I can create 2D geometry using CAD or UG and then import it to openlb,could this works?

    Yours sincerely,


    Its certainly possible to read in external data to set the material numbers. E.g. one possibility that I have encountered in (non-OpenLB) example codes is to read in a bitmap image file to set geometry information. All you would need is some loop to iterate over the input data and set the material numbers using e.g. SuperGeometry2D::get.

    However the most straight forward way is to use the OpenLB-provided interfaces, specifically indicators in combination with the rename functions. See e.g. examples/laminar/cylinder2d for a basic example. What specifically do you want to model?

    (In 3D we support CAD import via STL data)


    Good afternoon guys!
    I’m working on a similar problem and would like to know if it is possible to edit the source code of the indicators. I’m currently trying to create a “Sierpinski carpet” made solely of cuboids, but I’m currently struggling on adding a second “IndicatorCuboid” on the Cylinder2d example. My code goes as:

    // Parameters for the simulation setup
    const int N = 10; // resolution of the model
    const T Re = 20.; // Reynolds number
    const T maxPhysT = 10; // max. simulation time in s, SI unit
    const T L = 0.1/N; // latticeL
    const T lengthX = 3;
    const T lengthY = 3;
    const T centerCylinderX = lengthX/3;
    const T centerCylinderY = lengthY/3;
    const T centerCylinderX2 = lengthX/6;
    const T centerCylinderY2 = lengthY/6;
    const T radiusCylinder = 0.05;
    const T originMainX = lengthX/3;
    const T originMainY = lengthY/3;
    const T originMainX2 = lengthX/6;
    const T originMainY2 = lengthY/6;

    // Stores geometry information in form of material numbers
    void prepareGeometry( UnitConverter<T, DESCRIPTOR> const& converter,
    SuperGeometry2D<T>& superGeometry )

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

    Vector<T,2> extend( lengthX,lengthY );
    Vector<T,2> square( centerCylinderX,centerCylinderY );
    Vector<T,2> square2( centerCylinderX2,centerCylinderY2 );
    Vector<T,2> originS( originMainX,originMainY );
    Vector<T,2> originS2( originMainX2,originMainY2 );
    Vector<T,2> origin;
    IndicatorCuboid2D<T> circle( square, originS );
    IndicatorCuboid2D<T> circle2( square2, originS2 );

    But this unfortunally is not being able to generate a second square.
    Do you know how can I do it?


    The cuboid indicator setup looks ok. You’ll just have to call the super geometry’s rename method to actually set the material numbers (not shown in the code snippet).


    Hey Adrian,

    Thanks A LOT for your answer, it was a silly mistake on the material numbers, now it worked perfectly.
    There’s now another doubt (You know, we solve a problem and then create another):
    Is it possible for me to create indicator cuboids in a loop? Without having to name each one individually, just create lots of squares changing their coordinates and sizes through an algorithim?

    Sorry for the silly question, I’m a new C++ user as well.
    Also, is it possible for me to acess the indicator cuboid source code and change the definitions of the squares to make the lines not exactly straight but “senoid-like”?

    Again, thanks A LOT!
    Best regards!


    Glad to hear that it worked.

    As for your followup question: Yes, this is possible. As the indicators passed to rename are only evaluated and not stored you do not need to preserve them. i.e. you can write a loop where you construct a new indicator, pass it to rename and delete it again during every iteration.
    However this is unlikely to be the best approach – I would suggest to either generate the carpet fractal externally as STL (if you already have code that does this) or to write a new indicator that evaluates the fractal internally. Although if you don’t care about initialization times you can get away with the loop-based approach.

    You can definitely access and modify the indicator source code (any part of OpenLB really). This is the main point of open source after all 🙂 A good place to get an overview of OpenLB’s classes and where they are implemented is the Doxygen documentation.


    Hey Adrian, good morning!

    I am advancing with my research thanks to you and open LB, I’m so grateful!
    However, right now I’m stuck with the Doxygen Documentation. The type of definition I used for the “IndicatorCuboid2D” is described in the line 78 of indicatorF2D.hh, using center, xlength, ylength and theta.
    My doubt is: In this definition, there are only 2 lines of code and we only define the Maximum and the Minimum values for X and Y, uniting these points with straight lines to create a square. Is it possible for me to change these straight lines to curvy lines with a cossene function? Where should I include it in the code? I’ve tried some unsuccessful syntaxes, but couldn’t make it work in any way.
    Here is the original code for the IndicatorCuboid2D:

    78 IndicatorCuboid2D<S>::IndicatorCuboid2D(S xLength, S yLength, Vector<S,2> center, S theta )
    79 : _center(center), _xLength(xLength), _yLength(yLength), _theta(-theta)
    80 {
    81 this->_myMin = {_center[0] – _xLength/2., _center[1] – _yLength/2.};
    82 this->_myMax = {_center[0] + _xLength/2., _center[1] + _yLength/2.};
    83 }


    The method you mention is only the constructor which sets up the parameters as you describe. In order to change the actual geometry described by the indicator you will also have to modify the operator() implementation. I would suggest to start by finding a abstract indicator function of the specific geometry you want to model.

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