I haven't tested this, but something like this should work. The key is to
use global variables.

sim = ...
total_flux = ...
flux1 = 0
flux2 = 0

def output_power(sim):
    return mp.get_fluxes(total_flux)[0]

def flux1_step(sim):
    flux1 = output_power(sim)

def flux2_step(sim):
    flux2 = output_power(sim)

def ratio_test()
    return abs(flux2 / flux1 - 1) < 0.01

sim.run(mp.at_every(3, flux1_step), mp.at_every(5, flux2_step),
until=ratio_test)


On Fri, Mar 22, 2019 at 9:09 AM Karl-Johan Olofsson <karol...@student.liu.se>
wrote:

> Hello!
>
> I am attempting to implement a stopping criteria that compares the total
> flux at two different points in time, and when the difference between the
> total power radiated is small, I want to stop the simulation. I seem to be
> misunderstanding the programming aspect of it all, I attemped a very basic
> implementation this way:
>
>
> def output_power(sim):
>     return(mp.get_fluxes(flux_total))
>
> def ratio_test(Flux1,Flux2):
>     if abs(Flux2/Flux1-1)<0.01:
>         return True
>
>     else:
>         return False
>
> ..
>
> sim.run(flux1=mp.at_every(3,output_power),
> flux2=mp.at_every(5,output_power),
> until=ratio_test(flux1,flux2))
>
> -----
>
> But it clearly doesn't work. (It returns
> ValueError: Unrecognized keyword arguments: dict_keys(['flux1', 'flux2']))
>
> How would I go about to implement this. Or maybe you have some more
> sophisticated way to solve the stop condition for my simulation?
>
> Karl-Johan
>
>
>
>
> _______________________________________________
> meep-discuss mailing list
> meep-discuss@ab-initio.mit.edu
> http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss
_______________________________________________
meep-discuss mailing list
meep-discuss@ab-initio.mit.edu
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to