Commit c03dbf3d authored by William F Godoy's avatar William F Godoy

Added usage example for AmrexCastro

parent 1b13014e
import Exio
function main()
#### Configuration section ######
## exio_init requires three inputs and returns a handler of type exioH
# only supported: AmrexCastro
app::String = "AmrexCastro"
# location where several run outputs are located they must have a common prefix
outputPrefix::String = "/home/wgodoy/workspace/Castro/Exec/hydro_tests/Sedov/case"
# file name inside outputs directories
logFile::String = "run.log"
#################################
# init Exio (can create as many entities as needed)
exio = Exio.exio_init(app, outputPrefix, logFile)
# create a linear model based on provided runs (the larger, the better)
# it will report the formula for dependent and independent variables
Exio.run_linear_models(exio)
end
main()
......@@ -21,5 +21,8 @@ function exio_init(app::String, outputPrefix::String, runlogFile::String)::ExioH
return exioH
end
function run_linear_models(exioH::ExioH)
run_linear_models(exioH.extractor)
end
end
......@@ -24,10 +24,14 @@ struct AmrexCastro <: AbstractAmrex
"castro.max_grid_size",
],
Dict{String,Array{String}}(
"plots_size" => ["amr.nplot_files", "amr.ncells", "amr.max_level"
],
"checks_size" => ["amr.check_int", "amr.ncheck_files", "amr.ncells", "amr.max_level",
"amr.regrid_int"],
"plots_size" => ["amr.nplot_files", "amr.ncells", "amr.max_level"],
"checks_size" => [
"amr.check_int",
"amr.ncheck_files",
"amr.ncells",
"amr.max_level",
"amr.regrid_int",
],
),
runlogFile,
)
......@@ -98,9 +102,9 @@ end
function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.DataFrame)
outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
# single column DataFrame Y in the linear model
plotsSizesData = DataFrames.DataFrame(plots_sizes = Int64[])
plotsSizesData = DataFrames.DataFrame(plots_sizes = Int64[])
for outputDir in outputDirs
......@@ -117,33 +121,31 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data
sizeDir::Int64 = helper_get_directory_size(plotFileDir)
plotsSize += sizeDir
end
push!(plotsSizesData, [plotsSize])
end
# Prepare the X independent variables in the linear model
XNames::Array{String} = extractor.outputs["plots_size"]
for XName in XNames
columnName = Symbol(XName)
# this syntax [!, symbol] does not make a copy, use [:, symbol] for copies
plotsSizesData[!,columnName] = X[!,columnName]
columnName = Symbol(XName)
# this syntax [!, symbol] does not make a copy, use [:, symbol] for copies
plotsSizesData[!, columnName] = X[!, columnName]
end
# formula from https://discourse.julialang.org/t/glm-jl-with-unknown-column-names/20692/5
response = Symbol(names(plotsSizesData)[1])
println(response)
predictors = Symbol.(names(plotsSizesData)[2:end])
println(predictors)
println(plotsSizesData)
f = @eval(GLM.@formula($response ~ (+)(1, $(predictors...))))
println(f)
ols = GLM.lm(f, plotsSizesData)
println(ols)
println("I/O linear model formula:")
println(ols)
#import Plots
#display(Plots.plot(X, Y))
end
......@@ -76,4 +76,3 @@ end
test_AmrexCastro()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment