UWGeodynamics icon indicating copy to clipboard operation
UWGeodynamics copied to clipboard

Tracing the velocity and displacement using passive tracer

Open Peigen-L opened this issue 5 years ago • 2 comments

Hi, I am trying to trace the velocity and displacement for a specific particle by updating the position of the passive tracer for every timestep using post solve hook function as:

import numpy as np
x1 = GEO.nd(-200. * u.kilometer + 10. * u.kilometer)
y1 = GEO.nd( 0. * u.kilometer - 10. * u.kilometer)
coords = np.ndarray((1, 2))
coords[:, 0] = np.array([x1])
coords[:, 1] = np.array([y1])

tip_tracer = Model.add_passive_tracers(name="tip tracer", vertices=coords)


tTracer       = [GEO.nd(Model.time)]
xDisplacement = [0.]
yDisplacement = [0.]

def postSolveHook():
    global tTracer,xDisplacement,yDisplacement
    
tTracer.append(GEO.nd(Model.time))
xDisplacement.append(GEO.nd(GEO.nd(tip_tracer.particleCoordinates.data[0][1])))
yDisplacement.append(GEO.nd(GEO.nd(tip_tracer.particleCoordinates.data[0][1])))

x1 = GEO.nd(x1 + xDisplacement)
y1 = GEO.nd(y1 + yDisplacement)

coords = np.ndarray((1, 2))
coords[:, 0] = np.array([x2])
coords[:, 1] = np.array([y2])

tip_tracer = Model.add_passive_tracers(name="tip_tracer", vertices=coords)

tip_tracer.add_tracked_field(Model.velocityField[1],
                              name="velocity1",
                              units=u.centimetre / u.year,
                              dataType="double",
                              count=1)

tip_tracer.add_tracked_field(Model.velocityField[0],
                              name="velocity0",
                              units=u.centimetre / u.year,
                              dataType="double",
                              count=1)


tip_tracer.velocity1.data[:10]
tip_tracer.velocity0.data[:10]

Machine recalled error as 'TypeErrorTraceback (most recent call last)

<ipython-input-17-19434dbf3408> in <module>
     20 yDisplacement.append(GEO.nd(GEO.nd(tip_tracer.particleCoordinates.data[0][1])))
     21 
---> 22 x1 = GEO.nd(x1 + xDisplacement)
     23 y1 = GEO.nd(y1 + yDisplacement)
     

TypeError: unsupported operand type(s) for +: 'float' and 'list' 

Is there any possibility to trace the movement for a specific point and out put its velocity every time-step?

Peigen-L avatar Feb 08 '21 05:02 Peigen-L

Hi @Peigen-L You can use a postSolveHook function, that is fine. However the one you have implemented does not do anything. It is called by the code after each iteration so you need to define what is done in there...

As for the error, it is a classic Python error. You are trying to add a float to a list. In Python we usually use list comprehension to do this: new_list = [val + something for val in old_list]

An alternative is to use numpy arrays... you can convert your list to a numpy array...

I hope this helps!

R

rbeucher avatar Feb 08 '21 22:02 rbeucher

Hi @rbeucher

Thank you so much for your help, I will try with your suggestions.

kind regards

Peigen

Peigen-L avatar Feb 08 '21 23:02 Peigen-L