- DMC McStas simulation working
SKIPPED: psi/amorstat.c psi/nxamor.c psi/pimotor.c psi/polterwrite.c
This commit is contained in:
@ -13,6 +13,7 @@ if { [info exists vdmcinit] == 0 } {
|
||||
Publish storedmcdata User
|
||||
Publish rundmcsim User
|
||||
Publish copydmcdata User
|
||||
Publish sample User
|
||||
mcinstall
|
||||
}
|
||||
source $home/log.tcl
|
||||
@ -23,19 +24,85 @@ proc SplitReply { text } {
|
||||
set l [split $text =]
|
||||
return [lindex $l 1]
|
||||
}
|
||||
#---------------------------------------------------------------------
|
||||
# load a lazy pulverix file
|
||||
#---------------------------------------------------------------------
|
||||
proc washlazy {name} {
|
||||
global home
|
||||
set newNam [file rootname [file tail $name]]
|
||||
set in [open $name r]
|
||||
set out [open $home/$newNam.q w]
|
||||
#------- proceed to first header line
|
||||
while { [gets $in line] >= 0} {
|
||||
if { [string first "H K L THETA 2THETA D VALUE" $line] > 0} {
|
||||
break
|
||||
}
|
||||
}
|
||||
#------- process data lines
|
||||
puts $out "// mult Q(hkl) F2 DW w"
|
||||
while { [gets $in line] >= 0} {
|
||||
set num [scan $line "%d %d %d %f %f %f %f %f %d %d %d %f %f %f %f %f %d"\
|
||||
h k l th th2 d di sin h2 k2 l2 I F A B ang mul]
|
||||
if { $num == 17} {
|
||||
set q [expr (2.*3.14159265358979323846)/$d]
|
||||
set f2 [expr $F * $F]
|
||||
puts $out [format "%d %f %f 1 0" $mul $q $f2]
|
||||
}
|
||||
}
|
||||
close $in
|
||||
close $out
|
||||
}
|
||||
#----------------------------------------------------------------------
|
||||
# script for setting the sample. We only allow samples for which
|
||||
# there is a corresponing q data file
|
||||
#------------------------------------------------------------------------
|
||||
proc sample args {
|
||||
global home
|
||||
if { [llength $args] < 1} {
|
||||
set sa [SplitReply [sampleintern]]
|
||||
return "sample = $sa"
|
||||
}
|
||||
set txt [lindex $args 0]
|
||||
#-------- list
|
||||
if { [string compare $txt list] == 0} {
|
||||
set l [glob $home/*.q]
|
||||
foreach f $l {
|
||||
append out [file rootname [file tail $f]] "\n"
|
||||
}
|
||||
return $out
|
||||
}
|
||||
#--------- load
|
||||
if { [string compare $txt load] == 0} {
|
||||
if { [llength $args] < 2} {
|
||||
error "Need path to lazy pulverix output file to load"
|
||||
}
|
||||
set nam [lindex $args 1]
|
||||
washlazy $nam
|
||||
set nam2 [file rootname [file tail $nam]]
|
||||
eval sampleintern $nam2
|
||||
return OK
|
||||
}
|
||||
if { ![file exists $home/$txt.q] } {
|
||||
error "No Q data for sample $txt"
|
||||
} else {
|
||||
eval sampleintern $txt
|
||||
return OK
|
||||
}
|
||||
}
|
||||
#-----------------------------------------------------------------------
|
||||
# Scripts required for controlling McStas simulations
|
||||
#-----------------------------------------------------------------------
|
||||
proc rundmcsim {mode preset} {
|
||||
global home
|
||||
append command $home/dmc_sics01 " -f $home/dmc.xml --format=\"XML\""
|
||||
append command " -n 9e15 "
|
||||
append command $home/dmc_sics05 " -f $home/dmc.xml --format=\"XML\""
|
||||
append command " -n 1e10 "
|
||||
append command " lambda=[string trim [SplitReply [lambda]]]"
|
||||
append command " TKOFF=[string trim [SplitReply [TwoThetaM]]]"
|
||||
append command " samplefile=$home/[string trim [SplitReply [sample]]].q"
|
||||
append command " Det_start=[string trim [SplitReply [TwoThetaD]]]"
|
||||
append command " samplefile=$home/[string trim [SplitReply [sampleintern]]].q"
|
||||
append command " monfile=$home/monfile "
|
||||
append command " >& $home/dmc.log &"
|
||||
clientput "Starting McStas.. "
|
||||
# clientput $command
|
||||
set ret [catch {eval exec $command} msg]
|
||||
if {$ret != 0} {
|
||||
error $msg
|
||||
@ -44,23 +111,85 @@ proc rundmcsim {mode preset} {
|
||||
}
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
# Run the DMC simulation in an optimized mode with neutrons
|
||||
# precalculated for various wave length until the sample slit
|
||||
#------------------------------------------------------------------------
|
||||
set dmcdata(2.56) dmc256.dat
|
||||
set dmcdata(4.2) dmc420.dat
|
||||
set dmcdata(2.45) dmc245.dat
|
||||
set dmcdata(3.8) dmc380.dat
|
||||
#-------------------------------------------------------------------------
|
||||
proc rundmcoptsim {mode preset } {
|
||||
global home dmcdata
|
||||
#--------- locate closest precalculated neutron data file
|
||||
set lambda [SplitReply [lambda]]
|
||||
set myLambda $lambda
|
||||
set wv [array names dmcdata]
|
||||
set diff 999999.99
|
||||
set lambdafile $dmcdata(2.56)
|
||||
foreach w $wv {
|
||||
set tmp [expr abs($w - $lambda)]
|
||||
if { $tmp < $diff} {
|
||||
set diff $tmp
|
||||
set lambdafile $dmcdata($w)
|
||||
set myLambda $w
|
||||
}
|
||||
}
|
||||
#-------- build McStas command line
|
||||
append command $home/dmcafter " -f $home/dmc.xml --format=\"XML\""
|
||||
append command " -n 1e10 "
|
||||
append command " lambdafile=$home/$lambdafile"
|
||||
append command " Det_start=[string trim [SplitReply [TwoThetaD]]]"
|
||||
append command " samplefile=$home/[string trim [SplitReply [sampleintern]]].q"
|
||||
append command " monfile=$home/monfile "
|
||||
append command " repeat=1000000000 "
|
||||
append command " >& $home/dmc.log &"
|
||||
#--------- start McStas
|
||||
clientput "Starting McStas.. "
|
||||
clientput "Coercing $lambda to precalculated $myLambda"
|
||||
# clientput $command
|
||||
set ret [catch {eval exec $command} msg]
|
||||
if {$ret != 0} {
|
||||
error "ERROR: $msg"
|
||||
} else {
|
||||
return $msg
|
||||
}
|
||||
}
|
||||
#------------------------------------------------------------------------
|
||||
proc copydmcdata { } {
|
||||
global home
|
||||
set mcversion "McStas 1.8 - Mar. 05, 2004"
|
||||
washsimfile $home/dmc.xml
|
||||
mcreader open $home/dmc.xml
|
||||
mcreader insertmon \
|
||||
"/$mcversion/DMC_diff/dmc.xml/PSD_sample/PSD_sample.dat/values" \
|
||||
counter 1
|
||||
"/$mcversion/DMC_diff/dmc.xml/PSD_sample/values" \
|
||||
counter 1 [expr 1./10000]
|
||||
mcreader insertmon \
|
||||
"/$mcversion/DMC_diff/dmc.xml/Det9/det9.dat/values" \
|
||||
counter 5
|
||||
set hmScale [SplitReply [counter getmonitor 5]]
|
||||
if { $hmScale <= 0} {
|
||||
set hmScale 1e9
|
||||
} else {
|
||||
set hmScale [expr $hmScale * 1e9]
|
||||
}
|
||||
clientput "HM scale = $hmScale"
|
||||
mcreader inserthm \
|
||||
"/$mcversion/DMC_diff/dmc.xml/Det9/det9.dat/data" banana
|
||||
"/$mcversion/DMC_diff/dmc.xml/Det9/det9.dat/data" banana $hmScale
|
||||
mcreader close
|
||||
}
|
||||
#-------------------------------------------------------------------------
|
||||
proc dmcdump {pid} {
|
||||
#--do nothing: progress is doing it for us
|
||||
}
|
||||
#--------------------------------------------------------------------------
|
||||
mccontrol configure mcstart rundmcsim
|
||||
#mccontrol configure mcstart rundmcsim
|
||||
mccontrol configure mcstart rundmcoptsim
|
||||
mccontrol configure mccopydata copydmcdata
|
||||
mccontrol configure update 60
|
||||
mccontrol configure mcmonfile $home/monfile
|
||||
mccontrol configure monitorscale [expr 1. /10000]
|
||||
mccontrol configure mcdump mcstasdump
|
||||
#--------------------------------------------------------------------------
|
||||
# A count command for VDMC
|
||||
# All arguments are optional. The current values will be used if not
|
||||
|
Reference in New Issue
Block a user