Loading and saving models
TOML input files
TASOPT models can be loaded from and saved to human-readable TOML files via read_aircraft_model()
and save_aircraft_model()
. These scripts are written to process files based on the /example/defaults/default_input.toml
, as is done when load_default_model()
is run; they are usable for simple cases that alter the default inputs. For larger deviations from the default (e.g., mission-specific aero or engine performance), customized scripts are recommended when not required.
Once it is loaded in this fashion, the aircraft
can be manipulated and re-sized. Note: TOML-based saves do not store the performance of the sized model, so a model must be sized before data can be referenced usefully:
using TASOPT
include(__TASOPTindices__) #import array indices from ./src/data_structs/index.inc, including igTmetal
filepath = "/path/to/your/aircraft.toml"
ac = read_aircraft_model(filepath) #creates new aircraft using default input .toml
size_aircraft!(ac)
ac.parg[igTmetal] = 2000 #set max metal temp to 2000 K
size_aircraft!(ac) #resizing after parameter change
Quicksave and quickload to .jld2
Complete aircraft
structs can also be serialized to JLD2 files by calling quicksave_aircraft()
. Though inscrutable to the human eye, these saves capture ALL elements of the aircraft
and can be loaded via quickload_aircraft()
to a fresh REPL in an already-sized state.
#load and size the default aircraft model
using TASOPT
ac2 = load_default_model()
size_aircraft!(ac2)
#quicksave aircraft
filepath2 = "/path/to/your/new/quicksave.toml"
quicksave_aircraft(ac2, filepath2)
#quickload aircraft, ready to pull results
ac2 = quickload_aircraft(filepath2)
Output data to CSV
aircraft
data can be saved to CSVs via output_csv()
, where each column will be a par
array quantity and each row can be a different aircraft
or case. This is especially useful for post-processing of parameter sweeps.
The data that is output can be customized by specifying individual par
array quantities, flight points, or missions. By default, only the first cruise point of the design mission is output for a representative set of values (i.e., those in default_output_indices
).
For ease of use, the default behavior is to create or append to the file at the user-given filepath
, though if the requested indices are changed, a new file will be created to avoid inconsistency. This file will also appendable without further input. Overwrite behavior can also be specified.
The following example shows the basic functionalities for a parameter sweep. See the output_csv()
docstring for details.
# Sweeping a parameter space and outputting each design
using TASOPT
include(__TASOPTindices__) #import par array indices, including igTmetal
ac = load_default_model()
filepath = "path/to/your/newfile.csv"
#set up sweep of max metal temp in engine
Tmetals = [1800, 1850, 1900, 1950] # Kelvin
for Tmetal in Tmetals
ac.parg[igTmetal] = Tmetal
size_aircraft!(ac)
#output default quantities, appending each time
output_csv(ac, filepath)
#output with more engine quantities and with data at all flight points
#due to inconsistent headings at filepath, a new file will be created and appended to
output_csv(ac, filepath, indices = output_indices_wEngine, includeMissions = true)
end
IO Functions
TASOPT.read_aircraft_model
— Methodread_aircraft_model(datafile;
defaultfile = joinpath(TASOPT.__TASOPTroot__, "../example/defaults/default_input.toml"))
Reads a specified TOML file that describes a TASOPT aircraft
model with a fall back to the default aircraft
definition provided in "/example/defaults/default_input.toml""
Extending read_input.jl
and save_model.jl
is recommended for models deviating appreciably from the default functionality. Thorough knowledge of the model is required.
Examples
julia> read_aircraft_model("examples/defaults/default_input.toml")
┌ Info: engine_location not found in user specified input file.
│ Reading engine_location from default TASOPT input:
│
│ engine_location = wing
└
┌ Info: pylon_weight_fraction not found in user specified input file.
│ Reading pylon_weight_fraction from default TASOPT input:
│
│ pylon_weight_fraction = 0.1
└
Name: Example TASOPT Model;
Wpay = 210.0 kN
Des. Range = 5.56e6 km
Cruise Mach = 0.8
TASOPT.save_aircraft_model
— Methodsave_aircraft_model(ac::TASOPT.aircraft=TASOPT.read_aircraft_model(),
datafile=joinpath(TASOPT.__TASOPTroot__, "IO/default_output.toml"),
save_output::Bool=false)
Converts an aircraft model into a dictionary and writes it to a TOML file. Values to be written are explicitly set following the default_input.toml. All values are written in SI units.
This save operation makes add'l* assumptions about parameter repetition. Namely: The same value is applied for all flight segments/points for: - parm[] parameters - excrescencedragfactors, wing overspeeds, wing/stabilizer Re_refs The same value is applied for all missions and flight segments for: - parg[] and pare[] parameters - fuel temperature
Said value is the first entry in the corresponding array axis, except for some aero parameters where other points are more relevant (e.g., "Cruise" "Takeoff").
*and modifiable
TASOPT.quicksave_aircraft
— Methodquicksave_aircraft(ac::TASOPT.aircraft=TASOPT.read_aircraft_model(),
filepath=joinpath(TASOPT.__TASOPTroot__, "IO/default_quicksave_aircraft.jld2"))
Serializes and saves aircraft struct
to a .jld2 using JLD2 (not human-readable). Intended to store aircraft models with ALL fields (since not everything is stored by saveaircraftmodel).
TASOPT.quickload_aircraft
— Methodquickload_aircraft(datafile=joinpath(TASOPT.__TASOPTroot__, "IO/default_quicksave_aircraft.jld2"))
Reads a .jld2 file generated by quicksave_aircraft()
and returns the generated aircraft
structure.
TASOPT.output_csv
— Methodoutput_csv(ac::TASOPT.aircraft=TASOPT.load_default_model(),
filepath::String=joinpath(TASOPT.__TASOPTroot__, "IO/default_output.csv");
overwrite::Bool = false, indices::Dict = default_output_indices,
includeMissions::Union{AbstractVector,Colon,Bool,Integer} = false,
includeFlightPoints::Union{AbstractVector,Colon,Bool,Integer} = false,
forceMatrices::Bool = false)
writes the values of ac
to CSV file filepath
with index variables as headers. A typical set of values is output by default for the design mission at the first cruise point. Appends to extant filepath
if headers are compatible, appending integer suffixes to filename when not.
Output is customizable by:
indices
: specifies the desired indices of each par array,includeMissions
: allows output of all missions (i.e., =true) or specifiable indices (e.g., =[1,2,3]),includeFlightPoints
: allows output of all flight points (as forincludeMissions
).
🔃 Inputs and Outputs
Inputs:
ac::TASOPT.aircraft
: TASOPT aircraftstruct
containing model in any state.filepath::String
: path and name of .csv file to be written.overwrite::Bool
: deletes existing file at filepath when true, default is false.indices::Dict{String => Union{AbstractVector,Colon(), Integer}}
: specifies desired indices of par arrays given as keys. Customizable; built-in options:default_output_indices
,output_indices_all
, andoutput_indices_wEngine
.includeMissions::Union{AbstractVector,Colon,Bool,Integer}
: saves all mission entries as an array in a CSV cell when true, default is false, inner nested array when flight points are also output. specific indices can also be specified as Vectors of Ints.includeFlightPoints::Union{AbstractVector,Colon,Bool,Integer}
: saves all flight point entries as an array in a CSV cell when true, default is false, outer nested array when missions are also output. specific indices can also be specified as Vectors of Ints.forceMatrices::Bool
: forces all entries that vary with mission and flight point to follow nested array structurestruct_excludes::AbstractVector{String}
: names/substrings of fields to exclude from output of ac struct. Default is[]
, excluding nothing.
Outputs:
newfilepath::String
: actual output filepath; updates in case of header conflicts. same as input filepath ifoverwrite = true
.
TASOPT.default_output_indices
— ConstantIndices of quantities of par arrays selected to be output by default by output_csv()
. Formatted as a Dict() where keys are par array names and values are arrays of indices. Note that this selection is only along the first dimension of par arrays (i.e., selecting quantities, not missions or flight points).
Custom Dicts() can be passed to output_csv()
following the format: Dict(){String => Union{AbstractVector,Colon(), Integer}}
.
For example: 1 : default_output_indices["parg"] = [1, 5, igtotal]
> when submitted to output_csv()
, will output as columns the first, fifth, and last entry of parg
2 : default_output_indices["para"] = Colon() #NOT [Colon()]
> when submitted to output_csv()
, will output all indices of para
(whether all flights or missions are included is controlled by a separate parameter)