Coordinates of Mesh-Nodes
Hi,
I have a Mesh with many nodes. I want to rotate those nodes with the Rotation Matrix. So i need the coordinates of them. Is there any method to get them in a easy way as a vector ?
Sorry for bad english
Cheers Oguz
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Revision history for this message
|
#1 |
Hi Oguz,
ESyS-Particle currently does not have a method to obtain the coordinates of mesh nodes during simulations.
In the past, when I have wanted to rotate a mesh, I have written a runnable that initially reads the mesh file to store the initial coordinates and ids of mesh nodes. Then, during the Runnable.run() call, I update the positions of the nodes and inform the simulation to move the nodes via a LsmMpi.
This probably isn't the most elegant solution but it works...
Cheers,
Dion
Revision history for this message
|
#2 |
Hi Dion,
Is it possible, that you can send me that Runnable? So i have an example how to do that. Only if it's okay for you :)
Greetings
Oguz
Revision history for this message
|
#3 |
i tried here a runnable:
from __future__ import division
from esys.lsm import *
from esys.lsm.util import *
import math
import numpy as np
from numpy import matrix,array
class kinematic (Runnable):
def __init__ (self,
"""
Subroutine to initialise the Runnable and store parameter values.
"""
Runnable.
self.sim = LsmMpi
self.meshName = meshName
self.dt = self.sim.
self.rampTime = rampTime
self.
self.Nt = 0
def run (self):
alpha=
R_z = np.matrix( [[math.
#node coordinates
node0 = np.array( ((-5),(0),(0)) )
node1 = np.array( ((-5),(0),(5)) )
node2 = np.array( ((0),(0),(-5)) )
node3 = np.array( ((0),(0),(0)) )
node4 = np.array( ((5.0),(0),(-5)) )
node5 = np.array( ((5.0),(0),(5)) )
rotate0 = np.dot(node0,R_z)
rotate1 = np.dot(node1,R_z)
rotate2 = np.dot(node2,R_z)
rotate3 = np.dot(node3,R_z)
rotate4 = np.dot(node4,R_z)
rotate5 = np.dot(node5,R_z)
#moving nodes
self.
self.meshName,
nodeId = 0,
delta = Vec3(rotate0[
)
self.
self.meshName,
nodeId = 1,
delta = Vec3(rotate1[
)
self.
self.meshName,
nodeId = 2,
delta = Vec3(rotate2[
)
self.
self.meshName,
nodeId = 3,
delta = Vec3(rotate3[
)
self.
self.meshName,
nodeId = 4,
delta = Vec3(rotate4[
)
self.
self.meshName,
nodeId = 5,
delta = Vec3(rotate5[
)
self.Nt += .00075
where R_z is the rotation matrix in Z direction, and alpha the angular ,which changes every step. My problem is, that the mesh behaves very strange wenn I visualize it. It gets infinital long and does not rotate correctly. The mesh is the example from the Tutorial.
Here is the part from the main code:
sim.readMesh(
fileName = "trianglemesh.lsm",
meshName = "mesh"
)
movemesh = kinematic(
LsmMpi = sim,
meshName = "mesh",
startTime = 0,
rampTime = 0
)
sim.addPreTimeS
Did i miss something? maybe it's a dump question :D
Cheers Oguz
Revision history for this message
|
#4 |
Hi Oguz,
I think the problem might be that you are moving each node by an amount equal to the difference between the current desired position of the nodes (rotate*) and the initial locations of the nodes (node*). LsmMpi.
Perhaps your problem will be solved by setting node* = rotate* after the six moveSingleMeshN
Cheers,
Dion
Revision history for this message
|
#5 |
Hi,
First of all thanks for your help! I tried your approach but nothing changed.
There is some problem with the "delta" in "self.sim.
Greetings
Oguz
Revision history for this message
|
#6 |
Hi Oguz,
To get your runnable to work correctly you must do two things:
1) set the rotation angle to be a constant = the angle by which you wish to rotate the mesh in a single timestep. Currently alpha increases with time and this is the main reason your mesh explodes. The script is progressively rotating the mesh by larger and larger angles each timestep.
2) ensure that you set node* = rotate* after the sim.moveSingleM
I suspect the reason delta=Vec3(2,2,2) splatters the mesh is because this displacement increment is too large. Consequently the simulation becomes numerically unstable. To avoid this, displacement increments should always be smaller than the verletDist.
Pasted below is my modified version of your Runnable (rotate.py) and a small simulation script (sim.py) to test out the mesh rotations. Having run the simulation and generated snapshot files, run the following to generate VTK files of the rotating mesh:
dump2vtk -i snapshot -o snaps_ -mesh -t 0 1001 1
These can then be visualised in Paraview.
Have fun!
Cheers,
Dion
#rotate.py:
from __future__ import division
from esys.lsm import *
from esys.lsm.util import *
import math
import numpy as np
from numpy import matrix,array
class kinematic (Runnable):
def __init__ (self,
"""
Subroutine to initialise the Runnable and store parameter values.
"""
Runnable.
self.sim = LsmMpi
self.meshName = meshName
self.rampTime = rampTime
self.
self.Nt = 0
self.Nt = .00075
def run (self):
alpha=
R_z = np.matrix( [[math.
#node coordinates
node0 = np.array( ((-5),(0),(0)) )
node1 = np.array( ((-5),(0),(5)) )
node2 = np.array( ((0),(0),(-5)) )
node3 = np.array( ((0),(0),(0)) )
node4 = np.array( ((5.0),(0),(-5)) )
node5 = np.array( ((5.0),(0),(5)) )
rotate0 = np.dot(node0,R_z)
rotate1 = np.dot(node1,R_z)
rotate2 = np.dot(node2,R_z)
rotate3 = np.dot(node3,R_z)
rotate4 = np.dot(node4,R_z)
rotate5 = np.dot(node5,R_z)
#moving nodes
self.
nodeId = 0,
delta = Vec3(rotate0[
)
self.
nodeId = 1,
delta = Vec3(rotate1[
)
self.
nodeId = 2,
delta = Vec3(rotate2[
)
self.
nodeId = 3,
delta = Vec3(rotate3[
)
self.
nodeId = 4,
delta = Vec3(rotate4[
)
self.
nodeId = 5,
delta = Vec3(rotate5[
)
"""
"""
#self.Nt += .00075
#print '#',self.Nt
node0[0] = rotate0[0,0]
node1[0] = rotate1[0,0]
node2[0] = rotate2[0,0]
node3[0] = rotate3[0,0]
node4[0] = rotate4[0,0]
node5[0] = rotate5[0,0]
node0[1] = rotate0[0,1]
node1[1] = rotate1[0,1]
node2[1] = rotate2[0,1]
node3[1] = rotate3[0,1]
node4[1] = rotate4[0,1]
node5[1] = rotate5[0,1]
"""
print rotate0[
print rotate1[
print rotate2[
print rotate3[
print rotate4[
print rotate5[
"""
if __name_
runner = kinematic()
runner.run()
#sim.py:
from esys.lsm import *
from esys.lsm.util import *
from rotate import kinematic
sim = LsmMpi(1,[1,1,1])
sim.initNeighbo
particleType = "NRotSphere",
gridSpacing = 2.5000,
verletDist = 0.1000
)
sim.setNumTimeSteps (1000)
sim.setTimeStepSize (1.0000e-04)
domain = BoundingBox(
sim.setSpatialD
sim.readMesh(
fileName = "mesh.lsm",
meshName = "mesh_wall"
)
runner = kinematic(LsmMpi = sim, meshName=
sim.addPreTimeS
sim.createCheck
CheckPointPrms (
fileNameP
beginTimeStep = 0,
endTimeStep = 1000,
timeStepIncr = 1
)
)
sim.run()
Can you help with this problem?
Provide an answer of your own, or ask Oguz Cebeci for more information if necessary.