Skip to content

Commit

Permalink
update field
Browse files Browse the repository at this point in the history
  • Loading branch information
obouchaara committed Jun 10, 2024
1 parent ff5e991 commit d01b399
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
16 changes: 8 additions & 8 deletions notebooks/symbolic/field.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/mechpy/core/symbolic/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def plot(self, x_range=(-10, 10), y_range=(-10, 10), z_range=(-10, 10), num_poin

# Create sliders for each field parameter
for i, (param, values) in enumerate(self.field_params.items()):
if values is None:
raise ValueError(f"the param {param} values in not defined")
if isinstance(values, set):
ax_slider = plt.axes([0.1, 0.1 + 0.05 * i, 0.65, 0.03], facecolor="lightgoldenrodyellow")
slider = Slider(ax_slider, str(param), min(values), max(values), valinit=min(values), valstep=list(values))
Expand Down
33 changes: 33 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,39 @@ def test_create(self):
field = SymbolicScalarField.create(coord_system=coord_system, data=data)
self.assertEqual(field.data, sp.NDimArray([x1 * x1 - x2 * x2]))

def test_plot(self):
n, m = sp.symbols("n m")
field_params = {
n: {-0.2, -0.1, 0, 0.1, 0.2},
m: {-0.2, -0.1, 0, 0.1, 0.2},
}
data = sp.Array([1 * n, -2 * m, 0])
linear_scalar_field = SymbolicScalarField.create_linear(
data=data,
field_params=field_params,
)
try:
linear_scalar_field.plot()
except Exception as e:
self.fail(f"Test failed due to unexpected exception: {e}")

n, m = sp.symbols("n m")
field_params = {
n: {0, 0.1, 0.2, 0.3, 0.4, 0.5},
m: None,
}
data = sp.Array([1 * n, -2 * m, 0])
linear_scalar_field = SymbolicScalarField.create_linear(
data=data,
field_params=field_params,
)
with self.assertRaises(ValueError) as context:
linear_scalar_field.plot()
self.assertEqual(
str(context.exception),
"the param m values in not defined",
)


# class TestSymbolicThreeByThreeTensor(unittest.TestCase):
# def test_initialization_valid_data(self):
Expand Down

0 comments on commit d01b399

Please sign in to comment.