Example #1
0
def chi2(a, b, err, trans=None):
    """Return chi square value."""
    if trans is None:
        trans = pg.RTrans()

    d = (trans(a) - trans(b)) / trans.error(a, err)
    return pg.dot(d, d) / len(d)
Example #2
0
def chi2(a, b, err, trans=None):
    """Return chi square value."""
    if trans is None:
        trans = pg.RTrans()
    d = (trans(a) - trans(b)) / trans.error(a, err)
    return pg.dot(d, d) / len(d)
            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 1],
                                        grid), rhs)

    else:
        solver.assembleDirichletBC(
            S,
            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 0],
                                        grid), rhs)
        solver.assembleDirichletBC(
            S,
            solver.parseArgToBoundaries([grid.findBoundaryByMarker(2), 0],
                                        grid), rhs)

    v[n] = solver.linsolve(S, rhs)

    e[n] = 0.5 * (pg.dot(M * v[n], v[n]) + pg.dot(A * u[n], u[n]))

    print(n, times[n], "Energy", e[n], k / (h * h))

import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(e)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

lineFEM, = ax.plot(pg.x(grid.positions()), u[0])
ax.set_ylim(-0.1, 0.1)

    if n==1:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 1], grid),
                            rhs)
        
    else:
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(1), 0], grid),
                            rhs)
        solver.assembleDirichletBC(S,
                            solver.parseArgToBoundaries([grid.findBoundaryByMarker(2), 0], grid),
                            rhs)
    
    v[n] = solver.linsolve(S, rhs)

    e[n] = 0.5 * (pg.dot(M * v[n], v[n]) + pg.dot(A * u[n], u[n]))
    
    print(n, times[n], "Energy", e[n], k/(h*h))

    
import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(e)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

lineFEM, = ax.plot(pg.x(grid.positions()), u[0])
ax.set_ylim(-0.1, 0.1)