Skip to content

Commit

Permalink
Merge branch 'application2' of github.com:sean-engelstad/funtofem int…
Browse files Browse the repository at this point in the history
…o application2
  • Loading branch information
sean-engelstad committed Nov 1, 2023
2 parents 713e3fb + d93a0cb commit 29f28b8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 24 deletions.
13 changes: 13 additions & 0 deletions funtofem/driver/oneway_aero_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,19 @@ def _setup_grid_filepaths(self):
grid_filepaths.append(filepath)
# set the grid filepaths into the fun3d aim
self.flow_aim.grid_filepaths = grid_filepaths

# also setup the mapbc files
mapbc_filepaths = []
for scenario in self.model.scenarios:
filepath = os.path.join(
fun3d_dir,
scenario.name,
"Flow",
f"{scenario.fun3d_project_name}.mapbc",
)
mapbc_filepaths.append(filepath)
# set the mapbc filepaths into the fun3d aim
self.flow_aim.mapbc_filepaths = mapbc_filepaths
return

@property
Expand Down
45 changes: 30 additions & 15 deletions funtofem/interface/fun3d_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,17 @@ def post(self, scenario, bodies):
"""

# report warning if flow residual too large
resid = self.get_forward_residual(step=scenario.steps) # step=scenario.steps
resid = self.get_forward_residual(
step=scenario.steps, all=True
) # step=scenario.steps
if self.comm.rank == 0:
print(f"Forward residuals = {resid}")
self._forward_done = True
self._forward_resid = resid
if abs(resid.real) > 1.0e-10:
if abs(np.linalg.norm(resid).real) > self.forward_tolerance:
if self.comm.rank == 0:
print(
f"Warning: fun3d forward flow residual = {resid} > 1.0e-10, is rather large..."
f"\tWarning: fun3d forward flow residual = {resid} > {self.forward_tolerance:.2e}, is rather large..."
)

self.fun3d_flow.post()
Expand Down Expand Up @@ -970,21 +974,23 @@ def post_adjoint(self, scenario, bodies):
"""

# report warning if flow residual too large
resid = self.get_adjoint_residual(step=scenario.steps)
resid = self.get_adjoint_residual(step=scenario.steps, all=True)
if self.comm.rank == 0:
print(f"Adjoint residuals = {resid}")
self._adjoint_done = True
self._adjoint_resid = resid
if abs(resid.real) > 1.0e-10:
if abs(np.linalg.norm(resid).real) > self.adjoint_tolerance:
if self.comm.rank == 0:
print(
f"Warning fun3d adjoint residual = {resid} > 1.0e-10, is rather large..."
f"\tWarning fun3d adjoint residual = {resid} > {self.adjoint_tolerance:.2e}, is rather large..."
)

# solve the initial condition adjoint
self.fun3d_adjoint.post()
os.chdir(self.root_dir)
return

def get_forward_residual(self, step=0):
def get_forward_residual(self, step=0, all=False):
"""
Returns L2 norm of scalar residual norms for each flow state
L2norm([R1,...,R6])
Expand All @@ -993,31 +999,40 @@ def get_forward_residual(self, step=0):
----------
step: int
the time step number
all: bool
whether to return a list of all residuals or just a scalar
"""
if not self._forward_done:
residuals = self.fun3d_flow.get_flow_rms_residual(step)
if self.comm.rank == 0:
print(f"Forward residuals = {residuals}")
return np.linalg.norm(residuals)
else:
return self._forward_resid
residuals = self._forward_resid

def get_adjoint_residual(self, step=0):
if all:
return residuals
else:
return np.linalg.norm(residuals)

def get_adjoint_residual(self, step=0, all=False):
"""
Returns L2 norm of list of scalar adjoint residuals L2norm([R1,...,R6])
Parameters
----------
step: int
the time step number
all: bool
whether to return a list of all residuals or a scalar
"""
if not self._adjoint_done:
residuals = self.fun3d_adjoint.get_flow_rms_residual(step)
if self.comm.rank == 0:
print(f"Adjoint residuals = {residuals}")
return np.linalg.norm(residuals)
else:
return self._adjoint_resid
residuals = self._adjoint_resid

if all:
return residuals
else:
return np.linalg.norm(residuals)

def set_states(self, scenario, bodies, step):
"""
Expand Down
32 changes: 23 additions & 9 deletions funtofem/model/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,18 +1598,32 @@ def _distribute_aero_loads(self, data):
"""
distribute the aero loads and heat flux from a loads file
"""
print(f"F2F - starting to distribute loads")

for scenario_id in data:
scenario_data = data[scenario_id]

# create a dict for this entry
scenario_entry_dict = {}
for entry in scenario_data:
for ind, aero_id in enumerate(self.aero_id):
if entry["aeroID"] == aero_id and entry["bodyName"] == self.name:
if self.transfer is not None:
self.aero_loads[scenario_id][3 * ind : 3 * ind + 3] = entry[
"load"
]
if self.thermal_transfer is not None:
self.aero_heat_flux[scenario_id][ind] = entry["hflux"]
break
if entry["bodyName"] == self.name:
scenario_entry_dict[entry["aeroID"]] = {
"load": entry["load"],
"hflux": entry["hflux"],
}

for ind, aero_id in enumerate(self.aero_id):
if self.transfer is not None:
self.aero_loads[scenario_id][
3 * ind : 3 * ind + 3
] = scenario_entry_dict[aero_id]["load"]
if self.thermal_transfer is not None:
self.aero_heat_flux[scenario_id][ind] = scenario_entry_dict[
aero_id
]["hflux"]
break

print(f"F2F - done distribute loads")

def _collect_aero_mesh(self, comm, root=0):
"""
Expand Down

0 comments on commit 29f28b8

Please sign in to comment.