Skip to content

Commit

Permalink
working functors
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-engelstad committed Oct 8, 2024
1 parent e020e43 commit d71c8ee
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 71 deletions.
61 changes: 30 additions & 31 deletions examples/gp_stiffened_plate/mlb_plate_compare_highAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ class uses T stiffeners.


# Overall plate dimensions
width = 0.422
length = 1.0
width = 1.0
length = 6.25773

# Material properties (UD tape properties from textbook case)
rho = 1609.0
E1 = 138e9
E2 = 9.177e9
nu12 = 0.326
G12 = 4.957e9
G13 = 4.957e9
E2 = 138e9
nu12 = 0.3
G12 = E1 / 2.0 / (1+nu12)
G13 = E1 / 2.0 / (1+nu12)
Xt = 2068e6
Xc = 1723e6
Yt = 96.5e6
Expand All @@ -112,29 +112,29 @@ class uses T stiffeners.
panelLength = length
panelWidth = width

stiffenerPitch = 0.111
stiffenerPitch = 0.5
stiffenerPitchMin = 0.1
stiffenerPitchMax = 0.7

panelThickness = 1e-2
panelThicknessMin = 0.6e-3
panelThicknessMax = 0.1

stiffenerHeight = 27.4e-3
stiffenerHeightMin = 25e-3
stiffenerHeight = 76.633e-3
stiffenerHeightMin = 10e-3
stiffenerHeightMax = 0.15

stiffenerThickness = 5.49e-3
stiffenerThickness = 3.8316e-3
stiffenerThicknessMin = 0.6e-3
stiffenerThicknessMax = 0.1

# Ply angles/initial ply fractions
ply_angles = np.deg2rad([0.0, 45.0])
skin_ply_fractions = np.array([0.7, 0.3])
stiffener_ply_fractions = np.array([0.7, 0.3])
ply_angles = np.deg2rad([0.0])
skin_ply_fractions = np.array([1.0])
stiffener_ply_fractions = np.array([1.0])

# Shear and compressive traction loads
Ny = 30209 # N/m
Ny = 121167 # N/m
Nxy = 0.0 # N/m


Expand Down Expand Up @@ -177,11 +177,10 @@ def element_callback(
skin_ply_fraction_dv_nums = np.array(
[
currentDVNum,
currentDVNum + 1,
],
dtype=np.intc,
)
currentDVNum += 2
currentDVNum += 1

stiffenerHeightNum = currentDVNum
currentDVNum = currentDVNum + 1
Expand All @@ -194,11 +193,10 @@ def element_callback(
stiffener_ply_fraction_dv_nums = np.array(
[
currentDVNum,
currentDVNum + 1,
],
dtype=np.intc,
)
currentDVNum += 2
currentDVNum += 1
else:
skin_ply_fraction_dv_nums = -np.ones(len(ply_angles), dtype=np.intc)
stiffener_ply_fraction_dv_nums = -np.ones(
Expand Down Expand Up @@ -231,17 +229,17 @@ def element_callback(
panelWidthNum=panelWidthNum,
flangeFraction=0.0,
)
# con.setStiffenerPitchBounds(stiffenerPitchMin, stiffenerPitchMax)
# con.setPanelThicknessBounds(panelThicknessMin, panelThicknessMax)
# con.setStiffenerThicknessBounds(
# stiffenerThicknessMin, stiffenerThicknessMax
# )
# con.setPanelPlyFractionBounds(
# np.array([1.0]), np.array([1.0])
# )
# con.setStiffenerPlyFractionBounds(
# np.array([1.0]), np.array([1.0])
# )
con.setStiffenerPitchBounds(stiffenerPitchMin, stiffenerPitchMax)
con.setPanelThicknessBounds(panelThicknessMin, panelThicknessMax)
con.setStiffenerThicknessBounds(
stiffenerThicknessMin, stiffenerThicknessMax
)
con.setPanelPlyFractionBounds(
np.array([0.0]), np.array([1.0])
)
con.setStiffenerPlyFractionBounds(
np.array([0.0]), np.array([1.0])
)

# We need to enforce that stiffenerHeight <= stiffenerPitch, if we are not
# using a stiffener pitch DV we can simply enforce this as an upper bound
Expand Down Expand Up @@ -278,10 +276,10 @@ def element_callback(
DVScales.append(stiffPitchScale)
DVScales.append(panelThicknessScale)
if args.usePlyFracDV:
DVScales += [1.0] * 4
DVScales += [1.0] * 1
DVScales += [stiffenerHeightScale, stiffenerThicknessScale]
if args.usePlyFracDV:
DVScales += [1.0] * 4
DVScales += [1.0] * 1

return elem, DVScales

Expand Down Expand Up @@ -583,6 +581,7 @@ def configure(self):
prob.setup(mode="rev")

prob.run_model()
print("done", flush=True)
exit()

# Output N2 representation of OpenMDAO model
Expand Down
51 changes: 42 additions & 9 deletions src/constitutive/TACSBladeStiffenedShellConstitutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ TACSBladeStiffenedShellConstitutive::TACSBladeStiffenedShellConstitutive(
// Arrays for storing ply failure sensitivities
this->panelPlyFailSens = new TacsScalar[2 * this->numPanelPlies];
this->stiffenerPlyFailSens = new TacsScalar[2 * this->numStiffenerPlies];

// initialize the functions using the base class
// these function pointers are overwritten in the derived class for GP/ML buckling
evalLocalPanelBuckling = [this](const TacsScalar e[]) {
return this->_evalLocalPanelBuckling(e);
};
evalGlobalPanelBuckling = [this](const TacsScalar e[]) {
return this->_evalGlobalPanelBuckling(e);
};
evalStiffenerCrippling = [this](const TacsScalar stiffenerStrain[]) {
return this->_evalStiffenerCrippling(stiffenerStrain);
};
evalLocalPanelBucklingStrainSens = [this](const TacsScalar e[], TacsScalar localBucklingSens[]) {
return this->_evalLocalPanelBucklingStrainSens(e, localBucklingSens);
};
evalGlobalPanelBucklingStrainSens = [this](const TacsScalar e[], TacsScalar globalBucklingSens[]) {
return this->_evalGlobalPanelBucklingStrainSens(e, globalBucklingSens);
};
evalStiffenerCripplingStrainSens = [this](const TacsScalar stiffenerStrain[], TacsScalar stiffenerStrainSens[]) {
return this->_evalStiffenerCripplingStrainSens(stiffenerStrain, stiffenerStrainSens);
};
addLocalPanelBucklingDVSens = [this](int elemIndex, TacsScalar scale, const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen, TacsScalar dfdx[]) {
return this->_addLocalPanelBucklingDVSens(elemIndex, scale, pt, X, strain, dvLen, dfdx);
};
addGlobalPanelBucklingDVSens = [this](int elemIndex, TacsScalar scale, const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen, TacsScalar dfdx[]) {
return this->_addGlobalPanelBucklingDVSens(elemIndex, scale, pt, X, strain, dvLen, dfdx);
};
addStiffenerCripplingDVSens = [this](const TacsScalar scale, const TacsScalar stiffenerStrain[], TacsScalar dfdx[]) {
return this->_addStiffenerCripplingDVSens(scale, stiffenerStrain, dfdx);
};

}

// ==============================================================================
Expand Down Expand Up @@ -2031,7 +2064,7 @@ void TACSBladeStiffenedShellConstitutive::computeStiffenerMOISens(
// Buckling functions
// ==============================================================================

TacsScalar TACSBladeStiffenedShellConstitutive::evalGlobalPanelBuckling(
TacsScalar TACSBladeStiffenedShellConstitutive::_evalGlobalPanelBuckling(
const TacsScalar e[]) {
TacsScalar stress[TACSShellConstitutive::NUM_STRESSES];
TacsScalar D1, D2, D3;
Expand Down Expand Up @@ -2102,7 +2135,7 @@ void TACSBladeStiffenedShellConstitutive::
}

TacsScalar
TACSBladeStiffenedShellConstitutive::evalGlobalPanelBucklingStrainSens(
TACSBladeStiffenedShellConstitutive::_evalGlobalPanelBucklingStrainSens(
const TacsScalar e[], TacsScalar sens[]) {
TacsScalar stiffness[NUM_TANGENT_STIFFNESS_ENTRIES], stress[NUM_STRESSES];
this->computeStiffness(stiffness);
Expand Down Expand Up @@ -2131,7 +2164,7 @@ TACSBladeStiffenedShellConstitutive::evalGlobalPanelBucklingStrainSens(
return strengthRatio;
}

void TACSBladeStiffenedShellConstitutive::addGlobalPanelBucklingDVSens(
void TACSBladeStiffenedShellConstitutive::_addGlobalPanelBucklingDVSens(
int elemIndex, TacsScalar scale, const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen, TacsScalar dfdx[]) {
TacsScalar stress[NUM_STRESSES];
Expand Down Expand Up @@ -2675,7 +2708,7 @@ void TACSBladeStiffenedShellConstitutive::testGlobalBucklingStiffnessSens() {
delete[] DVPert;
}

TacsScalar TACSBladeStiffenedShellConstitutive::evalLocalPanelBuckling(
TacsScalar TACSBladeStiffenedShellConstitutive::_evalLocalPanelBuckling(
const TacsScalar e[]) {
// Compute panel stiffness matrix and loads
TacsScalar panelStiffness[NUM_TANGENT_STIFFNESS_ENTRIES],
Expand Down Expand Up @@ -2722,7 +2755,7 @@ TacsScalar TACSBladeStiffenedShellConstitutive::computeCriticalShearLoad(
}

TacsScalar
TACSBladeStiffenedShellConstitutive::evalLocalPanelBucklingStrainSens(
TACSBladeStiffenedShellConstitutive::_evalLocalPanelBucklingStrainSens(
const TacsScalar e[], TacsScalar sens[]) {
// Compute panel stiffness matrix and loads
TacsScalar panelStiffness[NUM_TANGENT_STIFFNESS_ENTRIES],
Expand Down Expand Up @@ -2757,7 +2790,7 @@ TACSBladeStiffenedShellConstitutive::evalLocalPanelBucklingStrainSens(
return strengthRatio;
}

void TACSBladeStiffenedShellConstitutive::addLocalPanelBucklingDVSens(
void TACSBladeStiffenedShellConstitutive::_addLocalPanelBucklingDVSens(
int elemIndex, TacsScalar scale, const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen, TacsScalar dfdx[]) {
// Compute panel stiffness matrix and loads
Expand Down Expand Up @@ -3316,7 +3349,7 @@ void TACSBladeStiffenedShellConstitutive::computeStiffenerCripplingValues(
}
}

TacsScalar TACSBladeStiffenedShellConstitutive::evalStiffenerCrippling(
TacsScalar TACSBladeStiffenedShellConstitutive::_evalStiffenerCrippling(
const TacsScalar stiffenerStrain[]) {
const int numPlies = this->numStiffenerPlies;
this->computeStiffenerCripplingValues(stiffenerStrain,
Expand All @@ -3328,7 +3361,7 @@ TacsScalar TACSBladeStiffenedShellConstitutive::evalStiffenerCrippling(
}

TacsScalar
TACSBladeStiffenedShellConstitutive::evalStiffenerCripplingStrainSens(
TACSBladeStiffenedShellConstitutive::_evalStiffenerCripplingStrainSens(
const TacsScalar stiffenerStrain[], TacsScalar sens[]) {
const int numPlies = this->numStiffenerPlies;
const int numStrain = TACSBeamConstitutive::NUM_STRESSES;
Expand Down Expand Up @@ -3452,7 +3485,7 @@ TACSBladeStiffenedShellConstitutive::evalStiffenerCripplingStrainSens(
return fail;
}

void TACSBladeStiffenedShellConstitutive::addStiffenerCripplingDVSens(
void TACSBladeStiffenedShellConstitutive::_addStiffenerCripplingDVSens(
const TacsScalar scale, const TacsScalar stiffenerStrain[],
TacsScalar dfdx[]) {
TACSOrthotropicPly* ply = this->stiffenerPly;
Expand Down
30 changes: 21 additions & 9 deletions src/constitutive/TACSBladeStiffenedShellConstitutive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bladeFSDT model from previous versions of TACS developed by Graeme Kennedy.
#include "TACSMaterialProperties.h"
#include "TACSShellConstitutive.h"
#include "TacsUtilities.h"
#include <functional>

void printStiffnessMatrix(const TacsScalar* const C);

Expand Down Expand Up @@ -885,7 +886,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
* @param e Shell strains
* @return TacsScalar Strength ratio
*/
TacsScalar evalGlobalPanelBuckling(const TacsScalar e[]);
TacsScalar _evalGlobalPanelBuckling(const TacsScalar e[]);

/**
* @brief Compute the panel + stiffener stiffness values used to compute the
Expand All @@ -907,7 +908,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
* @param sens Sensitivity of the output w.r.t the shell strains
* @return TacsScalar Strength Ratio
*/
TacsScalar evalGlobalPanelBucklingStrainSens(const TacsScalar e[],
TacsScalar _evalGlobalPanelBucklingStrainSens(const TacsScalar e[],
TacsScalar sens[]);

/**
Expand All @@ -922,7 +923,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
@param dvLen The length of the design vector (not used)
@param dfdx The DV sensitivity array to add to
*/
void addGlobalPanelBucklingDVSens(int elemIndex, TacsScalar scale,
void _addGlobalPanelBucklingDVSens(int elemIndex, TacsScalar scale,
const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen,
TacsScalar dfdx[]);
Expand Down Expand Up @@ -973,7 +974,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
* @param e Shell strains
* @return TacsScalar Strength ratio
*/
TacsScalar evalLocalPanelBuckling(const TacsScalar e[]);
TacsScalar _evalLocalPanelBuckling(const TacsScalar e[]);

/**
* @brief Compute the critical axial load for local buckling of the panel
Expand All @@ -1000,7 +1001,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
* @param sens Sensitivity of the output w.r.t the shell strains
* @return TacsScalar Strength Ratio
*/
TacsScalar evalLocalPanelBucklingStrainSens(const TacsScalar e[],
TacsScalar _evalLocalPanelBucklingStrainSens(const TacsScalar e[],
TacsScalar sens[]);

/**
Expand All @@ -1015,7 +1016,7 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
@param dvLen The length of the design vector (not used)
@param dfdx The DV sensitivity array to add to
*/
void addLocalPanelBucklingDVSens(int elemIndex, TacsScalar scale,
void _addLocalPanelBucklingDVSens(int elemIndex, TacsScalar scale,
const double pt[], const TacsScalar X[],
const TacsScalar strain[], int dvLen,
TacsScalar dfdx[]);
Expand Down Expand Up @@ -1281,14 +1282,14 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
* @param stiffenerStrain Stiffener centroid beam strains
* @return TacsScalar Strength ratio
*/
TacsScalar evalStiffenerCrippling(const TacsScalar stiffenerStrain[]);
TacsScalar _evalStiffenerCrippling(const TacsScalar stiffenerStrain[]);
void computeStiffenerCripplingValues(const TacsScalar stiffenerStrain[],
TacsScalar plyFailValues[]);

TacsScalar evalStiffenerCripplingStrainSens(
TacsScalar _evalStiffenerCripplingStrainSens(
const TacsScalar stiffenerStrain[], TacsScalar sens[]);

void addStiffenerCripplingDVSens(const TacsScalar scale,
void _addStiffenerCripplingDVSens(const TacsScalar scale,
const TacsScalar stiffenerStrain[],
TacsScalar dfdx[]);

Expand Down Expand Up @@ -1389,6 +1390,17 @@ class TACSBladeStiffenedShellConstitutive : public TACSShellConstitutive {
TacsScalar* panelPlyFailSens;
TacsScalar* stiffenerPlyFailSens;

// function pointers for overridden buckling loads for ML/GP buckling subclass
std::function<TacsScalar(const TacsScalar[])> evalLocalPanelBuckling;
std::function<TacsScalar(const TacsScalar[])> evalGlobalPanelBuckling;
std::function<TacsScalar(const TacsScalar[])> evalStiffenerCrippling;
std::function<TacsScalar(const TacsScalar[],TacsScalar[])> evalLocalPanelBucklingStrainSens;
std::function<TacsScalar(const TacsScalar[],TacsScalar[])> evalGlobalPanelBucklingStrainSens;
std::function<TacsScalar(const TacsScalar[],TacsScalar[])> evalStiffenerCripplingStrainSens;
std::function<void(int,TacsScalar,const double[],const TacsScalar[],const TacsScalar[],int dvLen,TacsScalar[])> addLocalPanelBucklingDVSens;
std::function<void(int,TacsScalar,const double[],const TacsScalar[],const TacsScalar[],int dvLen,TacsScalar[])> addGlobalPanelBucklingDVSens;
std::function<void(const TacsScalar, const TacsScalar[], TacsScalar[])> addStiffenerCripplingDVSens;

static const char* const constName; ///< Constitutive model name
static const int NUM_Q_ENTRIES = 6; ///< Number of entries in the Q matrix
static const int NUM_ABAR_ENTRIES =
Expand Down
Loading

0 comments on commit d71c8ee

Please sign in to comment.