Exemplo n.º 1
0
def test_ScalarView_mpl_unknown():
    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")
Exemplo n.º 2
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()
Exemplo n.º 3
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")
Exemplo n.º 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)
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
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