Пример #1
0
def test_Lorentzian_normalization():
    Lorentzian = LorentzianLine("Lorentzian1", (-5., 5), x0=0.0, width=0.5, c=0.0)
    n = Lorentzian.normalize()

    from scipy.integrate import quad
    to_integrate = lambda x: Lorentzian(x)
    val, err = quad(to_integrate, min(Lorentzian.domain), max(Lorentzian.domain))
    print(f"Integration value: {val:.5f} +- {err:.5f}   |   normalization factor: {n:.5f}")
    print(f"Normalized Line area: {val*n}")
Пример #2
0
L3 = LineFactory.create('lorentzian',
                        name="Lorentzian3",
                        domain=(-5.0, 5.0),
                        x0=-1.0,
                        width=0.4,
                        c=0.02,
                        weight=1)

### Evaluate a Line directly
### compare it with its normalized version and plot it
f1 = plt.figure(figsize=(6.0, 4.0))
ax1 = f1.add_subplot(111)
ax1_label = f"A simple Lorentzian line\n$\int L_1(E)\,dE= ${quad(L1, *L1.domain)[0]:.4f}"
ax1.plot(e, L1(e), color="C0", lw=2.0, label=ax1_label)
ax1.plot(e,
         L1(e) * L1.normalize(),
         color="C1",
         ls="--",
         lw=1.0,
         label="(re)normalized")
ax1.set_title("A simple Line")
ax1.legend()
#plt.show()
#------------------------------------------------------------------------------

### Create a SqE model from the three lines
### Add the three weighted lines individually
icalcstrat = InelasticCalcStrategy(T=20.)
qcalcstrat = QuasielasticCalcStrategy()
# This creates the sqe model
sqe1 = SqE(lines=(L1, L2, L3), lam=6.0, dlam=0.12, l_SD=3.43, T=20)
Пример #3
0
def test_normalization():
    Lorentzian = LorentzianLine("Lorentzian1", (-5., 5),
                                x0=0.0,
                                width=0.5,
                                c=0.0)
    n = Lorentzian.normalize()

    from scipy.integrate import quad
    to_integrate = lambda x: Lorentzian(x)
    val, err = quad(to_integrate, min(Lorentzian.domain),
                    max(Lorentzian.domain))
    print(
        f"Integration value: {val:.5f} +- {err:.5f}   |   normalization factor: {n:.5f}"
    )
    print(f"Normalized Line area: {val*n}")

    # - - - - - - - - - - - - - - - - - - - -

    F_c = F_cLine("FcLine1", (-15, 15),
                  x0=0.0,
                  width=0.02,
                  A=350.0,
                  q=0.023,
                  c=0.0,
                  weight=1.0)
    nfc = F_c.normalize()
    ifc = F_c.integrate()

    x = np.linspace(-1000, 1000, 5000000)
    y = F_c.calc(x, **F_c.line_params)
    ifctrapz = np.trapz(y, x)
    ifcquadv, ifcquade = quad(lambda x: nfc * F_c(x), min(F_c.domain),
                              max(F_c.domain))
    print(f"{F_c.line_params}")
    print(f"Standard Integration value for 10000 steps: {ifc}")
    print(
        f"QUADPACK Integration value (after normal.): {ifcquadv} +- {ifcquade}"
    )
    print(f"TRAPEZOID Integration value -1e3 from 1e3 : {ifctrapz}")

    # - - - - - - - - - - - - - - - - - - - -

    F_I = F_ILine("FILine1", (-15, 15),
                  x0=0.0,
                  width=0.02,
                  A=350.0,
                  q=0.023,
                  kappa=0.01,
                  c=0.0,
                  weight=1.0)
    nfI = F_I.normalize()
    ifI = F_I.integrate()

    x = np.linspace(-1000, 1000, 5000000)
    y = F_I.calc(x, **F_I.line_params)
    ifItrapz = np.trapz(y, x)
    ifIquadv, ifIquade = quad(lambda x: F_I(x), min(F_I.domain),
                              max(F_I.domain))
    print(f"{F_I.line_params}")
    print(f"Standard Integration value for 10000 steps: {ifI}")
    print(
        f"QUADPACK Integration value                : {ifIquadv} +- {ifIquade}"
    )
    print(f"TRAPEZOID Integration value -1e3 from 1e3 : {ifItrapz}")