From 8cfa1cafda7c28a31ec6c7f07b17d71afac2f8cf Mon Sep 17 00:00:00 2001 From: Christophe DAVID Date: Wed, 26 Jun 2024 16:03:38 +0200 Subject: [PATCH 1/2] Testing ValidityDomainChecker for array variable. --- src/fastoad/openmdao/tests/openmdao_sellar_example/disc1.py | 4 ++-- src/fastoad/openmdao/tests/test_validity_checker.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fastoad/openmdao/tests/openmdao_sellar_example/disc1.py b/src/fastoad/openmdao/tests/openmdao_sellar_example/disc1.py index 838cb1888..df89890af 100644 --- a/src/fastoad/openmdao/tests/openmdao_sellar_example/disc1.py +++ b/src/fastoad/openmdao/tests/openmdao_sellar_example/disc1.py @@ -18,7 +18,7 @@ from ...validity_checker import ValidityDomainChecker -@ValidityDomainChecker({"x": (-1, 1)}) # This validity domain should not apply +@ValidityDomainChecker({"x": (-1, 1), "z": (0, 10)}) # This validity domain should not apply class Disc1(BasicDisc1): """An OpenMDAO component to encapsulate Disc1 discipline""" @@ -44,6 +44,6 @@ def setup(self): self.add_output("y1", val=1.0, desc="variable y1") # for testing output description capture -@ValidityDomainChecker({"x": (0, 1)}) # This validity domain should apply in case 2 +@ValidityDomainChecker({"x": (0, 1), "z": (0, 1)}) # This validity domain should apply in case 2 class Disc1Ter(Disc1Bis): """Same component with different validity domain.""" diff --git a/src/fastoad/openmdao/tests/test_validity_checker.py b/src/fastoad/openmdao/tests/test_validity_checker.py index f4c8b6891..d9329f9a4 100644 --- a/src/fastoad/openmdao/tests/test_validity_checker.py +++ b/src/fastoad/openmdao/tests/test_validity_checker.py @@ -254,3 +254,7 @@ def test_sellar(caplog): problem.setup() problem.run_model() assert 'Variable "x" out of bound: value [2.] is over upper limit ( 1 )' in caplog.text + assert ( + 'Variable "z" out of bound: value [5. 2.] m**2 is over upper limit ( 1 m**2 )' + in caplog.text + ) From 0714bd4ebd1f9ac7528fdac0fd3f9fd7c5bf9a73 Mon Sep 17 00:00:00 2001 From: Christophe DAVID Date: Tue, 18 Jun 2024 14:57:21 +0200 Subject: [PATCH 2/2] Fix for array variables --- src/fastoad/openmdao/validity_checker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fastoad/openmdao/validity_checker.py b/src/fastoad/openmdao/validity_checker.py index 829097bb5..1a6f6e0be 100644 --- a/src/fastoad/openmdao/validity_checker.py +++ b/src/fastoad/openmdao/validity_checker.py @@ -190,10 +190,10 @@ def check_variables( ) and var.name in limit_definitions: limit_def = limit_definitions[var.name] value = convert_units(var.value, var.units, limit_def.units) - if value < limit_def.lower: + if np.any(value < limit_def.lower): status = ValidityStatus.TOO_LOW limit = limit_def.lower - elif value > limit_def.upper: + elif np.any(value > limit_def.upper): status = ValidityStatus.TOO_HIGH limit = limit_def.upper else: @@ -226,7 +226,9 @@ def log_records(records: List[CheckRecord]): for record in records: if record.status != ValidityStatus.OK: logger = logging.getLogger(record.logger_name) - limit_text = "under lower" if record.value < record.limit_value else "over upper" + limit_text = ( + "under lower" if np.any(record.value < record.limit_value) else "over upper" + ) logger.warning( 'Variable "%s" out of bound: value %s%s is %s limit ( %s%s ) in file %s', record.variable_name,