\documentclass[12pt]{beamer}
\input{BEAMERoptions.tex}

% ----- Packages and libraries ----- %
\usepackage[T1]{fontenc} 				% cut/paste and search with "_"
\usepackage[english]{babel}
\usepackage{graphics}
\usepackage{verbatim}
\usepackage{times}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{subfigure}
\usepackage{amssymb}
\usepackage{amsmath, amsfonts}
\usepackage{amsthm}
\usepackage{color}
\usepackage{alltt}
\usepackage{anyfontsize}
\usepackage{tikz}
   \usetikzlibrary{shapes, arrows, shadows}

\newcommand{\Frametitle}[1]{\frametitle{\includegraphics[width=0.25in]{esp_logo.png}
      \hspace{0.05in} #1}}

\newcommand{\FrameTitle}[1]{\frametitle{\includegraphics[width=0.3in]{caps_logo.png}
      \hspace{0.05in} #1}}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]

%============================
% command to repeate a ~ n-times
%============================
\newcount\myloopcounter

\newcommand{\spaces}[1][10]{%
  \myloopcounter0% initialize the loop counter
  \loop\ifnum\myloopcounter < #1 % Test if the loop counter is < #1
  ~%
  \advance\myloopcounter by 1 %
  \repeat % start again
}
%============================

% ----- Presentation information ----- %
\title[AIM Programming -- Sensitivities]{
\includegraphics[width=1.0in]{caps_logo.png}\\
Computational Aircraft Prototype Syntheses\\
AIM Programming -- Sensitivities\\[0.02in]
For {\tt ESP} Rev 1.28}

\author[Haimes]{
Bob Haimes \\
  {\footnotesize \textcolor{blue}{bob@geocentrictech.com}~~or~~\textcolor{blue}{haimes@mit.edu} \\[-0.03in]
    Geocentric Technologies LLC}
}

\date[July 2025]{}

% ----- Document follows ----- %

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}
  \FrameTitle{Introduction}
  
   \begin{block}{Geometric Sensitivities}
   \begin{itemize}
   \item Provides access to {\tt OpenCSM}'s sensitivity calculations
   \item Accomplished one Design Parameter at a time
   \item pyCAPS user has access through built-in {\it dataSets} named with the CSM Design Parameter --
   seen in {\it exercises/session12} by running {\tt sensitivities.py}.
   \end{itemize}
   \end{block}
   
   \begin{block}{Output Values -- derivatives}
   \begin{itemize}
   \item The {\tt CAPS} Value structure has slots to store derivative information if available from the analysis at-hand
   \item This should be populated when the value is set
   \end{itemize}
   \end{block}
   
\end{frame}

\begin{frame}

 \center
 {\LARGE AIM Helper Functions}

 \vspace{0.05in}
\normalsize Sensitivity Access

 \vspace{0.3in}
   \begin{itemize}
  \item provides useful functions for the AIM programmer
  \item gives access to CAPS Object data
  \item provides a dynamically loadable writer interface for dealing with large meshes
  \item note that all function names begin with {\tt aim\_}
  \item if any of these functions are used, then the library must be included (libaimUtil.a/aimUtil.lib) in the AIM so/DLL build
  \end{itemize}

\end{frame}


\begin{frame}
  \FrameTitle{AIM Utility Library -- Sensitivities}

 \begin{block}{Define Parameter Associated with Sensitivities}
{\scriptsize

{\tt
icode = aim\_setSensitivity(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *GIname, \\
\hspace{1.725in} \textcolor{magenta}{int} *irow, \textcolor{magenta}{int} *icol)}

\begin{description}

\item[aimInfo] the AIM context
\item[GIname] the  pointer to the string that matches the {\it Geometry Input} Parameter name
\item[irow] the parameter row to use -- 1 bias
\item[icol] the parameter column to use -- 1 bias
\item[icode] integer return code
\end{description}}
\vspace{0.075in}
\scriptsize
Notes:
\begin{enumerate}
\item {\tt aim\_newTess} must have been invoked sometime before calling this function to set the\\
tessellations for the Bodies of interest
\item Call {\tt aim\_setSensitivity} before call(s) to {\tt aim\_getSensitivity}.
\end{enumerate}
\end{block}

\end{frame}

\begin{frame}
  \FrameTitle{AIM Utility Library -- Sensitivities}

 \begin{block}{Get Sensitivities based on Tessellation Components}
{\scriptsize

{\tt
icode = aim\_getSensitivity(\textcolor{magenta}{void} *aimInfo,  \textcolor{blue}{ego} tess, \textcolor{magenta}{int} ttype, \\
\hspace{1.725in} \textcolor{magenta}{int} index, \textcolor{magenta}{int} *npts, \textcolor{magenta}{double} **dxyz)}

\begin{description}

\item[aimInfo] the AIM context
\item[tess]  the EGADS Tessellation Object
\item[ttype] topological type -- 0 - NODE, {\it Tessellation Sensitivities}: 1 - EDGE, \hspace{0.032in}2 - FACE \\
\hspace{1.31in} {\it Geometric Sensitivities}: ~-1 - EDGE, -2 - FACE
\item[index] the index in the Body (associated with the tessellation) based on the {\it type} (bias 1)
\item[npts] the returned number of sensitivities (number of tessellation points)
\item[dxyz] a pointer to the returned sensitivities -- 3*npts in length ({\it freeable})
\item[icode] integer return code
\end{description}}
\scriptsize
Note:\\
\begin{itemize}
\item Call {\tt aim\_setSensitivity} before call(s) to {\tt aim\_getSensitivity}
\end{itemize}
\end{block}

\end{frame}

\begin{frame}
  \FrameTitle{AIM Utility Library -- Sensitivities}
  
 \begin{block}{Get Global Tessellation Sensitivities}
{\scriptsize

{\tt
icode = aim\_tessSensitivity(\textcolor{magenta}{void} *aimInfo,  \textcolor{magenta}{const char} *name, \\
\hspace{1.79in} \textcolor{magenta}{int} irow, \textcolor{magenta}{int} icol, \textcolor{blue}{ego} tess, \textcolor{magenta}{int} *npts, \\
\hspace{1.79in} \textcolor{magenta}{double} **dxyz)}

\begin{description}

\item[aimInfo] the AIM context
\item[name] the  pointer to the string that matches the {\it Geometry Input} Parameter name
\item[irow] the parameter row to use -- 1 bias
\item[icol] the parameter column to use -- 1 bias
\item[tess]  the EGADS Tessellation Object
\item[npts] the returned number of sensitivities (number of global vertices)
\item[dxyz] a pointer to the returned sensitivities -- 3*npts in length ({\it freeable})
\item[icode] integer return code
\end{description}}
\scriptsize
Notes:
\begin{enumerate}
\item Used to get the tessellation sensitivities for the entire Tessellation Object
\item The number of points is the global number of vertices in the tessellation
\item This function does not require that {\tt aim\_setSensitivity} be called first
\end{enumerate}
\end{block}

\end{frame}

\begin{frame}
  \FrameTitle{AIM Utility Library -- Sensitivities}

 \begin{block}{Set Step Size for Sensitivities}
{\scriptsize

{\tt
icode = aim\_setStepSize(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{double} step)}

\begin{description}

\item[aimInfo] the AIM context
\item[step] the step size used for subsequent AIM-based sensitivity calculations\\
minus indicates defaulting to CAPS, 0.0 is for analytic, positive sets the finite difference step size
\item[icode] integer return code
\end{description}}
\end{block}

 \begin{block}{Get Step Size for Sensitivities}
{\scriptsize

{\tt
icode = aim\_getStepSize(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{double} *step)}

\begin{description}

\item[aimInfo] the AIM context
\item[step] the step size used for subsequent AIM-based sensitivity calculations\\
minus indicates defaulting to CAPS, 0.0 is for analytic, positive sets the finite difference step size
\item[icode] integer return code
\end{description}}
\end{block}

\vspace{-0.075in}
\center These functions should only be used for debugging
\end{frame}

\begin{frame}[fragile]
\FrameTitle{Storing derivative information in {\tt CAPS}}

\vspace{-0.05in}
\begin{block}{Filling in the Value Structure}
{\scriptsize
\begin{verbatim}
  char   *sensVar;                 // filled with WRT string
  double value_dot;                // filled with the derivative

  /* only 1 derivative (WRT sensVar) */
  val->nderiv = 1;                 // only 1 derivative of rank 1
  AIM_ALLOC(val->derivs, val->nderiv, capsDeriv, aimInfo, status);
  val->derivs[0].name  = NULL;
  val->derivs[0].deriv = NULL;

  /* set what the first (only) derivative is with respect to */
  AIM_STRDUP(val->derivs[0].name, sensVar, aimInfo, status);

  /* the rank (i.e., area, volume, and mass all have rank 1) */
  val->derivs[0].len_wrt = 1;

  /* allocate storage for the derivative(s) */
  length = val->length * val->derivs[0].len_wrt;
  AIM_ALLOC(val->derivs[0].deriv, length, double, aimInfo, status);
  
  /* fill it */
  val->derivs[0].deriv[0] = value_dot;
\end{verbatim}
}
\end{block}

\end{frame}

\begin{frame}
\FrameTitle{Exercises}

\begin{block}{Sensitivities} 
Setup {\tt theAIM} to deal with sensitivities through {\tt tankCalc}
\begin{itemize}
\item Select an GeometryIn or AnalysisIn to get the derivative WRT. This should be in the form of a string value.
\item Get the geometry {\it dot} information via the routines listed above\\
The dot value for AnalysisIn sensitivities is 1.0 for the input of interest, 0.0 for all others
\item Fill the derivative information into the {\tt derivs} member of the appropriate AnalysisOut Value structure in {\it Post} or {\it CalcOutput}
\item The type of any Output Value Structure that contains derivatives must be set to {\it DoubleDeriv} (not {\it Double})
\end{itemize}
\vspace{0.075in}
Note that in {\it exercises/session12} we will be looking at geometric sensitivities associated with {\it Bounds}
\end{block}
  
 \end{frame}
 
  \begin{frame}
\FrameTitle{Exercises}
 
\begin{block}{The simple analysis: {\tt tankCalc}}
Computes a fuel tank's mass with {\bf AnalysisIn Sensitivities}
\begin{itemize}
\item Input file format -- ASCII
\begin{itemize}
\item An integer -- 1
\item 4 doubles -- wallDensity, wallDensity\_dot, fuelDensity and fuelDensity\_dot
\item 9 floating point numbers -- 3 {\it xyzs} for 3 points for the triangle\\
There may be as many triangles as necessary, which should represent a closed volume
\end{itemize}
\item Output file format -- ASCII
\begin{itemize}
\item 6 floating point numbers on a single line
\item area, area\_dot, volume, volume\_dot, mass and mass\_dot of the fuel tank
\end{itemize}
\end{itemize}
\end{block}
  
 \end{frame}
 
   \begin{frame}
\FrameTitle{Exercises}
 
\begin{block}{The simple analysis: {\tt tankCalc}}
Computes a fuel tank's mass with {\bf GeometryIn Sensitivities}
\begin{itemize}
\item Input file format -- ASCII
\begin{itemize}
\item An integer -- 2
\item 4 doubles -- wallDensity, wallDensity\_dot, fuelDensity and fuelDensity\_dot
\item 18 floating point numbers  representing a single triangle\\
3 {\it xyzs} then 3 {\it xyz}\_dots for the 3 points that support the triangle\\
There may be as many triangles as necessary, which should represent a closed volume
\end{itemize}
\item Output file format -- ASCII
\begin{itemize}
\item 6 floating point numbers on a single line
\item area, area\_dot, volume, volume\_dot, mass and mass\_dot of the fuel tank
\end{itemize}
\end{itemize}
\end{block}
  
 \end{frame}



\end{document}
