Facing Problem with IntersectionOfWalls in MercuryDPM

Hi, I am trying to make a Box shaped container in MercuryDPM, or say BoxWall.
I used IntersectionOfWalls to do this, as learnt from Tutorial8.

Main part of the code is:

IntersectionOfWalls w1;
Vec3D minPos = Vec3D(0, 0, 0), maxPos = Vec3D(getXMax(), getYMax(), getZMax());
w1.setSpecies(speciesHandler.getObject(0));
w1.addObject(Vec3D(-1.0,  0.0,  0.0), minPos); // back
w1.addObject(Vec3D( 0.0, -1.0,  0.0), minPos); // left
w1.addObject(Vec3D( 0.0,  0.0, -1.0), minPos); // bottom
w1.addObject(Vec3D( 1.0,  0.0,  0.0), maxPos); // front
w1.addObject(Vec3D( 0.0,  1.0,  0.0), maxPos); // right
w1.addObject(Vec3D( 0.0,  0.0,  1.0), maxPos); // top
wallHandler.copyAndAddObject(w1);

Then I place a particle there, and give it a velocity - or just release it under gravity.
However, just by doing so and Visualizing vtu files in ParaView, Walls are not visualized - and they didn’t get formed. As a result, particle escapes to infinity - as also evident in XBALLS animation.

One confusing part was whether the surface normals were set in intended direction. I have set them facing in the direction of particle’s path - when it comes to collide with wall in normal direction (see code above). I understand this is the right way, isn’t it?

However, When I set walls with surface normals in the opposite directions, the behaviors is different based on whether I have gravity set or not.

  1. If I have gravity set, ParaView actually generates the Walls! – but for particles, it looks like a weird situation and they escape to somewhere.
  2. But at the same time, if there is no gravity set - then walls are also not shown in ParaView and particle still jumps somewhere without any force set. I guess this kind behavior is not surprising if wall normals are not set in the right way. But I am not able to figure out other behaviors.
  • So, first question is am I not supposed to use IntersectionOfWalls this way?
  • Otherwise, is there any mistakes in my code? - could you review it?, I have made a fresh branch on Bitbucket, as a simple test implementation.
  • I guess it could be also some bad selection of combination of particle radius, collision time, etc. ( I use similar material properties as in Tutorial9, i.e., they are set to get a collisonTime=0.005s and NormalCOR=0.88 - and I use a particle of radius 1cm, instead of 5mm used there. )

Frames

Thanks in advance,
Fahad.

p.s: I need Box as single WallObject, since I want to assign it a prescribed motion of my like. And I guess it will be totally messy if I have to move each wall element. And I am also not familiar with making things in CAD, which might be alternative solution.

I have tried few more things:
( I use wall positions -Lhalf, Lhalf here, and domain is defined from [-L, L] in each dimensions. )

As @TiPlath suggested, I tried printing the following before adding box to the wallHandler.

std::cout << "Number of box walls = " << box.getNumberOfObjects() << std::endl;

And it shows right number anytime.


I tried to look at one thing, that is - does the order matter?

Even if I have only 3 walls, ( which finally intersects ) - if I do the following, ( where wall1 and wall2 has no intersection ):

//Attempt-01: failed
//------------------
box.addObject(Vec3D(-1, 0, 0), Vec3D(-Lhalf, 0, 0));
box.addObject(Vec3D( 1, 0, 0), Vec3D( Lhalf, 0, 0));

box.addObject(Vec3D( 0,-1, 0), Vec3D(0, -Lhalf, 0));
//box.addObject(Vec3D(0,  1, 0), Vec3D(0,  Lhalf, 0)); // not added now

it generates a vtu file which is empty, or something like:

<?xml version="1.0"?>
<!-- time 0-->
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="0" NumberOfCells="0">
<Points>
  <DataArray type="Float32" Name="Position" NumberOfComponents="3" format="ascii">
  </DataArray>
</Points>
<Cells>
  <DataArray type="Int32" Name="connectivity" format="ascii">
  </DataArray>
  <DataArray type="Int32" Name="offsets" format="ascii">
  </DataArray>
  <DataArray type="UInt8"  Name="types" format="ascii">
  </DataArray>
</Cells>
<CellData>
</CellData>
<PointData>
</PointData>
</Piece>
</UnstructuredGrid>
</VTKFile>

Did it fail because the order walls were added was not a good way?
So, I thought - walls should be added in the order that newly added wall should have an intersection to last added wall.

Naturally, I tried the following then:

//Attempt-02: failed
//------------------
box.addObject(Vec3D(-1, 0, 0), Vec3D(-Lhalf, 0, 0)); //back
box.addObject(Vec3D( 0,-1, 0), Vec3D(0, -Lhalf, 0)); //left

 box.addObject(Vec3D( 1, 0, 0), Vec3D( Lhalf, 0, 0)); //front

Which will be in the order back, left, front (if you take +x to be out of plane) - each of which have intersection with next. But this also doesn’t work.

Then I added a 4th wall, to make it complete ( maybe that works? ):

//Attempt-03: failed
//------------------
box.addObject(Vec3D(-1, 0, 0), Vec3D(-Lhalf, 0, 0));
box.addObject(Vec3D( 0,-1, 0), Vec3D(0, -Lhalf, 0));
box.addObject(Vec3D( 1, 0, 0), Vec3D( Lhalf, 0, 0));
box.addObject(Vec3D( 0, 0,-1), Vec3D(0, 0, -Lhalf));

This also fails!


A working version is, adding 3 walls - where all of them has a common intersection point:

//Attempt-04: SUCCESS
//------------------
box.addObject(Vec3D(-1, 0, 0), Vec3D(-Lhalf, 0, 0));
box.addObject(Vec3D( 0,-1, 0), Vec3D(0, -Lhalf, 0));
box.addObject(Vec3D( 0, 0,-1), Vec3D(0, 0, -Lhalf)); 

This works successfully!
However, if I add a 4th wall to it, keeping the same order:
box.addObject(Vec3D( 1, 0, 0), Vec3D( Lhalf, 0, 0));
Then it fails immediately!


But now, I realized Tutorial8 has a working version of something similar to failed Attempt-03

//! \[T8:finiteWall\]
IntersectionOfWalls w1;
w1.setSpecies(speciesHandler.getObject(0));
        
w1.addObject(Vec3D(-1.0,  0.0, 0.0), Vec3D(0.75 * getXMax(), 0.0, 0.0));
w1.addObject(Vec3D( 1.0,  0.0, 0.0), Vec3D(0.25 * getXMax(), 0.0, 0.0));
w1.addObject(Vec3D( 0.0, -1.0, 0.0), Vec3D(0.0, 0.75 * getYMax(), 0.0));
w1.addObject(Vec3D( 0.0,  1.0, 0.0), Vec3D(0.0, 0.25 * getYMax(), 0.0));
wallHandler.copyAndAddObject(w1);
//! \[T8:finiteWall\]

- But it is different, they were inward pointing walls.

- I inverted the normal there, then it also fails in Tutorial8 → vtu file is empty.

I am still not able to understand this properly.

Hi Fahad,

This took me too long to see the problem.

`IntersectionOfWalls` builds a **solid, convex object**: the region that lies inside **all** of the half-spaces you add. Particles are meant to be **outside** that object, as with the obstacle in Tutorial 8. For each `addObject(normal, point)`, the solid is on the side the normal points to ("normal into the wall").

So with your outward-pointing normals, the six half-spaces are x < 0, x > L, y < 0, y > L, and so on. No point is in all of them, so the intersection is **empty**. That is why the `.vtu` file has no points and the particle flies off. Your "successful" attempt 4 works because three half-spaces with a common corner *do* overlap: you get a solid corner block. As soon as you add the opposite face, it becomes empty again.

If you flip the normals inward, the intersection is the *inside* of the box, which is now a solid block with your particle trapped inside it. That explains the odd behaviour you saw with gravity.

Your normals were actually correct for individual walls. A container is the **union** of six walls, not their intersection.

**How to make a moving box**

The simplest robust way is six `InfiniteWall`s that share one prescribed motion. It only takes a loop, so it isn't messy:

```cpp
auto centre = [](double t) { return Vec3D(0.02 * std::sin(4 * constants::pi * t), 0, 0); }; // your motion
const Mdouble L = 0.05; // half-width of the box
const std::vector<Vec3D> normals = {{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};
for (const Vec3D& n : normals) {
    InfiniteWall w;
    w.setSpecies(speciesHandler.getObject(0));
    w.set(n, L * n);                       // normal points out of the box, into the wall
    auto wall = wallHandler.copyAndAddObject(w);
    Vec3D offset = L * n;
    wall->setPrescribedPosition([centre, offset](double t) { return centre(t) + offset; });
}
```

You don't need to set the velocity: MercuryDPM computes the wall velocity from the prescribed position, so contact forces with the moving walls are correct. For rotation as well, use `setPrescribedOrientation` in the same way. Note, though, that each wall then rotates about its own position, so you'd also need to rotate the offsets.

If you really want a single wall object, there is `BasicUnionOfWalls` (see `Drivers/SelfTests/Walls/UnionOfWallsSelfTest.cpp`). Add the six `InfiniteWall`s to it and give the union the prescribed motion. Be aware that it only uses the contact with the first face a particle touches. A particle at an edge or corner, touching two faces at once, therefore only feels one of them. For a box with many particles resting against the walls, the six-wall approach above is more reliable.


Best wishes,
Anthony
1 Like

P.S. There was a plan to make WallGroup for prescribed motion to make this a better interface but I never fnished it. Maybe I should reopen that job.

1 Like

Thanks for the explanation.
Problem was I was using it for wrong purpose then.
My assumption was IntersectionOfWalls will be the way to make any Polygonal sample-cell/ containers, where I can put particles in.

That will be great!
I have now a working version with 6 InfiniteWalls something similar to you suggested.
But the nice thing with a Combined wall will be, being able to visualize it as a single object in ParaView easily (as IntersectionOfWalls can do if used to make a closed object/obstacle, as I understand now). Otherwise ParaView just shows 6 infinite walls moving and overlaping ( of course cropped within the problem domain ).