# Using Arbitrary DEM in 2D

**URL:** <https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195>\
**Category:** Issues\
**Created:** [February 14, 2024, 7:10pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195 "2024-02-14T19:10:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlirezaZarei](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@AlirezaZarei](https://gpusph.discourse.group/u/AlirezaZarei)\
**Post date:** [February 14, 2024, 7:10pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/1 "2024-02-14T19:10:15Z")

</div>

Hi,  
I hope all is well with you.

I want to use an arbitrary DEM and run it in 2D but I got “FATAL: non-zero z world size: spurious particles generated in the z direction?” error. Is it possible to use an arbitrary DEM in 2D? Do we need to use another format for DEM rather than the default one?

Regards,  
Alireza

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 14, 2024, 8:32pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/2 "2024-02-14T20:32:06Z")

</div>

Hello @AlirezaZarei,

When support for 2D was introduced in GPUSPH, not all features were tested and DEM was among the ones that were postponed, so I’m not surprised you’re seeing the error you report.

The error comes from the fact that in 2D mode GPUSPH uses only x and y components (with y assumed to be the vertical one unless gravity is intentionally oriented differently). To avoid issues during problem setup, a check is done along the z axis and if any particles have non-zero z it is assumed that something went wrong, since the z axis is orthogonal to the simulation plane.

The DEM topology, on the other hand, is assumed to be (as needed for 3D) a regular array of heights over the ground xy plane. So particles get placed entirely outside of the simulation domain. This is also largely independent from the specific file format used, be it ASCII grid, VTK or XYZ. These assumption about the DEM topology are currently hard-coded both host-side (if you’re curious, the source file that manages this is `src/geometries/TopoCube.cc` and its companion `.hh` file), and device-side (when the geometric form of the DEM is used with the `ENABLE_DEM` flag).

At least for standard particle-filling, a new `TopoRect` or similar geometry should be introduced, designed specifically for 2D. This would be the geometry used by `addDEM` in the problem API when the system is 2D.

This is a useful feature to add. Could you please open a feature request for this [on GitHub](https://github.com/GPUSPH/gpusph/issues)?

(In the mean time, a workaround could be to generate Segments for the ground, although this will produce a different filling.)

---

<div class="post-metadata">

**Author:** ![AlirezaZarei](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@AlirezaZarei](https://gpusph.discourse.group/u/AlirezaZarei)\
**Post date:** [February 14, 2024, 8:45pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/3 "2024-02-14T20:45:06Z")

</div>

Thank You, Giuseppe!  
I will add a feature request on GitHub.

I have another question about the boundary module when using DEM. I want to use 3 layers of non-fluid particles instead of planes for the boundary, but my problem is how to implement these layers of non-fluid particles in a way that they get the shape of DEM! I think the “addBox” function doesn’t work well for this problem. Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 15, 2024, 7:04am UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/4 "2024-02-15T07:04:32Z")

</div>

The box is a 3D geometry, so you should not use it in 2D. The geometries you can use safely in 2D are Segment, Rectangle and Disk. For composite borders, in particular, you want the Segment geometry.

There is a somewhat convoluted example in the `SlidingWedge` test case. This test case is designed to be used both in 2D and 3D mode, which makes the code more complex than a simple 2D case would be, but it should give you an idea about how a complex boundary can be created with segments.

(`SlidingWedge` actually defines and uses an `addSurface` function that maps to `addRect` in 3D and `addSegment` in 2D.)

---

<div class="post-metadata">

**Author:** ![AlirezaZarei](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@AlirezaZarei](https://gpusph.discourse.group/u/AlirezaZarei)\
**Post date:** [February 15, 2024, 10:10am UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/5 "2024-02-15T10:10:07Z")

</div>

Actually, I want to use an arbitrary DEM in a 3D model. I want to use Dummy or Dynamic boundary conditions with 3 layers of non-fluid particles instead of planes, but the problem is that using “addDEM” and “addDEMfluidBox” is not enough to create 3 layers of non-fluid particles for the DEM. Moreover, I think “addBox” can only create a rectangular shape and cannot produce the DEM shape.  
I think someone else had this problem before when I read the " [DEM in combination with other geometries](https://gpusph.discourse.group/t/dem-in-combination-with-other-geometries/99)" in the Application part, but I couldn’t figure out whether you solved the problem or not.

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 15, 2024, 10:57am UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/6 "2024-02-15T10:57:52Z")

</div>

(For the future: I recommend using different forum topics for different questions, even if they are releated, it makes things a bit more clear ;-))

I see what you mean now. A fix for (at least some of) the issues reported in that forum thread is available in the `candidate-v6` branch of the development repository. If you `addDEM` with `FT_OUTER_BORDER` filltype it should work correctly.

---

<div class="post-metadata">

**Author:** ![AlirezaZarei](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@AlirezaZarei](https://gpusph.discourse.group/u/AlirezaZarei)\
**Post date:** [February 15, 2024, 4:46pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/7 "2024-02-15T16:46:49Z")

</div>

Ok. I will create a new forum topic for the future.  
I used `FT_OUTER_BORDER` filltype based on the following lines (without using any planes):

```
    if (tangent_filling)
           setFillingMethod(Object::BORDER_TANGENT);
           addDEM(dem_file, DEM_FMT_ASCII, use_geometries ? FT_NOFILL : FT_OUTER_BORDER);
           addDEMFluidBox(water_height);

```

Now I have 3 layers of boundary layers but the problem is that there is a leakage in the model and particles don’t respect the boundary.

---

<div class="post-metadata">

**Author:** ![giuseppe.bilotta](https://yyz2.discourse-cdn.com/free1/user_avatar/gpusph.discourse.group/giuseppe.bilotta/32/72_2.png) [@giuseppe.bilotta](https://gpusph.discourse.group/u/giuseppe.bilotta)\
**Post date:** [February 15, 2024, 9:11pm UTC](https://gpusph.discourse.group/t/using-arbitrary-dem-in-2d/195/8 "2024-02-15T21:11:17Z")

</div>

I’m running some tests now and there are indeed still some issues with multilayer fills for the boundaries. I’m currently working on some fixes.
