File: sim.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (49 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- encoding=utf-8 -*-
# see https://yade-dem.org/doc/user.html#batch-execution-on-job-based-clusters-oar

readParamsFromTable(unknownOk=True, important=6, unimportant='foo', this=-1, notInTable='notInTable')
from yade.params import table

print(O.tags['description'])
print('important', table.important)
print('unimportant', table.unimportant)
print(O.tags['params'].replace(',', '_'))
print(O.tags['defaultParams'])
import time
import os
import re

# Stop script before walltime ends
m_hasWalltime = 'YADE_WALLTIME' in os.environ
m_Walltime = 0
m_WalltimeStopAt = 0.95

if m_hasWalltime:
	walltime = os.environ['YADE_WALLTIME']
	if re.search("^([0-9]+):([0-9]{2}):([0-9]{2})$", walltime):
		w = re.match("^([0-9]+):([0-9]{2}):([0-9]{2})$", walltime)
		g = w.groups()
		m_Walltime = 3600 * float(g[0]) + 60 * float(g[1]) + float(g[2])
		print("Will run for %i seconds" % m_Walltime)
	else:
		print("Wrong walltime format.")
		m_hasWalltime = False


def SaveAndQuit():
	print("Quit due to walltime expiration")
	O.stopAtIter = O.iter + 1


#time.sleep(5)
O.engines = [PyRunner(command='time.sleep(.005)', iterPeriod=1)]

if m_hasWalltime:
	O.engines += [PyRunner(command='SaveAndQuit()', realPeriod=m_Walltime * m_WalltimeStopAt)]

O.run(1000, True)
print('finished')
import sys

sys.stdout.flush()
sys.exit(0)