Skip to content

Commit 585bbd0

Browse files
test aero module
1 parent 0be76d1 commit 585bbd0

File tree

2 files changed

+101
-7
lines changed

2 files changed

+101
-7
lines changed

funtofem/interface/test_interfaces/fun3d_ae_interface.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def __init__(
573573
adjoint_options=None,
574574
complex_mode=False,
575575
test_flow_states=False,
576-
test_aero_block=False,
576+
test_aero_module=False,
577577
):
578578
"""
579579
The instantiation of the FUN3D Grid interface class will populate the model with the aerodynamic surface
@@ -608,8 +608,8 @@ def __init__(
608608
self.comm.Barrier()
609609
# get the number of grid volume coordinates
610610
self.test_flow_states = test_flow_states
611-
self.test_aero_block = test_aero_block
612-
if test_flow_states or test_aero_block:
611+
self.test_aero_module = test_aero_module
612+
if test_flow_states or test_aero_module:
613613
self.nvol = self.fun3d_flow.extract_num_volume_nodes()
614614
self.nflow = 5 # if inviscid, else 6 if turb
615615
else:
@@ -650,7 +650,7 @@ def __init__(
650650
(self.nflow * self.nvol, nf), dtype=TransferScheme.dtype
651651
) # 1 func for now
652652

653-
if self.test_aero_block:
653+
if self.test_aero_module:
654654
body._grid_coords[scenario.id] = np.zeros(
655655
(3 * self.nvol), dtype=TransferScheme.dtype
656656
)
@@ -694,7 +694,7 @@ def solve_forward(self):
694694

695695
self.fun3d_flow.input_deformation(dx, dy, dz, body=ibody)
696696

697-
if self.test_aero_block: # test q(xG)
697+
if self.test_aero_module: # test q(xG)
698698
x0, y0, z0 = self.fun3d_flow.extract_grid_coords(self.nvol)
699699

700700
grid_coords = body._grid_coords[scenario.id]
@@ -808,7 +808,7 @@ def solve_adjoint(self):
808808
lam_x, lam_y, lam_z, body=ibody
809809
)
810810

811-
if self.test_aero_block: # test q(xG)
811+
if self.test_aero_module: # test q(xG)
812812
x0, y0, z0 = self.fun3d_adjoint.extract_grid_coordinates(
813813
self.nvol
814814
)
@@ -822,7 +822,7 @@ def solve_adjoint(self):
822822
self.fun3d_adjoint.input_aero_test_grid_coords(x, y, z)
823823

824824
# set the flow state adjoint in
825-
if self.test_flow_states or self.test_aero_block:
825+
if self.test_flow_states or self.test_aero_module:
826826
dtype = TransferScheme.dtype
827827
flow_ajp = body._flow_ajp[scenario.id] * 1.0
828828
lamq1 = flow_ajp[0::5, :]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""
2+
Unittest for FUN3D 14.0.2 finite-difference test
3+
"""
4+
5+
import numpy as np, unittest, importlib, os
6+
from mpi4py import MPI
7+
import time
8+
9+
# Imports from FUNtoFEM
10+
from funtofem.model import (
11+
FUNtoFEMmodel,
12+
Variable,
13+
Scenario,
14+
Body,
15+
Function,
16+
)
17+
from funtofem.interface import (
18+
TacsSteadyInterface,
19+
SolverManager,
20+
TestResult,
21+
make_test_directories,
22+
)
23+
from funtofem.driver import FUNtoFEMnlbgs, TransferSettings
24+
25+
# check whether fun3d is available
26+
fun3d_loader = importlib.util.find_spec("fun3d")
27+
has_fun3d = fun3d_loader is not None
28+
if has_fun3d:
29+
from funtofem.interface import Fun3d14AeroelasticTestInterface
30+
31+
np.random.seed(1234567)
32+
comm = MPI.COMM_WORLD
33+
base_dir = os.path.dirname(os.path.abspath(__file__))
34+
bdf_filename = os.path.join(base_dir, "meshes", "nastran_CAPS.dat")
35+
results_folder, output_dir = make_test_directories(comm, base_dir)
36+
37+
# TEST SETTINGS
38+
# get more accurate derivatives when early stopping is off and fully converges
39+
early_stopping = True
40+
forward_tol = 1e-15
41+
adjoint_tol = 1e-15
42+
43+
44+
class TestFun3dTacs(unittest.TestCase):
45+
FILENAME = "aero_module_quads.txt"
46+
FILEPATH = os.path.join(results_folder, FILENAME)
47+
48+
def test_alpha_turbulent_aeroelastic_quads(self):
49+
# build the funtofem model with one body and scenario
50+
model = FUNtoFEMmodel("plate")
51+
plate = Body.aeroelastic("plate", boundary=2)
52+
plate.register_to(model)
53+
54+
# build the scenario
55+
test_scenario = Scenario.steady(
56+
"plate_flow_quads",
57+
steps=25,
58+
forward_coupling_frequency=20, # 500 total fun3d steps
59+
adjoint_steps=25,
60+
adjoint_coupling_frequency=20,
61+
uncoupled_steps=10,
62+
)
63+
test_scenario.set_stop_criterion(
64+
early_stopping=early_stopping, min_forward_steps=50
65+
)
66+
test_scenario.set_temperature(T_ref=300.0, T_inf=300.0)
67+
# Function.lift().register_to(test_scenario)
68+
Function.ksfailure().register_to(test_scenario)
69+
aoa = test_scenario.get_variable("AOA", set_active=True)
70+
aoa.set_bounds(lower=5.0, value=10.0, upper=15.0)
71+
test_scenario.set_flow_ref_vals(qinf=1.05e5)
72+
test_scenario.register_to(model)
73+
74+
# build the solvers and coupled driver
75+
solvers = SolverManager(comm)
76+
solvers.flow = Fun3d14AeroelasticTestInterface(
77+
comm, model, test_aero_module=True, fun3d_dir="meshes"
78+
)
79+
solvers.structural = TacsSteadyInterface.create_from_bdf(
80+
model, comm, nprocs=1, bdf_file=bdf_filename, prefix=output_dir
81+
)
82+
83+
max_rel_error = Fun3d14AeroelasticTestInterface.finite_diff_test_aero_module(
84+
solvers.flow, epsilon=1e-4, filename=self.FILEPATH
85+
)
86+
self.assertTrue(max_rel_error < 1e-7)
87+
88+
89+
if __name__ == "__main__":
90+
# open and close the file to reset it
91+
if comm.rank == 0:
92+
open(TestFun3dTacs.FILEPATH, "w").close()
93+
94+
unittest.main()

0 commit comments

Comments
 (0)