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


Python Function.rename方法代码示例

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


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

示例1: visualize

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
  def visualize(self, it=0):
    var = "cell_powers"
    try:
      should_vis = divmod(it, self.parameters["visualization"][var])[1] == 0
    except ZeroDivisionError:
      should_vis = False

    if should_vis:
      if not self.up_to_date[var]:
        self.calculate_cell_powers()
      else:
        qfun = Function(self.DD.V0)
        qfun.vector()[:] = self.E
        qfun.rename("q", "Power")
        self.vis_files["cell_powers"] << (qfun, float(it))

    var = "flux"
    try:
      should_vis = divmod(it, self.parameters["visualization"][var])[1] == 0
    except ZeroDivisionError:
      should_vis = False

    if should_vis:
      if not self.up_to_date[var]:
        self.update_phi()

      for g in xrange(self.DD.G):
        self.vis_files["flux"][g] << (self.phi_mg[g], float(it))
开发者ID:mhanus,项目名称:GOAT,代码行数:30,代码来源:flux_module.py

示例2: expand

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
  def expand(self, f, target = None):
    """
    Takes a function defined on the sub mesh and returns a function
    defined on the super mesh with unknown values set to zero.

    *Arguments*
      f (:class:`dolfin.Function`)
        The function on the sub mesh.

    *Returns*
      The function on the super mesh.
    """

    mapping = self._get_mapping(f.function_space())
    if target is None:
      target = Function(mapping['Vsuper'])
      target.rename(f.name(), f.label())
    target.vector()[mapping['map']] = f.vector().array()
    return target
开发者ID:getzze,项目名称:magnum.fe,代码行数:21,代码来源:wrapped_mesh.py

示例3: cut

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
  def cut(self, f, **kwargs):
    """
    Takes a function defined on the super mesh and returns a truncated
    function defined on the sub mesh.

    *Arguments*
      f (:class:`dolfin.Function`)
        The function on the super mesh.

    *Returns*
      :class:`dolfin.Function`
        The function on the sub mesh.
    """

    mapping = self._get_mapping(f.function_space())
    result = Function(mapping['Vsub'])
    result.vector()[:] = f.vector().array()[mapping['map']]
    result.rename(f.name(), f.label())
    return result
开发者ID:getzze,项目名称:magnum.fe,代码行数:21,代码来源:wrapped_mesh.py

示例4: expand_vp_dolfunc

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
def expand_vp_dolfunc(PrP, vp=None, vc=None, pc=None, pdof=None):
    """expand v and p to the dolfin function representation

    pdof = pressure dof that was set zero
    """

    v = Function(PrP.V)
    p = Function(PrP.Q)

    if vp is not None:
        if vp.ndim == 1:
            vc = vp[:len(PrP.invinds)].reshape(len(PrP.invinds), 1)
            pc = vp[len(PrP.invinds):].reshape(PrP.Q.dim() - 1, 1)
        else:
            vc = vp[:len(PrP.invinds), :]
            pc = vp[len(PrP.invinds):, :]

    ve = np.zeros((PrP.V.dim(), 1))

    # fill in the boundary values
    for bc in PrP.velbcs:
        bcdict = bc.get_boundary_values()
        ve[bcdict.keys(), 0] = bcdict.values()

    ve[PrP.invinds] = vc

    if pdof is None:
        pe = pc
    elif pdof == 0:
        pe = np.vstack([[0], pc])
    elif pdof == -1:
        pe = np.vstack([pc, [0]])
    else:
        pe = np.vstack([pc[:pdof], np.vstack([[0], pc[pdof:]])])

    v.vector().set_local(ve)
    p.vector().set_local(pe)

    v.rename("v", "field")
    p.rename("p", "field")

    return v, p
开发者ID:highlando,项目名称:TayHoodMinExtForFlowEqns,代码行数:44,代码来源:time_int_schemes.py

示例5: __init__

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
  def __init__(self, PD, DD, verbosity):
    """
    Constructor
    :param ProblemData PD: Problem information and various mesh-region <-> xs-material mappings
    :param Discretization DD: Discretization data
    :param int verbosity: Verbosity level.
    """

    super(FluxModule, self).__init__()

    self.verb = verbosity
    self.print_prefix = ""

    self.mat_file_name = dict()

    self.PD = PD
    self.DD = DD
    self.BC = PD.bc

    try:
      self.fixed_source_problem = PD.fixed_source_problem
      self.eigenproblem = PD.eigenproblem
    except AttributeError:
      PD.distribute_material_data(DD.cell_regions, DD.M)

    self.A = PETScMatrix()

    # unused in case of an eigenvalue problem
    self.Q = PETScVector()

    # used only for saving the algebraic system
    self.rows_A = None
    self.cols_A = None
    self.vals_A = None
    self.rows_B = None
    self.cols_B = None
    self.vals_B = None

    if self.fixed_source_problem:
      self.fixed_source = Function(self.DD.V0)
      self.vals_Q = None

    # multigroup scalar fluxes
    self.phi_mg = []
    for g in range(self.DD.G):
      phig = Function(self.DD.Vphi1)
      phig.rename("phi","phi_g{}".format(g))
      self.phi_mg.append(phig)

    self.sln = Function(DD.V)
    self.sln_vec = as_backend_type(self.sln.vector())
    self.local_sln_size = self.sln_vec.local_size()

    # auxiliary function for storing various DG(0) quantities (cross sections, group-integrated reaction rates, etc.)
    self.R = Function(self.DD.V0)

    # fission spectrum
    if 'chi' in self.PD.used_xs:
      self.chi = Function(self.DD.V0)
    else:
      self.chi = None

    if 'eSf' in self.PD.used_xs:
      self.E = numpy.zeros(self.DD.local_ndof0)
    else:
      self.E = None

    self.up_to_date = {"flux" : False, "cell_powers" : False}

    self.bnd_matrix_form = None

    self.parameters = parameters["flux_module"]

    if self.eigenproblem:
      assert self.parameters.has_parameter_set("eigensolver")
      self.eigen_params = self.parameters["eigensolver"]
      self.adaptive_eig_tol_end = 0

      self.B = PETScMatrix()
      self.keff = 1
      self.prev_keff = self.keff
      self.set_initial_approximation(numpy.random.random(self.local_sln_size))
      self.update_phi()

    self.u = TrialFunction(self.DD.V)
    self.v = TestFunction(self.DD.V)

    self.v0 = TestFunction(self.DD.V0)
    self.phig = Function(self.DD.Vphi1) # single group scalar flux
    self.cell_RR_form = self.R * self.phig * self.v0 * dx
    self._cell_RRg_vector = PETScVector()

    self.vis_folder = os.path.join(self.PD.out_folder, "FLUX")

    self.vis_files = dict()
    var = "cell_powers"
    self.vis_files[var] = File(os.path.join(self.vis_folder, var+".pvd"), "compressed")
    var = "flux"
    self.vis_files[var] = [
      File(os.path.join(self.vis_folder, "{}_g{}.pvd".format(var, g)), "compressed") for g in range(self.DD.G)
#.........这里部分代码省略.........
开发者ID:mhanus,项目名称:GOAT,代码行数:103,代码来源:flux_module.py

示例6: test

# 需要导入模块: from dolfin import Function [as 别名]
# 或者: from dolfin.Function import rename [as 别名]
def test(show=False):
    problem = problems.Crucible()
    # The voltage is defined as
    #
    #     v(t) = Im(exp(i omega t) v)
    #          = Im(exp(i (omega t + arg(v)))) |v|
    #          = sin(omega t + arg(v)) |v|.
    #
    # Hence, for a lagging voltage, arg(v) needs to be negative.
    voltages = [
        38.0 * numpy.exp(-1j * 2 * pi * 2 * 70.0 / 360.0),
        38.0 * numpy.exp(-1j * 2 * pi * 1 * 70.0 / 360.0),
        38.0 * numpy.exp(-1j * 2 * pi * 0 * 70.0 / 360.0),
        25.0 * numpy.exp(-1j * 2 * pi * 0 * 70.0 / 360.0),
        25.0 * numpy.exp(-1j * 2 * pi * 1 * 70.0 / 360.0),
    ]

    lorentz, joule, Phi = get_lorentz_joule(problem, voltages, show=show)

    # Some assertions
    ref = 1.4627674791126285e-05
    assert abs(norm(Phi[0], "L2") - ref) < 1.0e-3 * ref
    ref = 3.161363929287592e-05
    assert abs(norm(Phi[1], "L2") - ref) < 1.0e-3 * ref
    #
    ref = 12.115309575057681
    assert abs(norm(lorentz, "L2") - ref) < 1.0e-3 * ref
    #
    ref = 1406.336109054347
    V = FunctionSpace(problem.submesh_workpiece, "CG", 1)
    jp = project(joule, V)
    jp.rename("s", "Joule heat source")
    assert abs(norm(jp, "L2") - ref) < 1.0e-3 * ref

    # check_currents = False
    # if check_currents:
    #     r = SpatialCoordinate(problem.mesh)[0]
    #     begin('Currents computed after the fact:')
    #     k = 0
    #     with XDMFFile('currents.xdmf') as xdmf_file:
    #         for coil in coils:
    #             for ii in coil['rings']:
    #                 J_r = sigma[ii] * (
    #                     voltages[k].real/(2*pi*r) + problem.omega * Phi[1]
    #                     )
    #                 J_i = sigma[ii] * (
    #                     voltages[k].imag/(2*pi*r) - problem.omega * Phi[0]
    #                     )
    #                 alpha = assemble(J_r * dx(ii))
    #                 beta = assemble(J_i * dx(ii))
    #                 info('J = {:e} + i {:e}'.format(alpha, beta))
    #                 info(
    #                     '|J|/sqrt(2) = {:e}'.format(
    #                         numpy.sqrt(0.5 * (alpha**2 + beta**2))
    #                     ))
    #                 submesh = SubMesh(problem.mesh, problem.subdomains, ii)
    #                 V1 = FunctionSpace(submesh, 'CG', 1)
    #                 # Those projections may take *very* long.
    #                 # TODO find out why
    #                 j_v1 = [
    #                     project(J_r, V1),
    #                     project(J_i, V1)
    #                     ]
    #                 # show=Trueplot(j_v1[0], title='j_r')
    #                 # plot(j_v1[1], title='j_i')
    #                 current = project(as_vector(j_v1), V1*V1)
    #                 current.rename('j{}'.format(ii), 'current {}'.format(ii))
    #                 xdmf_file.write(current)
    #                 k += 1
    #     end()

    filename = "./maxwell.xdmf"
    with XDMFFile(filename) as xdmf_file:
        xdmf_file.parameters["flush_output"] = True
        xdmf_file.parameters["rewrite_function_mesh"] = False

        # Store phi
        info("Writing out Phi to {}...".format(filename))
        V = FunctionSpace(problem.mesh, "CG", 1)
        phi = Function(V, name="phi")
        Phi0 = project(Phi[0], V)
        Phi1 = project(Phi[1], V)
        omega = problem.omega
        for t in numpy.linspace(0.0, 2 * pi / omega, num=100, endpoint=False):
            # Im(Phi * exp(i*omega*t))
            phi.vector().zero()
            phi.vector().axpy(sin(problem.omega * t), Phi0.vector())
            phi.vector().axpy(cos(problem.omega * t), Phi1.vector())
            xdmf_file.write(phi, t)

        # Show the resulting magnetic field
        #
        #   B_r = -dphi/dz,
        #   B_z = 1/r d(rphi)/dr.
        #
        r = SpatialCoordinate(problem.mesh)[0]
        g = 1.0 / r * grad(r * Phi[0])
        V_element = FiniteElement("CG", V.mesh().ufl_cell(), 1)
        VV = FunctionSpace(V.mesh(), V_element * V_element)

#.........这里部分代码省略.........
开发者ID:nschloe,项目名称:maelstrom,代码行数:103,代码来源:test_maxwell.py


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