当前位置: 首页>>代码示例>>Python>>正文


Python dolfin.Function方法代码示例

本文整理汇总了Python中dolfin.Function方法的典型用法代码示例。如果您正苦于以下问题:Python dolfin.Function方法的具体用法?Python dolfin.Function怎么用?Python dolfin.Function使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dolfin的用法示例。


在下文中一共展示了dolfin.Function方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [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)) 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:23,代码来源:fenics_mesh.py

示例2: eval_f

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def eval_f(self, u, t):
        """
        Routine to evaluate both parts of the RHS

        Args:
            u (dtype_u): current values
            t (float): current time

        Returns:
            dtype_f: the RHS divided into two parts
        """

        f = self.dtype_f(self.V)

        self.w.assign(u.values)
        f.values = df.Function(self.V, df.assemble(self.F))

        f = self.__invert_mass_matrix(f)

        return f 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:22,代码来源:GrayScott_1D_FEniCS_implicit.py

示例3: __eval_fimpl

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def __eval_fimpl(self, u, t):
        """
        Helper routine to evaluate the implicit part of the RHS

        Args:
            u (dtype_u): current values
            t (float): current time

        Returns:
            implicit part of RHS
        """

        tmp = self.dtype_u(self.V)
        tmp.values = df.Function(self.V, -1.0 * self.params.nu * self.K * u.values.vector())
        fimpl = self.__invert_mass_matrix(tmp)

        return fimpl 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:19,代码来源:VorticityVelocity_2D_FEniCS_periodic.py

示例4: eval_f

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def eval_f(self, u, t):
        """
        Routine to evaluate both parts of the RHS

        Args:
            u (dtype_u): current values
            t (float): current time

        Returns:
            dtype_f: the RHS divided into two parts
        """

        self.g.t = t

        f = self.dtype_f(self.V)

        self.w.assign(u.values)
        f.values = df.Function(self.V, df.assemble(self.a_K))

        f = self.__invert_mass_matrix(f)

        return f 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:24,代码来源:HeatEquation_1D_FEniCS_weak_forced.py

示例5: init_field_fenics

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def init_field_fenics(mesh, V, order=3, seed=None):
    # https://fenicsproject.org/qa/3975/interpolating-vector-function-from-python-code-to-fenics/

    u0 = df.Function(V)
    # Extract x and y coordinates of mesh and
    # align with dof structure
    dim = V.dim()
    N = mesh.geometry().dim()
    coor = V.tabulate_dof_coordinates().reshape(dim, N)
    dofs_V = V.dofmap().dofs()
    x = coor[:, 0]
    x_f = x[dofs_V]

    np.random.seed(seed)
    lam = np.random.randn(2, 2*order+1)
    c = np.random.rand() - 0.5
    k = np.arange(-order, order+1)
    kx = np.outer(k, x_f)*2*np.pi

    # vector field
    f = np.dot(lam[[0]], np.cos(kx)) + np.dot(lam[[1]], np.sin(kx))
    f = 2 * f / np.amax(np.abs(f)) + 2.0*c

    # Insert values of f into the function u0
    u0.vector()[dofs_V] = f[0]

    return u0, lam, c 
开发者ID:cics-nd,项目名称:ar-pde-cnn,代码行数:29,代码来源:fenics_burger1D.py

示例6: init_field_fenics

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def init_field_fenics(mesh, V, order=4, seed=0):
    # https://fenicsproject.org/qa/3975/interpolating-vector-function-from-python-code-to-fenics/

    u0 = df.Function(V)
    # Extract x and y coordinates of mesh and
    # align with dof structure
    dim = V.dim()
    N = mesh.geometry().dim()
    coor = V.tabulate_dof_coordinates().reshape(dim, N)
    f0_dofs = V.sub(0).dofmap().dofs()
    f1_dofs = V.sub(1).dofmap().dofs()

    x = coor[:, 0]   # x for fx and fy
    y = coor[:, 1]   # y for fx and fy
    f0_x, f0_y = x[f0_dofs], y[f0_dofs]  # x, y of components
    # f1_x, f1_y = x[f1_dofs], y[f1_dofs]

    np.random.seed(seed)
    lam = np.random.randn(2, 2, (2*order+1)**2)
    c = -1 + np.random.rand(2) * 2
    aa, bb = np.meshgrid(np.arange(-order, order+1), np.arange(-order, order+1))
    k = np.stack((aa.flatten(), bb.flatten()), 1)
    kx_plus_ly = (np.outer(k[:, 0], f0_x) + np.outer(k[:, 1], f0_y))*2*np.pi

    # vector field
    f = np.dot(lam[0], np.cos(kx_plus_ly)) + np.dot(lam[1], np.sin(kx_plus_ly))
    f = f * 2 / np.amax(np.abs(f), axis=1, keepdims=True) + c[:, None]

    # Insert values of fx and fy into the function fe
    u0.vector()[f0_dofs] = f[0]
    u0.vector()[f1_dofs] = f[1]

    return u0, lam, c 
开发者ID:cics-nd,项目名称:ar-pde-cnn,代码行数:35,代码来源:fenics_burgers2d.py

示例7: __apply_mass_matrix

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def __apply_mass_matrix(self, u):
        """
        Routine to apply mass matrix

        Args:
            u (dtype_u): current values

        Returns:
            dtype_u: M*u
        """

        me = self.dtype_u(self.V)
        me.values = df.Function(self.V, self.M * u.values.vector())

        return me 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:17,代码来源:VorticityVelocity_2D_FEniCS_periodic.py

示例8: __init__

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [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 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:62,代码来源:GrayScott_1D_FEniCS_implicit.py

示例9: __init__

# 需要导入模块: import dolfin [as 别名]
# 或者: from dolfin import Function [as 别名]
def __init__(self, problem_params, dtype_u=fenics_mesh, dtype_f=rhs_fenics_mesh):
        """
        Initialization routine

        Args:
            problem_params (dict): custom parameters for the example
            dtype_u: particle data type (will be passed parent class)
            dtype_f: acceleration data type (will be passed 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_imex, 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.u = df.TrialFunction(self.V)
        self.v = df.TestFunction(self.V)
        self.a_K = -self.params.nu * df.inner(df.grad(self.u), df.grad(self.v)) * df.dx

        # mass matrix
        a_M = self.u * self.v * df.dx
        self.M = df.assemble(a_M)

        self.bc = df.DirichletBC(self.V, df.Constant(0.0), Boundary) 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:58,代码来源:HeatEquation_1D_FEniCS_weak_forced.py


注:本文中的dolfin.Function方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。