\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]

\newcommand{\pytext}[1]{\textcolor{violet}{#1}}

%============================
% 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[AIMs and Units]{
\includegraphics[width=1.0in]{caps_logo.png}\\
Computational Aircraft Prototype Syntheses\\
AIM Programming -- AIMs and Units\\[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{{\tt CAPS} and Units}

Any {\tt CAPS} Value Object can be assigned Units

\begin{itemize}
\item It is best to give any AnalysisIn, AnalysisOut or AnalysisDynO the appropriate units
that the analysis expects. This makes dealing with the analysis much simpler.
\item Any AnalysisIn Value will have already gone through a units conversion when exposed to the AIM.
\item Examine the Body's {\it capsLength} attribute to determine the geometry's units.
\item The AIM should either be unit-less as with all previous exercises {\bf or} with all appropriate units defined.
\end{itemize}

\end{frame}

\begin{frame}[fragile]
\FrameTitle{pyCAPS/Python Units}

\footnotesize
pyCAPS uses the CAPS unit manipulation functions (from {\tt udunits}) to be consistent with internal use of units in CAPS.  Similar to the Pint\footnotemark ~Python package,  this defines the following two classes:
\begin{itemize}
\vspace{-0.03in}
\item \pytext{pyCAPS.Unit}
\vspace{-0.03in}
\item \pytext{pyCAPS.Quantity}
\end{itemize}
where \pytext{pyCAPS.Unit} defines a unit which can be manipulated with standard operator, and \pytext{pyCAPS.Quantity} represents a value with units. This is designed to work with these classes as the C API uses the optional \textcolor{espred}{units} string of the Value Structure. The best way to extract a value from a \pytext{pyCAPS.Quantity} is to divide it out by its units.

\begin{columns}
\begin{column}{0.44\textwidth}
\begin{block}{Unit Manipulation}
\tiny
\begin{verbatim}
kg  = pyCAPS.Unit("kg")
m   = pyCAPS.Unit("m")
s   = pyCAPS.Unit("s")

Newton = kg*m/s**2
\end{verbatim}
\end{block}
\end{column}
\begin{column}{0.44\textwidth}
\begin{block}{Value from Quantity}
\tiny
\begin{verbatim}
m  = pyCAPS.Unit("m")
ft = pyCAPS.Unit("ft")

q = 10 * m     # Make a Quantity

assert(10 == q/m)
assert(10 == q.value())
assert(q.convert(ft).value() == q/ft)
\end{verbatim}
\end{block}
\end{column}
\end{columns}

\footnotetext{\scriptsize https://pint.readthedocs.io}
\end{frame}

\begin{frame}
\FrameTitle{Other uses for {\it Units} in the Value Structure}

\begin{block}{Path strings}
If the Value type is {\it String} and units member of the Value Structure is set to ``PATH'' then any slashes are converted automatically based
on the OS type currently in use.
\end{block}

\begin{block}{Pointer types and {\it linkages}}
For Value types of either {\it Pointer} or {\it PointerMesh} the units member of the Value Structure can be used to insure that there 
is an appropriate match when linking Values. That is; the unit strings must also match.\\[0.075in]
Note: using pointer linkages between AIMs should only be done cautiously because the data pointed to always needs to be structurally identical
across the AIMs.
\end{block}

\end{frame}

\begin{frame}

 \center
 {\LARGE AIM Helper Functions}
 
 \vspace{0.05in}
\normalsize Units Handling

 \vspace{0.3in}
   \begin{itemize}
  \item provides useful functions for the AIM programmer
  \item gives access to CAPS Object data
  \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 -- Units}

\vspace{-0.075in}
 \begin{block}{Unit conversion}
{\scriptsize

{\tt
icode = aim\_convert(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const int} count \\
\spaces[20]\textcolor{magenta}{const char}~~*inUnits, \textcolor{magenta}{double}~~*inValue, \\
\spaces[20]\textcolor{magenta}{const char} *outUnits,  \textcolor{magenta}{double} *outValue)}

\begin{description}

\item[aimInfo] the AIM context
\vspace{-0.02in}
\item[count]  length of {\tt inValue} and {\tt outValue}
\vspace{-0.02in}
\item[inUnits]  the pointer to the string declaring the source units
\vspace{-0.02in}
\item[inValue] array of values to be converted
\vspace{-0.02in}
\item[outUnits]  the pointer to the string declaring the desired units
\vspace{-0.02in}
\item[outValue] array of returned converted value (may be same pointer as {\tt inValue})
\vspace{-0.02in}
\item[icode] integer return code
\end{description}}
\end{block}

\vspace{-0.05in}
\begin{block}{Unit invertion}
{\scriptsize

{\tt
icode = aim\_unitInvert(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits, \\
\hspace{1.46in} \textcolor{magenta}{char} **outUnits)}

\begin{description}

\item[aimInfo] the AIM context
\vspace{-0.02in}
\item[inUnits] the pointer to the string declaring units
\vspace{-0.02in}
\item[outUnits] the returned string units = 1/inUnits (freeable)
\vspace{-0.02in}
\item[icode] integer return code
\end{description}}
\end{block}


\end{frame}

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

\begin{block}{Unit multiplication}
{\scriptsize

{\tt
icode = aim\_unitMultiply(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits1,  \\
\hspace{1.60in} \textcolor{magenta}{const char} *inUnits2, \textcolor{magenta}{char} **outUnits)}

\begin{description}

\item[aimInfo] the AIM context
\item[inUnits1] the pointer to the string declaring left units
\item[inUnits2] the pointer to the string declaring right units
\item[outUnits] the returned string units = inUnits1*inUnits2 (freeable)
\item[icode] integer return code
\end{description}}
\end{block}

\begin{block}{Unit division}
{\scriptsize

{\tt
icode = aim\_unitDivision(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits1,\\
\hspace{1.60in} \textcolor{magenta}{const char} *inUnits2, \textcolor{magenta}{char} **outUnits)}

\begin{description}

\item[aimInfo] the AIM context
\item[inUnits1] the pointer to the string declaring numerator units
\item[inUnits2] the pointer to the string declaring denominator units
\item[outUnits] the returned string units = inUnits1/inUnits2 (freeable)
\item[icode] integer return code
\end{description}}
\end{block}

\end{frame}

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

\begin{block}{Unit raise to a power}
{\scriptsize

{\tt
icode = aim\_unitRaise(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits, \\
\spaces[22]\textcolor{magenta}{const int} power, \textcolor{magenta}{char} **outUnits)}

\begin{description}
\item[aimInfo] the AIM context
\item[inUnits] the pointer to the string declaring units
\item[power] power to raise \textcolor{espred}{inUnits}
\item[outUnits] the returned string units = \textcolor{espred}{inUnits} \string^ \textcolor{espred}{power} (freeable)
\item[icode] integer return code
\end{description}}
\end{block}

\begin{block}{Unit raise to root}
  {\scriptsize

  {\tt
  icode = aim\_unitRoot(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits, \\
  \spaces[22]\textcolor{magenta}{const int} root, \textcolor{magenta}{char} **outUnits)}

  \begin{description}
  \item[aimInfo] the AIM context
  \item[inUnits] the pointer to the string declaring units
  \item[root] root to raise \textcolor{espred}{inUnits}
  \item[outUnits] the returned string units = \textcolor{espred}{inUnits} \string^ 1/\textcolor{espred}{root} (freeable)
  \item[icode] integer return code
  \end{description}}
  \end{block}

\end{frame}

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

\begin{block}{Unit Offset}
{\scriptsize

{\tt
icode = aim\_unitOffset(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *inUnits, \\
\spaces[23]\textcolor{magenta}{const double} offset, \textcolor{magenta}{char} **outUnits)}

\begin{description}
\item[aimInfo] the AIM context
\item[inUnits] the pointer to the string declaring units
\item[offset] offset to add to inUnits
\item[outUnits] the returned string units = inUnits @ offset (freeable)
\item[icode] integer return code
\end{description}}
\end{block}

\begin{block}{Check if two unit strings are convertible}
{\scriptsize

{\tt
icode = aim\_unitConvertible(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} *unit1, \\
\spaces[28]\textcolor{magenta}{const char} *unit2)}

\begin{description}
\item[aimInfo] the AIM context
\item[unit1] string pointer declaring units
\item[unit2] string pointer declaring units
\item[icode] integer return code
\end{description}}
\end{block}

\end{frame}

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

\begin{block}{Retrieve capsLength length unit attribute from bodies}
{\scriptsize

{\tt
icode = aim\_capsLength(\textcolor{magenta}{void} *aimInfo, \textcolor{magenta}{const char} **lengthUnit)}

\begin{description}
\item[aimInfo] the AIM context
\item[lengthUnit] the returned string length unit of the bodies
\item[icode] integer return code
\end{description}}
\end{block}

 \begin{block}{Get Unit System}
{\scriptsize

{\tt
icode = aim\_unitSys(\textcolor{magenta}{void} *aimInfo,  \textcolor{magenta}{char} **unitSys)}

\begin{description}

\item[aimInfo] the AIM context
\item[unitSys] a returned pointer to a character string declaring the unit system -- can be \textcolor{espred} {NULL}
\item[icode] integer return code
\end{description}

Note: This is a string set at Problem initialization and was supposed to set the unit system in use (i.e., {\it SI},\\[-0.01in]
{\it US} or the like) for the problem at-hand. This standardization never took hold, but this string got used for\\[-0.075in]
 other unit information (so it could not be easily removed). Best to ignore!
}
\end{block}

\end{frame}


\begin{frame}
\FrameTitle{Exercises}

In {\it exercises/session11} modify {\footnotesize {\tt theAIM.c}} to work with {\footnotesize {\tt session11.py}}:
\begin{itemize}
\item Mass should be in {\bf kg} and length should be in {\bf m}
\item Add another input (wallThickness -- in {\bf m}), so that all densities can be in {\bf kg/m3}
\item Add unit definitions for the variables set by {\tt aimInputs} and {\tt aimOutputs}
\item Allow for the scaling of the geometry (when the triangulation is written)
\vspace{0.15in}
\item Once functioning, explore changing units in the Python script
\end{itemize}
  
 \end{frame}


\end{document}

