Error when defining units
Hi everyone. I am encountering errors related to unit definitions. Details of my setup/script/mesh/errors below.
Setup: I am running FM through a docker container on a Windows 10 machine. Docker version 20.10.6.
Script: PointSource_UnitIssue.tcl
package require FullMonte
# Set the path and file name of the mesh
set fn "/sims/210711/Mesh_Sphere20mm_PointSource.out.vtk"
# Define the type of reader you need for your mesh file
VTKMeshReader MeshR
MeshR filename $fn
#Read the data from the file and load it into FullMonte
MeshR read
# 'MeshR mesh' converts the data into a usable format for FullMonte and stores it into a variable for later access
set M [MeshR mesh]
# Optional: You can specify the unit dimension of the material properties to ensure that all units are consistent within the simulation
# Valid options are "mm", "cm", "m"
#$M unitDimension "mm"
# Define a material set
MaterialSet MS
# Define a material and specifiy its optical properties (scattering coefficient, absorption coefficient
# refractive index, and anisotropy)
Material air
air scatteringCoeff 0
air absorptionCoeff 0
air refractiveIndex 1.0
air anisotropy 0.0
# Optional: You can specify the unit dimension of the material properties to ensure that all units are consistent within the simulation
# Valid options are "mm", "cm", "m"
#air unitDimension "mm"
# Define next material and specifiy its optical properties (scattering coefficient, absorption coefficient
# refractive index, and anisotropy)
Material tissue
# 'scatteringCoeff' is the method that is called. The number after the method is the scattering coefficient
# value of the respective material
tissue scatteringCoeff 10
tissue absorptionCoeff 0.01
tissue refractiveIndex 1.33
tissue anisotropy 0.9
# Optional: You can specify the unit dimension of the material properties to ensure that all units are consistent within the simulation
# Valid options are "mm", "cm", "m"
#tissue unitDimension "mm"
# Now insert the previously defined materials into the material set. It is important to define an exterior medium,
# otherwise you will receive an error during runtime
MS exterior air
# You can append as many materials as you like. Keep in mind, that you should not insert a material twice
# The first material you append will apply to region #0 in the mesh, the second material appended will
# apply to region #1 in the mesh and so on.
MS append tissue
Point P1
P1 position "0.0 0.0 0.0"
# If you define one source and do not insert several sources in a Composite source type, you can ignore the
# power method since it defaults to 1
#P1 power 1.0
TetraInternalKernel k
# Define the number of photons to be launched in the kernel.
# higher number--> better accuracy--> longer execution time
k packetCount 1000000
# Specify if the simulated photon packets should represent energy (J) or power (W)
# Valid options are "W", "Watt", "J", "Joule"
# This feature is optional
#k is_Energy_or_Power "Joule"
# Specify the energy/power value that the simulated photon packets represent
# This feature only works, when you also specify the unit
k energyPowerValue 1000.0
# P1 from 'Creating a Source'; the source to launch from
k source P1
# $M from 'Loading the Mesh'; the mesh of the simulation target
k geometry $M
# MS from 'Creating a MaterialSet'; the materials within the mesh
k materials MS
############ Monte Carlo kernel properties########################################################
# These values are standard and it is very unlikely that they need to be changed.
# If you do not plan on changing the values below, you do not have to include them in the TCL file
k roulettePrWin 0.1
k rouletteWMin 1e-4
k maxSteps 10000
k maxHits 10000
k randSeed 1
##################################################################################################
# Run kernel and wait until simulation completes
k runSync
# Get results from kernel
set OutData [k results]
# Convert energy absorbed per volume element to volume average fluence
EnergyToFluence E2F
# Provide the conversion with the mesh, materials, and packet simulation count
E2F kernel k
# IMPORTANT: input[...] and output[...] have to be executed prior to the source command
# Define the type of the input data
# Options: "inputPhotonWeight" "inputEnergy" "inputFluence" "inputEnergyPerVolume"
E2F inputPhotonWeight
# Define the target conversion output data
# Options: "outputPhotonWeight" "outputEnergy" "outputFluence" "outputEnergyPerVolume"
E2F outputFluence
# Set the source data which should be converted. (Option 1)
# Options: "VolumeEnergy", "SurfaceExitEnergy", "DirectedSurfaceEnergy"
# You can convert the energy per volume (tetra) to an average fluence over the tetras faces,
# or you can convert the energy exiting the mesh (exterior surface) to a fluence over the
# faces forming the mesh exterior boundary.
E2F data [$OutData getByName "VolumeEnergy"]
# We can also use a slightly different syntax to get fluence on interior surfaces (Option 2).
# The option below computes fluence on the internal surface scored by TetraInternalKernel
# Options: "DirectedSurface"
#E2F data [$OutData getByType "DirectedSurface"]
# Start conversion
E2F update
# Write the mesh with fluence appended
VTKMeshWriter MeshW
MeshW filename "/sims/210711/Fluence.out.vtk"
MeshW addData "Fluence" [E2F result]
MeshW mesh $M
MeshW write
Mesh: I am using a simple model (point source in a 20 mm diameter sphere). Mesh_Sphere20mm_PointSource.out.vtk
Error: I receive the following error when I call the 'is_Energy_or_Power' method (line 70) when defining the kernel:
Running in docker container.
AVX2 support detected
[warning] vtkFullMonteMeshFromUnstructuredGrid: Could not find specified region label field 'Tissue Type', using default field 'Region' instead
[info] Building faces with 10002 points and 55737 tetrahedrons
[info] Done (112892 faces, 2838 on the surface)
Invalid method. Must be one of: configure cget -acquire -disown -delete eventScorer conservationScorer volumeScorer surfaceScorer directedSurfaceScorer parentPrepare
while executing
"k is_Energy_or_Power "Joule""
(file "PointSource_UnitIssue.tcl" line 70)
If I comment out the 'is_Energy_or_Power' method, I receive the following error due to the dimension unit mismatch between the energy unit and the mesh:
Running in docker container.
AVX2 support detected
[warning] vtkFullMonteMeshFromUnstructuredGrid: Could not find specified region label field 'Tissue Type', using default field 'Region' instead
[info] Building faces with 10002 points and 55737 tetrahedrons
[info] Done (112892 faces, 2838 on the surface)
terminate called after throwing an instance of 'std::logic_error'
what(): Kernel::runSync called while the dimension unit is defined but the energy unit is set to 'NONE'.
rlwrap: warning: tclsh crashed, killed by SIGABRT.
rlwrap itself has not crashed, but for transparency,
it will now kill itself (without dumping core) with the same signal
warnings can be silenced by the --no-warnings (-n) option
/usr/local/FullMonteSW/bin/tclmonte.sh: line 23: 1158 Aborted env LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/VTK-7.1.1/lib:/usr/local/FullMonteSW$AVX/lib:/usr/local/boost-1.58.0/lib TCLLIBPATH=/usr/local/FullMonteSW$AVX/lib/tcl rlwrap /usr/bin/tclsh $*
I can get the program to run if I comment out the mesh unit definitions (lines 15, 30, 43), but the results only matched the expected values from the analytical solution of a point source if I define the input through the 'energyPowerValue' method (line 73) in the kernel. Changing the input to the power method (line 60) under the point source definition did not have an effect on the output.
I think I am misunderstanding the method definitions or how to properly define the input energy. Is it when I am defining the source, or during the kernel setup? In the tutorial's source definition, there is a comment on the power method that it will default to 1 if we only define one source. Is the power method a ratio of the input power that will be emitted by each source? Can someone help clarify - thanks!
Last note - the TCL command wiki mentions that the 'energyPowerValue' method is only active if the units are specified. It seems that it is still active even after I comment out any unit definitions. It was the only way I could modify the input and get the expected results in the output. Am I misunderstanding?