Skip to content

Commit

Permalink
arguments_for wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjanvanzwieten committed Feb 3, 2025
1 parent 4630119 commit 70b4a40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/drivencavity.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def main(nelems: int = 32,
# strong enforcement of non-penetrating boundary conditions
sqr = domain.boundary.integral('(u_k n_k)^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)
cons['p'] = numpy.zeros(res.argshapes['p'], dtype=bool)
cons['p'] = numpy.zeros(function.arguments_for(res)['p'].shape, dtype=bool)
cons['p'].flat[0] = True # point constraint

if strongbc:
Expand Down Expand Up @@ -158,7 +158,7 @@ def postprocess(domain, ns, **arguments):

# reconstruct velocity streamlines
sqr = domain.integral('Σ_i (u_i - ε_ij ∇_j(ψ))^2 dV' @ ns, degree=4)
consψ = numpy.zeros(sqr.argshapes['ψ'], dtype=bool)
consψ = numpy.zeros(function.arguments_for(sqr)['ψ'].shape, dtype=bool)
consψ.flat[0] = True # point constraint
arguments = System(sqr, trial='ψ').solve(arguments=arguments, constrain={'ψ': consψ})

Expand Down
5 changes: 5 additions & 0 deletions nutils/SI.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ def __field(op, *args, **kwargs):
dims, args = zip(*Quantity.__unpack(*args)) # we abuse the fact that unpack str returns dimensionless
return functools.reduce(operator.mul, dims).wrap(op(*args, **kwargs))

@register('arguments')
def __attribute(op, *args, **kwargs):
__dims, args = zip(*Quantity.__unpack(*args))
return op(*args, **kwargs)

Check warning on line 417 in nutils/SI.py

View workflow job for this annotation

GitHub Actions / Test coverage

Lines not covered

Lines 416–417 of `nutils/SI.py` are not covered by tests.

del register

## DEFINE OPERATORS
Expand Down
15 changes: 15 additions & 0 deletions nutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,21 @@ def lower(self, args: LowerArgs) -> evaluable.Array:
return evaluable.prependaxes(self._array, args.points_shape)


@nutils_dispatch
def arguments_for(*arrays):
arguments = {}
for array in arrays:
for name, (shape, dtype) in array.arguments.items():
argument = arguments.get(name)
if argument is None:
arguments[name] = Argument(name, shape, dtype)
elif argument.shape != shape:
raise ValueError(f'inconsistent shapes for argument {name!r}')
elif argument.dtype != dtype:
raise ValueError(f'inconsistent dtypes for argument {name!r}')
return arguments

Check warning on line 2429 in nutils/function.py

View workflow job for this annotation

GitHub Actions / Test coverage

Lines not covered

Lines 2419–2429 of `nutils/function.py` are not covered by tests.


# BASES


Expand Down

0 comments on commit 70b4a40

Please sign in to comment.