diff --git a/examples/fluids/smartsim_regression_framework.py b/examples/fluids/smartsim_regression_framework.py index 820f28a9e9..724baab773 100755 --- a/examples/fluids/smartsim_regression_framework.py +++ b/examples/fluids/smartsim_regression_framework.py @@ -36,6 +36,22 @@ class NoError(Exception): pass +def assert_np_all(test, truth): + """Assert with better error reporting""" + try: + assert np.all(test == truth) + except Exception as e: + raise Exception(f"Expected {truth}, but got {test}") from e + + +def assert_equal(test, truth): + """Assert with better error reporting""" + try: + assert test == truth + except Exception as e: + raise Exception(f"Expected {truth}, but got {test}") from e + + class SmartSimTest(object): def __init__(self, directory_path: Path): @@ -66,8 +82,8 @@ def setup(self): def test(self, ceed_resource) -> Tuple[bool, Exception, str]: client = None arguments = [] + exe_path = "../../build/fluids-navierstokes" try: - exe_path = "../../build/fluids-navierstokes" arguments = [ '-ceed', ceed_resource, '-options_file', (fluids_example_dir / 'blasius.yaml').as_posix(), @@ -96,16 +112,16 @@ def test(self, ceed_resource) -> Tuple[bool, Exception, str]: client = Client(cluster=False, address=self.database.get_address()[0]) assert client.poll_tensor("sizeInfo", 250, 5) - assert np.all(client.get_tensor("sizeInfo") == np.array([35, 12, 6, 1, 1, 0])) + assert_np_all(client.get_tensor("sizeInfo"), np.array([35, 12, 6, 1, 1, 0])) assert client.poll_tensor("check-run", 250, 5) - assert client.get_tensor("check-run")[0] == 1 + assert_equal(client.get_tensor("check-run")[0], 1) assert client.poll_tensor("tensor-ow", 250, 5) - assert client.get_tensor("tensor-ow")[0] == 1 + assert_equal(client.get_tensor("tensor-ow")[0], 1) assert client.poll_tensor("step", 250, 5) - assert client.get_tensor("step")[0] == 2 + assert_equal(client.get_tensor("step")[0], 2) assert client.poll_tensor("y.0", 250, 5) test_data_path = fluids_example_dir / "tests-output/y0_output.npy" diff --git a/examples/fluids/src/smartsim/sgs_dd_training.c b/examples/fluids/src/smartsim/sgs_dd_training.c index 7895d0073b..955497b31d 100644 --- a/examples/fluids/src/smartsim/sgs_dd_training.c +++ b/examples/fluids/src/smartsim/sgs_dd_training.c @@ -184,11 +184,15 @@ PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, User user, CeedData ceed_data, Pr { PetscSection global_section; - PetscInt num_dofs, num_comps; + PetscInt num_dofs, num_comps, local_min_max[2] = {0.}, global_min_max[2] = {0.}; + PetscCall(DMGetGlobalSection(sgs_dd_train->dm_dd_training, &global_section)); PetscCall(DMGetGlobalVectorInfo(sgs_dd_train->dm_dd_training, &num_dofs, NULL, NULL)); PetscCall(PetscSectionGetFieldComponents(global_section, 0, &num_comps)); - sgs_dd_train->training_data_array_dims[0] = num_dofs / num_comps; + local_min_max[0] = num_dofs; + PetscCall(PetscGlobalMinMaxInt(user->comm, local_min_max, global_min_max)); + + sgs_dd_train->training_data_array_dims[0] = global_min_max[0] / num_comps; sgs_dd_train->training_data_array_dims[1] = num_comps; }