Beispiel #1
0
 def __dataop__(self, other, linear_if_scalar, data_operator):
     if isinstance(other, StaggeredGrid):
         assert self.compatible(
             other), 'Fields are not compatible: %s and %s' % (self, other)
         data = [
             data_operator(c1, c2) for c1, c2 in zip(self.data, other.data)
         ]
         flags = propagate_flags_operation(self.flags + other.flags, False,
                                           self.rank, self.component_count)
     elif math.ndims(other) > 0 and math.staticshape(other)[-1] > 1:
         other_components = math.unstack(math.as_tensor(other),
                                         axis=-1,
                                         keepdims=True)
         data = [
             data_operator(c1, c2)
             for c1, c2 in zip(self.data, other_components)
         ]
         flags = propagate_flags_operation(self.flags, False, self.rank,
                                           self.component_count)
     else:
         data = [data_operator(c1, other) for c1 in self.data]
         flags = propagate_flags_operation(self.flags, linear_if_scalar,
                                           self.rank, self.component_count)
     return self.copied_with(data=np.array(data, dtype=np.object),
                             flags=flags)
Beispiel #2
0
 def resolution(self):
     if self.content_type in (struct.VALID, struct.INVALID):
         return math.as_tensor(math.staticshape(self.data)[1:-1])
     elif self.content_type in (struct.shape, struct.staticshape):
         return self.data[1:-1]
     else:
         raise AssertionError(
             'Cannot compute resolution of invalid CenteredGrid (content type = %s)'
             % self.content_type)
Beispiel #3
0
def buoyancy(density, gravity, buoyancy_factor):
    """
Computes the buoyancy force proportional to the density.
    :param density: CenteredGrid
    :param gravity: vector or float
    :param buoyancy_factor: float
    :return: StaggeredGrid for the domain of the density
    """
    if isinstance(gravity, (int, float)):
        gravity = math.to_float(math.as_tensor([gravity] + ([0] * (density.rank - 1))))
    result = StaggeredGrid.from_scalar(density, -gravity * buoyancy_factor)
    return result
Beispiel #4
0
def buoyancy(density, gravity, buoyancy_factor):
    """
Computes the buoyancy force proportional to the density.
    :param density: CenteredGrid
    :param gravity: vector or float
    :param buoyancy_factor: float
    :return: StaggeredGrid for the domain of the density
    """
    warnings.warn(
        'buoyancy() is deprecated. Use (density * -gravity * buoyancy_factor).at(target_grid) instead.',
        DeprecationWarning)
    if isinstance(gravity, (int, float)):
        gravity = math.to_float(
            math.as_tensor([gravity] + ([0] * (density.rank - 1))))
    result = StaggeredGrid.from_scalar(density, -gravity * buoyancy_factor)
    return result
Beispiel #5
0
 def resolution(self):
     return math.as_tensor(math.staticshape(self.data)[1:-1])
Beispiel #6
0
 def upper(self, upper):
     return math.to_float(math.as_tensor(upper))
Beispiel #7
0
 def lower(self, lower):
     return math.to_float(math.as_tensor(lower))
Beispiel #8
0
 def center(self, center):
     return math.as_tensor(center)
Beispiel #9
0
 def radius(self, radius):
     return math.as_tensor(radius)