underworldcode / UWGeodynamics

Underworld Geodynamics
Other
81 stars 32 forks source link

Tracing the velocity and displacement using passive tracer #222

Closed Peigen-L closed 3 years ago

Peigen-L commented 3 years ago

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?

rbeucher commented 3 years ago

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

Peigen-L commented 3 years ago

Hi @rbeucher

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

kind regards

Peigen