Skip to content

IndicatorCuboid2D : Need extra Explanation

OpenLB – Open Source Lattice Boltzmann Code Forums on OpenLB General Topics IndicatorCuboid2D : Need extra Explanation

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #5412
    at8i
    Participant

    Hello,
    New user of OpenLB here. I am trying to use galliumMelting2D example of OpenLB to simulate a problem of mine. I have read userguide till chapter 7 and I feel like, I should be able to write the a simple
    program. I want to learn OpenLB in Depth if possible ( new c++ user as well).
    In Gallium example a cuboid is defined like this: IndicatorCuboid2D<T> cuboid(extend, origin).

    `void prepareGeometry(SuperGeometry2D<T>& superGeometry,
    ThermalUnitConverter<T, NSDESCRIPTOR, TDESCRIPTOR> const& converter)
    {

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

    superGeometry.rename(0,4); // turn geometry from out of geometry to constant pressure or outflow

    std::vector<T> extend(2,T()); // create a vector and first element of it is lx and second
    extend[0] = lx; // ly . Cuboid extends till here in x and y directions .
    extend[1] = ly;
    std::vector<T> origin(2,T()); //create origin vector. first element is physical
    origin[0] = converter.getPhysLength(1); //length of a 1 lattice and second element is half of
    origin[1] = 0.5* converter.getPhysLength(1); // it.
    clout << “origin ” << origin[0] << “,” << origin[1] << std::endl; // I added these to see if I
    clout << “extend ” << extend[0] << “,” << extend[1] << std::endl;// could make sense of origin if
    IndicatorCuboid2D<T> cuboid2(extend, origin); // I saw the numbers.

    superGeometry.rename(4,1,cuboid2); // change the cells on cuboid2 from 4 to fluid.

    I did go and take a look at indicatorF2d.h file but I guess my lack of knowledge in c++ is the heart of the problem. I could not figure out what was going on in there.

    Second part : for my own problem I need to create a circle which I did with IndicatorCircle2D
    and after I need to rename the cells ofc. Now for a bounce back boundary all around the circle:
    1-Is there a specific method that I can use ?
    2- What I wanted to do is create another circle indicator with a radios just one lattice smaller than
    the original and subtract the smaller from main and rename the resulting indicator using the material numbers. (seems feasible based on the userguide)
    3- (Should not be necessarily answered – trivial question) I do want to add a specific model to OpenLB . But based on a week long study, I feel like my c++ knowledge is lacking . Which one is better add it to OpenLB or just use Fortran and be done with it?

    #5413
    at8i
    Participant

    The first part of the question is not clear: I do not know what origin does. What is it exactly indicating?

    #5415
    stephan
    Participant

    Dear at8i,

    in case you are not yet familiar with the C++ syntax standardly used in OpenLB, please have a look at introductory books/tutorials for C++ programming and our User Guide.
    Then start with compiling, and running the most simplified examples (e.g. laminar, single-phase flows in simple geometries) offered in the latest OpenLB release.

    The Example section in the current User Guide should help you with understanding the purpose of each sample code (e.g.: geometry primitives, which are necessary for your code snippet above).
    You could then identify the example which is most suitable as a basis for extension towards your own application and have a detailed look on that.

    Please note, that we unfortunately cannot debug your code within this forum, but we can however assist you in doing that by yourself.

    In that sense, I’ll provide hints and try to answer your questions below.

    – The .rename function is simply “renaming” the material numbers assigned to the voxels in your geometry, under (if any are specified) certain indicator constraints. These material numbers are then used as specifiers to be assigned with e.g. different boundary or initial conditions.
    – Please use the doxygen documentation to double-check the arguments for renaming and indicator functions.
    – First part (origin): Let me explain that via perceiving the 2D cuboid as a planar rectangle. The origin vector comprises the location of the lower left corner of the cuboid. The extend in turn is then the vector which is added to the origin to obtain the upper right corner of the cuboid. The center of the rectangle is then subsequently defined as “origin + 1/2 * extend”, and the angle theta is the rotation (counter-clockwise) which can addtionally be specified.
    – Circular boundary: (1) Yes, please have a look at an example with a circular geometry. An incremental search in the olb folder for indicatorCircle2D / 3D should lead you to the specific sections. Copy or code along the syntax of your geometry and boundary conditions from that application after you made sure that it does what you want. (2) That should work, yes, however make sure to hit the nodes correctly with your indicator function (i.e. maybe you should consider a larger distance between the circles than one lattice unit or add a buffer distance e.g. half a lattice unit). (3) You can add multiphysics models in OpenLB in the same manner as the dynamics which are currently implemented. This of course requires knowledge in: C++, LBM for the actual model, and OpenLB in terms of code structure. From my point of view (I am not an expert in Fortran) realizing the same LB algorithm from scratch in Fortran should take you way longer than implementing it in OpenLB.

    Hopefully, I could help you a bit.
    In case you have further questions, please let me know.

    BR
    Stephan

    #5416
    at8i
    Participant

    Thanks Stephan for your answer.
    The answers were complete and satisfactory. Doing this LBM project is a self-interest rather than a project at work or university and of course a self-study. The code in the question is from the examples in OpenLB and I will definitely try to avoid including any code in questions in future and make it minimal.
    Regarding the origin, I thought it was the left bottom corner of the rectangle but I could not make sense of the rest of the code. I need to study a bit more I guess.
    I use vim+xolox’s easytags + ctags for finding relevant data/tags/files in a project but I did make the doxygen doc and it has helped me a couple times.
    The facilities in OpenLB makes it an attractivbe choice for doing my project.
    I do not know the rules of the forum but if you think this question is redundant or unnecessary please remove it.
    And again, thank you for the answers.
    Kind Regards,
    Amir Toosi

    #5417
    stephan
    Participant

    Dear Amir,

    thanks for your reply.
    Please continue posting in case you need further help with the implementation, and use the “CODE” macro in the text field to highlight the snippets you include.

    Your questions are absolutely not redundant, this is the right place to ask them.
    We are always glad to help you with realizing your project.

    BR
    Stephan

    #5418
    at8i
    Participant

    Dear Stephan,
    Is there a way in OpenLB to remove gravity from the dynamics and implement them ?

    Kind Regards,
    Amir

    #5426
    at8i
    Participant

    Another Question popped up today .Is below code a valid operation in OpenLB:

    IndicatorCircle2D<T> Circle1(center , radius);
    IndicatorCircle2D<T> Circle2(center , radius2);

    IndicatorIdentity2D<T> shell(Circle2 - / + / . Circle1);

    I get an error if I do any of these operations and I am trying to use venturi3d’s approach in
    User-guide to set up my geometry.
    Now let’s say after solving the problem and the getting a “shell”. Will this code work(using shell as a condition indicator in rename method):

    SuperGeometry.rename(4,2,1,shell);

    Kind Regards,
    Amir Toosi

    #5428
    at8i
    Participant

    Update to Previous Question:
    I can confirm that the operations on Indicators mentioned in the UserGuide-1.4 section
    12.7.5- venturi3d is not working at my end to be exact (lslisting) the code in page 148 of
    the document.
    1-Are these operators on geometries removed from OpenLB or is it an error on my end?
    2-If they are removed, are there any alternatives?
    3-If these errors are related to my implementing them since I am using the official userguide, if
    possible, I would like to a see a simple working example of these operation by any of the OpenLB users.
    4-If there are new or other ways of manipulating 2D primitive geometries in OpenLB, please teach me.

    King Regards,
    Amir Toosi

    #5429
    Adrian
    Participant

    This is an oversight in the documentation. Functor and indicator arithmetic use std::shared_ptr since version 1.3. See section 10.3.2 of the userguide for an introduction.

    Basically you can write any indicator as

    `
    std::shared_ptr<IndicatorF2D<T>> box1 = std::make_shared<IndicatorCuboid2D<T>>(extend1, origin1);
    std::shared_ptr<IndicatorF2D<T>> box2 = std::make_shared<IndicatorCuboid2D<T>>(extend2, origin2);
    auto unified_box = box1 + box2;
    `

    and so on. This also works for functors.

    #5430
    at8i
    Participant

    Thanks Adrian for your answers. It did solve the problem of creating and manipulating the primitive geometries.
    Is there any of using these with rename function.For example:
    superGeometry.rename(4,1,unified_box);
    (unified_box is from you sample code).
    Thanks in advance for your advises.
    Kind Regards,
    Amir Toosi

    #5431
    Adrian
    Participant

    Sure, fur functions that are not yet converted to using FunctorPtr arguments such as rename you can dereference the shared_ptr using the “*” operator:

    `
    superGeometry.rename(4,1,*unified_box);
    `

    #5432
    at8i
    Participant

    Thanks Adrian, with this I was able to run my test run without any problems. I have to say OpenLB’s ways and methods are so generic that is really simple that is very simple to use even for a new person like me.
    Last question : I want to simulate all my experiments in weightless conditions. Is there any way for me to not add new methods and dynamics to OpenLB ( which will require quite a bit of time to study and learn structure of OpenLB due to lack c++ knowledge) and still be able to simulate such conditions?
    For example : Create an extForce equal to -g and make the force field act as a negator?
    Seems feasible just wanted to see if you have experimented with such a thing.

    Kind Regards,
    Amir Toosi

    #5433
    Adrian
    Participant

    Any external force has to be added manually in OpenLB using forced dynamics. So if you currently use e.g. a normal BGK collision you already model a “weightless” system.

    #5434
    at8i
    Participant

    Thanks, Adrian. After the points you and Stephan made , I realized I need to study OpenLB step by step while I am studying OpenLB’s user guide and sometimes hacking into the examples and changing parameters and etc. to get a better understanding of it.
    My end project is simulating a melting solid in a chamber (cylinder) . I wanted to make it simpler for myslef so I decided to look at a 2D circle first. So right now, I am changing a bit of examples/thermal/galliumMelting2d/galliumMelting2d.cpp.
    I decided to change geometry of the said example as below:
    `
    superGeometry.rename(0,4);

    `std::vector<T> center(2,T());
    center[0]= lx + converter.getPhysLength(1);
    center[1]= lx + 0.5 * converter.getPhysLength(1);
    IndicatorCircle2D<T> circle(center,lx);
    superGeometry.rename(4,1,circle);`

    `std::vector<T> extendwallleft(2,T(0));
    extendwallleft[0] = converter.getPhysLength(1);
    extendwallleft[1] = 2 * lx + converter.getPhysLength(1);
    std::vector<T> originwallleft(2,T(0));
    originwallleft[0] = 0.0;
    originwallleft[1] = 0.0;
    IndicatorCuboid2D<T> wallleft(extendwallleft, originwallleft);`

    `std::vector<T> extendwallright(2,T(0));
    extendwallright[0] = converter.getPhysLength(1);
    extendwallright[1] = 2 * lx + converter.getPhysLength(1) ;
    std::vector<T> originwallright(2,T(0));
    originwallright[0] = 2 * lx + converter.getPhysLength(1);
    originwallright[1] = 0.0;
    IndicatorCuboid2D<T> wallright(extendwallright, originwallright);`

    `superGeometry.rename(4,2,1,wallleft);
    superGeometry.rename(4,3,1,wallright);`
    `
    lx is radius of the circle and is 2.5 cm (25e-3).
    And I also changed lx in ThermalUniConverter converter declaration in main from lx to 2 * lx.
    And also prepared geometry in main as below:
    `

    std::vector<T> extend(2,T());
        extend[0] = 2 * lx + 2*converter.getPhysLength(1);
        extend[1] = 2 * lx  + converter.getPhysLength(1);
        std::vector<T> origin(2,T());
        IndicatorCuboid2D<T> cuboid(extend, origin);

    `
    The last part I changed was coupling declaration, I changed lx to 2*lx also ly to 2*lx.

    I get no error when I am compiling the programm and programm is getting executed as well. The problem is avEnergy value is always zero and is not changing .
    I know that walls are not really optimal to initiate the boundaries for a circle 2d but I wanted to make sure that I ma going in the right path? or do I need to change the way I look at the problem?
    I would appreciate it if you could point out my mistakes.
    Kind Regards
    Amir Toosi

    • This reply was modified 2 weeks ago by at8i. Reason: code
    #5436
    at8i
    Participant

    To another OpenLB and LBM lost soul who wanders here, hey what’s upp? road is long and we have to continue. SO if you are like me , a person who is casually interested in LBM and simulation world with superficial knowledge in cpp and LBM and simulation in general; take note of 3 things:
    1- Have better knowledge of Cpp RAII and smart pointers in general . I never cared for smart pointers and I always managed my memory manually. So you better start learning. (de-referencing does work on these folks)
    2- I am summarizing and taking notes of everything as I am going through them and will put them in repo
    and post it here after I am done. I hope it will be slightly better userguide for less fortunate ones like myself.
    3- If you are interested in learning from each other as we go along , please contact me : amir.tusi@gmail.com and my github repo : github.com/at8i

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