Skip to content

Commit f35575c

Browse files
Convert turek example to nutils.units
1 parent 0e9e237 commit f35575c

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

examples/turek.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from nutils import cli, export, function, testing
22
from nutils.mesh import gmsh
33
from nutils.solver import System
4-
from nutils.SI import Length, Density, Viscosity, Velocity, Time, Pressure, Acceleration
4+
try:
5+
from nutils.units.typing import Length, Density, Viscosity, Velocity, Time, Pressure, Acceleration
6+
except ModuleNotFoundError as e:
7+
if hasattr(e, 'add_note'):
8+
e.add_note("Consider installing the units package via: pip install nutils-units")
9+
raise
510
from nutils.expression_v2 import Namespace
611
from collections import defaultdict, deque
712
from dataclasses import dataclass
@@ -221,7 +226,7 @@ def main(domain: Domain = Domain(), solid: Optional[Solid] = Solid(), fluid: Opt
221226
if dynamic:
222227
ns.v, ns.a = dynamic.newmark_defo(ns.d)
223228
else:
224-
ns.a = Acceleration.wrap(function.zeros((2,)))
229+
ns.a = numpy.repeat(Acceleration.zero, 2)
225230

226231
# Deformed geometry
227232
ns.x_i = 'xref_i + d_i'
@@ -260,8 +265,8 @@ def main(domain: Domain = Domain(), solid: Optional[Solid] = Solid(), fluid: Opt
260265
else: # fully rigid solid
261266

262267
ns.x = ns.xref
263-
ns.v = Velocity.wrap(function.zeros((2,)))
264-
ns.a = Acceleration.wrap(function.zeros((2,)))
268+
ns.v = numpy.repeat(Velocity.zero, 2)
269+
ns.a = numpy.repeat(Acceleration.zero, 2)
265270

266271
if fluid:
267272

@@ -339,7 +344,7 @@ def main(domain: Domain = Domain(), solid: Optional[Solid] = Solid(), fluid: Opt
339344

340345
DL = uxy = None # for unit tests only
341346

342-
for t in log.iter.fraction('timestep', dynamic.times) if dynamic else [Time.wrap(float('inf'))]:
347+
for t in log.iter.fraction('timestep', dynamic.times) if dynamic else [Time.zero * float('inf')]:
343348

344349
if dynamic:
345350
if solid:

0 commit comments

Comments
 (0)