Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to mphys interface for getting DV bounds and scaling factors #218

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tacs/mphys/mphys_tacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,57 @@ def get_initial_dvs(self):
else:
return self.fea_assembler.getOrigDesignVars()

def get_dv_bounds(self):
"""Get arrays containing the lower and upper bounds for the design variables,
in the form needed by OpenMDAO's `add_design_variable` method.

Returns
-------
list of ndarray
lower and upper bounds for the design variables
"""
if MPI is not None and self.comm.size > 1:
# Get bounds owned by this processor
local_dv_bounds = self.fea_assembler.getDesignVarRange()
local_dv_bounds = list(local_dv_bounds)
local_dv_bounds[0] = local_dv_bounds[0].astype(float)
local_dv_bounds[1] = local_dv_bounds[1].astype(float)

# Size of design variable on this processor
local_ndvs = self.fea_assembler.getNumDesignVars()
# Size of design variable vector on each processor
dv_sizes = self.comm.allgather(local_ndvs)
# Offsets for global design variable vector
offsets = np.zeros(self.comm.size, dtype=int)
offsets[1:] = np.cumsum(dv_sizes)[:-1]
# Gather the portions of the design variable array distributed across each processor
tot_ndvs = sum(dv_sizes)
global_dv_bounds = []
for ii in [0, 1]:
global_dv_bounds.append(
np.zeros(tot_ndvs, dtype=local_dv_bounds[ii].dtype)
)
self.comm.Allgatherv(
local_dv_bounds[ii],
[global_dv_bounds[ii], dv_sizes, offsets, MPI.DOUBLE],
)
# return the global dv array
return global_dv_bounds
else:
return self.fea_assembler.getDesignVarRange()

def get_dv_scalers(self):
"""Get an array containing the scaling factors for the design
variables, in the form needed by OpenMDAO's `add_design_variable`
method.

Returns
-------
array
Scaling values
"""
return np.array(self.fea_assembler.scaleList)

def get_ndv(self):
"""
Get total number of structural design variables across all procs
Expand Down
15 changes: 10 additions & 5 deletions tests/integration_tests/test_mphys_struct_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

"""
This is a simple 1m by 2m plate made up of four quad shell elements.
The plate is structurally loaded under a 100G gravity load and a unit force,
"f_struct", is applied on on every node. The mass and KSFailure of the plate
The plate is structurally loaded under a 100G gravity load and a unit force,
"f_struct", is applied on on every node. The mass and KSFailure of the plate
are evaluated as outputs and have their partial and total sensitivities checked.
"""

Expand Down Expand Up @@ -58,7 +58,7 @@ def element_callback(
E = 73.1e9 # elastic modulus, Pa
nu = 0.33 # poisson's ratio
ys = 324.0e6 # yield stress, Pa
thickness = 0.012
thickness = 0.01
min_thickness = 0.002
max_thickness = 0.05

Expand Down Expand Up @@ -125,10 +125,15 @@ def setup(self):
write_solution=False,
)
tacs_builder.initialize(self.comm)
ndv_struct = tacs_builder.get_ndv()

dvs = self.add_subsystem("dvs", om.IndepVarComp(), promotes=["*"])
dvs.add_output("dv_struct", np.array(ndv_struct * [0.01]))
structDVs = tacs_builder.get_initial_dvs()
dvs.add_output("dv_struct", structDVs)
lb, ub = tacs_builder.get_dv_bounds()
structDVScaling = tacs_builder.get_dv_scalers()
self.add_design_var(
"dv_struct", lower=lb, upper=ub, scaler=structDVScaling
)

f_size = tacs_builder.get_ndof() * tacs_builder.get_number_of_nodes()
forces = self.add_subsystem("forces", om.IndepVarComp(), promotes=["*"])
Expand Down