本文整理汇总了Python中hermes2d.Mesh.get_element方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.get_element方法的具体用法?Python Mesh.get_element怎么用?Python Mesh.get_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hermes2d.Mesh
的用法示例。
在下文中一共展示了Mesh.get_element方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: schroedinger_solver
# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import get_element [as 别名]
def schroedinger_solver(n_eigs=4, iter=2, verbose_level=1, plot=False,
potential="hydrogen", report=False, report_filename="report.h5",
force=False, sim_name="sim", potential2=None):
"""
One particle Schroedinger equation solver.
n_eigs ... the number of the lowest eigenvectors to calculate
iter ... the number of adaptive iterations to do
verbose_level ...
0 ... quiet
1 ... only moderate output (default)
2 ... lot's of output
plot ........ plot the progress (solutions, refined solutions, errors)
potential ... the V(x) for which to solve, one of:
well, oscillator, hydrogen
potential2 .. other terms that should be added to potential
report ...... it will save raw data to a file, useful for creating graphs
etc.
Returns the eigenvalues and eigenvectors.
"""
set_verbose(verbose_level == 2)
set_warn_integration(False)
pot = {"well": 0, "oscillator": 1, "hydrogen": 2, "three-points": 3}
pot_type = pot[potential]
if report:
from timeit import default_timer as clock
from tables import IsDescription, UInt32Col, Float32Col, openFile, \
Float64Col, Float64Atom, Col, ObjectAtom
class Iteration(IsDescription):
n = UInt32Col()
DOF = UInt32Col()
DOF_reference = UInt32Col()
cpu_solve = Float32Col()
cpu_solve_reference = Float32Col()
eig_errors = Float64Col(shape=(n_eigs,))
eigenvalues = Float64Col(shape=(n_eigs,))
eigenvalues_reference = Float64Col(shape=(n_eigs,))
h5file = openFile(report_filename, mode = "a",
title = "Simulation data")
if hasattr(h5file.root, sim_name):
if force:
h5file.removeNode(getattr(h5file.root, sim_name),
recursive=True)
else:
print "The group '%s' already exists. Use -f to overwrite it." \
% sim_name
return
group = h5file.createGroup("/", sim_name, 'Simulation run')
table = h5file.createTable(group, "iterations", Iteration,
"Iterations info")
h5eigs = h5file.createVLArray(group, 'eigenvectors', ObjectAtom())
h5eigs_ref = h5file.createVLArray(group, 'eigenvectors_reference',
ObjectAtom())
iteration = table.row
mesh = Mesh()
mesh.load("square.mesh")
if potential == "well":
# Read the width of the mesh automatically. This assumes there is just
# one square element:
a = sqrt(mesh.get_element(0).get_area())
# set N high enough, so that we get enough analytical eigenvalues:
N = 10
levels = []
for n1 in range(1, N):
for n2 in range(1, N):
levels.append(n1**2 + n2**2)
levels.sort()
E_exact = [pi**2/(2.*a**2) * m for m in levels]
elif potential == "oscillator":
E_exact = [1] + [2]*2 + [3]*3 + [4]*4 + [5]*5 + [6]*6
elif potential == "hydrogen":
Z = 1 # atom number
E_exact = [-float(Z)**2/2/(n-0.5)**2/4 for n in [1]+[2]*3+[3]*5 +\
[4]*8 + [5]*15]
else:
E_exact = [1.]*50
if len(E_exact) < n_eigs:
print n_eigs
print E_exact
raise Exception("We don't have enough analytical eigenvalues.")
#mesh.refine_element(0)
mesh.refine_all_elements()
#mesh.refine_all_elements()
#mesh.refine_all_elements()
#mesh.refine_all_elements()
#mview = MeshView()
#mview.show(mesh)
shapeset = H1Shapeset()
space = H1Space(mesh, shapeset)
space.set_uniform_order(2)
space.assign_dofs()
pss = PrecalcShapeset(shapeset)
#bview = BaseView()
#bview.show(space)
#.........这里部分代码省略.........