underworldcode / underworld3

https://underworldcode.github.io/underworld3/
Other
21 stars 10 forks source link

Navier Stokes solver - error when running _setup_pointwise_functions() and smoothing still present in self.Unknowns.DuDt #256

Closed jcgraciosa closed 1 month ago

jcgraciosa commented 1 month ago

When using a Navier Stokes solver with order set to 1, an error occurs when _setup_pointwise_functions() is called (e.g. during solve). To replicate this issue:

import petsc4py
import underworld3 as uw
import sympy

# %%
resolution = 8
vel     = 1.
order = 1

qdeg = 3
Vdeg = 2
Pdeg = Vdeg - 1
Pcont = False

# %%
width   = 1.
height  = 1.

# %%
minX, maxX = 0, width
minY, maxY = 0, height

# %%
meshbox = uw.meshing.UnstructuredSimplexBox( minCoords=(minX, minY), maxCoords=(maxX, maxY), cellSize = 1 / resolution, qdegree = qdeg, regular = False)

# %%
v_soln = uw.discretisation.MeshVariable("U", meshbox, meshbox.dim, degree=Vdeg)
p_soln = uw.discretisation.MeshVariable("P", meshbox, 1, degree=Pdeg, continuous = Pcont)

# %%
navier_stokes = uw.systems.NavierStokesSLCN(
    meshbox,
    velocityField = v_soln,
    pressureField = p_soln,
    rho = 1.,
    verbose=False,
    solver_name="navier_stokes",
    order=order,
)

navier_stokes.constitutive_model = uw.constitutive_models.ViscousFlowModel
navier_stokes.constitutive_model.Parameters.viscosity = 1.

# Velocity boundary conditions
navier_stokes.add_dirichlet_bc((vel, 0.0), "Top")
navier_stokes.add_dirichlet_bc((0.0, 0.0), "Bottom")

# %%
# shows error
navier_stokes.solve(timestep = 0.01, zero_init_guess=True)

# %%
# specific cause of the error
navier_stokes._setup_pointwise_functions(True)

Also, putting this here since it's a minor issue: the self.Unknowns.DuDt still has a non-zero value assigned. I think this was a remnant of some debugging done in the past.

lmoresi commented 1 month ago

That really was a JIT error and I have no idea why the integration order triggers this ! Fixed for now, but we should certainly simplify the JIT and make the debugging more straightforward for users.