Rotate cylinder
Hi,
How can I rotate this half cylinder 90 degrees in y-axis:
#Cylinderpunch
cyl1 =geom.facetCyli
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.
for j in cyl1:
body= O.bodies[j]
body.
I tried this, but it did not move my cylinder.
Here is my code:
#!/usr/bin/env python
#encoding: ascii
# Testing of the Deformation Enginge with Luding Contact Law
# Modified Oedometric Test
from yade import utils, plot, timing
from yade import pack
import pandas as pd
o = Omega()
# Physical parameters
fr = 0.52
rho = 1050 #kg/m3
Diameter = 0.0079 #79 micrometer
r1 = Diameter
r2 = Diameter
k1 = 126000.0
kp = 12.0*k1
kc = k1 * 0.1
ks = k1 * 0.1
DeltaPMax = Diameter/3.0
Chi1 = 0.34
o.dt = 1.0e-5
particleMass = 4.0/3.0*
Vi1 = math.sqrt(
PhiF1=0.999
#PhiF1 = DeltaPMax*
#******
# Add material
mat1 = O.materials.
# Spheres for compression
# Spheres for compression
sp=pack.
sp.makeCloud(
#Cylinder cloud sphere pack
cyl = pack.inCylinder
sp = pack.filterSphe
sp.toSimulation
##No of particles
count = 0
for b in O.bodies:
if isinstance(b.shape, Sphere):
count +=1
##Mass of particles
n_p=count
#######
walls=O.
#height=0.067
##Top punch##
#find max Z coordinate of your cloud
max_z = aabbExtrema()[1][2]
min_z = aabbExtrema()[0][2]
#Top_punch=
#O.bodies[
#Cylinderpunch
cyl1 =geom.facetCyli
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.
for j in cyl1:
body= O.bodies[j]
body.state.
for i in cyl1:
body= O.bodies[i]
body.state.vel = (0,1,0)
df = pd.DataFrame(
df.to_csv(
from csv import writer
def append_
# Open file in append mode
with open(file_name, 'a+', newline='') as write_obj:
# Create a writer object from csv module
csv_writer = writer(write_obj)
# Add contents of list as last row in the csv file
# Add engines
o.engines = [
ForceResetter(),
InsertionSort
InteractionLoop(
[Ig2_
Ig2_
Ig2_
[Ip2_
[Law2_
),
NewtonIntegra
#VTKRecorder(
#PyRunner(
#PyRunner(
PyRunner(
PyRunner(
DeformControl
]
def checkdata():
if O.iter < 20000:
return
else:
time=o.realtime
porosity=
Maxoverlap=
stress=
row_contents = [time,time,
append_
def checkForce():
# at the very start, unbalanced force can be low as there is only few
# contacts, but it does not mean the packing is stable
if O.iter < 20000:
return
# the rest will be run only if unbalanced is < .1 (stabilized packing)
timing.reset()
if unbalancedForce() > 0.2:
return
# add plate at upper box side
highSphere = 0.0
for b in O.bodies:
if highSphere < b.state.pos[2] and isinstance(b.shape, Sphere):
else:
pass
O.bodies.
# without this line, the plate variable would only exist inside this
# function
global plate
plate = O.bodies[-1] # the last particles is the plate
# Wall objects are "fixed" by default, i.e. not subject to forces
# prescribing a velocity will therefore make it move at constant velocity
# (downwards)
plate.state.vel = (0, 0, -0.01)
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Yade Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Jan Stránský
- Solved:
- 2021-03-30
- Last query:
- 2021-03-30
- Last reply:
- 2021-03-26
|
#1 |
Hello,
> Here is my code:
most of the code is irrelevant to the problem.
Please try to create a MWE [1], M = minimal (unnecessary code removed, focusing on the problem)
Your "initial" code would be just fine (with "Diamater" variable defined), showing the entire problem ("I intended to rotate these bodies, but they are not rotated")
The rest just scares/discourages potential helpers :-)
state.rot is a method to get relative rotation from initial rotation [1], something like state.displ().
With your code, you just overwritten the method to the (0,90,0) tuple, try this:
###
Diameter = 0.0079 #79 micrometer
cyl1 =geom.facetCyli
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.
for j in cyl1:
body= O.bodies[j]
print(
body.
print(
###
Just a note, in Yade the angles are rarely (if at all) in degrees..
To rotate a body, you have to modify state.ori. If the center of rotation is not state.pos, you have to modify state.pos as well:
###
Diameter = 0.0079 #79 micrometer
cyl1 =geom.facetCyli
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.
rot = Quaternion(
center = Vector3(0,0,0) # center of rotation
for j in cyl1:
body= O.bodies[j]
# change rotation
body.state.ori *= rot
# shift the body
p = body.state.pos - center # relative vector from center to pos
p = rot * p # rotated relative vector
body.state.pos = center + p # new pos
###
cheers
Jan
[1] https:/
Jérôme Duriez (jduriez) said : | #2 |
Depending on your needs (change the default initial orientation by a 90 degrees rotation, or impose a gradual rotation up to 90 degrees), it is a good YADE habit (for the 2nd case) to go through angular velocities, resp. velocities, and not update directly orientation, resp. position.
See https:/
Thanks Jan Stránský, that solved my question.