Calculate gravity on a 1D field Given a string or list, calculate the effects of gravity on that string/list. 

The string will be made of 5 characters:


N has a weight of 2
L has a weight of 1
S has a weight of -2
D has a weight of -1


(the 5th character is whatever you want, it means empty space. I use  (space) in my examples)

Items with negative weight fall upwards (towards the top of the string), and items with positive weight fall downwards (towards the bottom of the string). 

When an object collides with something, one of three things happens:


If the object collides with the top or bottom "walls" of the input, then it just stops. 
If the object collides with another object, their weight/velocity is summed (i.e. N and D would give 1). If the result is positive, both objects fall downwards. If it's negative, they fall upwards.
If an object  (let's call it A) collides with an object B, and B is already pinned against the ceiling/floor, A will just come to rest against B.


All non-occupied spaces of the string/list should be filled with the empty character.

If it wasn't clear already: each character in the string/line is on top of the next one.  i.e. NL is the same as:

N
L


And  SD is:

(blank)
S
D


Test cases: (uses  (the space character) to show empty space)

" L D " -&gt; " LD  " or "  LD "

" SDLN " -&gt; "SD  LN"

" NLLSSD " -&gt; "NLLSSD  "
Haskell, 169 180 bytes



g s=sum[n|c&lt;-s,(d,n)&lt;-zip"SD LN"[-2..],c==d]
w=elem ' '
h(x:y:r)|(w x&amp;&amp;g y&lt;0)||(w y&amp;&amp;g x&gt;0)=y:h(x:r)|w(x++y)||g x&lt;0=x:h(y:r)|t&lt;-x++y=h$t:r
h r=r
concat.until((==)=&lt;&lt;h)h.map(:[])


Try it online!
 Example usage: concat.until((==)=&lt;&lt;h)h.map(:[]) $ " SDLN ".

Edit: +11 bytes, now also works for the "  NSDLLD  " test case proposed by @zgrep.

(short) Explanation:

h works on a list of tokens where initially each char of the input string is token. Until the token list no longer changes, h bubbles through the list comparing two tokens x and y at a time. Depending on the tokens their order is kept (x:h(y:r)), they are swapped (y:h(x:r)) or combined to a single token (t&lt;-x++y=h$t:r).

g computes the weight of a token and w checks whether a token contains a space.