Skip to content

Commit

Permalink
Fix some bugs in print_summary (#252)
Browse files Browse the repository at this point in the history
* Add analysis_type property to CompositeFunction

* Print which vartype is not recognized.

* Include a catch for composite functions in print summary.

* List valid vartypes at top of _base.py

* Lint
  • Loading branch information
bburke38 authored Nov 9, 2023
1 parent 740b92c commit f8c62fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
19 changes: 11 additions & 8 deletions funtofem/model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class Base(object):
Base class for FUNtoFEM bodies and scenarios
"""

VAR_TYPES = [
"structural",
"aerodynamic",
"rigid_motion",
"shape",
"control",
"thermal",
]

def __init__(self, name, id=0, group=None):
"""
Expand Down Expand Up @@ -193,15 +202,9 @@ def verify_vartype(self, vartype):
type of variable
"""

if not vartype in [
"structural",
"aerodynamic",
"rigid_motion",
"shape",
"controls",
]:
if not vartype in self.VAR_TYPES:
print(
"Warning: vartype specified is not a recognized variable type",
f'Warning: vartype "{vartype}" is not a recognized variable type',
flush=True,
)

Expand Down
1 change: 1 addition & 0 deletions funtofem/model/composite_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
self.functions = unique(functions)
self.variables = unique(variables)
self.optim = optim
self.analysis_type = "composite"

# optimization settings
self.lower = None
Expand Down
33 changes: 23 additions & 10 deletions funtofem/model/funtofem_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import numpy as np, os, importlib
from .variable import Variable
from .function import CompositeFunction

# optional tacs import for caps2tacs
tacs_loader = importlib.util.find_spec("tacs")
Expand Down Expand Up @@ -1029,36 +1030,48 @@ def _print_functions(self):
" ------------------------------------------------------------------------------------"
)
for func in model_functions:
if isinstance(func, CompositeFunction):
analysis_type = func.analysis_type
adjoint = "N/A"
start = "N/A"
stop = "N/A"
averaging = "N/A"
else:
analysis_type = func.analysis_type
adjoint = func.adjoint
start = func.start
stop = func.stop
averaging = func.averaging
if len(func.name) >= 8:
print(
" | ",
func.name,
"\t| ",
func.analysis_type,
analysis_type,
"\t| ",
func.adjoint,
adjoint,
"\t| [",
func.start,
start,
",",
func.stop,
stop,
"] \t| ",
func.averaging,
averaging,
"\t|",
)
else:
print(
" | ",
func.name,
"\t\t| ",
func.analysis_type,
analysis_type,
"\t| ",
func.adjoint,
adjoint,
"\t| [",
func.start,
start,
",",
func.stop,
stop,
"] \t| ",
func.averaging,
averaging,
"\t|",
)
print(
Expand Down

0 comments on commit f8c62fc

Please sign in to comment.