Accumulation effect of heat over time steps
Dear all,
I am trying to simulate the heat generation at the contacts of all interacting spheres over time steps.
Considering generated heat at each time step can accumulate on the contact through time, how can I calculate the total generated heat within total time?
For example, at t1=0.05s, I can obtain the total heat of each sphere (H1) from the last time step, and after a time step (5e-6s) where t2=0.050005, I can again obtain the total heat of each sphere (H2) from last time step.
So my question is how to calculate the accumulative heat of each sphere over time step?
Here's the code I use for calculating the total generated heat of the sphere from the last time step:
###
def get_totalHeat():
list_
for a in range(2,
totalHeat = 0
for i in O.bodies[
if i.isReal:
return list_totalHeat
###
How to modify if I want to involve the accumulation effect of heat by time step?
Thanks!
Cheers,
Chien-Cheng
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Yade Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Jan Stránský
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
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.
self.
def collect(self):
"""Collect data from simulation"""
# acumulate cumulative data
for k,v in self.currentDat
# compute new current data
self.
def getDataFromOneP
b = O.bodies[a]
ret = 0
for i in b.intrs():
if not i.isReal: continue
ret += i.geom.
return ret
def pprint(self):
print()
print(
print(
for k,v in self.currentDat
print(k,v)
print(
print(
for k,v in self.cumulative
print(k,v)
O.engines = [
ForceResetter(),
InsertionSor
InteractionLoop(
[
[
[
),
NewtonIntegr
PyRunner(
PyRunner(
]
s1,s2,s3 = (
sphere(
sphere(
sphere(
)
O.bodies.
# currently needs to be after bodies are created, could be adjusted..
someCalculator = SomeCalculator()
O.dt = 0.003
O.run(10,True)
###
cheers
Jan
Revision history for this message
|
#2 |
Hi Jan,
Thanks for your code and prompt reply! It works well.
So if I want to export these accumulate values and visualize in the Paraview, what could I do?
I would be grateful if you could provide me more instructions.
Cheers,
Chien-Cheng
Revision history for this message
|
#3 |
Updated MWE:
### assuming Python3, Python2 can be adjusted
from __future__ import print_function
from yade import export
class SomeCalculator:
def __init__(self):
self.
self.
def collect(self):
"""Collect data from simulation"""
# acumulate cumulative data
for k,v in self.currentDat
# compute new current data
self.
def getDataFromOneP
b = O.bodies[a]
ret = 0
for i in b.intrs():
if not i.isReal: continue
ret += i.geom.
return ret
def pprint(self):
print()
print(
print(
for k,v in self.currentDat
print(k,v)
print(
print(
for k,v in self.cumulative
print(k,v)
def getCurrent(self,b):
return self.currentDat
def getCumulative(
return self.cumulative
O.engines = [
ForceResetter(),
InsertionSor
InteractionLoop(
[
[
[
),
NewtonIntegr
PyRunner(
PyRunner(
PyRunner(
]
s1,s2,s3 = (
sphere(
sphere(
sphere(
)
O.bodies.
vtk = export.
def vtkExport():
vtk.
# currently needs to be after bodies are created, could be adjusted..
someCalculator = SomeCalculator()
import builtins
builtins.
O.dt = 0.003
O.run(10,True)
###
cheers
Jan
Revision history for this message
|
#4 |
Hi Jan,
Many thanks again!
This time I got some errors as below. The cumulative data can still be printed out but the exported vtk file cannot be opened in the Paraview.
-------
KeyError Traceback (most recent call last)
/home/hung/
/home/hung/
223 vtk = export.
224 def vtkExport():
--> 225 vtk.exportSpher
226
227 import builtins
/home/hung/
427 # write additional data from 'what' param
428 for name,command in what.items(): # for each name...
--> 429 test = eval(command) # ... eval one example to see what type (float, Vector3, Matrix3) the result is ...
430 # ... and write appropriate header line and loop over all bodies and write appropriate vtk line(s)
431 if isinstance(
/home/hung/
/home/hung/
127 return self.currentDat
128 def getCumulative(
--> 129 return self.cumulative
130
131
KeyError: 1666
-------
Do you have any ideas about this?
Cheers,
Chien-Cheng
Revision history for this message
|
#5 |
> the exported vtk file cannot be opened in the Paraview.
because of the errors, no output is generated
> Do you have any ideas about this?
you try to access data, which are not present, a complete script would be needed to answer why..
cheers
Jan
Revision history for this message
|
#6 |
Dear Jan,
I simplified my script and hope that you could have a look.
#######
from __future__ import print_function
import builtins
from yade import pack,plot,export
import numpy as np
import math
sp1=pack.
sp2=pack.
sp3=pack.
O.periodic=True
# dimensions of sample
RADIUS=0.025
a=15
b=1
c=1
length=a*(2*RADIUS)
height=length/b
width=length/c
thickness=RADIUS
psdSizes=
psdCumm=[0,0.5,1]
# friction angles
wallFRIC=0
spFRIC=26.6
# boundary conditions
PI=1.e5
SN=5.e6
RATE_shear=1
# simulation control
DAMPSHEAR=0.
O.cell.
O.materials.
O.materials.
upBox = utils.box(
lowBox = utils.box(
O.bodies.
sp1.makeCloud(
sp2.makeCloud(
sp3.makeCloud(
sphere_id = O.bodies.
bottomLayer_id = O.bodies.
topLayer_id = O.bodies.
effCellVol=
volRatio=
class SomeCalculator:
def __init__(self):
def collect(self):
"""Collect data from simulation"""
# acumulate cumulative data
for key,valve in self.currentDat
# compute new current data
def getDataFromOneP
b = O.bodies[a]
totalHeat = 0
for i in b.intrs():
if not i.isReal: continue
radius1 = i.geom.refR1
radius2 = i.geom.refR2
return totalHeat
def pprint(self):
print()
for key,valve in self.currentDat
for key,valve in self.cumulative
def getCurrent(self,b):
return self.currentDat
def getCumulative(
return self.cumulative
O.engines=[
ForceResetter()
,InsertionSort
,InteractionLoop(
[Ig2_
[Ip2_
[Law2_
)
,GlobalStiffne
,PeriTriaxCont
,NewtonIntegra
,PyRunner(
,PyRunner(
,PyRunner(
,PyRunner(
]
someCalculator = SomeCalculator()
def triaxDone():
triax.dead=True
O.pause()
vtk = export.
def vtkExport():
vtk.
builtins.
O.run(1000000,1)
O.step()
#### Applying normal stress
stage=0
stiff=fnPlaten=
def servo():
global stage,stiff,
if stage==0:
currentSN=
unbF=
boundaryVel=
O.bodies[
if ( (abs(currentSN-
stage+=1
fnPlaten=
print ('Normal stress =',currentSN,' | unbF=',unbF)
for i in O.interactions.
stiff+
print ('DONE! iter=',O.iter)
O.pause()
if stage==1:
fnDesired=
boundaryVel=
O.bodies[
O.engines = O.engines[
O.run(1000000,1)
vtkExp.dead=False
collect.dead=False
pprint.dead=False
newton.
fixVel.dead = False
def fixVelocity(
O.bodies[
topLayer_id = identify_topLayer()
for i in topLayer_id:
O.run(100,1)
###
Thank you for taking your time!
Cheers,
Chien-Cheng
Revision history for this message
|
#7 |
> I simplified my script
> O.run(1000000,1)
thanks, but is it possible to make it run shorter to demonstrate the error?
thanks
Jan
Revision history for this message
|
#8 |
>is it possible to make it run shorter to demonstrate the error?
Yes, I also adjusted other parameters to make it run shorter to display the error.
I sent the modified script to you by email to avoid making the layout here too messy.
Hope you don't mind.
thanks!
Chien-Cheng
Revision history for this message
|
#9 |
Thanks for more details
> self.cumulativeData = dict((a,0) for a in range(2,10))
here you tell that you only want to store bodies with ids in range(2,10)...
> vtk.exportSpher
... but exportSpheres exports all spheres by default, resulting in the error
You can (depending on your needs):
a) limit the export to the range:
vtk.exportSpher
b) return some artificial value for not-stored bodies:
class SomeCalculator:
...
def getCurrent(self,b): # the same modification for getCumulative
return self.currentDat
cheers
Jan
Revision history for this message
|
#12 |
Dear Jan,
Sorry that I still have one more question...
If I would like to further use the cumulative data to calculate other parameters, such as temperature, how can I adjust the "singleton" class to print out the temperature?
thanks for your help again!
Chien-Cheng
Revision history for this message
|
#13 |
to compute temperature, probably some loop inside collect method:
###
def __init__(self):
...
self.
...
def collect(self):
def computeTemperat
for k,cur in self.currentDat
cum = self.cumulative
temerature = ... # some computation here
###
to print, just print it then :-)
###
def pprint(self):
...
for key,valve in self.temperatur
###
What I have created was just to show the idea of the approach, according to your specific needs, you can modify it to look completely different :-)
Also if the computation takes too long with Python, it is possible to create a C++ engine. But it is a nice feature that you can play easily with Python beforehand :-)
cheers
Jan
Revision history for this message
|
#14 |
Hi Jan,
Thanks again for your reply and suggestion.
I am still learning programming with Python and am also a beginner in Yade. I am really thankful for these codes which save me plenty of time and allow me to learn faster. I will try to modify it with my own needs after getting more familiar with the details.
I tried your code but it turned out the cumulative and temperature cannot be printed out...
###
class SomeCalculator:
def __init__(self):
def collect(self):
for key,value in self.currentHea
def getHeatFromOneP
b = O.bodies[a]
totalHeat = 0
for i in b.intrs():
if not i.isReal: continue
radius1 = i.geom.refR1
radius2 = i.geom.refR2
return totalHeat
def computeTemperat
density = 2500 # [kg/m3]
for key,cur in self.currentHea
cum = self.cumulative
for a in range(2,10):
b = O.bodies[a]
def pprint(self):
print()
for key,value in self.currentHea
for key,value in self.cumulative
for key,valve in self.temperatur
###
Is there something wrong with my code?
Cheers,
Chien-Cheng
Revision history for this message
|
#15 |
Hello,
I have tried your code (put SomeClass in the script you have sent me) and the temperature was printed in terminal without problem..
> vtk.exportSpher
it was not saved to vtk, because of the error
AttributeError: 'SomeCalculator' object has no attribute 'getCurrent'
If it behaves differently on your side, please provide more info
cheers
Jan
Revision history for this message
|
#16 |
Hi Jan,
My mistake... the iterPeriod value I input for "someCalculator
That explains the reason why I saw the zero value in cumulative data and temperature.
Cheers,
Chien-Cheng
Revision history for this message
|
#17 |
Thanks Jan Stránský, that solved my question.