help debugging function
- From: "Eric Lavigne" <lavigne.eric@xxxxxxxxx>
- Date: 23 Apr 2005 19:23:38 -0700
I am having trouble debugging a function. I have included the function
and the beginning of the backtrace. The complete source code is
available on my website: plaza.ufl.edu/lavigne/ and is called
"Diffusion Code 3." I am using clisp and slime (LispBox) on windows xp.
Backtrace line 5 shows that
(NODE-FLUX (AREF RESULT-FLUX I J (1- K)))
was evaluated before
(NODE-FLUX (AREF RESULT-FLUX I J (1+ K)))
but that the latter was the first to cause an error. This suggests that
(i,j,k-1) has a value but (i,j,k+1) does not. Both of these have fewer
odd indices than (i,j,k) and therefore should have been set earlier
(see the dotimes... n... in the function).
SYSTEM::%STRUCTURE-REF: NIL is not a structure of type NODE
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Abort handling SLIME request.
Backtrace:
0: frame binding variables (~ = dynamically):
| ~ SYSTEM::*FASOUTPUT-STREAM* <--> NIL
1: EVAL frame for form (SYSTEM::%STRUCTURE-REF 'NODE SYSTEM::OBJECT
2)
2: EVAL frame for form (THE T (SYSTEM::%STRUCTURE-REF 'NODE
SYSTEM::OBJECT 2))
3: APPLY frame for call (NODE-FLUX 'NIL)
4: EVAL frame for form (NODE-FLUX (AREF RESULT-FLUX I J (1+ K)))
5: EVAL frame for form (+ (NODE-FLUX (AREF RESULT-FLUX I J (1- K)))
(NODE-FLUX (AREF RESULT-FLUX I J (1+ K))))
6: EVAL frame for form (* (MATERIAL-V-SIGMA-F MATERIAL) (/ CRIT) 0.5
(+ (NODE-FLUX (AREF RESULT-FLUX I J (1- K))) (NODE-FLUX (AREF
RESULT-FLUX I J (1+ K)))))
....
(defun expand-flux-3d (flux dx material-selector crit)
; let result-flux be an array that is twice as long
; in each direction as flux
(let ((result-flux
(make-array
(mapcar
#'(lambda (x) (* 2 x))
(array-dimensions flux)))))
; fill in the gaps based on a 1-D estimate
; start with nodes that have the fewest
; odd indices to guarantee that there
; will be enough flux information
; in nearby nodes
; n is the number of odd indices, 4 possibilities starting with 0
(dotimes (n 4)
(dotimes (i (array-dimension flux 0))
(dotimes (j (array-dimension flux 1))
(dotimes (k (array-dimension flux 2))
(when (eql n (number-odd i j k))
(let ((material (funcall material-selector i j k)))
(setf
(aref result-flux i j k)
(make-node
:material material
:flux
(cond
((oddp i) (phi-1d
(aref result-flux (1+ i) j k)
(aref result-flux (1- i) j k)
(* (material-v-sigma-f material)
(/ crit) 0.5
(+ (node-flux
(aref result-flux (1+ i) j k))
(node-flux
(aref result-flux (1- i) j k))))
dx
material))
((oddp j) (phi-1d
(aref result-flux i (1+ j) k)
(aref result-flux i (1- j) k)
(* (material-v-sigma-f material)
(/ crit) 0.5
(+ (node-flux
(aref result-flux i (1+ j) k))
(node-flux
(aref result-flux i (1- j) k))))
dx
material))
((oddp k) (phi-1d
(aref result-flux i j (1+ k))
(aref result-flux i j (1- k))
(* (material-v-sigma-f material)
(/ crit) 0.5
(+ (node-flux
(aref result-flux i j (1- k)))
(node-flux
(aref result-flux i j (1+ k)))))
dx
material))
; no odd indices? that's the easy case
; just copy the value from flux
(t (node-flux
(aref flux (/ i 2) (/ j 2) (/ k 2)))))))))))))
result-flux))
The input "flux" was an array of nodes.
The input I used at the terminal was...
(setf my-material (make-material :D .9 :v-sigma-f .07 :sigma-a .066))
(setf flux (make-array '(20 20 20)))
(dotimes (i (array-dimension flux 0))
(dotimes (j (array-dimension flux 1))
(dotimes (k (array-dimension flux 2))
(setf (aref flux i j k)
(make-node :flux 1 :material my-material)))))
(expand-flux-3d flux .2 #'simple-material-selector .1)
.
- Follow-Ups:
- Re: help debugging function
- From: Alan Crowe
- Re: help debugging function
- Prev by Date: Lisp is dead and smells like fish
- Next by Date: Re: newbie: m-expressions
- Previous by thread: Lisp is dead and smells like fish
- Next by thread: Re: help debugging function
- Index(es):