Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor update to first two Nutils examples #273

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions flow-over-heated-plate/solid-nutils/solid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python3

import nutils
from nutils import cli, mesh, function, solver, export
import treelog
import numpy as np
import precice
Expand All @@ -9,14 +9,14 @@

def main():

print("Running utils")
print("Running nutils")

# define the Nutils mesh
grid = [np.linspace(a, b, round((b - a) / size) + 1) for (a, b, size) in [(0, 1, 0.05), (-.25, 0, 0.05)]]
domain, geom = nutils.mesh.rectilinear(grid)
domain, geom = mesh.rectilinear(grid)

# Nutils namespace
ns = nutils.function.Namespace()
ns = function.Namespace()
ns.x = geom

ns.basis = domain.basis('std', degree=1) # linear finite elements
Expand All @@ -31,7 +31,7 @@ def main():

# define Dirichlet boundary condition
sqr = domain.boundary['bottom'].integral('(u - uwall)^2 d:x' @ ns, degree=2)
cons = nutils.solver.optimize('lhs', sqr, droptol=1e-15)
cons = solver.optimize('lhs', sqr, droptol=1e-15)

# preCICE setup
interface = precice.Interface("Solid", "../precice-config.xml", 0, 1)
Expand Down Expand Up @@ -63,11 +63,11 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)

# set u = uwall as initial condition and visualize
sqr = domain.integral('(u - uwall)^2' @ ns, degree=2)
lhs0 = nutils.solver.optimize('lhs', sqr)
lhs0 = solver.optimize('lhs', sqr)
bezier = domain.sample('bezier', 2)
x, u = bezier.eval(['x_i', 'u'] @ ns, lhs=lhs0)
with treelog.add(treelog.DataLog()):
nutils.export.vtk('Solid_0', bezier.tri, x, T=u)
export.vtk('Solid_0', bezier.tri, x, T=u)

while interface.is_coupling_ongoing():

Expand All @@ -77,7 +77,7 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
temperature_function = coupling_sample.asfunction(temperature_values)

sqr = coupling_sample.integral((ns.u - temperature_function)**2)
cons = nutils.solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0)
cons = solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0)

# save checkpoint
if interface.is_action_required(precice.action_write_iteration_checkpoint()):
Expand All @@ -89,7 +89,7 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
dt = min(dt, precice_dt)

# solve nutils timestep
lhs = nutils.solver.solve_linear('lhs', res, constrain=cons, arguments=dict(lhs0=lhs0, dt=dt))
lhs = solver.solve_linear('lhs', res, constrain=cons, arguments=dict(lhs0=lhs0, dt=dt))

# write heat fluxes to interface
if interface.is_write_data_required(dt):
Expand All @@ -114,10 +114,10 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
bezier = domain.sample('bezier', 2)
x, u = bezier.eval(['x_i', 'u'] @ ns, lhs=lhs)
with treelog.add(treelog.DataLog()):
nutils.export.vtk('Solid_' + str(timestep), bezier.tri, x, T=u)
export.vtk('Solid_' + str(timestep), bezier.tri, x, T=u)

interface.finalize()


if __name__ == '__main__':
nutils.cli.run(main)
cli.run(main)
21 changes: 10 additions & 11 deletions partitioned-heat-conduction/nutils/heat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python3

import nutils
from nutils import cli, mesh, function, solver, export
import treelog
import numpy as np
import precice
Expand All @@ -27,10 +27,10 @@ def main(side='Dirichlet'):
y_grid = np.linspace(y_bottom, y_top, n)

# define the Nutils mesh
domain, geom = nutils.mesh.rectilinear([x_grid, y_grid])
domain, geom = mesh.rectilinear([x_grid, y_grid])

# Nutils namespace
ns = nutils.function.Namespace()
ns = function.Namespace()
ns.x = geom

degree = 1 # linear finite elements
Expand Down Expand Up @@ -96,11 +96,11 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)

# initial condition
sqr = domain.integral('(u - uexact)^2' @ ns, degree=degree * 2)
lhs0 = nutils.solver.optimize('lhs', sqr, droptol=1e-15, arguments=dict(t=t))
lhs0 = solver.optimize('lhs', sqr, droptol=1e-15, arguments=dict(t=t))
bezier = domain.sample('bezier', degree * 2)
x, u, uexact = bezier.eval(['x_i', 'u', 'uexact'] @ ns, lhs=lhs0, t=t)
with treelog.add(treelog.DataLog()):
nutils.export.vtk(side + '-0', bezier.tri, x, Temperature=u, reference=uexact)
export.vtk(side + '-0', bezier.tri, x, Temperature=u, reference=uexact)

t += precice_dt
timestep = 0
Expand All @@ -109,7 +109,7 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
while interface.is_coupling_ongoing():

# update (time-dependent) boundary condition
cons0 = nutils.solver.optimize('lhs', sqr0, droptol=1e-15, arguments=dict(t=t))
cons0 = solver.optimize('lhs', sqr0, droptol=1e-15, arguments=dict(t=t))

# read data from interface
if interface.is_read_data_available():
Expand All @@ -118,7 +118,7 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)

if side == 'Dirichlet':
sqr = coupling_sample.integral((ns.u - read_function)**2)
cons = nutils.solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0, arguments=dict(t=t))
cons = solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0, arguments=dict(t=t))
res = res0
else:
cons = cons0
Expand All @@ -135,7 +135,7 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
dt = min(dt, precice_dt)

# solve nutils timestep
lhs = nutils.solver.solve_linear('lhs', res, constrain=cons, arguments=dict(lhs0=lhs0, dt=dt, t=t))
lhs = solver.solve_linear('lhs', res, constrain=cons, arguments=dict(lhs0=lhs0, dt=dt, t=t))

# write data to interface
if interface.is_write_data_required(dt):
Expand Down Expand Up @@ -166,10 +166,9 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
x, u, uexact = bezier.eval(['x_i', 'u', 'uexact'] @ ns, lhs=lhs, t=t)

with treelog.add(treelog.DataLog()):
nutils.export.vtk(side + "-" + str(timestep), bezier.tri, x, Temperature=u, reference=uexact)
export.vtk(side + "-" + str(timestep), bezier.tri, x, Temperature=u, reference=uexact)

interface.finalize()


if __name__ == '__main__':
nutils.cli.run(main)
cli.run(main)