On Fri, 12 Jan 2007, Huazhong Wang wrote:
i want to take out the Ex at point (0 0 0) after running. my code is below:

...
(define (myfun Ex) (get-field-point Ex (vector3 0 0 0)))
...
(run-util 100
(at-end (output-field-function "Ex" (list Ex) myfun))
)
...

but meep stops running, its response is: Error: wrong number of arguments to #<procedure myfun(Ex)>

i am confued here. who can tell me why?

You have many, many errors in this code, I'm afraid. I hardly know where to begin.

First, as explained in the manual, the function (myfun) you pass to output-field-function must take as its first argument the position vector r. The subsequent arguments are then the field components that you requested (here, Ex). So, for example, a valid function would be say:

        (define (myfun r ex) ex)

which just returns the value of ex, ignoring the position argument.

Second, your function myfun is called at every point in the volume and is *passed* the value of the field. There is no need to call get-field-point, and in fact calling get-field-point inside your field function will deadlock on a parallel machine.

Third, in your "myfun" function you took a parameter named "Ex". Even if this were correct, which it isn't as I explained above, it would mean that "Ex" inside that function would be the *value* of the Ex field at each point. Then, even if calling get-field-point were correct (which it isn't as I explained above), you would be passing the *value* of the Ex field as the first argument, and not the symbolic name "Ex" for the component, causing get-field-point to fail.

Fourth, by passing (output-field-function ...) to run-until, you are passing the *result* of *calling* the function, and not the function itself. This means that you are actually calling output-field-function *before* starting your run-until. What you want to do is to pass a *function* to run-until, which *calls* output-field-function, so that this function can be called on each time step, or in this case at the end of the simultation. See also my previous message to the mailing list where I explained this point.

Fifth, if you only want to output the field at a *single* point (0,0,0), then you need to do one of two things. (By default, output-field-function, like all the output functions, outputs the value of calling your function for every point in the computational cell.) You can either:

   1) use (in-volume (volume (size 0 0 0) (center 0 0 0)) ......)
      as another poster suggested.  This will output an HDF5
      file with a dataset consisting of a single point.

      (if you are outputting this data at lots of time-steps, not
       just at the end, you might also want to use to-appended
       to create a single HDF5 file with a 1d dataset with
       that point as a function of time, rather than a whole
       bunch of individual single-point HDF5 files)

or

   2) don't use HDF5 files at all, which are overkill for outputting
      a single point.  Just use the "print" function to output
      directl to standard output.  For example:
        (define (myoutput)
            (print "myoutput:, " (meep-time) ", "
                (get-field-point Ex (vector3 0 0 0)) "\n"))
      And then do
        (run-until 200 my-output)
      or whatever you want.    Note that in this case you *do*
      just want to call get-field-output directly.

Steven

_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to