Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Loic Gouarin
    @gouarin
    For you case, if you have a lot of holes, it is indeed a good idea to have this flag
    which is generally the case for porous media
    Amin Sadeghi
    @ma-sadeghi
    So, I added this flag:
            "lbm_algorithm": {
                'name': PullAlgorithm,
                'settings': {'check_isfluid': True}
            },
    and here's the error I got
    Traceback (most recent call last):
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\symbolic.py", line 251, in call_genfunction
        func_args = function.arg_dict.keys()
    
    AttributeError: 'cython_function_or_method' object has no attribute 'arg_dict'
    
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    
      File "C:\Users\Amin\Code\Image-Based Conductance\lbm_blobs.py", line 307, in <module>
        sol, err_log = run(im, dx, Tf, generator="cython", rtol=1e-5, with_plot=False)
    
      File "C:\Users\Amin\Code\Image-Based Conductance\lbm_blobs.py", line 137, in run
        sol.one_time_step()
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\monitoring.py", line 121, in wrapper
        output = f(*args, **kwds)
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\simulation.py", line 374, in one_time_step
        self.algo.call_function('one_time_step', self, **kwargs)
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\algorithm\base.py", line 624, in call_function
        call_genfunction(func, args)
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\symbolic.py", line 256, in call_genfunction
        d = {k:args[k] for k in func_args} #pylint: disable=invalid-name
    
      File "C:\Users\Amin\anaconda3\envs\pylbm\lib\site-packages\pylbm\symbolic.py", line 256, in <dictcomp>
        d = {k:args[k] for k in func_args} #pylint: disable=invalid-name
    
    KeyError: 'iv'
    Btw, I really appreciate the help you're providing. I have managed to convert the Poiseuille example to work on a binary image. If you think it's worth it, I can clean it up and make it a proper example on "How to get the permeability of porous materials using pylbm", and make a pull request.
    Loic Gouarin
    @gouarin
    It's a really good idea !
    I can reproduce your issue
    Loic Gouarin
    @gouarin
    @ma-sadeghi I fixed your issue in pylbm/pylbm#131
    Amin Sadeghi
    @ma-sadeghi
    @gouarin Thanks!
    I find that for using pylbm on binary images, a huge chunk of the time is spent generating pylbm-compatible geometry
    and it's because it involves nested for loops (2 for 2d and 3 for 3d) for creating a stack of Parallelograms
    Amin Sadeghi
    @ma-sadeghi
    is there a way to speed that up? I'm not familiar with cython, do you think it's doable in cython?
    it's not doable using numba because it only works with pure python objects (and a subset of numpy's), but we're creating a pylbm object (i.e. Parallelogram) inside the for loop, so it can't be jit-accelerated
    Amin Sadeghi
    @ma-sadeghi
    Also, on another note, is there a reason you have an upper limit on sympy version? Would it be too much work to lift it?
    Loic Gouarin
    @gouarin
    We use an old version of sympy because I rewrote the codegen of sympy which is broken for our usage. I have decided to integrate my changes into the sympy repo a long time ago.
    The PR was hard to review and I finally never finished it.
    But last week, I decided to make small PRs to have these new features inside sympy
    I hope to have all that I need in a few weeks since the changes will be split and easier to read and review
    It is a really bad issue now to have this limitation since we can't update python version
    For your first problem, could you explain more precesely where the nested loops come from ?
    What is your algortihm ?
    Loic Gouarin
    @gouarin
    @ma-sadeghi I started the process to update sympy ;) (https://github.com/sympy/sympy/pull/20877)
    Amin Sadeghi
    @ma-sadeghi
    @gouarin Really appreciate it :)
    Ok, here's my for loop
    Amin Sadeghi
    @ma-sadeghi
    def im2geom(im, voxel_size, label):
        r"""
        Converts a 2D binary image to a suitable pylbm geometry.
    
        The returned list is to be passed to pylbm `dico` dict under
        'elements' key. This method assumes that in the input image, fluid and
        solid are labeled with 1s and 0s, respectively.
    
        Parameters
        ----------
        im : ndarray
            Input binary image, ones indicate fluid and zeros indicate solid.
        voxel_size : float
            Voxel size in desired units.
        label : int
            Label of the pylbm geometry needed for adding boundary conditions.
    
        Returns
        -------
        boxes : list
            List of parallelogram to subtract from the bounding box to obtain
            the simulation domain. In the contect of porous materials, this
            list constitues all of the solid phase.
    
        """
        if im.ndim != 2:
            raise Exception("This method only works for 2D images for now.")
        Nx, Ny = im.shape
        boxes = []
        for i in range(Nx):
            for j in range(Ny):
                if not im[i, j]:
                    voxel = pylbm.Parallelogram(
                        point=(i * voxel_size, j * voxel_size),
                        vecta=(voxel_size, 0),
                        vectb=(0, voxel_size),
                        isfluid=False,
                        label=label
                    )
                    boxes.append(voxel)
        return boxes
    Loic Gouarin
    @gouarin
    @ma-sadeghi you don't have to create boxes for each pixel. You can use the pixel values of your image as the in_or_out array defined into the domain class.
    But you also have to compute the distance between a cell and the border. In your case, I think it's always 0.5 the lattice since you don't have a parametric equation of the borders
    I can try to implement it next week if you want.
    Amin Sadeghi
    @ma-sadeghi
    @gouarin That'd be great! I knew there must be a better way than the naïve for-loop :) Really appreciate your efforts.
    Amin Sadeghi
    @ma-sadeghi
    Hi @gouarin, did you get a chance to look into it? Thanks
    Loic Gouarin
    @gouarin
    Hi @ma-sadeghi, I'm completely busy these days and unfortunately I don't think I'll have time to look at it before April...
    Amin Sadeghi
    @ma-sadeghi
    @gouarin Thanks for getting back to me. It's all good, and I totally understand. Just a quick question: is there an example that somehow explains the idea behind what you explained in a few comments above (i.e., how to use pixel values of the image as the in_or_out)? Thank you again.
    Loic Gouarin
    @gouarin
    I will try to give you a short example soon.
    Loic Gouarin
    @gouarin
    @ma-sadeghi do you still have the issue on the boundary if you not use loopy ?
    Amin Sadeghi
    @ma-sadeghi
    @gouarin Sorry I didn't get notified of your messages. Do you mean the issue of qx and qy not being exactly 0 on boundary cells and solid cells?
    Loic Gouarin
    @gouarin
    @ma-sadeghi sorry but I don't remember what it was about
    Amin Sadeghi
    @ma-sadeghi
    @gouarin never mind, do you remember our conversation on how to generate pylbm-compatible geometry from a binary image? If you scroll up, you can find a code snippet I posted that contains im2geom method. You told me before that the way I do it in im2geom is not optimal and there's a better way to do it using in_or_out API. Did you get a chance to make a minimal example on how to do that?
    Would really appreciate it :)
    Loic Gouarin
    @gouarin
    I didn't have enough time to work on it
    but since few weeks, you can load stl files
    I will try to work on this topic in July
    Amin Sadeghi
    @ma-sadeghi
    So, basically I can first convert my binary image to STL (maybe using numpy-stl or some other library) and then import it directly as a pylbm geometry. Right?
    Loic Gouarin
    @gouarin
    This is what we use: numpy-stl
    this is @bgraille who worked on this topic
    you have several examples in the directory demo/examples/geometry
    It's a first attempt
    so let us know if you find bugs