abstract type AbstractAmrex <: AbstractExtractor end mutable struct Amrex <: AbstractAmrex app::String outputPrefix::String inputs::Array{String} outputs::Array{String} runlogFile::String Amrex(outputPrefix::String, runlogFile::String) = new( "Amrex", outputPrefix, [ "max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level", "caseID", ], ["plots_size", "checkpoints_size"], runlogFile, ) end """ Parses an input file with entries key = value, returns all entries in a Dict # Arguments - `extractor::AbstractAmrex` : input type extending AbstractAmrex - `inputFile::String` : input file to be parsed, absolute path is preferred """ function _input_parser(extractor::AbstractAmrex, inputFile::String)::Dict{String,String} parameters = Dict{String,String}() # get file contents in a single iterable type, \n newline is removed fileContents = readlines(inputFile) # go through each line for line in fileContents if isempty(line) continue end # remove comments marked with # result = findfirst("#", line) if isnothing(result) == false line = SubString(line, 1, result[1] - 1) if isempty(line) continue end end parameter = split(line, "=") parameters[strip(parameter[1])] = strip(parameter[2]) end return parameters end """ Get actual independent variables for I/O characterization: number of cells or ncells, output frequency or nplots, ncheckpoints, etc. from input parameters # Arguments - `extractor::AbstractAmrex` : input type extending AbstractAmrex - `parameters::Dict{Any,Any}` : input file to be parsed, absolute path is preferred """ function _get_independent_variables(extractor::AbstractAmrex, parameters)::Dict{String,Any} independentVariables = Dict{String,Any}() # Number of output events, # get is the safe way. 3rd argument is a default fallback if key not found maxStepStr = get(parameters, "max_step", "") if maxStepStr != "" # safe string conversion to a type maxStep = parse(Int64, maxStepStr) plotIntStr = get(parameters, "amr.plot_int", "") if plotIntStr != "" plotFrequency = parse(Int64, plotIntStr) independentVariables["amr.plot_int"] = plotFrequency independentVariables["amr.nplot_files"] = floor(Int32, maxStep / plotFrequency) else throw(NoSuchFieldException("jexio Amrex: Can't find amr.plot_int")) end checkIntStr = get(parameters, "amr.check_int", "") if checkIntStr != "" checkpointFrequency = parse(Int64, checkIntStr) independentVariables["amr.check_int"] = checkpointFrequency independentVariables["amr.ncheck_files"] = floor(Int32, maxStep / checkpointFrequency) else throw(NoSuchFieldException("jexio Amrex: Can't find amr.check_int")) end end # Using the dot "." operator to apply it on an element-by-element basis (like a dot product) # input is a dictionary with key="amr.ncell" and value = {"nx" "ny" "nz"}, # output is nx*ny*nz # Example: # input Dict[ "amr.n_cell" => ["16" "16"] ], if key not found return 0 # >ncells # 256 ncells = prod(parse.(Int64, split(get(parameters, "amr.n_cell", ["0"])))) independentVariables["amr.ncells"] = ncells maxLevel = get(parameters, "amr.max_level", "") independentVariables["amr.max_level"] = maxLevel == "" ? 1 : parse(Int32, maxLevel) regrid = prod(parse.(Int64, split(get(parameters, "amr.regrid_int", ["0"])))) independentVariables["amr.regrid_int"] = regrid return independentVariables end function _get_inputs_X(extractor::AbstractAmrex) end