本文整理汇总了Python中dolfin.FunctionSpace方法的典型用法代码示例。如果您正苦于以下问题:Python dolfin.FunctionSpace方法的具体用法?Python dolfin.FunctionSpace怎么用?Python dolfin.FunctionSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dolfin
的用法示例。
在下文中一共展示了dolfin.FunctionSpace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import FunctionSpace [as 别名]
def __init__(self, init=None, val=0.0):
"""
Initialization routine
Args:
init: can either be a FunctionSpace or another fenics_mesh object
val: initial value (default: 0.0)
Raises:
DataError: if init is none of the types above
"""
# if init is another fenic_mesh, do a deepcopy (init by copy)
if isinstance(init, type(self)):
self.values = init.values.copy(deepcopy=True)
# if init is FunctionSpace, create mesh object with val as initial value
elif isinstance(init, df.Function):
self.values = init.copy(deepcopy=True)
elif isinstance(init, df.FunctionSpace):
self.values = df.Function(init)
self.values.vector()[:] = val
else:
raise DataError('something went wrong during %s initialization' % type(init))
示例2: __init__
# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import FunctionSpace [as 别名]
def __init__(self, problem_params, dtype_u=fenics_mesh, dtype_f=fenics_mesh):
"""
Initialization routine
Args:
problem_params: custom parameters for the example
dtype_u: FEniCS mesh data type (will be passed to parent class)
dtype_f: FEniCS mesh data data type (will be passed to parent class)
"""
# define the Dirichlet boundary
def Boundary(x, on_boundary):
return on_boundary
# these parameters will be used later, so assert their existence
essential_keys = ['c_nvars', 't0', 'family', 'order', 'refinements', 'Du', 'Dv', 'A', 'B']
for key in essential_keys:
if key not in problem_params:
msg = 'need %s to instantiate problem, only got %s' % (key, str(problem_params.keys()))
raise ParameterError(msg)
# set logger level for FFC and dolfin
df.set_log_level(df.WARNING)
logging.getLogger('FFC').setLevel(logging.WARNING)
# set solver and form parameters
df.parameters["form_compiler"]["optimize"] = True
df.parameters["form_compiler"]["cpp_optimize"] = True
# set mesh and refinement (for multilevel)
mesh = df.IntervalMesh(problem_params['c_nvars'], 0, 100)
for i in range(problem_params['refinements']):
mesh = df.refine(mesh)
# define function space for future reference
V = df.FunctionSpace(mesh, problem_params['family'], problem_params['order'])
self.V = V * V
# invoke super init, passing number of dofs, dtype_u and dtype_f
super(fenics_grayscott, self).__init__(self.V, dtype_u, dtype_f, problem_params)
# rhs in weak form
self.w = df.Function(self.V)
q1, q2 = df.TestFunctions(self.V)
self.w1, self.w2 = df.split(self.w)
self.F1 = (-self.params.Du * df.inner(df.nabla_grad(self.w1), df.nabla_grad(q1)) -
self.w1 * (self.w2 ** 2) * q1 + self.params.A * (1 - self.w1) * q1) * df.dx
self.F2 = (-self.params.Dv * df.inner(df.nabla_grad(self.w2), df.nabla_grad(q2)) +
self.w1 * (self.w2 ** 2) * q2 - self.params.B * self.w2 * q2) * df.dx
self.F = self.F1 + self.F2
# mass matrix
u1, u2 = df.TrialFunctions(self.V)
a_M = u1 * q1 * df.dx
M1 = df.assemble(a_M)
a_M = u2 * q2 * df.dx
M2 = df.assemble(a_M)
self.M = M1 + M2
示例3: __init__
# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import FunctionSpace [as 别名]
def __init__(self, problem_params, dtype_u=fenics_mesh, dtype_f=fenics_mesh):
"""
Initialization routine
Args:
problem_params (dict): custom parameters for the example
dtype_u: FEniCS mesh data type (will be passed to parent class)
dtype_f: FEniCS mesh data type (will be passed to parent class)
"""
# define the Dirichlet boundary
def Boundary(x, on_boundary):
return on_boundary
# these parameters will be used later, so assert their existence
essential_keys = ['c_nvars', 't0', 'family', 'order', 'refinements', 'nu']
for key in essential_keys:
if key not in problem_params:
msg = 'need %s to instantiate problem, only got %s' % (key, str(problem_params.keys()))
raise ParameterError(msg)
# set logger level for FFC and dolfin
logging.getLogger('ULF').setLevel(logging.WARNING)
logging.getLogger('FFC').setLevel(logging.WARNING)
df.set_log_level(30)
# set solver and form parameters
df.parameters["form_compiler"]["optimize"] = True
df.parameters["form_compiler"]["cpp_optimize"] = True
# set mesh and refinement (for multilevel)
mesh = df.UnitIntervalMesh(problem_params['c_nvars'])
for i in range(problem_params['refinements']):
mesh = df.refine(mesh)
# define function space for future reference
self.V = df.FunctionSpace(mesh, problem_params['family'], problem_params['order'])
tmp = df.Function(self.V)
print('DoFs on this level:', len(tmp.vector()[:]))
# invoke super init, passing number of dofs, dtype_u and dtype_f
super(fenics_heat_weak_fullyimplicit, self).__init__(self.V, dtype_u, dtype_f, problem_params)
self.g = df.Expression('-sin(a*x[0]) * (sin(t) - b*a*a*cos(t))', a=np.pi, b=self.params.nu, t=self.params.t0,
degree=self.params.order)
# rhs in weak form
self.w = df.Function(self.V)
v = df.TestFunction(self.V)
self.a_K = -self.params.nu * df.inner(df.nabla_grad(self.w), df.nabla_grad(v)) * df.dx + self.g * v * df.dx
# mass matrix
u = df.TrialFunction(self.V)
a_M = u * v * df.dx
self.M = df.assemble(a_M)
self.bc = df.DirichletBC(self.V, df.Constant(0.0), Boundary)