Skip to content

Commit

Permalink
Merge pull request #171 from timryanb/run_dir_update
Browse files Browse the repository at this point in the history
Making run_directory API forward compatible with new OpenMDAO changes
  • Loading branch information
kejacobson authored Mar 1, 2024
2 parents c6ccda0 + 915654b commit b4e4634
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions mphys/scenario.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from functools import wraps

from .mphys_group import MphysGroup
from .utils.directory_utils import cd

# Define decorator functions for methods where run directory must be switched before calling
def switch_run_directory(method):
@wraps(method)
def wrapped_method(self, *args, **kwargs):
with cd(self.options['run_directory']):
return method(self, *args, **kwargs)

return wrapped_method

class Scenario(MphysGroup):
"""
A group to represent a specific analysis condition or point of the MPhys
Expand Down Expand Up @@ -60,21 +71,21 @@ def mphys_add_post_subsystem(self, name, subsystem,
# setup() to add the builder subsystems before adding these
self._post_subsystems.append((name, subsystem, promotes_inputs, promotes_outputs, promotes))

def _solve_nonlinear(self):
with cd(self.options['run_directory']):
return super()._solve_nonlinear()
@switch_run_directory
def _solve_nonlinear(self, *args, **kwargs):
return super()._solve_nonlinear(*args, **kwargs)

def _solve_linear(self, mode, rel_systems, scope_out=..., scope_in=...):
with cd(self.options['run_directory']):
return super()._solve_linear(mode, rel_systems, scope_out, scope_in)
@switch_run_directory
def _solve_linear(self, *args, **kwargs):
return super()._solve_linear(*args, **kwargs)

def _apply_nonlinear(self):
with cd(self.options['run_directory']):
return super()._apply_nonlinear()
@switch_run_directory
def _apply_nonlinear(self, *args, **kwargs):
return super()._apply_nonlinear(*args, **kwargs)

def _apply_linear(self, jac, rel_systems, mode, scope_out=None, scope_in=None):
with cd(self.options['run_directory']):
return super()._apply_linear(jac, rel_systems, mode, scope_out, scope_in)
@switch_run_directory
def _apply_linear(self, *args, **kwargs):
return super()._apply_linear(*args, **kwargs)

def _mphys_add_pre_coupling_subsystem_from_builder(self, name, builder, scenario_name=None):
"""
Expand Down

0 comments on commit b4e4634

Please sign in to comment.