-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial tests for Quad 2d element
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import jax.numpy as jnp | ||
from diffmpm.element import Quadrilateral4Node | ||
|
||
|
||
class TestLinear1D: | ||
pass | ||
|
||
|
||
class TestQuadrilateral4Node: | ||
elements = Quadrilateral4Node((1, 1), 1, (1.0, 1.0), []) | ||
|
||
def test_shapefn(self): | ||
particle_coord = jnp.array([[0, 0]]).reshape(-1, 1, 2) | ||
sfn = self.elements.shapefn(particle_coord) | ||
assert jnp.allclose( | ||
sfn, jnp.array([0.25, 0.25, 0.25, 0.25]).reshape(1, 4, 1, 1) | ||
) | ||
|
||
particle_coord = jnp.array([[-1, -1]]).reshape(-1, 1, 2) | ||
sfn = self.elements.shapefn(particle_coord) | ||
assert jnp.allclose(sfn, jnp.array([1, 0, 0, 0]).reshape(1, 4, 1, 1)) | ||
|
||
particle_coord = jnp.array([[1, 1]]).reshape(-1, 1, 2) | ||
sfn = self.elements.shapefn(particle_coord) | ||
assert jnp.allclose(sfn, jnp.array([0, 0, 1, 0]).reshape(1, 4, 1, 1)) | ||
|
||
def test_shapefn_natural_grad(self): | ||
particle_coord = jnp.array([[0, 0]]).reshape(-1, 1, 2) | ||
sfn_grad = self.elements._shapefn_natural_grad(particle_coord) | ||
assert jnp.allclose( | ||
sfn_grad, | ||
jnp.array( | ||
[[-0.25, -0.25], [0.25, -0.25], [0.25, 0.25], [-0.25, 0.25]] | ||
).reshape(-1, 4, 2), | ||
) | ||
|
||
particle_coord = jnp.array([[-1, -1]]).reshape(-1, 1, 2) | ||
sfn_grad = self.elements._shapefn_natural_grad(particle_coord) | ||
assert jnp.allclose( | ||
sfn_grad, | ||
jnp.array([[-0.5, -0.5], [0.5, 0.0], [0.0, 0.0], [0.0, 0.5]]).reshape( | ||
-1, 4, 2 | ||
), | ||
) | ||
|
||
particle_coord = jnp.array([[1, 1]]).reshape(-1, 1, 2) | ||
sfn_grad = self.elements._shapefn_natural_grad(particle_coord) | ||
assert jnp.allclose( | ||
sfn_grad, | ||
jnp.array([[0.0, 0.0], [0.0, -0.5], [0.5, 0.5], [-0.5, 0.0]]).reshape( | ||
-1, 4, 2 | ||
), | ||
) | ||
|
||
def test_shapefn_grad(self): | ||
particle_coord = jnp.array([[0.5, 0.5]]).reshape(-1, 1, 2) | ||
nodal_coords = jnp.array( | ||
[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]] | ||
).reshape(-1, 4, 2) | ||
sfn_natural_grad = self.elements._shapefn_natural_grad(particle_coord) * 2 | ||
sfn_grad = self.elements.shapefn_grad(particle_coord, nodal_coords) | ||
assert jnp.allclose(sfn_grad, sfn_natural_grad) | ||
|
||
particle_coord = jnp.array([[-0.5, -0.5]]).reshape(-1, 1, 2) | ||
nodal_coords = jnp.array( | ||
[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]] | ||
).reshape(-1, 4, 2) | ||
sfn_natural_grad = self.elements._shapefn_natural_grad(particle_coord) * 2 | ||
sfn_grad = self.elements.shapefn_grad(particle_coord, nodal_coords) | ||
assert jnp.allclose(sfn_grad, sfn_natural_grad) |
File renamed without changes.
File renamed without changes.