Call different interpreter for Tcl in python -
i wish run tcl script different interpreter (opensees) python itself, similar this question, practical way? i've tried tkinter , subprocess routines far understand i'm running script in pure tcl , nothing happens (functions defined in opensees environment). i've tried calling tcl script via tkinter , can't life of me figure out how run tcl interpreter, i've tried is:
for-test.tcl
proc fractional_while {j float_increment upper_limit} { while {$j < $upper_limit} { set j [expr $j + $float_increment] } } puts "time took: [time {fractional_while 1 0.001 500} 1]"
python file
import tkinter r = tkinter.tk() r.eval('source {for-test.tcl}')
what want call opensees inside python , run following routine:
elastic-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 treated , assigned numberer plain # numbering schemes tied directly efficiency of numerical solvers system bandgeneral # defines matricial numerical solving method based on form of stiffness matrix test normdispincr 1e-5 10 0 integrator newmark $gamma $beta # defines integrator differential movement equation algorithm newton # solve nonlinear residual equation analysis transient # 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
it depends on how opensees built , options offers.
typically programs embed tcl have 2 main options how it, quite similar python.
variant 1 have normal c/c++ main program , link tcl library, in effect same thing tclsh
does, shell can execute tcl commands , providing commands statically.
variant 2 using normal tclsh
, loading extension modules add functionality. if case, can load package in tkinter
shell if similar enough, , done.
opensees seems program implements variant one, bigwish includes commands not available outside. cannot load code directly in tkinter
shell.
you have 3 options:
- use tcllib
comm
package communicate between tkinter , opensees shell (see running tcl code (on existing tcl shell) python example) - run opensees via
subprocess
, implement kind of communication protocol send commands. - hack @ opensees code build loadable package tcl , load tkinter process (might hard).
Comments
Post a Comment