Commit d690dcde authored by Godoy, William's avatar Godoy, William
Browse files

Merge branch 'init' into 'master'

Initialize the Julia framework

See merge request !1
parents c7e14793 1feb1e2e
name = "Exio"
uuid = "0525473d-17b7-4fd3-beb1-bf17216ddbac"
version = "0.0.1"
[deps]
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
[compat]
julia = "1"
JuliaFormatter = "0.6.2"
[extras]
Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
[targets]
test = ["Test"]
# jexio # jexio
Julia Extractor for Input Output.
Set of scripts to generate I/O patterns understanding for particular applications.
Supported:
- [AMReX-Astro Castro](https://amrex-astro.github.io/Castro/)
For simple usage see tests:
1. Install requirements (run once):
`$ julia scripts/requirements.jl`
2. Run tests:
`$ julia --project=. test/runtests.jl`
Formatting the code:
`$ julia scripts/formatter.jl`
# Usage run from root project
# julia ./scripts/formatter.jl
# Requires the JuliaFormatter package see scripts/requirements.jl
using JuliaFormatter
format(".")
# Use to install dependencies for this project
# Run:
# > julia scripts/requirements.jl
using Pkg
Pkg.add("JuliaFormatter")
Pkg.add("Glob")
exit()
module Exio
export ExioH, exio_init, input_parser
include("extractor/Extractor.jl")
mutable struct ExioH
extractor::AbstractExtractor
ExioH() = new()
end
function exio_init(app::String, outputPrefix::String)::ExioH
exioH = ExioH()
if app == "AmrexCastro"
println("Hello AmrexCastro")
exioH.extractor = AmrexCastro()
init!(exioH.extractor, outputPrefix)
end
return exioH
end
end
abstract type AbstractAmrex <: AbstractExtractor end
mutable struct Amrex <: AbstractAmrex
app::String
outputPrefix::String
degreesOfFreedom::Any
Amrex() = new()
end
"""
initialize members of the extractor::Amrex type
Using bang convention as init modifies the extractor::Amrex
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
"""
function init!(extractor::Amrex, outputPrefix::String)
extractor.app = "Amrex"
extractor.outputPrefix = outputPrefix
extractor.degreesOfFreedom =
["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level"]
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{String,String}` : input file to be parsed, absolute path is preferred
"""
function get_independent_variables(extractor::AbstractAmrex, parameters)::Dict
independentVariables = Dict()
# 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.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.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 = get(parameters, "amr.regrid_int", "")
independentVariables["amr.regrid_int"] = regrid == "" ? 1 : parse(Int32, regrid)
return independentVariables
end
import Glob
mutable struct AmrexCastro <: AbstractAmrex
app::String
degreesOfFreedom::Any
outputPrefix::String
AmrexCastro() = new()
end
"""
init!
initialize members of the extractor::AmrexCastro type
Using bang convention as init modifies the extractor::Amrex
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
"""
function init!(extractor::AmrexCastro, outputPrefix::String)
extractor.app = "AmrexCastro"
extractor.degreesOfFreedom = [
"max_step",
"amr.check_int",
"amr.plot_int",
"amr.n_cell",
"amr.max_level",
"castro.cfl",
"castro.max_grid_size",
]
extractor.outputPrefix = outputPrefix
end
function get_dependent_variable_datasize(extractor::AmrexCastro)
findDelimiter = findlast("/",extractor.outputPrefix)
println(extractor.outputPrefix)
println(findDelimiter)
searchDirectory = extractor.outputPrefix[ 1: findDelimiter[1]-1 ]
prefix = extractor.outputPrefix[ findDelimiter[1]+1:end]
println("Search directory: ", searchDirectory, " prefix: ", prefix)
outputDirs = Glob.glob( string(prefix,"*"), searchDirectory )
println(outputDirs)
end
abstract type AbstractExtractor end
include("Amrex.jl")
include("AmrexCastro.jl")
Copyright (c) 2017, The Regents of the University of California,
through Lawrence Berkeley National Laboratory and the Alliance for
Sustainable Energy, LLC., through National Renewable Energy Laboratory
(subject to receipt of any required approvals from the U.S. Dept. of
Energy). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
(1) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
(3) Neither the name of the University of California, Lawrence
Berkeley National Laboratory, Alliance for Sustainable Energy, LLC.,
National Renewable Energy Laboratory, U.S. Dept. of Energy nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
# ------------------ INPUTS TO MAIN PROGRAM -------------------
max_step = 20
stop_time = 0.1
# PROBLEM SIZE & GEOMETRY
geometry.is_periodic = 0 0
geometry.coord_sys = 0 # 0 => cart
geometry.prob_lo = 0 0
geometry.prob_hi = 1 1
amr.n_cell = 16 16
# >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<<
# 0 = Interior 3 = Symmetry
# 1 = Inflow 4 = SlipWall
# 2 = Outflow 5 = NoSlipWall
# >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<<
castro.lo_bc = 2 2
castro.hi_bc = 2 2
# WHICH PHYSICS
castro.do_hydro = 1
castro.do_react = 0
# TIME STEP CONTROL
castro.cfl = 0.5 # cfl number for hyperbolic system Courant-Friedrichs-Lewy condition
castro.init_shrink = 0.01 # scale back initial timestep
castro.change_max = 1.1 # maximum increase in dt over successive steps
# DIAGNOSTICS & VERBOSITY
castro.sum_interval = 1 # timesteps between computing mass
castro.v = 1 # verbosity in Castro.cpp
amr.v = 1 # verbosity in Amr.cpp
#amr.grid_log = grdlog # name of grid logging file
# REFINEMENT / REGRIDDING
amr.max_level = 2 # maximum level number allowed
amr.ref_ratio = 2 2 2 2 # refinement ratio
amr.regrid_int = 2 # how often to regrid
amr.blocking_factor = 8 # block factor in grid generation
amr.max_grid_size = 128
# CHECKPOINT FILES
amr.check_file = sedov_2d_cyl_in_cart_chk # root name of checkpoint file
amr.check_int = 20 # number of timesteps between checkpoints
# PLOTFILES
amr.plot_file = sedov_2d_cyl_in_cart_plt
amr.plot_int = 20
amr.derive_plot_vars=ALL
# PROBIN FILENAME
amr.probin_file = probin.2d.cyl_in_cartcoords
using Test, Base.Filesystem
import Exio
@testset "test_amrexCastro" begin
include("test_AmrexCastro.jl")
end;
@testset "test_Exio.input_parser_docstring" begin
@test println(@doc Exio.input_parser) === nothing
end;
"""
workaround function to update counter if scalar
Julia doesn't pass values by reference "address"
"""
function test_value(
counter,
parameters::Dict{String,String},
key::String,
test_value::String,
)
value = parameters[key]
@test value == test_value
counter += 1
return counter
end
function test_AmrexCastro()
exio = Exio.exio_init("AmrexCastro", "/home/wgodoy/workspace/Castro/Exec/hydro_tests/Sedov/case")
@test typeof(exio) == Exio.ExioH
println("Current directory: ", Filesystem.pwd())
inputFile = string(
Filesystem.pwd(),
"/test/data/amrexCastro/test_data_AmrexCastro_inputs.2d.cyl_in_cartcoords",
)
println("Input file: ", inputFile)
parameters = Exio.input_parser(exio.extractor, inputFile)
# keys counter
counter = 0
counter = test_value(counter, parameters, "max_step", "20")
counter = test_value(counter, parameters, "stop_time", "0.1")
counter = test_value(counter, parameters, "geometry.is_periodic", "0 0")
counter = test_value(counter, parameters, "geometry.coord_sys", "0")
counter = test_value(counter, parameters, "geometry.prob_lo", "0 0")
counter = test_value(counter, parameters, "geometry.prob_hi", "1 1")
counter = test_value(counter, parameters, "amr.n_cell", "16 16")
counter = test_value(counter, parameters, "castro.lo_bc", "2 2")
counter = test_value(counter, parameters, "castro.hi_bc", "2 2")
counter = test_value(counter, parameters, "castro.do_hydro", "1")
counter = test_value(counter, parameters, "castro.do_react", "0")
counter = test_value(counter, parameters, "castro.cfl", "0.5")
counter = test_value(counter, parameters, "castro.init_shrink", "0.01")
counter = test_value(counter, parameters, "castro.change_max", "1.1")
counter = test_value(counter, parameters, "castro.sum_interval", "1")
counter = test_value(counter, parameters, "castro.v", "1")
counter = test_value(counter, parameters, "amr.v", "1")
counter = test_value(counter, parameters, "amr.max_level", "2")
counter = test_value(counter, parameters, "amr.ref_ratio", "2 2 2 2")
counter = test_value(counter, parameters, "amr.regrid_int", "2")
counter = test_value(counter, parameters, "amr.blocking_factor", "8")
counter = test_value(counter, parameters, "amr.max_grid_size", "128")
counter = test_value(counter, parameters, "amr.check_file", "sedov_2d_cyl_in_cart_chk")
counter = test_value(counter, parameters, "amr.check_int", "20")
counter = test_value(counter, parameters, "amr.plot_file", "sedov_2d_cyl_in_cart_plt")
counter = test_value(counter, parameters, "amr.derive_plot_vars", "ALL")
counter =
test_value(counter, parameters, "amr.probin_file", "probin.2d.cyl_in_cartcoords")
@test counter == 27
independent_variables = Exio.get_independent_variables(exio.extractor, parameters)
println(independent_variables)
Exio.get_dependent_variable_datasize(exio.extractor)
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