← Back to team overview

yade-users team mailing list archive

Re: [Question #689919]: Accumulation effect of heat over time steps

 

Question #689919 on Yade changed:
https://answers.launchpad.net/yade/+question/689919

    Status: Open => Answered

Jan Stránský proposed the following answer:
Updated MWE:
### assuming Python3, Python2 can be adjusted
from __future__ import print_function
from yade import export

class SomeCalculator:
   def __init__(self):
      self.cumulativeData = dict((a,0) for a in range(0,3))
      self.currentData = dict(self.cumulativeData)
   def collect(self):
      """Collect data from simulation"""
      # acumulate cumulative data
      for k,v in self.currentData.items():
         self.cumulativeData[k] += v
      # compute new current data
      self.currentData = dict((a,self.getDataFromOneParticle(a)) for a in range(0,3))
   def getDataFromOneParticle(self,a):
      b = O.bodies[a]
      ret = 0
      for i in b.intrs():
         if not i.isReal: continue
         ret += i.geom.penetrationDepth
      return ret
   def pprint(self):
      print()
      print("current step")
      print("============")
      for k,v in self.currentData.items():
         print(k,v)
      print("cumulative")
      print("==========")
      for k,v in self.cumulativeData.items():
         print(k,v)
   def getCurrent(self,b):
      return self.currentData[b.id]
   def getCumulative(self,b):
      return self.cumulativeData[b.id]


O.engines = [
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb()]),
   InteractionLoop(
      [Ig2_Sphere_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()],
   ),
   NewtonIntegrator(),
   PyRunner(iterPeriod=1,command="someCalculator.collect()"),
   PyRunner(iterPeriod=1,command="someCalculator.pprint()"),
   PyRunner(iterPeriod=1,command="vtkExport()"),
]

s1,s2,s3 = (
   sphere((0,0,0),1),
   sphere((1,0,0),1),
   sphere((1,1,0),1),
)
O.bodies.append((s1,s2,s3))

vtk = export.VTKExporter("someData")
def vtkExport():
   vtk.exportSpheres(what=dict(current="someCalculator.getCurrent(b)",cumulative="someCalculator.getCumulative(b)"))

# currently needs to be after bodies are created, could be adjusted..
someCalculator = SomeCalculator()
import builtins
builtins.someCalculator = someCalculator # such that VTKExporter has acces to it

O.dt = 0.003
O.run(10,True)
###

cheers
Jan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.