Skip to content

Commit

Permalink
Make test_struct_solver support hot temps
Browse files Browse the repository at this point in the history
  • Loading branch information
bburke38 committed Nov 6, 2024
1 parent efb9e1b commit fc7f57b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
64 changes: 47 additions & 17 deletions funtofem/interface/test_interfaces/_test_struct_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@


class TestStructuralSolver(SolverInterface):
def __init__(self, comm, model, elastic_k=1.0, thermal_k=1.0, default_mesh=True):
def __init__(
self,
comm,
model,
elastic_k=1.0,
thermal_k=1.0,
default_mesh=True,
hot_temps=False,
):
"""
A test solver that provides the functionality that FUNtoFEM expects from
a structural solver.
Expand All @@ -32,6 +40,8 @@ def __init__(self, comm, model, elastic_k=1.0, thermal_k=1.0, default_mesh=True)
self.npts = 25
np.random.seed(54321)

self.hot_temps = hot_temps

# setup forward and adjoint tolerances
super().__init__()

Expand All @@ -58,9 +68,10 @@ def __init__(self, comm, model, elastic_k=1.0, thermal_k=1.0, default_mesh=True)

# scenario data for the multi scenario case
class ScenarioData:
def __init__(self, npts, struct_dvs):
def __init__(self, npts, struct_dvs, hot_temps=False):
self.npts = npts
self.struct_dvs = struct_dvs
self.hot_temps = hot_temps

# choose time step
self.dt = 0.01
Expand All @@ -82,20 +93,37 @@ def __init__(self, npts, struct_dvs):
* (np.random.rand(3 * self.npts, len(self.struct_dvs)) - 0.5)
)

# Struct temps = Jac2 * struct_flux + b2 * struct_X + c2 * struct_dvs + omega2 * time
self.Jac2 = (
0.05 * thermal_scale * (np.random.rand(self.npts, self.npts) - 0.5)
)
self.b2 = (
0.1
* thermal_scale
* (np.random.rand(self.npts, 3 * self.npts) - 0.5)
)
self.c2 = (
0.01
* thermal_scale
* (np.random.rand(self.npts, len(self.struct_dvs)) - 0.5)
)
if not self.hot_temps:
# Struct temps = Jac2 * struct_flux + b2 * struct_X + c2 * struct_dvs + omega2 * time
self.Jac2 = (
0.05
* thermal_scale
* (np.random.rand(self.npts, self.npts) - 0.5)
)
self.b2 = (
0.1
* thermal_scale
* (np.random.rand(self.npts, 3 * self.npts) - 0.5)
)
self.c2 = (
0.01
* thermal_scale
* (np.random.rand(self.npts, len(self.struct_dvs)) - 0.5)
)
elif self.hot_temps:
self.Jac2 = (
0.05
* thermal_scale
* (np.random.rand(self.npts, self.npts) + 0.5)
)
self.b2 = (
0.1 * thermal_scale * (np.random.rand(self.npts, 3 * self.npts))
)
self.c2 = (
0.5
* thermal_scale
* (np.random.rand(self.npts, len(self.struct_dvs)) - 0.5 * 0)
)

# Data for output functional values
self.func_coefs1 = np.random.rand(3 * self.npts)
Expand All @@ -109,7 +137,9 @@ def __init__(self, npts, struct_dvs):
# create scenario data for each scenario
self.scenario_data = {}
for scenario in model.scenarios:
self.scenario_data[scenario.id] = ScenarioData(self.npts, self.struct_dvs)
self.scenario_data[scenario.id] = ScenarioData(
self.npts, self.struct_dvs, self.hot_temps
)

if default_mesh:
# Set random initial node locations
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/framework/test_radiationFlux_adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _setup_model_and_driver(self):
comm = MPI.COMM_WORLD
solvers = SolverManager(comm)
solvers.flow = TestAerodynamicSolver(comm, model)
solvers.structural = TestStructuralSolver(comm, model)
solvers.structural = TestStructuralSolver(comm, model, hot_temps=True)
solvers.thermal_rad = RadiationInterface(comm, model)

# L&D transfer options
Expand Down

0 comments on commit fc7f57b

Please sign in to comment.