← 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:
Hello,

among many possible approaches, you can create a "singleton" class to do
the work (computing values for one step and collecting cumulative data),
something like below (example just store penetrationDepth, but the
approach should be clear):

###
from __future__ import print_function

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)

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()"),
]

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

# currently needs to be after bodies are created, could be adjusted..
someCalculator = SomeCalculator()

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.