Skip to content

Commit dc14edd

Browse files
committed
test: Created unit tests for SPH parsing
1 parent a835874 commit dc14edd

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

test/unit_tests/dyna/test_d3plot.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,94 @@ def test_reading_selected_states(self):
453453
node_disp = d3plot.arrays[ArrayType.node_displacement][:, node_index]
454454

455455
np.testing.assert_allclose(node_disp, disp_node_real, rtol=1e-4)
456+
457+
def test_read_sph_across_versions(self):
458+
"""Tests to parsing across several Dyna versions and history variables
459+
460+
R7.1.2: 11 positions in header data, isphfg(9) = 6 (strains only)
461+
R9.3.1: 10 or 11 positions in header data, isphfg(9) = 6 (strains only)
462+
R12.2.1: 10 or 11 positions of header data, isphfg(9) = 12 (strians and strain
463+
rate)
464+
465+
All tests data has 25 nodes and 10 states
466+
"""
467+
n_states = 10
468+
n_nodes = 25
469+
470+
# Test R7.1.2
471+
# Old database version, with no additonal history variables
472+
filepath = "test/test_data/sph_models/R7_1_2/d3plot"
473+
474+
d3plot = D3plot(filepath)
475+
476+
mass_array = d3plot.arrays["sph_mass"]
477+
strain_array = d3plot.arrays["sph_strain"]
478+
479+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
480+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
481+
self.assertTrue("sph_strainrate" not in d3plot.arrays.keys())
482+
483+
# Test R7.1.2 with history variables
484+
# Old database version, with 2 additonal history variables (NEIPHS)
485+
filepath = "test/test_data/sph_models/R7_1_2_Histvar=2/d3plot"
486+
487+
d3plot = D3plot(filepath)
488+
489+
mass_array = d3plot.arrays["sph_mass"]
490+
strain_array = d3plot.arrays["sph_strain"]
491+
self.assertTrue("sph_strainrate" not in d3plot.arrays.keys())
492+
493+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
494+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
495+
496+
# Test R9.3.1
497+
# New database version, with no additonal history variables
498+
filepath = "test/test_data/sph_models/R9_3_1/d3plot"
499+
500+
d3plot = D3plot(filepath)
501+
502+
mass_array = d3plot.arrays["sph_mass"]
503+
strain_array = d3plot.arrays["sph_strain"]
504+
505+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
506+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
507+
self.assertTrue("sph_strainrate" not in d3plot.arrays.keys())
508+
509+
# Test R9.3.1 with history variables
510+
# New database version with 2 additonal history variables (NEIPHS)
511+
filepath = "test/test_data/sph_models/R9_3_1_Histvar=2/d3plot"
512+
513+
d3plot = D3plot(filepath)
514+
515+
mass_array = d3plot.arrays["sph_mass"]
516+
strain_array = d3plot.arrays["sph_strain"]
517+
518+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
519+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
520+
self.assertTrue("sph_strainrate" not in d3plot.arrays.keys())
521+
522+
# Test R12.21
523+
# New database version, with no additonal history variables
524+
filepath = "test/test_data/sph_models/R12_2_1/d3plot"
525+
526+
d3plot = D3plot(filepath)
527+
528+
mass_array = d3plot.arrays["sph_mass"]
529+
strain_array = d3plot.arrays["sph_strain"]
530+
531+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
532+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
533+
self.assertTrue("sph_strainrate" in d3plot.arrays.keys())
534+
535+
# Test R12.21 with history variables
536+
# New database version with 2 additonal history variables (NEIPHS)
537+
filepath = "test/test_data/sph_models/R12_2_1_Histvar=2/d3plot"
538+
539+
d3plot = D3plot(filepath)
540+
541+
mass_array = d3plot.arrays["sph_mass"]
542+
strain_array = d3plot.arrays["sph_strain"]
543+
544+
np.testing.assert_equal(mass_array.shape, [n_states, n_nodes])
545+
np.testing.assert_equal(strain_array.shape, [n_states, n_nodes, 6])
546+
self.assertTrue("sph_strainrate" in d3plot.arrays.keys())

0 commit comments

Comments
 (0)