You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all. I was wondering if writing a GNU Makefile for each example might be useful. For fbar, as an example:
# Makefile for fbar SDFast Example
PROBLEM_NAME := fbar
# Naming of files all dependent upon the problem name -- pattern set up by sdfast examples
EXECUTABLE := ${PROBLEM_NAME}c
MAIN_PROGRAM := ${EXECUTABLE}.c
SDFAST_AUTOCODE_C_FILES := ${PROBLEM_NAME}_dyn.c ${PROBLEM_NAME}_sar.c sdlib.c
SDFAST_AUTOCODE_FILES := ${SDFAST_AUTOCODE_C_FILES} ${PROBLEM_NAME}_info
SDFAST_OBJECT_FILES := ${PROBLEM_NAME}_dyn.o ${PROBLEM_NAME}_sar.o sdlib.o
# For MacOS clang/llvm compiler...
COMPILER_FLAGS := --std=c90 -Wno-implicit-function-declaration -Wno-deprecated-non-prototype
# Running make without a specified target builds executable program only.
.DEFAULT := ${EXECUTABLE}
# Executable Program Build
${EXECUTABLE}: ${MAIN_PROGRAM} ${SDFAST_OBJECT_FILES}
cc -o ${EXECUTABLE} ${MAIN_PROGRAM} ${SDFAST_OBJECT_FILES} ${COMPILER_FLAGS}
.PHONY=exe
exe: ${EXECUTABLE}
# object files from SDFast Auto-code
${SDFAST_OBJECT_FILES}: ${SDFAST_AUTOCODE_C_FILES}
cc -c ${SDFAST_AUTOCODE_C_FILES} ${COMPILER_FLAGS}
.PHONY=obj
obj: ${SDFAST_OBJECT_FILES}
# C Autocoded SDFast Dynamics Files
${SDFAST_AUTOCODE_FILES}: ${PROBLEM_NAME}.sd
sdfast -lc -ge ${PROBLEM_NAME}.sd
.PHONY=autocode
autocode: ${SDFAST_AUTOCODE_FILES}
# Data from running executable (via STDOUT)
${PROBLEM_NAME}.dat: ${EXECUTABLE}
./${EXECUTABLE} >> ${PROBLEM_NAME}.dat
.PHONY=run
run: ${PROBLEM_NAME}.dat
# Analysis script (plotting data)
${PROBLEM_NAME}_output.pdf: ${PROBLEM_NAME}.dat
python ${PROBLEM_NAME}_analysis.py ${PROBLEM_NAME}.dat
.PHONY=.analysis
analysis: ${PROBLEM_NAME}_output.pdf
# Everything (including analysis)
.PHONY=all
all: ${PROBLEM_NAME}_output.pdf
# Cleanup Targets
.PHONY=clean
clean: clean-objects clean-autocode clean-executable clean-run-output clean-analysis
.PHONY=clean-objects
clean-objects:
-rm *.o
.PHONY=clean-autocode
clean-autocode:
-rm ${SDFAST_AUTOCODE_FILES}
.PHONY=clean-executable
clean-executable:
-rm ${EXECUTABLE}
.PHONY=clean-run-output
clean-run-output:
-rm ${PROBLEM_NAME}.dat
.PHONY=clean-analysis
clean-analysis:
-rm ${PROBLEM_NAME}_output.pdf
Note that this assumes you have a Python fbar_analysis.py file to plot the STDOUT saved to a file fbar.dat. Python is just an example of a generic open-source scientific computing analysis environment... we could pick something else, if we wanted to. The point of the Makefile is to show (in "Make-ese") the dependency chain described in fbar.txt, but automated. This could be pivoted into automated tests for all the examples pretty easily.
For what it's worth, that analysis script looks like this:
"""Import and plot SDFast fbar results"""
# Python standard packages (comes with Python)
import sys
# Open Source Python Imports (from pip/miniforge conda, etc.)
import pandas as pd
from matplotlib import pyplot as plt
# Local Organization Imports
# None
# Local Project Imports
# None
# grab program name from command line
data_fname = sys.argv[1]
exe_name = data_fname.split('.')[0]
# Ingest data
data = pd.read_csv(f'{data_fname}',sep='\s+',header=None,skiprows=[0,1])
data.columns=['time','crank_pos','crank_vel','reac_frc_x','reac_frc_y']
data.index = data['time']
data.drop(axis=1, columns=['time'], inplace=True)
# plot data
fig, ax = plt.subplots(2,1, figsize=(8,11), sharex=True)
data.loc[:,['crank_pos','crank_vel']].plot(ax=ax[0])
ax[0].grid()
data.iloc[:,2:].plot(ax=ax[1])
ax[1].grid()
fig.savefig(f'{exe_name}_output.pdf')
And it generates the same plots as found in the manual on page T-8.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all. I was wondering if writing a GNU Makefile for each example might be useful. For fbar, as an example:
Note that this assumes you have a Python fbar_analysis.py file to plot the STDOUT saved to a file
fbar.dat. Python is just an example of a generic open-source scientific computing analysis environment... we could pick something else, if we wanted to. The point of the Makefile is to show (in "Make-ese") the dependency chain described in fbar.txt, but automated. This could be pivoted into automated tests for all the examples pretty easily.For what it's worth, that analysis script looks like this:
And it generates the same plots as found in the manual on page T-8.
fbar_output.pdf
Nothing fancy.
All reactions