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 the possibility to change the position of the scaling for the chord design variable #410

Merged
merged 14 commits into from
Jun 26, 2023
7 changes: 6 additions & 1 deletion openaerostruct/geometry/geometry_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ def setup(self):
val = np.ones(ny)
if "chord_cp" in surface:
promotes = ["chord"]
if "chord_scaling_pos" in surface:
gamma = surface["chord_scaling_pos"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you change the option name, also change this variable name. Also can't this if else block be moved outside of the if "chord_cp" in surface block so that you don't need to duplicate the gamma = 0.25 line? If you want to be even nicer, you could throw a warning if "chord_scaling_pos" is specified but there are no chord DVs.

else:
gamma = 0.25 # if no scaling position is specified : chord scaling w.r.t quarter of chord
else:
promotes = []
gamma = 0.25

self.add_subsystem("scale_x", ScaleX(val=val, mesh_shape=mesh_shape), promotes_inputs=promotes)
self.add_subsystem("scale_x", ScaleX(val=val, mesh_shape=mesh_shape, gamma=gamma), promotes_inputs=promotes)

# 3. Sweep

Expand Down
23 changes: 14 additions & 9 deletions openaerostruct/geometry/geometry_mesh_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ def initialize(self):
"""
self.options.declare("val", desc="Initial value for chord lengths")
self.options.declare("mesh_shape", desc="Tuple containing mesh shape (nx, ny).")
self.options.declare(
"gamma",
eytanadler marked this conversation as resolved.
Show resolved Hide resolved
default=0.25,
desc="float in [0.,1.] which indicates the chord fraction where to do the chord scaling. 1. is trailing edge, 0. is leading edge",
eytanadler marked this conversation as resolved.
Show resolved Hide resolved
)

def setup(self):
mesh_shape = self.options["mesh_shape"]
val = self.options["val"]

self.gamma = self.options["gamma"]
self.add_input("chord", units="m", val=val)
self.add_input("in_mesh", shape=mesh_shape, units="m")

Expand Down Expand Up @@ -166,19 +171,19 @@ def compute(self, inputs, outputs):

te = mesh[-1]
le = mesh[0]
quarter_chord = 0.25 * te + 0.75 * le
gamma_chord = self.gamma * te + (1 - self.gamma) * le

outputs["mesh"] = np.einsum("ijk,j->ijk", mesh - quarter_chord, chord_dist) + quarter_chord
outputs["mesh"] = np.einsum("ijk,j->ijk", mesh - gamma_chord, chord_dist) + gamma_chord

def compute_partials(self, inputs, partials):
mesh = inputs["in_mesh"]
chord_dist = inputs["chord"]

te = mesh[-1]
le = mesh[0]
quarter_chord = 0.25 * te + 0.75 * le
gamma_chord = self.gamma * te + (1 - self.gamma) * le

partials["mesh", "chord"] = (mesh - quarter_chord).flatten()
partials["mesh", "chord"] = (mesh - gamma_chord).flatten()

nx, ny, _ = mesh.shape
nn = nx * ny * 3
Expand All @@ -187,12 +192,12 @@ def compute_partials(self, inputs, partials):

d_qc = (np.einsum("ij,i->ij", np.ones((ny, 3)), 1.0 - chord_dist)).flatten()
nnq = (nx - 1) * ny * 3
partials["mesh", "in_mesh"][nn : nn + nnq] = np.tile(0.25 * d_qc, nx - 1)
partials["mesh", "in_mesh"][nn + nnq :] = np.tile(0.75 * d_qc, nx - 1)
partials["mesh", "in_mesh"][nn : nn + nnq] = np.tile(self.gamma * d_qc, nx - 1)
partials["mesh", "in_mesh"][nn + nnq :] = np.tile((1 - self.gamma) * d_qc, nx - 1)

nnq = ny * 3
partials["mesh", "in_mesh"][nn - nnq : nn] += 0.25 * d_qc
partials["mesh", "in_mesh"][:nnq] += 0.75 * d_qc
partials["mesh", "in_mesh"][nn - nnq : nn] += self.gamma * d_qc
partials["mesh", "in_mesh"][:nnq] += (1 - self.gamma) * d_qc


class Sweep(om.ExplicitComponent):
Expand Down