Пример #1
0
def test_ScalarView_mpl_default():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(5)
    space.assign_dofs()

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    A = sys.get_matrix()
    b = sys.get_rhs()
    from scipy.sparse.linalg import cg
    x, res = cg(A, b)
    sln = Solution()
    sln.set_fe_solution(space, pss, x)

    view = ScalarView("Solution")
    view.show(sln, show=False, method="contour")
Пример #2
0
def test_ScalarView_mpl_default():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(5)
    space.assign_dofs()

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    A = sys.get_matrix()
    b = sys.get_rhs()
    from scipy.sparse.linalg import cg

    x, res = cg(A, b)
    sln = Solution()
    sln.set_fe_solution(space, pss, x)

    view = ScalarView("Solution")
    view.show(sln, show=False, method="contour")
Пример #3
0
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(1)

wf = WeakForm(1)
set_forms(wf)

sln = Solution()
rsln = Solution()
solver = DummySolver()

view = ScalarView("Solution")
iter = 0
while 1:
    space.assign_dofs()

    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)
    sys.assemble()
    sys.solve_system(sln)
    if interactive_plotting:
        view.show(sln)

    rsys = RefSystem(sys)
    rsys.assemble()
Пример #4
0
# Create the x- and y- displacement space using the default H1 shapeset
xdisp = H1Space(mesh, P_INIT)
ydisp = H1Space(mesh, P_INIT)
set_bc(xdisp, ydisp)

# Initialize the weak formulation
wf = WeakForm(2)
set_forms(wf)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(xdisp, ydisp)

# Assemble and solve the matrix problem
xsln = Solution()
ysln = Solution()
ls.assemble()
ls.solve_system(xsln, ysln, lib="scipy")

# Visualize the solution
view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600)
E = float(200e9)
nu = 0.3
l = (E * nu) / ((1 + nu) * (1 - 2 * nu))
mu = E / (2 * (1 + nu))
stress = VonMisesFilter(xsln, ysln, mu, l)
view.show(stress)

# Visualize the mesh
mesh.plot(space=xdisp)
Пример #5
0
    def calc(threshold=0.3,
             strategy=0,
             h_only=False,
             error_tol=1,
             interactive_plotting=False,
             show_mesh=False,
             show_graph=True):
        mesh = Mesh()
        mesh.create([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],
        ], [
            [2, 3, 0, 1, 0],
        ], [
            [0, 1, 1],
            [1, 2, 1],
            [2, 3, 1],
            [3, 0, 1],
        ], [])

        mesh.refine_all_elements()

        shapeset = H1Shapeset()
        pss = PrecalcShapeset(shapeset)

        space = H1Space(mesh, shapeset)
        set_bc(space)
        space.set_uniform_order(1)

        wf = WeakForm(1)
        set_forms(wf)

        sln = Solution()
        rsln = Solution()
        solver = DummySolver()

        selector = H1ProjBasedSelector(CandList.HP_ANISO, 1.0, -1, shapeset)

        view = ScalarView("Solution")
        iter = 0
        graph = []
        while 1:
            space.assign_dofs()

            sys = LinSystem(wf, solver)
            sys.set_spaces(space)
            sys.set_pss(pss)
            sys.assemble()
            sys.solve_system(sln)
            dofs = sys.get_matrix().shape[0]
            if interactive_plotting:
                view.show(sln,
                          lib=lib,
                          notebook=True,
                          filename="a%02d.png" % iter)

            rsys = RefSystem(sys)
            rsys.assemble()

            rsys.solve_system(rsln)

            hp = H1Adapt([space])
            hp.set_solutions([sln], [rsln])
            err_est = hp.calc_error() * 100

            err_est = hp.calc_error(sln, rsln) * 100
            print "iter=%02d, err_est=%5.2f%%, DOFS=%d" % (iter, err_est, dofs)
            graph.append([dofs, err_est])
            if err_est < error_tol:
                break
            hp.adapt(selector, threshold, strategy)
            iter += 1

        if not interactive_plotting:
            view.show(sln, lib=lib, notebook=True)

        if show_mesh:
            mview = MeshView("Mesh")
            mview.show(mesh, lib="mpl", notebook=True, filename="b.png")

        if show_graph:
            from numpy import array
            graph = array(graph)
            import pylab
            pylab.clf()
            pylab.plot(graph[:, 0], graph[:, 1], "ko", label="error estimate")
            pylab.plot(graph[:, 0], graph[:, 1], "k-")
            pylab.title("Error Convergence for the Inner Layer Problem")
            pylab.legend()
            pylab.xlabel("Degrees of Freedom")
            pylab.ylabel("Error [%]")
            pylab.yscale("log")
            pylab.grid()
            pylab.savefig("graph.png")
Пример #6
0
        [3, 0, 1],
    ], [])

# Perform initial mesh refinements
mesh.refine_all_elements()

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
set_bc(space)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize views
sview = ScalarView("Solution")
mview = MeshView("Mesh")
graph = []

# Initialize refinement selector
selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

# Initialize the coarse mesh problem
ls = LinSystem(wf)
ls.set_spaces(space)

# Adaptivity loop
iter = 0
done =  False
print "Calculating..."
sln_coarse = Solution()
Пример #7
0
ndofs += yvel.assign_dofs(ndofs)
ndofs += press.assign_dofs(ndofs)

xprev = Solution()
yprev = Solution()

xprev.set_zero(mesh)
yprev.set_zero(mesh)

# initialize the discrete problem
wf = WeakForm(3)
set_forms(wf, xprev, yprev)

# visualize the solution
vview = VectorView("velocity [m/s]", 0, 0, 1200, 350)
pview = ScalarView("pressure [Pa]", 0, 500, 1200, 350)
vview.set_min_max_range(0, 1.9)
vview.show_scale(False)
pview.show_scale(False)
pview.show_mesh(False)

solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(xvel, yvel, press)
sys.set_pss(pss)
#dp.set_external_fns(xprev, yprev)

EPS_LOW = 0.0014

for i in range(1000):
    print "*** Iteration %d ***" % i
Пример #8
0
# create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(5)
space.assign_dofs()

# initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)

solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(space)
sys.set_pss(pss)

# assemble the stiffness matrix and solve the system
sys.assemble()
A = sys.get_matrix()
b = sys.get_rhs()
from scipy.sparse.linalg import cg
x, res = cg(A, b)
sln = Solution()
sln.set_fe_solution(space, pss, x)

view = ScalarView("Solution")
view.show(sln, lib="mayavi")
# view.wait()

mview = MeshView("Hello world!", 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders", notebook=False)
mview.wait()
Пример #9
0
mesh = Mesh()
mesh.load(get_12_mesh())

# Perform initial mesh refinements
mesh.refine_all_elements()

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
set_bc(space)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize views
sview = ScalarView("Coarse solution", 0, 0, 600, 1000)
oview = OrderView("Polynomial orders", 1220, 0, 600, 1000)

# Initialize refinement selector
selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)

# Adaptivity loop
it = 0
done = False
sln_coarse = Solution()
sln_fine = Solution()
Пример #10
0
def show_sol(s):
    view = ScalarView("Eigenvector", 0, 0, 400, 400)
    view.show(s)
Пример #11
0
# Create the x- and y- displacement space using the default H1 shapeset
xdisp = H1Space(mesh, P_INIT)
ydisp = H1Space(mesh, P_INIT)
set_bc(xdisp, ydisp)

# Initialize the weak formulation
wf = WeakForm(2)
set_forms(wf)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(xdisp, ydisp)

# Assemble and solve the matrix problem
xsln = Solution()
ysln = Solution()
ls.assemble()
ls.solve_system(xsln, ysln, lib="scipy")

# Visualize the solution
view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600)
E = float(200e9)
nu = 0.3
l = (E * nu) / ((1 + nu) * (1 - 2*nu))
mu = E / (2*(1 + nu))
stress = VonMisesFilter(xsln, ysln, mu, l)
view.show(stress)

# Visualize the mesh
mesh.plot(space=xdisp)
Пример #12
0
ydisp = H1Space(ymesh, shapeset)
set_bc(ydisp)
ydisp.set_uniform_order(P_INIT)

# Enumerate basis functions
ndofs = xdisp.assign_dofs()
ydisp.assign_dofs(ndofs)

# Initialize the weak formulation
wf = WeakForm(2)
set_wf_forms(wf)

# Visualization of solution and meshes
xoview = OrderView("X polynomial orders", 0, 0, 500, 500)
yoview = OrderView("Y polynomial orders", 510, 0, 500, 500)
sview = ScalarView("Von Mises stress [Pa]", 1020, 0, 500, 500)

# Matrix solver
solver = DummySolver()

# adaptivity loop
it = 1
done = False
cpu = 0.0

x_sln_coarse = Solution()
y_sln_coarse = Solution()

x_sln_fine = Solution()
y_sln_fine = Solution()
Пример #13
0
def plot(f):
    s = ScalarView("")
    s.show(f)
Пример #14
0
ndofs += ydisp.assign_dofs(ndofs)

# Initialize the weak formulation
wf = WeakForm(2)
set_forms(wf)

# Initialize the linear system and solver
solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(xdisp, ydisp)
sys.set_pss(pss)

# Assemble the stiffness matrix and solve the system
xsln = Solution()
ysln = Solution()
sys.assemble()
sys.solve_system(xsln, ysln, lib="scipy")

# Visualize the solution
view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600)
E = float(200e9)
nu = 0.3
l = (E * nu) / ((1 + nu) * (1 - 2*nu))
mu = E / (2*(1 + nu))
stress = VonMisesFilter(xsln, ysln, mu, l)
view.show(stress, lib="mayavi")

# Visualize the mesh
mview = MeshView("Hello world!", 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders", notebook=False)
Пример #15
0
    def calc(
        threshold=0.3,
        strategy=0,
        h_only=False,
        error_tol=1,
        interactive_plotting=False,
        show_mesh=False,
        show_graph=True,
    ):
        mesh = Mesh()
        mesh.create(
            [[0, 0], [1, 0], [1, 1], [0, 1]], [[2, 3, 0, 1, 0]], [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]], []
        )

        mesh.refine_all_elements()

        shapeset = H1Shapeset()
        pss = PrecalcShapeset(shapeset)

        space = H1Space(mesh, shapeset)
        set_bc(space)
        space.set_uniform_order(1)

        wf = WeakForm(1)
        set_forms(wf)

        sln = Solution()
        rsln = Solution()
        solver = DummySolver()

        selector = H1ProjBasedSelector(CandList.HP_ANISO, 1.0, -1, shapeset)

        view = ScalarView("Solution")
        iter = 0
        graph = []
        while 1:
            space.assign_dofs()

            sys = LinSystem(wf, solver)
            sys.set_spaces(space)
            sys.set_pss(pss)
            sys.assemble()
            sys.solve_system(sln)
            dofs = sys.get_matrix().shape[0]
            if interactive_plotting:
                view.show(sln, lib=lib, notebook=True, filename="a%02d.png" % iter)

            rsys = RefSystem(sys)
            rsys.assemble()

            rsys.solve_system(rsln)

            hp = H1Adapt([space])
            hp.set_solutions([sln], [rsln])
            err_est = hp.calc_error() * 100

            err_est = hp.calc_error(sln, rsln) * 100
            print "iter=%02d, err_est=%5.2f%%, DOFS=%d" % (iter, err_est, dofs)
            graph.append([dofs, err_est])
            if err_est < error_tol:
                break
            hp.adapt(selector, threshold, strategy)
            iter += 1

        if not interactive_plotting:
            view.show(sln, lib=lib, notebook=True)

        if show_mesh:
            mview = MeshView("Mesh")
            mview.show(mesh, lib="mpl", notebook=True, filename="b.png")

        if show_graph:
            from numpy import array

            graph = array(graph)
            import pylab

            pylab.clf()
            pylab.plot(graph[:, 0], graph[:, 1], "ko", label="error estimate")
            pylab.plot(graph[:, 0], graph[:, 1], "k-")
            pylab.title("Error Convergence for the Inner Layer Problem")
            pylab.legend()
            pylab.xlabel("Degrees of Freedom")
            pylab.ylabel("Error [%]")
            pylab.yscale("log")
            pylab.grid()
            pylab.savefig("graph.png")
Пример #16
0
# Initial mesh refinements in the vmesh towards the boundary
if MULTI == True:
    vmesh.refine_towards_boundary(1, INIT_REF_BDY)

# Create the x displacement space
uspace = H1Space(umesh, P_INIT_U)
vspace = H1Space(vmesh, P_INIT_V)

# Initialize the weak formulation
wf = WeakForm(2)
set_wf_forms(wf)

# Initialize views
uoview = OrderView("Coarse mesh for u", 0, 0, 360, 300)
voview = OrderView("Coarse mesh for v", 370, 0, 360, 300)
uview = ScalarView("Coarse mesh solution u", 740, 0, 400, 300)
vview = ScalarView("Coarse mesh solution v", 1150, 0, 400, 300)

# Initialize refinement selector
selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

# Initialize the coarse mesh problem
ls = LinSystem(wf)
ls.set_spaces(uspace, vspace)

# adaptivity loop
it = 1
done = False
u_sln_coarse = Solution()
v_sln_coarse = Solution()
u_sln_fine = Solution()
Пример #17
0
set_bc(space)

# Set initial condition
tsln = Solution()
tsln.set_const(mesh, T_INIT)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)

# Visualisation
sview = ScalarView("Temperature", 0, 0, 450, 600)
#title = "Time %s, exterior temperature %s" % (TIME, temp_ext(TIME))
#Tview.set_min_max_range(0,20);
#Tview.set_title(title);
#Tview.fix_scale_width(3);

# Time stepping
nsteps = int(FINAL_TIME / TAU + 0.5)
rhsonly = False

for n in range(1, nsteps + 1):
    print("\n---- Time %s, time step %s, ext_temp %s ----------" %
          (TIME, n, temp_ext(TIME)))

    # Assemble and solve
    ls.assemble()
Пример #18
0
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(1)

wf = WeakForm(1)
set_forms(wf)

sln = Solution()
rsln = Solution()
solver = DummySolver()

view = ScalarView("Solution")
mview = MeshView("Mesh")
graph = []
iter = 0
print "Calculating..."

while 1:
    space.assign_dofs()

    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)
    sys.assemble()
    sys.solve_system(sln)
    dofs = sys.get_matrix().shape[0]
    if interactive_plotting:
Пример #19
0
xdisp.set_uniform_order(8)
ydisp.set_uniform_order(8)

set_bc(xdisp, ydisp)

ndofs = xdisp.assign_dofs(0)
ndofs += ydisp.assign_dofs(ndofs)

# initialize the discrete problem
wf = WeakForm(2)
set_forms(wf)

solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(xdisp, ydisp)
sys.set_pss(pss)

xsln = Solution()
ysln = Solution()
sys.assemble()
sys.solve_system(xsln, ysln)

view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600)
E = float(200e9)
nu = 0.3
stress = VonMisesFilter(xsln, ysln, E / (2*(1 + nu)),
        (E * nu) / ((1 + nu) * (1 - 2*nu)))
view.show(stress)

view.wait()
Пример #20
0
tsln.set_const(mesh, T_INIT)

# Weak formulation
wf = WeakForm(1)
set_forms(wf, tsln)

# Matrix solver
solver = DummySolver()

# Linear system
ls = LinSystem(wf, solver)
ls.set_spaces(space)
ls.set_pss(pss)

# Visualisation
sview = ScalarView("Temperature", 0, 0, 450, 600)
#title = "Time %s, exterior temperature %s" % (TIME, temp_ext(TIME))
#Tview.set_min_max_range(0,20);
#Tview.set_title(title);
#Tview.fix_scale_width(3);

# Time stepping
nsteps = int(FINAL_TIME/TAU + 0.5)
rhsonly = False;

for n in range(1,nsteps+1):
    print ("\n---- Time %s, time step %s, ext_temp %s ----------" % (TIME, n, temp_ext(TIME)) )

    # Assemble and solve
    ls.assemble()
    rhsonly = True
Пример #21
0
pss = PrecalcShapeset(shapeset)

# Create finite element space
space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(P_INIT)

# Enumerate basis functions
space.assign_dofs()

# Initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)

# Visualize solution, gradient, and mesh
sview = ScalarView("Coarse solution", 0, 0, 600, 1000)
gview = VectorView("Gradient", 610, 0, 600, 1000)
oview = OrderView("Polynomial orders", 1220, 0, 600, 1000)

# Matrix solver
solver = DummySolver()

# Adaptivity loop
it = 1
ndofs = 0

done = False
cpu = 0.0

sln_coarse = Solution()
sln_fine = Solution()
Пример #22
0
mesh.load(get_07_mesh())

# Perform initial mesh refinements.
for i in range(INIT_REF_NUM):
    mesh.refine_all_elements()

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
set_bc(space)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize views
sview = ScalarView("Coarse solution", 0, 100, 798, 700)
oview = OrderView("Polynomial orders", 800, 100, 798, 700)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)

# Assemble and solve the matrix problem
sln = Solution()
ls.assemble()
ls.solve_system(sln)

# View the solution
sln.plot()

# View the mesh
Пример #23
0
mesh = Mesh()
mesh.load(get_12_mesh())

# Perform initial mesh refinements
mesh.refine_all_elements()

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
set_bc(space)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize views
sview = ScalarView("Coarse solution", 0, 0, 600, 1000)
oview = OrderView("Polynomial orders", 1220, 0, 600, 1000)

# Initialize refinement selector
selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)

# Adaptivity loop
it = 0
done = False
sln_coarse = Solution()
sln_fine = Solution()
Пример #24
0
set_bc(space)

# Set initial condition
tsln = Solution()
tsln.set_const(mesh, T_INIT)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)

# Visualisation
sview = ScalarView("Temperature", 0, 0, 450, 600)
#title = "Time %s, exterior temperature %s" % (TIME, temp_ext(TIME))
#Tview.set_min_max_range(0,20);
#Tview.set_title(title);
#Tview.fix_scale_width(3);

# Time stepping
nsteps = int(FINAL_TIME/TAU + 0.5)
rhsonly = False;

for n in range(1,nsteps+1):
    print ("\n---- Time %s, time step %s, ext_temp %s ----------" % (TIME, n, temp_ext(TIME)) )

    # Assemble and solve
    ls.assemble()
    rhsonly = True