Skip to content

Commit

Permalink
Use static_configs() for testing directly
Browse files Browse the repository at this point in the history
  • Loading branch information
elrnv committed Sep 6, 2024
1 parent 2e6bf73 commit 2e4bc46
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions softy/src/constraints/penalty_point_contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3842,7 +3842,7 @@ mod tests {
use crate::attrib_defines::*;
use crate::nl_fem::state::{ResidualState, State};
use crate::nl_fem::{NonLinearProblem, SimParams, SolverBuilder};
use crate::test_utils::{default_solid, num_static_configs, static_nl_params};
use crate::test_utils::{default_solid, static_nl_params, static_configs};
use crate::{Elasticity, MaterialIdType};
use ad::F1;
use approx::assert_relative_eq;
Expand Down Expand Up @@ -4035,7 +4035,7 @@ mod tests {
vec![1; surface.num_vertices()],
)?;

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
max_iterations: 50,
gravity: [0.0f32, -9.81, 0.0],
Expand Down
7 changes: 1 addition & 6 deletions softy/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ use geo::mesh::VertexPositions;
use geo::ops::*;
use geo::topology::{CellVertex, CellVertexIndex};

/// Returns the total number of configurations availble.
pub fn num_static_configs() -> u32 {
4
}

/// Returns an iterator of supported configs.
pub fn static_configs() -> impl Iterator<Item = u32> {
static_config_slice().iter().cloned()
Expand All @@ -41,7 +36,7 @@ pub fn static_config_slice() -> &'static [u32] {

/// Gets the name of the config which points to a ron file in the assets directory.
pub fn config_name(config: u32) -> &'static str {
assert!(config < num_static_configs());
assert!(config < 4);
match config {
0 => "direct_static_nl_params",
1 => "direct_assisted_static_nl_params",
Expand Down
2 changes: 1 addition & 1 deletion softy/tests/bend_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn quasi_static_deformed() -> Result<(), Error> {

// Running the same sim again should produce deterministically identical results.
// This used to fail with bending enabled.
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mesh = make_three_tri_mesh();
let mut solver = SolverBuilder::new(SimParams {
velocity_clear_frequency: 20.0,
Expand Down
14 changes: 7 additions & 7 deletions softy/tests/box_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use test_utils::*;
#[test]
fn equilibrium() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
max_iterations: 1,
gravity: [0.0f32; 3],
Expand Down Expand Up @@ -48,7 +48,7 @@ fn equilibrium() -> Result<(), Error> {
#[test]
fn stretch_plain() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mesh = make_stretched_box(4);
let material: Material = load_material("assets/medium_solid_material.ron")?;
let mut solver = SolverBuilder::new(NLParams {
Expand All @@ -70,7 +70,7 @@ fn stretch_plain() -> Result<(), Error> {
#[ignore]
fn stretch_plain_large() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mesh = make_stretched_box(10);
let material: Material = load_material("assets/medium_solid_material.ron")?;
let mut solver = SolverBuilder::new(NLParams {
Expand All @@ -88,7 +88,7 @@ fn stretch_plain_large() -> Result<(), Error> {
#[test]
fn stretch_volume_penalty() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let material: Material = load_material("assets/medium_solid_material.ron")?;
let mut mesh = make_stretched_box(4);
mesh.insert_attrib_data::<VolumeZoneIdType, CellIndex>(
Expand Down Expand Up @@ -118,7 +118,7 @@ fn stretch_volume_penalty() -> Result<(), Error> {
#[test]
fn stretch_triangles() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let material: Material = load_material("assets/soft_shell_material.ron")?;
let mesh = make_stretched_box(2);
let mesh = mesh.surface_trimesh();
Expand All @@ -143,7 +143,7 @@ fn stretch_triangles() -> Result<(), Error> {
fn stretch_volume_penalty_triangles() -> Result<(), Error> {
use geo::attrib::Attrib;
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let material: Material = load_material("assets/soft_shell_material.ron")?;
let mesh = make_stretched_box(3);
let mut mesh = mesh.surface_trimesh();
Expand Down Expand Up @@ -173,7 +173,7 @@ fn stretch_volume_penalty_triangles() -> Result<(), Error> {
#[test]
fn twist_plain() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let material: Material = load_material("assets/no_poisson_soft_solid_material.ron")?;
let mesh = geo::io::load_tetmesh("assets/box_twist.vtk")?;
let params = NLParams {
Expand Down
6 changes: 3 additions & 3 deletions softy/tests/contact_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn single_tri_push() -> Result<(), Error> {

let contact_tolerance = 0.001;

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = static_nl_params(config_idx);
let mut solver = SolverBuilder::new(params.clone())
.set_mesh(Mesh::from(trimesh.clone()))
Expand Down Expand Up @@ -324,7 +324,7 @@ fn tet_push() -> Result<(), Error> {

compute_distance_potential_tetmesh(&orig_trimesh, &orig_tetmesh, kernel);

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
gravity: [0.0f32; 3],
..static_nl_params(config_idx)
Expand Down Expand Up @@ -439,7 +439,7 @@ fn ball_tri_push_tester(
vec![1; tetmesh.num_cells()],
)?;

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = static_nl_params(config_idx);

// If material is omitted it is assumed to be material 0 which is a completely fixed/animated mesh.
Expand Down
2 changes: 1 addition & 1 deletion softy/tests/friction_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn box_slide_experiment() -> Result<(), Error> {
..Default::default()
};

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mut params = static_nl_params(config_idx);
let pi = std::f64::consts::PI;

Expand Down
10 changes: 5 additions & 5 deletions softy/tests/one_tet_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn one_tet_solver(config_idx: u32) -> Solver<impl NLSolver<NLProblem<f64>, f64>,
/// Test that the solver produces no change for an equilibrium configuration.
#[test]
fn equilibrium() {
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
gravity: [0.0f32, 0.0, 0.0],
..static_nl_params(config_idx)
Expand All @@ -48,7 +48,7 @@ fn equilibrium() {
#[test]
fn simple_deformed() {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mut solver = one_tet_solver(config_idx);

geo::io::save_mesh(&solver.mesh(), "./out/before_one_tet.vtk").unwrap();
Expand All @@ -71,7 +71,7 @@ fn simple_deformed() {
#[test]
fn consistent_outer_iterations() -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
..static_nl_params(config_idx)
};
Expand Down Expand Up @@ -105,7 +105,7 @@ fn volume_penalty() -> Result<(), Error> {

let material = default_solid();

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mut solver = SolverBuilder::new(static_nl_params(config_idx))
.set_mesh(mesh.clone())
.set_material(material)
Expand All @@ -130,7 +130,7 @@ fn volume_penalty_triangles() -> Result<(), Error> {

let material = default_shell();

for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let mut solver = SolverBuilder::new(static_nl_params(config_idx))
.set_mesh(mesh.clone())
.set_material(material)
Expand Down
2 changes: 1 addition & 1 deletion softy/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn contact_tester(
num_steps: u32,
) -> Result<(), Error> {
init_logger();
for config_idx in 0..num_static_configs() {
for config_idx in static_configs() {
let params = SimParams {
time_step: Some(0.01),
..static_nl_params(config_idx)
Expand Down

0 comments on commit 2e4bc46

Please sign in to comment.