Я хочу запустить скрипт Tcl с другим интерпретатором (OpenSees) из самого python, аналогично this question, что было бы самым практичным способом? Я пробовал процедуры tkinter и подпроцессы, но насколько я понимаю, я запускаю скрипт в чистом Tcl, и ничего не происходит (функции определены в среде OpenSees). Я попытался назвать мой сценарий Tcl через Tkinter и, но я не могу за жизнь мне понять, как запустить Tcl с другим переводчиком, что я попытался это:Вызов другого интерпретатора для Tcl в python
для-test.tcl
proc fractional_while {j float_increment upper_limit} {
while {$j < $upper_limit} {
set j [expr $j + $float_increment]
}
}
puts "time it took: [time {fractional_while 1 0.001 500} 1]"
питон файл
import tkinter
r = tkinter.Tk()
r.eval('source {for-test.tcl}')
То, что я хочу сделать, это Opensees вызов внутри питона и выполните следующую рутина:
упруго-1dof-spectrum.tcl
model BasicBuilder -ndm 2 -ndf 3
set time_zero [clock clicks -millisec]
set node_restraint 1
set node_spring 2
...
set load_dir $x_direction
set x_mass 1
set elastic_modulus 2e6
set rotation_z 6
node $node_restraint 0 0 -mass 0 0 0
node $node_spring 0 0 -mass 0 0 0
fix $node_restraint 1 1 1
equalDOF $master_node $slave_node 1 2
geomTransf Linear $transf_tag
uniaxialMaterial Elastic $linear_elastic_mat_tag $elastic_modulus
element zeroLength 0 $node_restraint $node_spring -mat $linear_elastic_mat_tag -dir $rotation_z
set accel_series "Path -filePath acelerograma_85_ii.191 -dt $ground_motion_time_step -factor 1"
pattern UniformExcitation $load_tag $load_dir -accel $accel_series
set oscillator_length 1
set node_mass 3
set counter 1
while {$oscillator_length < 1000} {
set oscillator_length [expr $counter*0.1]
set node_mass [expr $counter + 2]
node $node_mass 0 $oscillator_length
mass $node_mass $x_mass 0 0
element elasticBeamColumn $node_mass $node_spring $node_mass $area_column $elastic_modulus $inertia_column $transf_tag
set eigenvalue [eigen -fullGenLapack 1]
set period [expr 2*$pi/sqrt($eigenvalue)]
recorder EnvelopeNode -file results/acceleration-envelope-period-$period.out -time -node $node_mass -dof $x_direction accel
...
rayleigh [expr 2*$damping_ratio*$x_mass*$eigenvalue] 0 0 0
constraints Transformation
# determines how dof constraits are treated and assigned
numberer Plain
# numbering schemes are tied directly to the efficiency of numerical solvers
system BandGeneral
# defines the matricial numerical solving method based on the form of the stiffness matrix
test NormDispIncr 1e-5 10 0
integrator Newmark $gamma $beta
# defines the integrator for the differential movement equation
algorithm Newton
# solve nonlinear residual equation
analysis Transient
# for uniform timesteps in excitations
analyze [expr int($duration_motion/$time_step)] $time_step
incr counter
}
puts stderr "[expr {([clock clicks -millisec]-$time_zero)/1000.}] sec" ;# RS
wipe
Я не могу работать, что это ваш спрашивать здесь, что вам нужно сделать это гораздо яснее, как к тому, что вы пытаетесь сделать, и включать в себя минимальный код, показывает, что вы уже пробовали. – Jackson
@Jackson Я отредактировал свой ответ соответственно. – Vyraj
Один подсказку 'brace your expr'. Может быть гораздо быстрее написать '[expr {$ counter + 2}]' вместо '[expr $ counter + 2]', поскольку выражение может быть байтовым скомпилировано и не перерисовывается каждый раз. Это также намного безопаснее. – schlenk