Steven G. Johnson wrote:
On Mon, 4 Sep 2006, Andrea Locatelli wrote:
I have some problems to understand how to manipulate fields at each time step. For example, I'm doing a 2D TM simulation, and I want to make some processing on Ez in order to calculate the time-averaged |Ez|^2. I need to define an auxiliary variable, and at each time step I should add the calculated |Ez|^2 to this auxiliary variable, and finally I should output the result. I think I should use the (before-time T step-function) command, but I have many doubts on how to define the proper step function, and in particular how I can define and manipulate "field" variables. Do you have any examples on this topic?

You can get the value of the field just by calling get-field, as described in the manual. Here is a quick example (hopefully with no typos) of computing the average |Ez|^2 over 100 time units.

(define Ezsum 0)
(define (do-Ez-sum)
    (set! Ezsum (+ Ezsum (sqr (magnitude
        (get-field Ez (vector3 0 0 0)))))))

(run-until 100 do-Ez-sum)
(print "the mean |Ez|^2 at (0,0,0) = "
       (* Ezsum (/ (meep-fields-dt-get fields) 100))
       "\n")

Cordially,
Steven G. Johnson

Thank you for the useful hint... The script works well for a single point, but I'm wondering if it is possible to make the same operation on the whole field structure, i.e. I have at each time step the 2D Ez field, and it would be great if I could have at the end of the simulation the 2D time-averaged |Ez|^2

Andrea


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

Reply via email to