yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #23242
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ý (honzik) :
Thank you very much. I attach the script as follow. There are two scripts: (1) the simulation to produce the position of 5 windows (2) display the process.
====================================================================================
script (1) Simulation script:
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
import sys
sys.path.append('~/PycharmProjects/Yade20191229/')
# from yadeImport import *
import math
import numpy as np
import os
from yade.gridpfacet import *
o = Omega()
o.dt = 1e-12
outputDir = 'Output'
checkCounter = 0
numWinds = 5
WinAction = np.zeros((5,1), dtype=int)
## =========== Environment ============##
widthSpace = 6.8 ## width is the distance from the front coal wall to the back
widthHydr = 1.5
lengthSpace = widthHydr * numWinds ## length is the width of 5 windows
highHydr = 3.8
CheckThick = 1
highDummy = 3
colorWind = (0, 1, 1)
angleShield = 50 * 3.1415926 / 180
angleSwingPositive = 15 * 3.1415926 / 180
angleSwingNegtive = 40 * 3.1415926 / 180
lengthShield = 3
lengthTail = 2
windUpperBoundary = 0.9
windLowerBoundary = 0.5019
stateUpperBoundary = highHydr
stateLowerBoundary = windLowerBoundary
positionWind = []
windPosition = np.zeros(5)
shield_y_0 = lengthTail * math.cos(angleShield - angleSwingPositive)
shield_y_1 = shield_y_0 + lengthShield * math.cos(angleShield)
shield_z_0 = highHydr - lengthShield * math.sin(angleShield)
shield_z_1 = highHydr #
wind_y_0 = lengthTail * (math.cos(angleShield - angleSwingPositive) - math.cos(angleShield))
wind_y_1 = shield_y_0
wind_z_0 = highHydr - (lengthShield + lengthTail) * math.sin(angleShield)
wind_z_1 = highHydr - lengthShield * math.sin(angleShield)
HyMat = O.materials.append(FrictMat(frictionAngle=0.1, density=3000, young=2e9))
myGraviaty = -1200
def HydraulicSupport():
for i in range(0, numWinds):
temp = [
Vector3(widthHydr * i, wind_y_0, wind_z_0),
Vector3(widthHydr * (i + 1), wind_y_0, wind_z_0),
Vector3(widthHydr * (i + 1), wind_y_1, wind_z_1),
Vector3(widthHydr * i, wind_y_1, wind_z_1)
]
positionWind.append(temp)
Wind1 = pack.sweptPolylines2gtsSurface([positionWind[0]], capStart=True, capEnd=True)
Wind2 = pack.sweptPolylines2gtsSurface([positionWind[1]], capStart=True, capEnd=True)
Wind3 = pack.sweptPolylines2gtsSurface([positionWind[2]], capStart=True, capEnd=True)
Wind4 = pack.sweptPolylines2gtsSurface([positionWind[3]], capStart=True, capEnd=True)
Wind5 = pack.sweptPolylines2gtsSurface([positionWind[4]], capStart=True, capEnd=True)
IDWind1 = O.bodies.append(pack.gtsSurface2Facets(Wind1, color=colorWind))
IDWind2 = O.bodies.append(pack.gtsSurface2Facets(Wind2, color=colorWind))
IDWind3 = O.bodies.append(pack.gtsSurface2Facets(Wind3, color=colorWind))
IDWind4 = O.bodies.append(pack.gtsSurface2Facets(Wind4, color=colorWind))
IDWind5 = O.bodies.append(pack.gtsSurface2Facets(Wind5, color=colorWind))
IDWind = [IDWind1, IDWind2, IDWind3, IDWind4, IDWind5]
WindList = IDWind1 + IDWind2 + IDWind3 + IDWind4 + IDWind5
return IDWind, WindList
##---------------------------------------##
def WindowsAction(IDWind):
global WinAction, windPosition, saveCounter, nEpisode
RotationW = [RotationW1, RotationW2, RotationW3, RotationW4, RotationW5]
for nW in range(0, numWinds):
RotationW[nW].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 WindList:
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, WindList = HydraulicSupport()
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, myGraviaty), damping=0.5, label='down'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind[0], zeroPoint=positionWind[0][2],
label='RotationW1'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind[1], zeroPoint=positionWind[1][2],
label='RotationW2'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind[2], zeroPoint=positionWind[2][2],
label='RotationW3'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind[3], zeroPoint=positionWind[3][2],
label='RotationW4'),
RotationEngine(rotationAxis=(1, 0, 0), rotateAroundZero=True, ids=IDWind[4], zeroPoint=positionWind[4][2],
label='RotationW5'),
PyRunner(command="WindowsAction(IDWind)", iterPeriod=200000),
PyRunner(command="WindowsControl()", iterPeriod=2000000),
]
=====================================================================================
script (2) Display the process
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
import sys
sys.path.append('~/PycharmProjects/Yade20191229/')
# from yadeImport import *
import math
import numpy as np
import os
from yade.gridpfacet import *
o = Omega()
o.dt = 1e-12
outputDir = 'Output'
checkCounter = 0
numWinds = 5
WinAction = np.zeros((5,1), dtype=int)
## =========== Environment ============##
widthSpace = 6.8 ## width is the distance from the front coal wall to the back
widthHydr = 1.5
lengthSpace = widthHydr * numWinds ## length is the width of 5 windows
highHydr = 3.8
CheckThick = 1
highDummy = 3
colorWind = (0, 1, 1)
angleShield = 50 * 3.1415926 / 180
angleSwingPositive = 15 * 3.1415926 / 180
angleSwingNegtive = 40 * 3.1415926 / 180
lengthShield = 3
lengthTail = 2
windUpperBoundary = 0.9
windLowerBoundary = 0.5019
stateUpperBoundary = highHydr
stateLowerBoundary = windLowerBoundary
positionWind = []
windPosition = np.zeros(5)
shield_y_0 = lengthTail * math.cos(angleShield - angleSwingPositive)
shield_y_1 = shield_y_0 + lengthShield * math.cos(angleShield)
shield_z_0 = highHydr - lengthShield * math.sin(angleShield)
shield_z_1 = highHydr #
wind_y_0 = lengthTail * (math.cos(angleShield - angleSwingPositive) - math.cos(angleShield))
wind_y_1 = shield_y_0
wind_z_0 = highHydr - (lengthShield + lengthTail) * math.sin(angleShield)
wind_z_1 = highHydr - lengthShield * math.sin(angleShield)
HyMat = O.materials.append(FrictMat(frictionAngle=0.1, density=3000, young=2e9))
myGraviaty = -1200
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(locationWind)
for i in range(0, len(locationWind)):
n = locationWind[i][0]
o.bodies[n].state.pos = locationWind[i][1]
def HydraulicSupport():
for i in range(0, numWinds):
temp = [
Vector3(widthHydr * i, wind_y_0, wind_z_0),
Vector3(widthHydr * (i + 1), wind_y_0, wind_z_0),
Vector3(widthHydr * (i + 1), wind_y_1, wind_z_1),
Vector3(widthHydr * i, wind_y_1, wind_z_1)
]
positionWind.append(temp)
Wind1 = pack.sweptPolylines2gtsSurface([positionWind[0]], capStart=True, capEnd=True)
Wind2 = pack.sweptPolylines2gtsSurface([positionWind[1]], capStart=True, capEnd=True)
Wind3 = pack.sweptPolylines2gtsSurface([positionWind[2]], capStart=True, capEnd=True)
Wind4 = pack.sweptPolylines2gtsSurface([positionWind[3]], capStart=True, capEnd=True)
Wind5 = pack.sweptPolylines2gtsSurface([positionWind[4]], capStart=True, capEnd=True)
IDWind1 = O.bodies.append(pack.gtsSurface2Facets(Wind1, color=colorWind))
IDWind2 = O.bodies.append(pack.gtsSurface2Facets(Wind2, color=colorWind))
IDWind3 = O.bodies.append(pack.gtsSurface2Facets(Wind3, color=colorWind))
IDWind4 = O.bodies.append(pack.gtsSurface2Facets(Wind4, color=colorWind))
IDWind5 = O.bodies.append(pack.gtsSurface2Facets(Wind5, color=colorWind))
IDWind = [IDWind1, IDWind2, IDWind3, IDWind4, IDWind5]
WindList = IDWind1 + IDWind2 + IDWind3 + IDWind4 + IDWind5
return IDWind, WindList
IDWind, WindList = HydraulicSupport()
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
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
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, myGraviaty), damping=0.5, label='down'),
PyRunner(command="Relocation()", iterPeriod=200000),
]
The position loaded in the second script is not right. That seems the stored location is wrong.
Thank you very much.
--
You received this question notification because your team yade-users is
an answer contact for Yade.