# A first test case with SHARPy¶

This notebook explains how to create a prismatic cantilever and flexible wing in SHARPy. It aims to provide a big picture about the simulations available in SHARPy describing the very fundamental concepts.

This notebook requires around two hours to be completed.

## Generation of the aeroelastic model¶

This section explains how to generate the input files for SHARPy including the structure, the aerodynamics and the simulation details.

```
[3]:
```

```
# Loading of the used packages
import numpy as np # basic mathematical and array functions
import os # Functions related to the operating system
import matplotlib.pyplot as plt # Plotting library
import sharpy.sharpy_main # Run SHARPy inside jupyter notebooks
import sharpy.utils.plotutils as pu # Plotting utilities
from sharpy.utils.constants import deg2rad # Constant to conver degrees to radians
import sharpy.utils.generate_cases as gc
```

The generate cases module of SHARPy includes a number of templates for the creation of simple cases using common parameters as inputs. It also removes clutter from this notebook.

The following cell configures the plotting library to show the next graphics, it is not part of SHARPy.

```
[4]:
```

```
%%capture
! pip install plotly
```

### Define the problem parameters¶

In this section, we define the basic parameters to generate a model for the wing shown in the image below. We use SI units for all variables.

```
[5]:
```

```
%config InlineBackend.figure_format = 'svg'
from IPython.display import Image
url = ('https://raw.githubusercontent.com/ImperialCollegeLondon/sharpy/dev_example/docs/' +
'source/content/example_notebooks/images/simple_wing_scheme.png')
Image(url=url, width=800)
```

```
[5]:
```

```
[6]:
```

```
# Geometry
chord = 1. # Chord of the wing
aspect_ratio = 16. # Ratio between lenght and chord: aspect_ratio = length/chord
wake_length = 50 # Length of the wake in chord lengths
# Discretization
num_node = 21 # Number of nodes in the structural discretisation
# The number of nodes will also define the aerodynamic panels in the
# spanwise direction
num_chord_panels = 4 # Number of aerodynamic panels in the chordwise direction
num_points_camber = 200 # The camber line of the wing will be defined by a series of (x,y)
# coordintes. Here, we define the size of the (x,y) vectors
# Structural properties of the beam cross section
mass_per_unit_length = 0.75 # Mass per unit length
mass_iner_x = 0.1 # Mass inertia around the local x axis
mass_iner_y = 0.05 # Mass inertia around the local y axis
mass_iner_z = 0.05 # Mass inertia around the local z axis
pos_cg_B = np.zeros((3)) # position of the centre of mass with respect to the elastic axis
EA = 1e7 # Axial stiffness
GAy = 1e6 # Shear stiffness in the local y axis
GAz = 1e6 # Shear stiffness in the local z axis
GJ = 1e4 # Torsional stiffness
EIy = 2e4 # Bending stiffness around the flapwise direction
EIz = 5e6 # Bending stiffness around the edgewise direction
# Operation
WSP = 2. # Wind speed
air_density = 0.1 # Air density
# Time discretization
end_time = 5.0 # End time of the simulation
dt = chord/num_chord_panels/WSP # Always keep one timestep per panel
```

First, we are going to compute the static equilibrium of the wing at an angle of attack (`aoa_ini_deg`

). Next, we will change the angle of attack to `aoa_end_deg`

and we will compute the dynamic response of the wing.

```
[7]:
```

```
aoa_ini_deg = 2. # Angle of attack at the beginning of the simulation
aoa_end_deg = 1. # Angle of attack at the end of the simulation
```

For now, we keep the size of the wake panels equal to the distance covered by the flow in one time step.

### Structural model¶

This section creates a class called `AeroelasticInformation`

. This class is not directly used by SHARPy, it has been thought as an intermediate step between common engineering inputs and the input information that SHARPy needs.

It has many functionalities (rotate objects, assembly simple strucures together …) which can be looked up in the documentation.

Let’s initialise an Aeroelastic system that will include a `StructuralInformation`

class and an `AerodynamicInformation`

class:

```
[8]:
```

```
wing = gc.AeroelasticInformation()
```

The attibutes that have to be defined (not all of them are compulsory) can be displayed with the code below. They constitute the input parameters to SHARPy and their names are intuitive, however, a complete description of the input variables to SHARPy can be found in the documentation: structural inputs and aerodynamic inputs

For example, the structural properties are:

```
[9]:
```

```
wing.StructuralInformation.__dict__.keys()
```

```
[9]:
```

```
dict_keys(['num_node_elem', 'num_node', 'num_elem', 'coordinates', 'connectivities', 'elem_stiffness', 'stiffness_db', 'elem_mass', 'mass_db', 'frame_of_reference_delta', 'structural_twist', 'boundary_conditions', 'beam_number', 'body_number', 'app_forces', 'lumped_mass_nodes', 'lumped_mass', 'lumped_mass_inertia', 'lumped_mass_position', 'lumped_mass_mat', 'lumped_mass_mat_nodes'])
```

For example, the connectivities between the nodes required by the finite element solver are empty so far:

```
[10]:
```

```
print(wing.StructuralInformation.connectivities)
```

```
None
```

For a list of methods that allow us to modify the structure, Check the documentation.

First, we need to define the basic characteristics of the equations as the number of nodes, the number of nodes per element, the number of elements and the location of the nodes in the space:

```
[11]:
```

```
# Define the number of nodes and the number of nodes per element
wing.StructuralInformation.num_node = num_node
wing.StructuralInformation.num_node_elem = 3
# Compute the number of elements assuming basic connections
wing.StructuralInformation.compute_basic_num_elem()
```

```
[12]:
```

```
# Generate an array with the location of the nodes
node_r = np.zeros((num_node, 3))
node_r[:,1] = np.linspace(0, chord*aspect_ratio, num_node)
print(node_r)
```

```
[[ 0. 0. 0. ]
[ 0. 0.8 0. ]
[ 0. 1.6 0. ]
[ 0. 2.4 0. ]
[ 0. 3.2 0. ]
[ 0. 4. 0. ]
[ 0. 4.8 0. ]
[ 0. 5.6 0. ]
[ 0. 6.4 0. ]
[ 0. 7.2 0. ]
[ 0. 8. 0. ]
[ 0. 8.8 0. ]
[ 0. 9.6 0. ]
[ 0. 10.4 0. ]
[ 0. 11.2 0. ]
[ 0. 12. 0. ]
[ 0. 12.8 0. ]
[ 0. 13.6 0. ]
[ 0. 14.4 0. ]
[ 0. 15.2 0. ]
[ 0. 16. 0. ]]
```

The following function creates a uniform beam from the previous parameters. On top of assigning the previous parameters, it defines other variables such as the connectivities between nodes

```
[13]:
```

```
wing.StructuralInformation.generate_uniform_beam(node_r,
mass_per_unit_length,
mass_iner_x,
mass_iner_y,
mass_iner_z,
pos_cg_B,
EA,
GAy,
GAz,
GJ,
EIy,
EIz,
num_node_elem = wing.StructuralInformation.num_node_elem,
y_BFoR = 'x_AFoR',
num_lumped_mass=0)
```

If we now show the connectivities between nodes, the function has created them for us. Further information

```
[14]:
```

```
print(wing.StructuralInformation.connectivities)
```

```
[[ 0 2 1]
[ 2 4 3]
[ 4 6 5]
[ 6 8 7]
[ 8 10 9]
[10 12 11]
[12 14 13]
[14 16 15]
[16 18 17]
[18 20 19]]
```

Let’s define the boundary conditions as clamped for node 0 and free for the last node (-1) Further information

```
[15]:
```

```
wing.StructuralInformation.boundary_conditions[0] = 1
wing.StructuralInformation.boundary_conditions[-1] = -1
```

### Aerodynamics¶

We need to define the number of panels in the wake (`wake_panels`

) and the camber line of the wing which, in this case, is flat. Further information

```
[16]:
```

```
# Compute the number of panels in the wake (streamwise direction) based on the previous paramete
wake_panels = int(wake_length*chord/dt)
# Define the coordinates of the camber line of the wing
wing_camber = np.zeros((1, num_points_camber, 2))
wing_camber[0, :, 0] = np.linspace(0, 1, num_points_camber)
```

The following function creates an aerodynamic surface uniform on top of the beam that we have already created

```
[17]:
```

```
# Generate blade aerodynamics
wing.AerodynamicInformation.create_one_uniform_aerodynamics(wing.StructuralInformation,
chord = chord,
twist = 0.,
sweep = 0.,
num_chord_panels = num_chord_panels,
m_distribution = 'uniform',
elastic_axis = 0.5,
num_points_camber = num_points_camber,
airfoil = wing_camber)
```

### Summary¶

Now, we have all the inputs that we need for SHARPy. In this section, a first simulation with SHARPy is run. However, it will perform no computation, it will just load the data so we can plot the system we have just created.

SHARPy runs a series of solvers and postprocessors in the order indicated by the `flow`

variable in the `SHARPy`

dictionary.

The `generate cases`

module also allows us to show all the avaiable solvers and all the parameters they accept as inputs. To do so, we need to run the following commands:

```
[18]:
```

```
# Gather data about available solvers
SimInfo = gc.SimulationInformation() # Initialises the SimulationInformation class
SimInfo.set_default_values() # Assigns the default values to all the solvers
# Print the available solvers and postprocessors
for key in SimInfo.solvers.keys():
print(key)
```

```
_BaseStructural
AerogridLoader
BeamLoader
DynamicCoupled
DynamicUVLM
LinDynamicSim
LinearAssembler
Modal
NoAero
NonLinearDynamic
NonLinearDynamicCoupledStep
NonLinearDynamicMultibody
NonLinearDynamicPrescribedStep
NonLinearStatic
PrescribedUvlm
RigidDynamicCoupledStep
RigidDynamicPrescribedStep
StaticCoupled
StaticCoupledRBM
StaticTrim
StaticUvlm
StepLinearUVLM
StepUvlm
_BaseTimeIntegrator
NewmarkBeta
GeneralisedAlpha
Trim
LiftDistribution
Cleanup
AerogridPlot
BeamPlot
UDPout
PlotFlowField
PickleData
SaveParametricCase
FrequencyResponse
StallCheck
WriteVariablesTime
CreateSnapshot
SHARPy
SaveData
AeroForcesCalculator
AsymptoticStability
BeamLoads
FloatingForces
ShearVelocityField
DynamicControlSurface
GustVelocityField
TrajectoryGenerator
TurbVelocityField
SteadyVelocityField
ModifyStructure
StraightWake
HelicoidalWake
GridBox
BumpVelocityField
TurbVelocityFieldBts
```

Let’s output as an example, the input parameters of the `BeamLoader`

solver. This solver is in charge of loading the structural infromation

```
[19]:
```

```
SimInfo.solvers['BeamLoader']
```

```
[19]:
```

```
{'unsteady': True, 'orientation': [1.0, 0, 0, 0], 'for_pos': [0.0, 0, 0]}
```

The following dictionary defines the basic inputs of SHARPy including the solvers to be run (`flow`

variable), the case name and the route in the file system. In this case we are turning off the screen output because it is useless because we are not running any computation.

```
[20]:
```

```
SimInfo.solvers['SHARPy']['flow'] = ['BeamLoader',
'AerogridLoader']
SimInfo.solvers['SHARPy']['case'] = 'plot'
SimInfo.solvers['SHARPy']['route'] = './'
SimInfo.solvers['SHARPy']['write_screen'] = 'off'
```

We do not modify any of the default input paramteters in `BeamLoader`

but we need to define the initial wake shape that we want and its size (`wake_panels`

)

```
[21]:
```

```
SimInfo.solvers['AerogridLoader']['unsteady'] = 'on'
SimInfo.solvers['AerogridLoader']['mstar'] = wake_panels
SimInfo.solvers['AerogridLoader']['freestream_dir'] = np.array([1.,0.,0.])
SimInfo.solvers['AerogridLoader']['wake_shape_generator'] = 'StraightWake'
SimInfo.solvers['AerogridLoader']['wake_shape_generator_input'] = {'u_inf': WSP,
'u_inf_direction' : np.array(
[np.cos(aoa_ini_deg*deg2rad),
0.,
np.sin(aoa_ini_deg*deg2rad)]),
'dt': dt}
```

The following functions write the input files needed by SHARPy

```
[22]:
```

```
gc.clean_test_files(SimInfo.solvers['SHARPy']['route'], SimInfo.solvers['SHARPy']['case'])
wing.generate_h5_files(SimInfo.solvers['SHARPy']['route'], SimInfo.solvers['SHARPy']['case'])
SimInfo.generate_solver_file()
```

The following line of code runs SHARPy inside the jupyter notebook. It is equivalent to run in a terminal: `sharpy plot.sharpy`

being “plot” the case name defined above

```
[23]:
```

```
sharpy_output = sharpy.sharpy_main.main(['',
SimInfo.solvers['SHARPy']['route'] +
SimInfo.solvers['SHARPy']['case'] +
'.sharpy'])
```

Let’s plot the case we have created. The function below provides a quick way of generating an interactive plot but it is not suitable for large cases. Luckily SHARPy has other more complex plotting capabilities.

If you download the original jupyter notebook, change thee geometric parameters above and rerun the jupyter notebook you will see its impact on the geometry.

Only the first 6 wake panels are plotted for efficiency.

```
[24]:
```

```
pu.plot_timestep(sharpy_output, tstep=-1, minus_mstar=(wake_panels - 6), plotly=True)
```