yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #23249
Re: [Question #691026]: Loading the stored the position of plank, but it wrong
Question #691026 on Yade changed:
https://answers.launchpad.net/yade/+question/691026
yang yi posted a new comment:
To Jan Stránský:
Thank you very much. I modified the script as follow, there just a plank. In the first It rotates around a axis and the location stored. Then the location load by the second script and display in the 3D show.
The plank consist of two triangles. The 3D show of the first script that the two triangles rotate together, however in the display script, the triangles are separated. As you found the location is the same. So please help me how to modify that.
(1) Rotation script
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
import sys
sys.path.append('~/PycharmProjects/Yade20191229/')
# from yadeImport import *
import numpy as np
import os
from yade.gridpfacet import *
o = Omega()
o.dt = 1e-12
outputDir = 'Output'
positionWind = []
def HydraulicSupport():
global positionWind
temp = [Vector3(0, 0, 0),
Vector3(0, 10, 0),
Vector3(10, 10, 0),
Vector3(10, 0, 0)]
positionWind.append(temp)
Wind1 = pack.sweptPolylines2gtsSurface([positionWind[0]], capStart=True, capEnd=True)
IDWind = O.bodies.append(pack.gtsSurface2Facets(Wind1))
return IDWind
def Ground():
O.bodies.append(utils.wall(position=-10, sense=0, axis=2, material=-1))
##---------------------------------------##
def WindowsAction(IDWind):
global WinAction, windPosition, saveCounter, nEpisode,RotationW1
RotationW1.angularVelocity = -0.000001
SaveProcessLocation(nEpisode, saveCounter)
saveCounter += 1
def SaveProcessLocation(Episode, iter):
outputDir = "Output/location/"
if not os.path.exists(outputDir):
os.makedirs(outputDir)
Position = []
for i in IDWind:
print(o.bodies[i].state.pos)
temp = [i, o.bodies[i].state.pos]
Position.append(temp)
location_name = outputDir + 'wind_' + str(Episode)+ '_' + str(iter)
np.save(location_name, Position)
def WindowsControl():
global saveCounter, nEpisode
nEpisode += 1
saveCounter = 0
nEpisode = 0
saveCounter = 0
IDWind = HydraulicSupport()
Ground()
O.engines = [
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Wall_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys(),
Ip2_JCFpmMat_JCFpmMat_JCFpmPhys(xSectionWeibullScaleParameter=0.5,
xSectionWeibullShapeParameter=0.5,
weibullCutOffMin=0,
weibullCutOffMax=10)],
[Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM(recordCracks=False, recordMoments=False,label='interactionLaw'),
Law2_ScGeom_FrictPhys_CundallStrack()]
),
GlobalStiffnessTimeStepper(),
NewtonIntegrator(gravity=(0, 0, 9.8), damping=0.5, label='down'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind, zeroPoint=positionWind[0][0],
label='RotationW1'),
PyRunner(command="WindowsAction(IDWind)", iterPeriod=200000),
PyRunner(command="WindowsControl()", iterPeriod=2000000),
]
# o.run(1200000000)
================================================================
(2) Display script
from __future__ import print_function
import sys
sys.path.append('~/PycharmProjects/Yade20191229/')
# from yadeImport import *
import numpy as np
import os
from yade.gridpfacet import *
o = Omega()
o.dt = 1e-12
positionWind=[]
def HydraulicSupport():
global positionWind
temp = [Vector3(0, 0, 0),
Vector3(0, 10, 0),
Vector3(10,10, 0),
Vector3(10,0, 0)]
positionWind.append(temp)
Wind1 = pack.sweptPolylines2gtsSurface([positionWind[0]], capStart=True, capEnd=True)
IDWind = O.bodies.append(pack.gtsSurface2Facets(Wind1))
return IDWind
def Ground():
O.bodies.append(utils.wall(position=-10, sense=0, axis=2, material=-1))
def Relocation():
global nEpisode, nIter, index
path = 'Output/location/'
wind_name = path + 'wind_' + str(nEpisode) + '_' + str(nIter) + '.npy'
if nIter >= index[nEpisode, 1]:
nIter = 0
nEpisode += 1
else:
nIter += 1
if nEpisode >= len(index):
O.pause()
locationWind = np.load(wind_name, allow_pickle=True)
print(nEpisode,nIter)
print(locationWind)
print('--------------')
for i in range(0, len(locationWind)):
n = locationWind[i][0]
o.bodies[n].state.pos = locationWind[i][1]
import os.path
rootdir = "Output/location/"
wind_locations = []
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
if filename[0:4] == 'wind':
wind_locations.append(filename)
episodeMax = 0
endNumber = 100000000
for i in wind_locations:
n = int(i[5])
if n >= episodeMax:
episodeMax = n
index = np.zeros((episodeMax+1, 2))
for i in range(episodeMax+1):
index[i,0] = i
for name in wind_locations:
episode = int(name[5])
iter = int(name[7])
if episode == i:
if (iter) >= index[i, 1]:
index[i, 1] = iter
IDWind = HydraulicSupport()
Ground()
nEpisode =0
nIter = 0
O.engines = [
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Wall_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys(),
Ip2_JCFpmMat_JCFpmMat_JCFpmPhys(xSectionWeibullScaleParameter=0.5,
xSectionWeibullShapeParameter=0.5,
weibullCutOffMin=0,
weibullCutOffMax=10)],
[Law2_ScGeom_JCFpmPhys_JointedCohesiveFrictionalPM(recordCracks=False, recordMoments=False,label='interactionLaw'),
Law2_ScGeom_FrictPhys_CundallStrack()]
),
GlobalStiffnessTimeStepper(),
NewtonIntegrator(gravity=(0, 0, 9.8), damping=0.5, label='down'),
PyRunner(command="Relocation()", iterPeriod=100000),
]
# o.run(1200000000, True)
Thank you very much
--
You received this question notification because your team yade-users is
an answer contact for Yade.