There have been many posts here based on code from the book Programming The Finite Element Method, with the Fortran code either translated to VBA, or with VBA links to compiled Fortran Code. I recently discovered:
This Julia package currently contains the programs in chapters 4, 5 and early sections of 6 as described in “Programming the Finite Element Method” by I M Smith, D V Griffiths and L. Margetts (PtFEM).
Another recent Github site with open source (Python based) FEA code is:
PyNite is a library for structural engineering that creates and analyzes 3D finite element models of frames, trusses, and beams. For information on how to get started with PyNite please visit the other pages in this wiki! You can also have a look at the “Examples” folder for examples of how to use PyNite.
Both sites are works in progress, but already contain much valuable open source code.
The book The Man Who Knew Infinity by Robert Kanigel describes the life of the Indian mathematician Srinivasa Ramanujan, and also his Cambridge mentor G.H. Hardy. It mentions that Hardy was influenced by reading “A Treatise on the Mathematical Theory of Elasticity”, by Augustus Love.
Looking for a copy of this book, the first search results led to:
The Internet Archive, with a download available from Google Books. Unfortunately this was a poor quality non-searchable scanned document, with some pages that were totally unreadable.
The Strand7 API provides an interface between the Strand7 Finite Element Analysis program and external software. It works with many different languages, including Python, which uses ctypes to transfer data to and from the API functions. It is essential that data is transferred with the right data types, and that arrays are correctly sized. This post provides a summary of the different data types, with an example of Python code that can be called as a user defined function (UDF) from Excel, using pyxll.
Input of integer, double or Boolean data types may be passed to ctype functions unchanged. In Release 3 versions of Python, strings must be converted using string.encode(). For input Python lists or Numpy arrays an empty ctype array of the required length must first be created, then the values are copied to the array.
Variables passed to a ctype function to return output values must be created in Python as shown above. The returned values must then be converted back to a Python type, using .value or .value.decode(), before being passed back to the spreadsheet.
Typical Python code to call an API function is shown below:
@xl_func
@xl_arg('uID', 'int')
@xl_arg('ResultType', 'int')
@xl_arg('ResultSubType', 'int')
@xl_arg('BeamNum', 'int')
@xl_arg('MinStations', 'int')
@xl_arg('ResultCase', 'int')
@xl_return('numpy_array<var>')
def py_GetBeamResultArray(uID, ResultType, ResultSubType, BeamNum, MinStations, ResultCase):
"""
Returns the specified beam result quantity at several stations along the length of the beam. Additional stations
are inserted to ensure that the maximum/minimum results are captured.
:param uID: Strand7 model file ID number.
:param ResultType: Beam result quantity; see Beam Results for additional information.
:param ResultSubType: Beam result sub-type; see Beam Results for additional information.
:param BeamNum: Beam number.
:param MinStations: Minimum number of stations required.
:param ResultCase: Result case number.
"""
NumStations = c_int()
NumColumns = c_int()
BeamPos = (c_double * kMaxBeamResult)()
BeamResult = (c_double * kMaxBeamResult)()
iErr = St7GetBeamResultArray(uID, ResultType, ResultSubType, BeamNum, MinStations, ResultCase, NumStations, NumColumns, BeamPos, BeamResult)
if iErr:
return py_ErrStringA(iErr)
else:
n = NumStations.value * NumColumns.value
res = np.array(BeamResult[0:n]).reshape(-1, NumColumns.value)
pos = np.array(BeamPos[0:NumStations.value]).reshape(-1,1)
return np.concatenate((pos, res), axis = 1)
The API function, St7GetBeamResultArray, returns two integers and two arrays (the positions along the beam where results are returned, and the result values). The integers and arrays are created in Python, then passed to the API function. The returned ctypes 1D arrays are then converted to Numpy 2D arrays, using .reshape(), and combined into a single array for return to Excel, using np.concatenate.
The function in use is shown in the screenshots below:
The function may return results for the two beam ends:
The spreadsheet Vincenty.zip uses those resources to perform the following calculations, using both on-sheet calculations and VBA user-defined functions (UDF’s):
Calculation of distance and azimuth angles given latitude and longitude for two points.
Calculation of latitude and longitude and azimuth for a second point, given the position and azimuth for the first point.
Calculation of the area inside a closed polygon, using the excess angle method.
The spreadsheet contains full open source code, and documentation for the on-sheet calculations. Examples are shown in the screenshots below (click any image for full-size view):
Input and geometry constants required for the VincentyLen Function:
The on-sheet calculation follows the procedure given in the Wikipedia article. The VincentyLen function returns the same end results (in bold), and can also return the intermediate results:
The VincentyCoord function solves the “Direct Problem”, returning the latitude and longitude for a point at a specified distance and bearing from another point:
The VincentyArea Function finds the area inside a polygon specified by the latitude and longitude for a series of points, listed in clockwise order, using the “Excess angle method”. Note that as well as the returning the area, if the optional second argument is set to 2 the function returns additional data for each segment of the polygon, as shown in columns H to L below:
The VincentyArea function has been used to calculate the area of the Australian mainland, using a series of 2900 points:
The data for the points is listed with longitude first then latitude. All three functions have an optional third “XY” argument to deal with this convention with the values: