Preisach Interactive
Download this Jupyter File
Interactive Scalar Preisach Model¶
In [1]:
import cempy as cp
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact
import ipywidgets as widgets
from myPackage import plotSPTriag
%matplotlib widget
ev = cp.preisachScalar.Everett_Lorentzian(401, 1640, 1.5)
p = cp.preisachScalar.preisach(ev)
In [2]:
def draw(axs):
axs[0].clear()
axs[0].set_ylim([-ev.maxB*1.1, ev.maxB*1.1])
axs[0].set_xlim([-ev.maxH*1.1, ev.maxH*1.1])
axs[0].set_ylabel("B in T")
axs[0].set_xlabel("H in A/m")
axs[0].plot(hi, bi)
axs[0].plot(hi[-1], bi[-1], '.')
axs[0].grid()
axs[1].clear()
plotSPTriag(p, ax=axs[1], fig=fig)
def update(val):
val_i = np.linspace(hi[-1], val, int(abs(hi[-1]-val)/2+1))
if len(val_i) == 0:
return
[hi.append(val) for val in val_i]
[bi.append(p.addH(val)) for val in val_i]
draw(axs)
def demagnetise(b=None):
hi.clear()
bi.clear()
hi.append(0)
bi.append(0)
sliderInput.value=0
p.demagnetise()
draw(axs)
def resetEv(val):
p.E = cp.preisachScalar.Everett_Lorentzian(val, 1640, 1.5)
draw(axs)
hi = []
bi = []
button = widgets.Button(description="Demagnetise")
textBoxEV = widgets.BoundedIntText( value=401, min=11, max=501, step=10, description="N_EV", disabled=False)
sliderInput = widgets.FloatSlider(min=-ev.maxH, max=ev.maxH, step=1, value=0, description="Input Value")
comboDiscEV = widgets.Combobox(value='adaptive',placeholder='Choose One',options=['adaptive', 'linear', 'sincos', 'poly'],description='discretisation of Ev:',ensure_option=True,disabled=False)
fig, axs = plt.subplots(1, 2, figsize=(10, 5))
demagnetise()
update(100)
update(-100)
update(200)
interact(update, val=sliderInput)
interact(resetEv, val=textBoxEV)
#interact(button_func, val=widgets.Button())
display(button, comboDiscEV)
button.on_click(demagnetise)
In [ ]: