Commit 8d81850e authored by William F Godoy's avatar William F Godoy

Building linear model

parent 7b4ab407
......@@ -10,12 +10,12 @@ mutable struct ExioH
end
function exio_init(app::String, outputPrefix::String)::ExioH
function exio_init(app::String, outputPrefix::String, runlogFile::String)::ExioH
exioH = ExioH()
if app == "AmrexCastro"
println("Hello AmrexCastro")
exioH.extractor = AmrexCastro(outputPrefix)
exioH.extractor = AmrexCastro(outputPrefix, runlogFile)
end
return exioH
......
......@@ -6,12 +6,14 @@ mutable struct Amrex <: AbstractAmrex
outputPrefix::String
inputs::Array{String}
outputs::Array{String}
runlogFile::String
Amrex(outputPrefix::String) = new(
Amrex(outputPrefix::String, runlogFile::String) = new(
"Amrex",
outputPrefix,
["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level"],
["plots_size", "checkpoints_size"],
runlogFile
)
end
......
......@@ -8,8 +8,9 @@ struct AmrexCastro <: AbstractAmrex
outputPrefix::String
inputs::Array{String}
outputs::Dict{String,Array{String}}
runlogFile::String
AmrexCastro(outputPrefix::String) = new(
AmrexCastro(outputPrefix::String, runlogFile::String) = new(
"AmrexCastro",
outputPrefix,
[
......@@ -21,36 +22,57 @@ struct AmrexCastro <: AbstractAmrex
"castro.cfl",
"castro.max_grid_size",
],
Dict{String,Array{String}}("plots_size" => ["max_step", "amr.plot_int", "amr.n_cell", "amr.max_level"])
Dict{String,Array{String}}("plots_size" => ["max_step", "amr.plot_int", "amr.n_cell", "amr.max_level"]),
runlogFile
)
end
# runs the linear models for each entry in outputs
function run_linear_models(extractor::AmrexCastro)
X::DataFrames.DataFrame = _get_linear_model_X(extractor)
for key in keys(extractor.outputs)
if (key == "plots_size")
_run_linear_model_plots_size(extractor, X)
end
end
end
function _get_linear_model(extractor::AmrexCastro)
# get directories runs output location
outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
# println(outputDirs)
X = DataFrames.DataFrame()
isXInit::Bool = false
for outputDir in outputDirs
inputFiles::Array{String} = helper_get_prefix_files("input", outputDir)
function _get_input_file(extractor::AmrexCastro, outputDir::String)::String
# hardcoded input...find out if this is always the case with Castro
inputFiles::Array{String} = helper_get_prefix_files("input", outputDir)
if isempty(inputFiles)
if isempty(inputFiles)
throw(NoSuchFieldException(
"jexio AmrexCastro: Can't find Castro input files in directories:",
outputDirs,
))
# use length, instead of size as it returns tuples
# use length, instead of size as it returns tuples
elseif length(inputFiles) != 1
print("Number of files: ", size(inputFiles))
throw(DimensionMismatch("jexio AmrexCastro: found more than one input file"))
else
end
inputFile = inputFiles[1]
return inputFiles[1]
end
function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame
# get directories runs output location
outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
# println(outputDirs)
X::DataFrames.DataFrame = DataFrames.DataFrame()
isXInit::Bool = false
for outputDir in outputDirs
inputFile::String = _get_input_file(extractor, outputDir)
# get relevant input parameters
parameters = _input_parser(extractor, inputFile)
independent_variables = _get_independent_variables(extractor, parameters)
......@@ -64,20 +86,36 @@ function _get_linear_model(extractor::AmrexCastro)
end
println(X)
return X
end
function _get_outputs_Y(extractor::AmrexCastro)
function _get_outputs_Y_plots_size(extractor::AmrexCastro)
maxStepStr = get(extractor.parameters, "", "")
end
function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.DataFrame)
XColumns::Array{String} = extractor.outputs["plots_size"]
outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
for outputDir in outputDirs
# TODO refactor this later
inputFile::String = _get_input_file(extractor, outputDir)
parameters = _input_parser(extractor, inputFile)
rootPlotName = get(parameters, "amr.plot_file", "")
# find all directories with rootPlotName and get its size
plotFileDirs = helper_get_prefix_directories(string(outputDir,"/",rootPlotName))
println(plotFileDirs)
# todo add nprocs to the X matrix
# extractor.runlogFile
end
end
for output in extractor.outputs
if (output == "plots_size")
_get_outputs_Y_plots_size(extractor)
end
end
end
......@@ -19,6 +19,7 @@ function test_AmrexCastro()
exio = Exio.exio_init(
"AmrexCastro",
"./test/data/AmrexCastro/hydro_tests/Sedov/2d.cyl_in_cartcoords/case",
"run.log"
)
@test typeof(exio) == Exio.ExioH
......@@ -69,7 +70,7 @@ function test_AmrexCastro()
independent_variables = Exio._get_independent_variables(exio.extractor, parameters)
println(independent_variables)
Exio._get_linear_model(exio.extractor)
Exio.run_linear_models(exio.extractor)
end
......
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