Defining obstacles via a numpy array

108 views
Skip to first unread message

Luca Massidda

unread,
Jul 13, 2018, 6:33:53 AM7/13/18
to mantaflow Forum
Many thanks to all the creators and developers of the project. Really impressive.
My question as a beginner concerns the setting of obstacles in the grid.
Is it possible to define obstacles "by filling the cells" using the python script? I would like to define the obtacles using a numpy array. 
I suppose it can be done, but I did not find an example of this in the documentation.
Thanks,
Luca

Nils Thuerey

unread,
Jul 16, 2018, 5:32:20 AM7/16/18
to mantaflow Forum
Hi Luca, yeah - there's no example for that at the moment, but you can initialize any grid as numpy first, and then copy it into a mantaflow grid (e.g., as described here https://ge.in.tum.de/research/mantaflow-tensorflow-tutorial-1/).

Just make sure to use the right integer values as defined in grid.h:
  
    enum CellType {
        TypeNone     = 0,
        TypeFluid    = 1,
        TypeObstacle = 2,
        TypeEmpty    = 4,
        TypeInflow   = 8,
        TypeOutflow  = 16,
...
    };

Cheers, Nils

Luca Massidda

unread,
Jul 16, 2018, 6:40:00 AM7/16/18
to mantaflow Forum
ok!
thanks a lot,
Luca

Jorge

unread,
Sep 28, 2018, 9:43:09 AM9/28/18
to mantaflow Forum
I'm sorry, I dont want to ask dumb questions (I have been trying to do this by myself), but can you please explicitely show me how to do this? how to initialize a FlagGrid from a numpy array. There is no copyArrayToGridFlag(source=npFlags, target=flags) function.

Again, many thanks in advance

Jorge

unread,
Oct 3, 2018, 8:35:08 PM10/3/18
to mantaflow Forum
For anyone having trouble doing this.

In the file "numpyconvert.cpp"  in source/plugin add:

PYTHON() void copyArrayToFlagGrid(const PyArrayContainer source, FlagGrid& target) {
copyArrayToGridScalar<FlagGrid>(source, target);
}

Then build manta.

This allowed me to initialize the flag grid with a numpy array.

Nils Thuerey

unread,
Oct 9, 2018, 10:18:05 AM10/9/18
to mantaflow Forum
Hello Jorge, good to hear you solved the problem - and thanks for posting a fix. This looks like a very good addition, we'll include it in the main branch...

Cheers, Nils
Reply all
Reply to author
Forward
0 new messages