Closed Prasanna2989 closed 5 years ago
Hi Pras,
A swarm variable numpy array (let's call it SVNA) is most likely stale because it was created before the increase in the number of particles. SVNAs that are created before the addition of extra particle don't know about the addition, hence the SVNA is still the original size (bad!) and the array is invalid.
Underworld checks for these invalid SVNAs. If found, a RuntimeError is generated as you received.
As the message explains you can fix this by del
the SVNA.
Consider this code snippet below
import numpy as np
import underworld as uw
# build mesh and swarm
mesh = uw.mesh.FeMesh_Cartesian()
swarm = uw.swarm.Swarm(mesh)
v1 = swarm.add_variable(dataType='int', count=1)
pos = np.random.rand(4,2)
swarm.add_particles_with_coordinates(pos)
v1.data[:,0] = -3
# create a numpy array view
view = v1.data
### UNCOMMENT FOR SUCCESS ###
# copy = np.copy(v1.data)
# del view
pos2 = np.random.rand(4,2)
# if swarm adds these particles then the `view` numpy array is stale.
swarm.add_particles_with_coordinates(pos2)
Hope this helps.
Thanks Jule. I have removed the swarm related np arrays. Now it seems working fine.
I had one for loop which navigate through the swarm. I have removed index and coord variables as follows
for index, coord in enumerate(swarm.particleCoordinates.data): x = coord[0] z = coord[1]
del index del coord
cheers Pras
Hi All,
I was producing the mantle melt in a rectangular convection model with a swarm and was trying to transport the melt particles instantaneously to the surface. In this case, I have selected the melt particles by constraining temperature field (comparing with the solidus) and applied an index for these particles to represent the mantle melt.
Then, I checked their coordinates(xmelt, ymelt) and transfer them directly to a new coordinate at the surface of the model (xmelt, 0.99). This is a rectangular model and model height is 1. Then, I added a new particle in the previous location of the melt marker to represent the residue of the melt. The model was running fine for few steps and gave me the attached error message. I have included the last figure of material indexes for your reference. I was wandering whether I can get some help to identify this error and to know how to avoid it. (This is not a proper melt generation model at the Earth surface. However, it simulate a prototype model by comparing temperature with some solidus like function)
Thank you Pras