Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
43 changes: 34 additions & 9 deletions UM2N/generator/burgers_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import movement as mv
import numpy as np # noqa

from firedrake.__future__ import interpolate # ej321 add

__all__ = ["BurgersSolver"]


Expand Down Expand Up @@ -203,6 +205,9 @@ def solve_problem(self, callback=None):
monitor_function=self.monitor_function,
rtol=1e-3,
)
# ej321 - added monitor_function for feature extraction
raw_monitor_val = self.monitor_function(self.mesh) # ej321 - is this the correct mesh to use?

adapter.move()
end = time.perf_counter()
dur_ms = (end - start) * 1000
Expand All @@ -216,6 +221,10 @@ def solve_problem(self, callback=None):
function_space = fd.FunctionSpace(self.mesh, "CG", 1)
uh_0 = fd.Function(function_space)
uh_0.project(self.u[0])

# ej321 - added monitor_function for feature extraction
monitor_val = fd.Function(function_space)
monitor_val.assign(raw_monitor_val)

# calculate solution on adapted mesh
self.mesh.coordinates.dat.data[:] = self.adapt_coord
Expand All @@ -240,27 +249,42 @@ def solve_problem(self, callback=None):

func_vec_space = fd.VectorFunctionSpace(self.mesh, "CG", 1)
uh_grad = fd.interpolate(fd.grad(uh_0), func_vec_space)

# ej321 - grad_norm copied from build_helmholtz_square.py
grad_uh_interpolate = fd.assemble(interpolate(fd.grad(self.u[0]),func_vec_space))
grad_norm = fd.Function(function_space)
grad_norm.project(grad_uh_interpolate[0] ** 2 + grad_uh_interpolate[1] ** 2)
grad_norm /= grad_norm.vector().max()

hessian_norm = self.f_norm
hessian = self.l2_projection
phi = adapter.phi
phi_grad = adapter.grad_phi
sigma = adapter.sigma
# sigma = adapter.sigma
sigma = adapter.H # ej321 - this may be the updated hessian?
I = fd.Identity(2) # noqa
jacobian = I + sigma
jacobian_det = fd.Function(function_space, name="jacobian_det")
jacobian_det.project(
# jacobian_det = fd.Function(function_space, name="jacobian_det")
# jacobian_det = fd.Function(adapter.P1, name="jacobian_det")
self.jacob_det = fd.Function(adapter.P1, name="jacobian_det").project(
jacobian[0, 0] * jacobian[1, 1] - jacobian[0, 1] * jacobian[1, 0]
)
self.jacob_det = fd.project(
jacobian_det, fd.FunctionSpace(self.mesh, "CG", 1)
)
self.jacob = fd.project(
jacobian, fd.TensorFunctionSpace(self.mesh, "CG", 1)
)
# self.jacob_det = jacobian_det
# self.jacob_det = fd.project(
# jacobian_det, fd.FunctionSpace(self.mesh, "CG", 1)
# ) # ej321 - not needed?
# self.jacob = jacobian # ej321 - this is copied from mesh_generator.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid commented out code - it makes diffs very hard to read. Also, old versions can always be deduced from the revision history.

self.jacob = fd.Function(adapter.P1_ten, name="jacobian").project(jacobian)
# self.jacob.project(jacobian)
# self.jacob = fd.project(
# jacobian, fd.TensorFunctionSpace(self.mesh, "CG", 1)
# ) # ej321 - not needed?


callback(
uh=uh_0,
uh_grad=uh_grad,
grad_norm = grad_norm, # ej321 - added grad_norm
hessian_norm=hessian_norm,
hessian=hessian,
phi=phi,
Expand All @@ -280,6 +304,7 @@ def solve_problem(self, callback=None):
dur=dur_ms,
t=t,
idx=self.idx,
monitor_val=monitor_val, # ej321 - added monitor_val
)

# step forward in time
Expand Down
3 changes: 2 additions & 1 deletion UM2N/generator/mesh_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def move_mesh(self):
)
mover.move()
# extract Hessian of the movement
sigma = mover.sigma
# sigma = mover.sigma
sigma = mover.H # ej321 - this may be the updated hessian?
I = fd.Identity(2) # noqa
jacobian = I + sigma
jacobian_det = fd.Function(mover.P1, name="jacobian_det")
Expand Down
29 changes: 18 additions & 11 deletions UM2N/generator/swirl_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,19 +660,24 @@ def solve_problem(self, callback=None, fail_callback=None):
hessian = self.l2_projection
phi = adapter.phi
phi_grad = adapter.grad_phi
sigma = adapter.sigma
# sigma = adapter.sigma
sigma = adapter.H # ej321 - this may be the updated hessian?
I = fd.Identity(2) # noqa
jacobian = I + sigma
jacobian_det = fd.Function(function_space, name="jacobian_det")
jacobian_det.project(
jacobian[0, 0] * jacobian[1, 1] - jacobian[0, 1] * jacobian[1, 0]
)
self.jacob_det = fd.project(
jacobian_det, fd.FunctionSpace(self.mesh, "CG", 1)
)
self.jacob = fd.project(
jacobian, fd.TensorFunctionSpace(self.mesh, "CG", 1)
)
# jacobian_det = fd.Function(function_space, name="jacobian_det")
# jacobian_det.project(
# jacobian[0, 0] * jacobian[1, 1] - jacobian[0, 1] * jacobian[1, 0]
# )
# self.jacob_det = fd.project(
# jacobian_det, fd.FunctionSpace(self.mesh, "CG", 1)
# )
self.jacob_det = fd.Function(adapter.P1, name="jacobian_det").project(
jacobian[0, 0] * jacobian[1, 1] - jacobian[0, 1] * jacobian[1, 0]
)
# self.jacob = fd.project(
# jacobian, fd.TensorFunctionSpace(self.mesh, "CG", 1)
# )
self.jacob = fd.Function(adapter.P1_ten, name="jacobian").project(jacobian)

if ((step + 1) % self.save_interval == 0) or (step == 0):
callback(
Expand All @@ -698,6 +703,8 @@ def solve_problem(self, callback=None, fail_callback=None):
sigma=self.sigma,
alpha=self.alpha,
r_0=self.r_0,
x_0=self.x_0,
y_0=self.y_0,
t=self.t,
)

Expand Down
3 changes: 2 additions & 1 deletion UM2N/generator/swirl_solver_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ def solve_problem(self, callback=None, fail_callback=None):
hessian = self.l2_projection
phi = adapter.phi
phi_grad = adapter.grad_phi
sigma = adapter.sigma
# sigma = adapter.sigma
sigma = adapter.H # ej321 - this may be the updated hessian?
I = fd.Identity(2) # noqa
jacobian = I + sigma
jacobian_det = fd.Function(function_space, name="jacobian_det")
Expand Down
Loading