Skip to content

Commit

Permalink
Merge pull request #12 from tataratat/ft-vedo-update
Browse files Browse the repository at this point in the history
udpate vedo syntax and add error plot
  • Loading branch information
j042 committed Feb 6, 2024
2 parents 2a7cb26 + 80c9d40 commit 5845405
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
14 changes: 7 additions & 7 deletions feigen/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def _process_spline_actors(plt):
plt._state["spline_cp_actors"] = new_cps
return None

plt._state["spline_cp_actors"][cp_id].SetPosition(
plt._state["spline"].cps[cp_id]
)
sphere_mesh = plt._s["spline_cp_actors"][cp_id]
sphere_mesh.pos(*plt._s["spline"].cps[cp_id])
sphere_mesh.apply_transform_from_actor()


def _process_boundary_actors(plt):
Expand Down Expand Up @@ -239,10 +239,9 @@ def _process_boundary_actors(plt):
plt._state["boundary_cp_actors"][b] = new_cps
continue

# now for specific cp
plt._state["boundary_cp_actors"][b][cp_id].SetPosition(
np.append(b_spl.cps[cp_id], [0])
)
sphere_mesh = plt._s["boundary_cp_actors"][b][cp_id]
sphere_mesh.pos(*b_spl.cps[cp_id])
sphere_mesh.apply_transform_from_actor()


def _process_parametric_view(plt):
Expand Down Expand Up @@ -668,6 +667,7 @@ def _iganet_sync(self, evt): # noqa ARG002
self.show(
*self._state["server_plot_actors"].values(),
at=self._config["server_plot"],
mode=self._c["plotter_mode"],
)

def start(self):
Expand Down
51 changes: 49 additions & 2 deletions feigen/custom_poisson2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def __init__( # noqa PLR0915
# plotter initialization constants
self._c["dim"] = 2 # 2D
# geometry, boundary condition, server response
self._c["n_subplots"] = 3
self._c["n_subplots"] = 4
self._c["geometry_plot"] = 0
self._c["bc_plot"] = 1
self._c["server_plot"] = 2
self._c["error_plot"] = 3

# field dim is temporary for now - (1)
self._c["field_dim"] = 1
Expand Down Expand Up @@ -184,6 +185,11 @@ def _left_click(self, evt): # noqa ARG002
self._s["right_click_counter"] = 0
super()._left_click(evt)

# clear error plot too
error_actors = self._s.get("error_plot_actors", None)
if error_actors is not None:
self.remove(*error_actors.values(), at=self._c["error_plot"])

def _right_click(self, evt): # noqa ARG002
"""
Syncs solution on right click.
Expand Down Expand Up @@ -212,21 +218,28 @@ def _right_click(self, evt): # noqa ARG002
self.show(
collo_actors,
at=self._c["server_plot"],
mode=self._c["plotter_mode"],
)
# counter++
# this should be from 1 to 2
self._s["right_click_counter"] += 1
return None

# remove if right click counter is not 1
# this also ensures that continuous right click
# this also ensures that continuous right click works
# although, it will recompute each time
server_actors = self._s.get("server_plot_actors", None)
if server_actors is not None:
self.remove(*server_actors.values(), at=self._c["server_plot"])
# reset counter
self._s["right_click_counter"] = 0

# if there's server actors, there will be error actors
# we can pack this into the `if` above also
error_actors = self._s.get("error_plot_actors", None)
if error_actors is not None:
self.remove(*error_actors.values(), at=self._c["error_plot"])

# we will solve the problem with collocation methods
geometry = self._s["spline"]
solution = self._s.get("solution_spline", None)
Expand Down Expand Up @@ -326,6 +339,33 @@ def _right_click(self, evt): # noqa ARG002
self.show(
*self._s["server_plot_actors"].values(),
at=self._c["server_plot"],
mode=self._c["plotter_mode"],
)

# plot error
err_actor = self._s["spline_actors"]["spline"].clone()
u_q = splinepy.utils.data.uniform_query(
solution.parametric_bounds,
splinepy.utils.data._enforce_len(
self._c["sample_resolutions"], self._s["spline"].para_dim
),
)
err = mapper.laplacian(u_q)
err = np.log10(abs(err + 1))

worst_id = np.argmax(err)
w_point = vedo.Point(self._s["spline"].evaluate([u_q[worst_id]])[0])

err_actor.cmap("coolwarm", err).add_scalarbar3d()
self._s["error_plot_actors"] = {
"spline": err_actor,
"knots": self._s["spline_actors"]["knots"],
"worst": w_point,
}
self.show(
*self._s["error_plot_actors"].values(),
at=self._c["error_plot"],
mode=self._c["plotter_mode"],
)

# counter += 1
Expand Down Expand Up @@ -383,6 +423,13 @@ def start(self):
mode=self._c["plotter_mode"],
)

self.show(
"Error - red dot marks the maximum",
at=self._c["error_plot"],
interactive=False,
mode=self._c["plotter_mode"],
)

# let's start
self.interactive()

Expand Down
8 changes: 4 additions & 4 deletions feigen/jacobian_determinant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import splinepy
import vedo

Expand Down Expand Up @@ -57,9 +56,9 @@ def _process_spline_actors(plt):
plt._s["spline_cp_actors"] = new_cps
return None

plt._s["spline_cp_actors"][cp_id].SetPosition(
np.append(plt._s["spline"].cps[cp_id], [0])
)
sphere_mesh = plt._s["spline_cp_actors"][cp_id]
sphere_mesh.pos(*plt._s["spline"].cps[cp_id])
sphere_mesh.apply_transform_from_actor()


class JacobianDeterminant(vedo.Plotter, FeigenBase):
Expand Down Expand Up @@ -281,6 +280,7 @@ def _right_click(self, evt): # noqa ARG002
self.show(
*self._s["server_plot_actors"].values(),
at=self._c["server_plot"],
mode=self._c["plotter_mode"],
)

def start(self):
Expand Down
14 changes: 7 additions & 7 deletions feigen/poisson2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ def _process_spline_actors(plt):
plt._s["spline_cp_actors"] = new_cps
return None

plt._s["spline_cp_actors"][cp_id].SetPosition(
np.append(plt._s["spline"].cps[cp_id], [0])
)
sphere_mesh = plt._s["spline_cp_actors"][cp_id]
sphere_mesh.pos(*plt._s["spline"].cps[cp_id])
sphere_mesh.apply_transform_from_actor()


def _process_boundary_actors(plt):
Expand Down Expand Up @@ -238,10 +238,9 @@ def _process_boundary_actors(plt):
plt._s["boundary_cp_actors"][b] = new_cps
continue

# now for specific cp
plt._s["boundary_cp_actors"][b][cp_id].SetPosition(
np.append(b_spl.cps[cp_id], [0])
)
sphere_mesh = plt._s["boundary_cp_actors"][b][cp_id]
sphere_mesh.pos(*b_spl.cps[cp_id])
sphere_mesh.apply_transform_from_actor()


def _process_parametric_view(plt):
Expand Down Expand Up @@ -694,6 +693,7 @@ def _right_click(self, evt): # noqa ARG002
self.show(
*self._s["server_plot_actors"].values(),
at=self._c["server_plot"],
mode=self._c["plotter_mode"],
)

def start(self):
Expand Down

0 comments on commit 5845405

Please sign in to comment.