Skip to content

Commit

Permalink
Reorganize files based on 2024-04-01 telecon discussion. More usage o…
Browse files Browse the repository at this point in the history
…f the naming convention classes throughout the tests
  • Loading branch information
kejacobson committed Apr 1, 2024
1 parent a1c680c commit 2499083
Show file tree
Hide file tree
Showing 47 changed files with 686 additions and 602 deletions.
2 changes: 1 addition & 1 deletion docs/_exts/embed_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from docutils.parsers.rst.directives import unchanged, images

from mphys.doc_utils._utils.docutil import get_source_code, remove_docstrings, \
from mphys.utils.docs._utils.docutil import get_source_code, remove_docstrings, \
remove_initial_empty_lines, replace_asserts_with_prints, \
strip_header, dedent, insert_output_start_stop_indicators, run_code, \
get_skip_output_node, get_interleaved_io_nodes, get_output_block_node, \
Expand Down
2 changes: 1 addition & 1 deletion docs/_exts/embed_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sphinx
from docutils.parsers.rst import Directive
from mphys.doc_utils._utils.docutil import get_source_code
from mphys.utils.docs._utils.docutil import get_source_code


class ContentContainerDirective(Directive):
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import importlib
from unittest.mock import Mock

from mphys.doc_utils.config_params import MOCK_MODULES
from mphys.doc_utils._utils.patch import do_monkeypatch
from mphys.utils.docs.config_params import MOCK_MODULES
from mphys.utils.docs._utils.patch import do_monkeypatch

# Only mock the ones that don't import.
for mod_name in MOCK_MODULES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AeroSolver(om.ImplicitComponent):
def initialize(self):
self.options.declare('solver')

self.x_aero_name = MPhysVariables.Aerodynamics.Surface.COORDINATES_DEFORMED
self.x_aero_name = MPhysVariables.Aerodynamics.Surface.COORDINATES

def setup(self):
self.solver = self.options['solver']
Expand Down Expand Up @@ -85,7 +85,7 @@ def initialize(self):
self.options.declare('solver')

def setup(self):
self.x_aero_name = MPhysVariables.Aerodynamics.Surface.COORDINATES_DEFORMED
self.x_aero_name = MPhysVariables.Aerodynamics.Surface.COORDINATES
self.f_aero_name = MPhysVariables.Aerodynamics.Surface.LOADS

self.solver = self.options['solver']
Expand Down
6 changes: 1 addition & 5 deletions mphys/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#!/usr/bin/env python
from .builder import Builder
from .variable_convention import MPhysVariables
from .multipoint import Multipoint, MultipointParallel
from .distributed_converter import DistributedConverter, DistributedVariableDescription
from .mask_converter import MaskedConverter, UnmaskedConverter, MaskedVariableDescription
from .core import *
10 changes: 10 additions & 0 deletions mphys/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python

from .builder import Builder
from .coupling_group import CouplingGroup
from .distributed_converter import DistributedConverter, DistributedVariableDescription
from .mask_converter import MaskedConverter, UnmaskedConverter, MaskedVariableDescription
from .multipoint import Multipoint, MultipointParallel
from .mphys_group import MphysGroup
from .scenario import Scenario
from .variable_convention import MPhysVariables
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import numpy as np

import openmdao.api as om
from openmdao.utils.mpi import MPI


class DistributedVariableDescription:
Expand Down
131 changes: 70 additions & 61 deletions mphys/mask_converter.py → mphys/core/mask_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,55 @@ class MaskedConverter(om.ExplicitComponent):
"""

def initialize(self):
self.options.declare("input", desc="MaskedVariableDescription object of input that will be masked")
self.options.declare("output", desc="MaskedVariableDescription object of masked output")
self.options.declare(
'input',
desc='MaskedVariableDescription object of input that will be masked')
"init_output",
default=1.0,
desc="initial value of the output. The default value matches the default value for val in add_output",
)
self.options.declare(
'output',
desc='MaskedVariableDescription object of masked output')
"distributed",
default=False,
desc="Flag to determine if the inputs and outputs should be distributed arrays",
)
self.options.declare(
'init_output', default=1.0,
desc='initail value of the ouput. The default value matches the default value for val in add_output')
self.options.declare(
'distributed', default=False,
desc='Flag to determine if the inputs and outputs should be distributed arrays')
self.options.declare(
'mask',
desc='masking array to apply to vectors. Contains boolean flags '
'indicating which indices should be included (True) or masked (False)')
"mask",
desc="masking array to apply to vectors. Contains boolean flags indicating which indices should be included (True) or masked (False)",
)

def setup(self):
distributed = self.options['distributed']
input = self.options['input']
output = self.options['output']
mask = self.options['mask']
distributed = self.options["distributed"]
input = self.options["input"]
output = self.options["output"]
mask = self.options["mask"]

self.add_input(input.name, shape=input.shape, tags=input.tags, distributed=distributed)

if isinstance(output, list):
if len(output) != len(mask):
raise ValueError("Output length and mask length not equal")
for i in range(len(output)):
self.add_output(output[i].name, shape=output[i].shape, tags=output[i].tags, val=self.options['init_output'], distributed=distributed)
self.add_output(
output[i].name,
shape=output[i].shape,
tags=output[i].tags,
val=self.options["init_output"],
distributed=distributed,
)
else:
self.add_output(output.name, shape=output.shape, tags=output.tags, val=self.options['init_output'], distributed=distributed)
self.add_output(
output.name,
shape=output.shape,
tags=output.tags,
val=self.options["init_output"],
distributed=distributed,
)

def compute(self, inputs, outputs):
input = self.options['input']
mask = self.options['mask']
output = self.options['output']
input = self.options["input"]
mask = self.options["mask"]
output = self.options["output"]

if isinstance(output, list):
for i in range(len(output)):
Expand All @@ -70,28 +82,29 @@ def compute(self, inputs, outputs):
outputs[output.name] = inputs[input.name][mask]

def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
input = self.options['input']
output = self.options['output']
mask = self.options['mask']
input = self.options["input"]
output = self.options["output"]
mask = self.options["mask"]

if isinstance(output, list):
for i in range(len(output)):
if mode == 'fwd':
if mode == "fwd":
if input.name in d_inputs and output[i].name in d_outputs:
d_outputs[output[i].name] += d_inputs[input.name][mask[i]]

if mode == 'rev':
if mode == "rev":
if input.name in d_inputs and output[i].name in d_outputs:
d_inputs[input.name][mask[i]] += d_outputs[output[i].name]
else:
if mode == 'fwd':
if mode == "fwd":
if input.name in d_inputs and output.name in d_outputs:
d_outputs[output.name] += d_inputs[input.name][mask]

if mode == 'rev':
if mode == "rev":
if input.name in d_inputs and output.name in d_outputs:
d_inputs[input.name][mask] += d_outputs[output.name]


class UnmaskedConverter(om.ExplicitComponent):
"""
An ExplicitComponent that undoes the procedure of the MaskedConverter component.
Expand All @@ -104,36 +117,32 @@ class UnmaskedConverter(om.ExplicitComponent):
"""

def initialize(self):
self.options.declare("input", desc="MaskedVariableDescription object of input that will be unmasked")
self.options.declare("output", desc="MaskedVariableDescription object of unmasked output")
self.options.declare("default_values", default=0.0, desc="default values for masked indices in output vector")
self.options.declare(
'input',
desc='MaskedVariableDescription object of input that will be unmasked')
self.options.declare(
'output',
desc='MaskedVariableDescription object of unmasked output')
self.options.declare(
'default_values', default=0.0,
desc='default values for masked indices in output vector')
self.options.declare(
'distributed', default=False,
desc='Flag to determine if the inputs and outputs should be distributed arrays')
"distributed",
default=False,
desc="Flag to determine if the inputs and outputs should be distributed arrays",
)
self.options.declare(
'mask',
desc='masking array to apply to vectors. Contains boolean flags '
'indicating which indices should be included (True) or masked (False)')
"mask",
desc="masking array to apply to vectors. Contains boolean flags indicating which indices should be included (True) or masked (False)",
)

def setup(self):
distributed = self.options['distributed']
input = self.options['input']
output = self.options['output']
mask = self.options['mask']
distributed = self.options["distributed"]
input = self.options["input"]
output = self.options["output"]
mask = self.options["mask"]

if isinstance(input, list):
if len(input) != len(mask):
raise ValueError("Input length and mask length not equal")

for i in range(len(input)-1):
for j in range(i+1, len(input)):
if (np.any(np.logical_and(mask[i], mask[j]))):
for i in range(len(input) - 1):
for j in range(i + 1, len(input)):
if np.any(np.logical_and(mask[i], mask[j])):
raise RuntimeWarning("Overlapping masking arrays, values will conflict.")

for i in range(len(input)):
Expand All @@ -144,10 +153,10 @@ def setup(self):
self.add_output(output.name, shape=output.shape, tags=output.tags, distributed=distributed)

def compute(self, inputs, outputs):
input = self.options['input']
output = self.options['output']
mask = self.options['mask']
def_vals = self.options['default_values']
input = self.options["input"]
output = self.options["output"]
mask = self.options["mask"]
def_vals = self.options["default_values"]
outputs[output.name][:] = def_vals

if isinstance(input, list):
Expand All @@ -157,24 +166,24 @@ def compute(self, inputs, outputs):
outputs[output.name][mask] = inputs[input.name]

def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
input = self.options['input']
output = self.options['output']
mask = self.options['mask']
input = self.options["input"]
output = self.options["output"]
mask = self.options["mask"]

if isinstance(input, list):
for i in range(len(input)):
if mode == 'fwd':
if mode == "fwd":
if input[i].name in d_inputs and output.name in d_outputs:
d_outputs[output.name][mask[i]] += d_inputs[input[i].name]

if mode == 'rev':
if mode == "rev":
if input[i].name in d_inputs and output.name in d_outputs:
d_inputs[input[i].name] += d_outputs[output.name][mask[i]]
else:
if mode == 'fwd':
if mode == "fwd":
if input.name in d_inputs and output.name in d_outputs:
d_outputs[output.name][mask] += d_inputs[input.name]

if mode == 'rev':
if mode == "rev":
if input.name in d_inputs and output.name in d_outputs:
d_inputs[input.name] += d_outputs[output.name][mask]
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions mphys/scenario.py → mphys/core/scenario.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from functools import wraps

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

# Define decorator functions for methods where run directory must be switched before calling
def switch_run_directory(method):
"""
Decorator function for methods where run directory must be switched before calling
"""
@wraps(method)
def wrapped_method(self, *args, **kwargs):
with cd(self.options['run_directory']):
Expand Down
65 changes: 65 additions & 0 deletions mphys/core/variable_convention.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class MPhysVariables:
class Aerodynamics:
class FlowConditions:
ANGLE_OF_ATTACK = "angle_of_attack"
YAW_ANGLE = "yaw_angle"
MACH_NUMBER = "mach_number"
REYNOLDS_NUMBER = "reynolds_number"
DYNAMIC_PRESSURE = "dynamic_pressure"

class Surface:
#: displacement distribution
DISPLACEMENTS = "u_aero"

#: force distribution
LOADS = "f_aero"

#: temperature distribution
TEMPERATURE = "T_aero"

#: distribution of heat flux * local surface area
HEAT_FLOW = "q_aero"

#: node coordinates at start of the analysis (jig shape)
COORDINATES_INITIAL = "x_aero0"

#: current node coordinates, deformed by geometry and/or structures
COORDINATES = "x_aero"

class Geometry:
#: node coordinates, input to geometry subsystem
COORDINATES_INPUT = "x_aero0_geometry_input"

#: node coordinates, output of geometry subsystem
COORDINATES_OUTPUT = "x_aero0_geometry_output"

class Mesh:
#: node coordinates, original surface from mesh file
COORDINATES = "x_aero0_mesh"

class Structures:
#: displacements at mesh nodes
DISPLACEMENTS = "u_struct"

#: loads at mesh nodes
LOADS_FROM_AERODYNAMICS = "f_aero_struct"

#: temperature at mesh nodes
TEMPERATURE = "T_struct"

#: heat flux * local surface area at mesh nodes
HEAT_FLOW = "q_aero_struct"

#: Coordinates at start of analysis
COORDINATES = "x_struct0"

class Geometry:
#: node coordinates, jig shape
COORDINATES_INPUT = "x_struct0_geometry_input"

#: node coordinates, jig shape
COORDINATES_OUTPUT = "x_struct0_geometry_output"

class Mesh:
#: node coordinates, original (no geometry changes)
COORDINATES = "x_struct0_mesh"
Loading

0 comments on commit 2499083

Please sign in to comment.