Skip to content

Commit

Permalink
Merge pull request #707 from evalf/misc-units
Browse files Browse the repository at this point in the history
add support for arrays with scale to several functions
  • Loading branch information
joostvanzwieten authored Sep 1, 2022
2 parents 6f7127f + e1192c1 commit 941811e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nutils/expression_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def define_for(self, __name: str, *, gradient: Optional[str] = None, curl: Optio
raise ValueError('The curl can only be defined for a geometry with shape (3,) but got {}.'.format(numpy.shape(geom)))
# Definition: `curl_ki(u_...)` := `ε_kji ∇_j(u_...)`. Should be used as
# `curl_ki(u_i)`, which is equivalent to `ε_kji ∇_j(u_i)`.
setattr(self, curl, lambda arg: (function.levicivita(3) * function.grad(arg, geom)[..., numpy.newaxis, :, numpy.newaxis]).sum(-2))
setattr(self, curl, lambda arg: numpy.sum(function.levicivita(3) * function.grad(arg, geom)[..., numpy.newaxis, :, numpy.newaxis], axis=-2))
if normal:
setattr(self, normal, function.normal(geom))
for i, jacobian in enumerate(jacobians):
Expand Down
10 changes: 4 additions & 6 deletions nutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,10 +1976,10 @@ def opposite(__arg: IntoArray) -> Array:
:func:`jump` : the jump at an interface
'''

arg = Array.cast(__arg)
arg, scale = Array.cast_withscale(__arg)
for space in sorted(arg.spaces):
arg = _Opposite(arg, space)
return arg
return arg * scale


def mean(__arg: IntoArray) -> Array:
Expand Down Expand Up @@ -2009,8 +2009,7 @@ def mean(__arg: IntoArray) -> Array:
array([ 1.5])
'''

arg = Array.cast(__arg)
return .5 * (arg + opposite(arg))
return .5 * (__arg + opposite(__arg))


def jump(__arg: IntoArray) -> Array:
Expand Down Expand Up @@ -2046,8 +2045,7 @@ def jump(__arg: IntoArray) -> Array:
array([ 1.])
'''

arg = Array.cast(__arg)
return opposite(arg) - arg
return opposite(__arg) - __arg

# REDUCTION

Expand Down
7 changes: 4 additions & 3 deletions nutils/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ def get_evaluable_indices(self, ielem: evaluable.Array) -> evaluable.Array:
return evaluable.Range(npoints) + offset

def __call__(self, __func: function.IntoArray) -> function.Array:
return _ConcatenatePoints(function.Array.cast(__func), self)
func, funcscale = function.Array.cast_withscale(__func)
return _ConcatenatePoints(func, self) * funcscale


class _CustomIndex(_TransformChainsSample):
Expand Down Expand Up @@ -538,8 +539,8 @@ def integral(self, __func: function.IntoArray) -> function.Array:
return function.zeros(func.shape, func.dtype)

def __call__(self, __func: function.IntoArray) -> function.Array:
func = function.Array.cast(__func)
return function.zeros((0, *func.shape), func.dtype)
func, funcscale = function.Array.cast_withscale(__func)
return function.zeros((0, *func.shape), func.dtype) * funcscale

def basis(self) -> function.Array:
return function.zeros((0,), float)
Expand Down

0 comments on commit 941811e

Please sign in to comment.