示例#1
0
def test_example_09():
    from hermes2d.examples.c09 import set_bc, temp_ext, set_forms

    # The following parameters can be changed:
    INIT_REF_NUM = 4  # number of initial uniform mesh refinements
    INIT_REF_NUM_BDY = 1  # number of initial uniform mesh refinements towards the boundary
    P_INIT = 4  # polynomial degree of all mesh elements
    TAU = 300.0  # time step in seconds

    # Problem constants
    T_INIT = 10  # temperature of the ground (also initial temperature)
    FINAL_TIME = 86400  # length of time interval (24 hours) in seconds

    # Global variable
    TIME = 0

    # Boundary markers.
    bdy_ground = 1
    bdy_air = 2

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_cathedral_mesh())

    # Perform initial mesh refinements
    for i in range(INIT_REF_NUM):
        mesh.refine_all_elements()
    mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY)

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    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)

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

    # Assemble and solve
    ls.assemble()
    rhsonly = True
    ls.solve_system(tsln, lib="scipy")
示例#2
0
def test_example_09():
    from hermes2d.examples.c09 import set_bc, temp_ext, set_forms

    # The following parameters can be changed:
    INIT_REF_NUM = 4      # number of initial uniform mesh refinements
    INIT_REF_NUM_BDY = 1  # number of initial uniform mesh refinements towards the boundary
    P_INIT = 4            # polynomial degree of all mesh elements
    TAU = 300.0           # time step in seconds

    # Problem constants
    T_INIT = 10           # temperature of the ground (also initial temperature)
    FINAL_TIME = 86400    # length of time interval (24 hours) in seconds

    # Global variable
    TIME = 0;

    # Boundary markers.
    bdy_ground = 1
    bdy_air = 2

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_cathedral_mesh())

    # Perform initial mesh refinements
    for i in range(INIT_REF_NUM):
        mesh.refine_all_elements()
    mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY)

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    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)

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

    # Assemble and solve
    ls.assemble()
    rhsonly = True
    ls.solve_system(tsln, lib="scipy")
示例#3
0
def test_example_08():
    from hermes2d.examples.c08 import set_bc, set_forms

    set_verbose(False)

    mesh = Mesh()
    mesh.load(cylinder_mesh)
    #mesh.refine_element(0)
    #mesh.refine_all_elements()
    mesh.refine_towards_boundary(5, 3)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    xvel = H1Space(mesh, shapeset)
    yvel = H1Space(mesh, shapeset)
    press = H1Space(mesh, shapeset)
    xvel.set_uniform_order(2)
    yvel.set_uniform_order(2)
    press.set_uniform_order(1)

    set_bc(xvel, yvel, press)

    ndofs = 0
    ndofs += xvel.assign_dofs(ndofs)
    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)

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

    # visualize the solution

    EPS_LOW = 0.0014

    for i in range(3):
        psln = Solution()
        sys.assemble()
        sys.solve_system(xprev, yprev, psln)
示例#4
0
def test_example_04():
    from hermes2d.examples.c04 import set_bc

    set_verbose(False)

    mesh = Mesh()
    mesh.load(domain_mesh)
    # mesh.refine_element(0)
    # mesh.refine_all_elements()
    mesh.refine_towards_boundary(5, 3)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

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

    set_bc(space)

    space.assign_dofs()

    xprev = Solution()
    yprev = Solution()

    # initialize the discrete problem
    wf = WeakForm()
    set_forms(wf, -4)

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

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    sln = Solution()
    sys.solve_system(sln)
    assert abs(sln.l2_norm() - 1.22729) < 1e-4
    assert abs(sln.h1_norm() - 2.90006) < 1e-4
示例#5
0
# Global variable
TIME = 0

# Boundary markers.
bdy_ground = 1
bdy_air = 2

# Load the mesh
mesh = Mesh()
mesh.load(get_cathedral_mesh())

# Perform initial mesh refinements
for i in range(INIT_REF_NUM):
    mesh.refine_all_elements()
mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY)

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
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)
示例#6
0
文件: 05.py 项目: Richardma/hermes2d
#! /usr/bin/env python

from hermes2d import Mesh, H1Shapeset, PrecalcShapeset, H1Space, \
        LinSystem, Solution, ScalarView, WeakForm, DummySolver

from hermes2d.examples.c05 import set_bc, set_forms
from hermes2d.examples.c05 import set_forms as set_forms_surf
from hermes2d.forms import set_forms
from hermes2d.examples import get_example_mesh

mesh = Mesh()
mesh.load(get_example_mesh())
#mesh.refine_element(0)
#mesh.refine_all_elements()
mesh.refine_towards_boundary(5, 3)
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

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

set_bc(space)

space.assign_dofs()

xprev = Solution()
yprev = Solution()

# initialize the discrete problem
wf = WeakForm(1)
示例#7
0
def test_example_11():
    from hermes2d.examples.c11 import set_bc, set_wf_forms, set_hp_forms

    SOLVE_ON_COARSE_MESH = True  # If true, coarse mesh FE problem is solved in every adaptivity step.
    P_INIT_U = 2  # Initial polynomial degree for u
    P_INIT_V = 2  # Initial polynomial degree for v
    INIT_REF_BDY = 3  # Number of initial boundary refinements
    MULTI = True  # MULTI = true  ... use multi-mesh,
    # MULTI = false ... use single-mesh.
    # Note: In the single mesh option, the meshes are
    # forced to be geometrically the same but the
    # polynomial degrees can still vary.
    THRESHOLD = 0.3  # This is a quantitative parameter of the adapt(...) function and
    # it has different meanings for various adaptive strategies (see below).
    STRATEGY = 1  # Adaptive strategy:
    # STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total
    #   error is processed. If more elements have similar errors, refine
    #   all to keep the mesh symmetric.
    # STRATEGY = 1 ... refine all elements whose error is larger
    #   than THRESHOLD times maximum element error.
    # STRATEGY = 2 ... refine all elements whose error is larger
    #   than THRESHOLD.
    # More adaptive strategies can be created in adapt_ortho_h1.cpp.

    CAND_LIST = CandList.H2D_HP_ANISO  # Predefined list of element refinement candidates.
    # Possible values are are attributes of the class CandList:
    # P_ISO, P_ANISO, H_ISO, H_ANISO, HP_ISO, HP_ANISO_H, HP_ANISO_P, HP_ANISO
    # See the Sphinx tutorial (http://hpfem.org/hermes2d/doc/src/tutorial-2.html#adaptive-h-fem-and-hp-fem) for details.

    MESH_REGULARITY = -1  # Maximum allowed level of hanging nodes:
    # MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default),
    # MESH_REGULARITY = 1 ... at most one-level hanging nodes,
    # MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc.
    # Note that regular meshes are not supported, this is due to
    # their notoriously bad performance.
    CONV_EXP = 1  # Default value is 1.0. This parameter influences the selection of
    # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
    MAX_ORDER = 10  # Maximum allowed element degree
    ERR_STOP = 0.5  # Stopping criterion for adaptivity (rel. error tolerance between the
    # fine mesh and coarse mesh solution in percent).
    NDOF_STOP = 60000  # Adaptivity process stops when the number of degrees of freedom grows over
    # this limit. This is mainly to prevent h-adaptivity to go on forever.

    H2DRS_DEFAULT_ORDER = -1  # A default order. Used to indicate an unkonwn order or a maximum support order

    # Load the mesh
    umesh = Mesh()
    vmesh = Mesh()
    umesh.load(get_bracket_mesh())
    if MULTI == False:
        umesh.refine_towards_boundary(1, INIT_REF_BDY)

    # Create initial mesh (master mesh).
    vmesh.copy(umesh)

    # 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 refinement selector
    selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

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

    u_sln_coarse = Solution()
    v_sln_coarse = Solution()
    u_sln_fine = Solution()
    v_sln_fine = Solution()

    # Assemble and Solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(u_sln_fine, v_sln_fine, lib="scipy")

    # Either solve on coarse mesh or project the fine mesh solution
    # on the coarse mesh.
    if SOLVE_ON_COARSE_MESH:
        ls.assemble()
        ls.solve_system(u_sln_coarse, v_sln_coarse, lib="scipy")

    # Calculate element errors and total error estimate
    hp = H1Adapt(ls)
    hp.set_solutions([u_sln_coarse, v_sln_coarse], [u_sln_fine, v_sln_fine])
    set_hp_forms(hp)
    err_est = hp.calc_error() * 100
示例#8
0
def test_example_11():
    from hermes2d.examples.c11 import set_bc, set_wf_forms, set_hp_forms

    SOLVE_ON_COARSE_MESH = True  # If true, coarse mesh FE problem is solved in every adaptivity step.
    P_INIT_U = 2             # Initial polynomial degree for u
    P_INIT_V = 2             # Initial polynomial degree for v
    INIT_REF_BDY = 3         # Number of initial boundary refinements
    MULTI = True             # MULTI = true  ... use multi-mesh,
                                # MULTI = false ... use single-mesh.
                                # Note: In the single mesh option, the meshes are
                                # forced to be geometrically the same but the
                                # polynomial degrees can still vary.
    THRESHOLD = 0.3          # This is a quantitative parameter of the adapt(...) function and
                                     # it has different meanings for various adaptive strategies (see below).
    STRATEGY = 1             # Adaptive strategy:
                                # STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total
                                #   error is processed. If more elements have similar errors, refine
                                #   all to keep the mesh symmetric.
                                # STRATEGY = 1 ... refine all elements whose error is larger
                                #   than THRESHOLD times maximum element error.
                                # STRATEGY = 2 ... refine all elements whose error is larger
                                #   than THRESHOLD.
                                # More adaptive strategies can be created in adapt_ortho_h1.cpp.

    CAND_LIST = CandList.H2D_HP_ANISO  # Predefined list of element refinement candidates.
                            # Possible values are are attributes of the class CandList:
                            # P_ISO, P_ANISO, H_ISO, H_ANISO, HP_ISO, HP_ANISO_H, HP_ANISO_P, HP_ANISO
                            # See the Sphinx tutorial (http://hpfem.org/hermes2d/doc/src/tutorial-2.html#adaptive-h-fem-and-hp-fem) for details.

    MESH_REGULARITY = -1     # Maximum allowed level of hanging nodes:
                                # MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default),
                                # MESH_REGULARITY = 1 ... at most one-level hanging nodes,
                                # MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc.
                                # Note that regular meshes are not supported, this is due to
                                # their notoriously bad performance.
    CONV_EXP = 1             # Default value is 1.0. This parameter influences the selection of
                                # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
    MAX_ORDER = 10           # Maximum allowed element degree
    ERR_STOP = 0.5           # Stopping criterion for adaptivity (rel. error tolerance between the
                                # fine mesh and coarse mesh solution in percent).
    NDOF_STOP = 60000        # Adaptivity process stops when the number of degrees of freedom grows over
                                # this limit. This is mainly to prevent h-adaptivity to go on forever.

    H2DRS_DEFAULT_ORDER = -1 # A default order. Used to indicate an unkonwn order or a maximum support order

    # Load the mesh
    umesh = Mesh()
    vmesh = Mesh()
    umesh.load(get_bracket_mesh())
    if MULTI == False:
        umesh.refine_towards_boundary(1, INIT_REF_BDY)
        
    # Create initial mesh (master mesh).
    vmesh.copy(umesh)

    # 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 refinement selector
    selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

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

    u_sln_coarse = Solution()
    v_sln_coarse = Solution()
    u_sln_fine = Solution()
    v_sln_fine = Solution()
    
    # Assemble and Solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(u_sln_fine, v_sln_fine, lib="scipy")

    # Either solve on coarse mesh or project the fine mesh solution 
    # on the coarse mesh.
    if SOLVE_ON_COARSE_MESH:
        ls.assemble()
        ls.solve_system(u_sln_coarse, v_sln_coarse, lib="scipy")

    # Calculate element errors and total error estimate
    hp = H1Adapt(ls)
    hp.set_solutions([u_sln_coarse, v_sln_coarse], [u_sln_fine, v_sln_fine]);
    set_hp_forms(hp)
    err_est = hp.calc_error() * 100
示例#9
0
CONV_EXP = 1             # Default value is 1.0. This parameter influences the selection of
                            # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
MAX_ORDER = 10           # Maximum allowed element degree
ERR_STOP = 0.5           # Stopping criterion for adaptivity (rel. error tolerance between the
                            # fine mesh and coarse mesh solution in percent).
NDOF_STOP = 60000        # Adaptivity process stops when the number of degrees of freedom grows over
                            # this limit. This is mainly to prevent h-adaptivity to go on forever.

H2DRS_DEFAULT_ORDER = -1 # A default order. Used to indicate an unkonwn order or a maximum support order

# Load the mesh
umesh = Mesh()
vmesh = Mesh()
umesh.load(get_bracket_mesh())
if MULTI == False:
    umesh.refine_towards_boundary(1, INIT_REF_BDY)
    
# Create initial mesh (master mesh).
vmesh.copy(umesh)

# 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)
示例#10
0
文件: 09.py 项目: Zhonghua/hermes2d
TAU = 300.0           # time step in seconds

# Problem constants
T_INIT = 10           # temperature of the ground (also initial temperature)
FINAL_TIME = 86400    # length of time interval (24 hours) in seconds

# Global variable
TIME = 0;

# Load the mesh
mesh = Mesh()
mesh.load(get_cathedral_mesh())

for i in range(INIT_REF_NUM):
    mesh.refine_all_elements()
mesh.refine_towards_boundary(2, 5)

# Set up shapeset
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

# Set up spaces
space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(P_INIT)

# Enumerate basis functions
space.assign_dofs()

# Set initial condition
tsln = Solution()
示例#11
0
# Global variable
TIME = 0;

# Boundary markers.
bdy_ground = 1
bdy_air = 2

# Load the mesh
mesh = Mesh()
mesh.load(get_cathedral_mesh())

# Perform initial mesh refinements
for i in range(INIT_REF_NUM):
    mesh.refine_all_elements()
mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY)

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
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)