Ejemplo n.º 1
0
 def as_coordinates(self):
     theta, phi = self._make_local_axes()
     if self.theta_phi:
         crds = viscid.wrap_crds("nonuniform_cartesian",
                                 (('x', theta), ('y', phi)))
     else:
         crds = viscid.wrap_crds("nonuniform_cartesian",
                                 (('x', phi), ('y', theta)))
     return crds
Ejemplo n.º 2
0
 def as_uv_coordinates(self):
     theta, phi = self._make_uv_axes()
     if self.theta_phi:
         crds = viscid.wrap_crds("nonuniform_spherical",
                                 (('theta', theta), ('phi', phi)),
                                 units="rad")
     else:
         crds = viscid.wrap_crds("nonuniform_spherical",
                                 (('phi', phi), ('theta', theta)),
                                 units="rad")
     return crds
Ejemplo n.º 3
0
 def as_uv_coordinates(self):
     theta, phi = self._make_uv_axes()
     if self.theta_phi:
         crds = viscid.wrap_crds("nonuniform_spherical",
                                 (('theta', theta), ('phi', phi)),
                                 units="rad")
     else:
         crds = viscid.wrap_crds("nonuniform_spherical",
                                 (('phi', phi), ('theta', theta)),
                                 units="rad")
     return crds
Ejemplo n.º 4
0
def get_trilinear_field():
    """get a generic trilinear field"""
    xl, xh, nx = -1.0, 1.0, 41
    yl, yh, ny = -1.5, 1.5, 41
    zl, zh, nz = -2.0, 2.0, 41
    x = np.linspace(xl, xh, nx)
    y = np.linspace(yl, yh, ny)
    z = np.linspace(zl, zh, nz)
    crds = viscid.wrap_crds("nonuniform_cartesian",
                            [('x', x), ('y', y), ('z', z)])
    b = viscid.empty(crds, name="f", nr_comps=3, center="Cell",
                     layout="interlaced")
    X, Y, Z = b.get_crds(shaped=True)

    x01, y01, z01 = 0.5, 0.5, 0.5
    x02, y02, z02 = 0.5, 0.5, 0.5
    x03, y03, z03 = 0.5, 0.5, 0.5

    b['x'][:] = (0.0 + 1.0 * (X - x01) + 1.0 * (Y - y01) + 1.0 * (Z - z01) +
                 1.0 * (X - x01) * (Y - y01) + 1.0 * (Y - y01) * (Z - z01) +
                 1.0 * (X - x01) * (Y - y01) * (Z - z01))
    b['y'][:] = (0.0 + 1.0 * (X - x02) - 1.0 * (Y - y02) + 1.0 * (Z - z02) +
                 1.0 * (X - x02) * (Y - y02) + 1.0 * (Y - y02) * (Z - z02) -
                 1.0 * (X - x02) * (Y - y02) * (Z - z02))
    b['z'][:] = (0.0 + 1.0 * (X - x03) + 1.0 * (Y - y03) - 1.0 * (Z - z03) +
                 1.0 * (X - x03) * (Y - y03) + 1.0 * (Y - y03) * (Z - z03) +
                 1.0 * (X - x03) * (Y - y03) * (Z - z03))
    return b
Ejemplo n.º 5
0
def get_trilinear_field():
    """get a generic trilinear field"""
    xl, xh, nx = -1.0, 1.0, 41
    yl, yh, ny = -1.5, 1.5, 41
    zl, zh, nz = -2.0, 2.0, 41
    x = np.linspace(xl, xh, nx)
    y = np.linspace(yl, yh, ny)
    z = np.linspace(zl, zh, nz)
    crds = viscid.wrap_crds("nonuniform_cartesian", [('x', x), ('y', y),
                                                     ('z', z)])
    b = viscid.empty(crds,
                     name="f",
                     nr_comps=3,
                     center="Cell",
                     layout="interlaced")
    X, Y, Z = b.get_crds(shaped=True)

    x01, y01, z01 = 0.5, 0.5, 0.5
    x02, y02, z02 = 0.5, 0.5, 0.5
    x03, y03, z03 = 0.5, 0.5, 0.5

    b['x'][:] = (0.0 + 1.0 * (X - x01) + 1.0 * (Y - y01) + 1.0 * (Z - z01) +
                 1.0 * (X - x01) * (Y - y01) + 1.0 * (Y - y01) * (Z - z01) +
                 1.0 * (X - x01) * (Y - y01) * (Z - z01))
    b['y'][:] = (0.0 + 1.0 * (X - x02) - 1.0 * (Y - y02) + 1.0 * (Z - z02) +
                 1.0 * (X - x02) * (Y - y02) + 1.0 * (Y - y02) * (Z - z02) -
                 1.0 * (X - x02) * (Y - y02) * (Z - z02))
    b['z'][:] = (0.0 + 1.0 * (X - x03) + 1.0 * (Y - y03) - 1.0 * (Z - z03) +
                 1.0 * (X - x03) * (Y - y03) + 1.0 * (Y - y03) * (Z - z03) +
                 1.0 * (X - x03) * (Y - y03) * (Z - z03))
    return b
Ejemplo n.º 6
0
 def as_local_coordinates(self):
     pts_local = np.linspace(0.0, 1.0, self.n, endpoint=True)
     x = self.to_3d(pts_local)
     dx = x[:, 1:] - x[:, :-1]
     ds = np.zeros_like(x[0])
     ds[1:] = np.linalg.norm(dx, axis=0)
     s = np.cumsum(ds)
     crd = viscid.wrap_crds("nonuniform_cartesian", (('s', s),))
     return crd
Ejemplo n.º 7
0
 def as_local_coordinates(self):
     pts_local = np.linspace(0.0, 1.0, self.n, endpoint=True)
     x = self.to_3d(pts_local)
     dx = x[:, 1:] - x[:, :-1]
     ds = np.zeros_like(x[0])
     ds[1:] = np.linalg.norm(dx, axis=0)
     s = np.cumsum(ds)
     crd = viscid.wrap_crds("nonuniform_cartesian", (('s', s),))
     return crd
Ejemplo n.º 8
0
def extend_boundaries(fld, nl=1, nh=1, axes='all', nr_comp=None, order=1,
                      crd_order=1, crds=None):
    """Extend and pad boundaries of field (leaves new corners @ 0.0)

    Warning:
        When using crd_order=0 (0 order hold), coordinates will be
        extended by repeating boundary values, so min_dx will be 0.
        Keep this in mind if dividing by dx.

    Args:
        fld (Field): Field to extend
        nl (int): extend this many cells in lower direction
        nh (int): extend this many cells in upper direction
        axes (str, list): something like 'xyz', ['x', 'theta'], etc.
        nr_comp (int, None): index of shape that corresponds to vector
            component dimension
        order (int): extrapolation order for data; 0 for repeating
            boundary values or 1 for linear extrapolation
        crd_order (int): extrapolation order for crds; 0 for repeating
            boundary values or 1 for linear extrapolation
        crds (Coordinates): Use these coordinates, no extrapolate them

    Returns:
        ndarray: A new extended / padded ndarray
    """
    arr_axes = fld.crds.axes
    axis_lookup = dict()
    for i, ax in enumerate(arr_axes):
        axis_lookup[i] = i
        axis_lookup[ax] = i
    if axes == 'all':
        axes = list([i for i, s in enumerate(fld.sshape) if s > 1])
    if not isinstance(axes, (list, tuple, viscid.string_types)):
        axes = list(axes)
    axes = [axis_lookup[ax] for ax in axes]

    try:
        nr_comp = fld.nr_comp
    except TypeError:
        nr_comp = None

    new_dat = extend_boundaries_ndarr(fld.data, nl=nl, nh=nh, axes=axes,
                                      nr_comp=nr_comp, order=order)

    if crds is not None:
        new_crds = crds
    else:
        new_clist = []
        crds_nc = fld.crds.get_crds_nc()
        crds_cc = fld.crds.get_crds_cc()
        for ax, nc, cc in zip(fld.crds.axes, crds_nc, crds_cc):
            if fld.crds.axes.index(ax) in axes:
                new_nc = extend_boundaries_ndarr(nc, nl=nl, nh=nh, axes=[0],
                                                 order=crd_order)
                new_cc = extend_boundaries_ndarr(cc, nl=nl, nh=nh, axes=[0],
                                                 order=crd_order)
            else:
                new_nc = nc
                new_cc = cc
            new_clist.append((ax, new_nc, new_cc))

        crdtype = fld.crds.crdtype
        if 'nonuniform' not in crdtype:
            crdtype = crdtype.replace('uniform', 'nonuniform')
        new_crds = viscid.wrap_crds(crdtype, new_clist)

    return fld.wrap(new_dat, context=dict(crds=new_crds))
Ejemplo n.º 9
0
 def as_local_coordinates(self):
     x, y, z = self._make_local_axes()
     crd = viscid.wrap_crds("nonuniform_cartesian",
                            (('x', x), ('y', y), ('z', z)))
     return crd
Ejemplo n.º 10
0
 def as_uv_coordinates(self):
     alpha, beta = self._make_uv_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian",
                             (('x', alpha), ('y', beta)))
     return crds
Ejemplo n.º 11
0
 def as_local_coordinates(self):
     l, m, n = self._make_local_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', l), ('y', m),
                                                      ('z', n)))
     return crds
Ejemplo n.º 12
0
 def as_uv_coordinates(self):
     x, y = self._make_uv_axes()
     crd = viscid.wrap_crds("nonuniform_cartesian",
                            (('x', x), ('y', y)))
     return crd
Ejemplo n.º 13
0
 def as_local_coordinates(self):
     dp = self.p1 - self.p0
     dist = np.sqrt(np.dot(dp, dp))
     x = np.linspace(0.0, dist, self.n)
     crd = viscid.wrap_crds("nonuniform_cartesian", (('x', x),))
     return crd
Ejemplo n.º 14
0
 def as_uv_coordinates(self):
     l, m = self._make_uv_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', l), ('y', m)))
     return crds
Ejemplo n.º 15
0
 def as_uv_coordinates(self):
     alpha, beta = self._make_uv_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian",
                             (('x', alpha), ('y', beta)))
     return crds
Ejemplo n.º 16
0
 def as_local_coordinates(self):
     x = self._make_local_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', x), ))
     return crds
Ejemplo n.º 17
0
def extend_boundaries(fld, nl=1, nh=1, axes='all', nr_comp=None, order=1,
                      crd_order=1, crds=None, invarient_dx=0.0,
                      crd_invarient_dx=1.0):
    """Extend and pad boundaries of field (leaves new corners @ 0.0)

    Args:
        fld (Field): Field to extend
        nl (int): extend this many cells in lower direction
        nh (int): extend this many cells in upper direction
        axes (str, list): something like 'xyz', ['x', 'theta'], etc.
        nr_comp (int, None): index of shape that corresponds to vector
            component dimension
        order (int): extrapolation order for data; 0 for repeating
            boundary values or 1 for linear extrapolation
        crd_order (int): extrapolation order for crds; 0 for repeating
            boundary values or 1 for linear extrapolation
        crds (Coordinates): Use these coordinates, no extrapolate them
        invarient_dx (float): if fld has a single cell in a given
            dimension, and order == 1, the field is extended with
            constant dx, using 0 here is synonymous with 0th order
        invarient_dx (float): if fld has a single cell in a given
            dimension, and crd_order == 1, the coordinates in that
            dimension are extended with constant dx, using 0 here is
            synonymous with crd_order = 0.

    Returns:
        ndarray: A new extended / padded ndarray

    Warning:
        When using crd_order=0 (0 order hold), coordinates will be
        extended by repeating boundary values, so min_dx will be 0.
        Keep this in mind if dividing by dx.
    """
    arr_axes = fld.crds.axes
    axis_lookup = dict()
    for i, ax in enumerate(arr_axes):
        axis_lookup[i] = i
        axis_lookup[ax] = i
    if axes == 'all':
        axes = list([i for i, s in enumerate(fld.sshape)])
    if not isinstance(axes, (list, tuple, viscid.string_types)):
        axes = list(axes)
    axes = [axis_lookup[ax] for ax in axes]

    try:
        nr_comp = fld.nr_comp
    except TypeError:
        nr_comp = None

    new_dat = extend_boundaries_ndarr(fld.data, nl=nl, nh=nh, axes=axes,
                                      nr_comp=nr_comp, order=order,
                                      invarient_dx=invarient_dx)

    if crds is not None:
        new_crds = crds
    else:
        new_clist = []
        crds_nc = fld.crds.get_crds_nc()
        crds_cc = fld.crds.get_crds_cc()
        for ax, nc, cc in zip(fld.crds.axes, crds_nc, crds_cc):
            if fld.crds.axes.index(ax) in axes:
                new_nc = extend_boundaries_ndarr(nc, nl=nl, nh=nh, axes=[0],
                                                 order=crd_order,
                                                 invarient_dx=crd_invarient_dx)
                new_cc = extend_boundaries_ndarr(cc, nl=nl, nh=nh, axes=[0],
                                                 order=crd_order,
                                                 invarient_dx=crd_invarient_dx)
            else:
                new_nc = nc
                new_cc = cc
            new_clist.append((ax, new_nc, new_cc))

        crdtype = fld.crds.crdtype
        if 'nonuniform' not in crdtype:
            crdtype = crdtype.replace('uniform', 'nonuniform')
        new_crds = viscid.wrap_crds(crdtype, new_clist)

    return fld.wrap(new_dat, context=dict(crds=new_crds))
Ejemplo n.º 18
0
 def as_local_coordinates(self):
     x = self._make_local_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', x), ))
     return crds
Ejemplo n.º 19
0
 def as_local_coordinates(self):
     dp = self.p1 - self.p0
     dist = np.sqrt(np.dot(dp, dp))
     x = np.linspace(0.0, dist, self.n)
     crd = viscid.wrap_crds("nonuniform_cartesian", (('x', x),))
     return crd
Ejemplo n.º 20
0
 def as_local_coordinates(self):
     x, y, z = self._make_local_axes()
     crd = viscid.wrap_crds("nonuniform_cartesian",
                            (('x', x), ('y', y), ('z', z)))
     return crd
Ejemplo n.º 21
0
 def as_uv_coordinates(self):
     x, y = self._make_uv_axes()
     crd = viscid.wrap_crds("nonuniform_cartesian",
                            (('x', x), ('y', y)))
     return crd
Ejemplo n.º 22
0
 def as_local_coordinates(self):
     l, m, n = self._make_local_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', l), ('y', m),
                                                      ('z', n)))
     return crds
Ejemplo n.º 23
0
 def as_uv_coordinates(self):
     l, m = self._make_uv_axes()
     crds = viscid.wrap_crds("nonuniform_cartesian", (('x', l), ('y', m)))
     return crds