72. Nano-optics: A ring-resonator#
from ring_resonator_import import *
from ngsolve import *
from ngsolve.webgui import Draw
0: 00000001011111010111110
Draw (mesh);
scene = Draw (gfu.components[0], order=3, min=-0.05, max=0.05, autoscale=False)
from time import time
ts = time()
with TaskManager():
while t < tend:
w.data = -fullB.T * gfu.vec
### time envelope for the src ################################################################
if abs((t-tpeak)/tpeak) < 1:
t_envelope = (2*exp(1)/sqrt(math.pi))*sin(2*math.pi*fcen*t)*exp (-1/(1-((t-tpeak)/tpeak)**2))
else:
t_envelope = 0
w.data += t_envelope*Lsrc.vec
w.data -= sigma * dampingp * gfu.vec
w.data -= emb_p @ Bstab.mat.T * gfstab.vec
gfu.vec.data += tau * invp * w
w.data = fullB * gfu.vec
hvstab.data = Bstab.mat @ emb_p.T * gfu.vec
w.data -= sigma * dampingu * gfu.vec
gfu.vec.data += tau * invu * w
gfstab.vec.data += tau * Mstabinv * hvstab
t += tau
i += 1
if i%20 == 0:
scene.Redraw()
print ("total time", time()-ts)
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[3], line 31
27
28 t += tau
29 i += 1
30 if i%20 == 0:
---> 31 scene.Redraw()
32
33
34 print ("total time", time()-ts)
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/netgen/webgui.py:241, in WebGLScene.Redraw(self, *args, **kwargs)
239 self.args = new_scene.args
240 self.kwargs = new_scene.kwargs
--> 241 super().Redraw()
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/webgui_jupyter_widgets/widget.py:81, in BaseWebGuiScene.Redraw(self)
79 def Redraw(self):
80 self.encoding='binary'
---> 81 self.widget.value = self.GetData(set_minmax=False)
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/netgen/webgui.py:254, in WebGLScene.GetData(self, set_minmax)
252 for t in inspect.getmro(typ):
253 if t in _registered_draw_types:
--> 254 d = _registered_draw_types[t](self.obj, self.args, self.kwargs)
255 break
256 if d is None and hasattr(self.obj, "_webgui_data"):
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/ngsolve/webgui.py:163, in GetData(obj, args, kwargs)
161 if 'intpoints' not in kwargs:
162 kwargs['intpoints'] = None
--> 163 d = BuildRenderData(mesh, cf, order=kwargs['order'], draw_surf=kwargs['draw_surf'], draw_vol=kwargs['draw_vol'], intpoints=kwargs['intpoints'], deformation=kwargs['deformation'], regions=regions, objects=kwargs['objects'], nodal_p1=kwargs['nodal_p1'], settings=kwargs['settings'])
165 if isinstance(cf, ngs.GridFunction) and len(cf.vecs)>1:
166 # multidim gridfunction - generate data for each component
167 gf = ngs.GridFunction(cf.space)
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/ngsolve/webgui.py:494, in BuildRenderData(mesh, func, order, draw_surf, draw_vol, intpoints, deformation, regions, objects, nodal_p1, encoding, settings)
492 timer3list.Start()
493 for i in range(ndtrig):
--> 494 Bezier_points.append(encode(BezierPnts[i], dtype=np.float32))
495 timer3list.Stop()
497 if pmat2 is not None:
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/ngsolve/webgui.py:264, in BuildRenderData.<locals>.encode(*args, **kwargs)
263 def encode(*args, **kwargs):
--> 264 return encodeData(*args, **kwargs, encoding=encoding)
File /Applications/Netgen.app/Contents/Resources/lib/python3.14/site-packages/netgen/webgui.py:22, in encodeData(data, dtype, encoding)
20 values = np.array(data.flatten(), dtype=dtype)
21 if encoding=='b64':
---> 22 return b64encode(values).decode("ascii")
23 elif encoding=='binary':
24 return values.tobytes()
File /Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/base64.py:55, in b64encode(s, altchars)
48 def b64encode(s, altchars=None):
49 """Encode the bytes-like object s using Base64 and return a bytes object.
50
51 Optional altchars should be a byte string of length 2 which specifies an
52 alternative alphabet for the '+' and '/' characters. This allows an
53 application to e.g. generate url or filesystem safe Base64 strings.
54 """
---> 55 encoded = binascii.b2a_base64(s, newline=False)
56 if altchars is not None:
57 assert len(altchars) == 2, repr(altchars)
KeyboardInterrupt:
B. Kapidani, J. Schöberl: A matrix-free Discontinuous Galerkin method for the time dependent Maxwell equations in unbounded domains (https://arxiv.org/abs/2002.08733)