Commit 2a138c08 authored by William F Godoy's avatar William F Godoy
Browse files

More setup

added scripts:
requirements
formatter

tests passing for AmrexCastro
parent b9141834
...@@ -3,15 +3,13 @@ name = "Exio" ...@@ -3,15 +3,13 @@ name = "Exio"
uuid = "0525473d-17b7-4fd3-beb1-bf17216ddbac" uuid = "0525473d-17b7-4fd3-beb1-bf17216ddbac"
version = "0.0.1" version = "0.0.1"
[deps]
Test
Filesystem
[compat] [compat]
julia = "1" julia = "1"
JuliaFormatter = "0.6.2"
[extras] [extras]
Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56" Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
[targets] [targets]
test = ["Test"] test = ["Test"]
......
# 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")
exit()
...@@ -2,26 +2,26 @@ module Exio ...@@ -2,26 +2,26 @@ module Exio
export ExioH, exio_init, input_parser export ExioH, exio_init, input_parser
include("extractor/extractor.jl") include("extractor/Extractor.jl")
mutable struct ExioH mutable struct ExioH
extractor::AbstractExtractor extractor::AbstractExtractor
ExioH() = new() ExioH() = new()
end end
function exio_init(app::String, outputPrefix::String)::ExioH function exio_init(app::String, outputPrefix::String)::ExioH
exioH = ExioH() exioH = ExioH()
if app == "AmrexCastro" if app == "AmrexCastro"
println("Hello AmrexCastro") println("Hello AmrexCastro")
exioH.extractor = AmrexCastro() exioH.extractor = AmrexCastro()
init!(exioH.extractor, outputPrefix) init!(exioH.extractor, outputPrefix)
end end
return exioH return exioH
end end
end
\ No newline at end of file end
abstract type AbstractAmrex <: AbstractExtractor end abstract type AbstractAmrex <: AbstractExtractor end
mutable struct Amrex <: AbstractAmrex mutable struct Amrex <: AbstractAmrex
app::String app::String
outputPrefix::String outputPrefix::String
degreesOfFreedom degreesOfFreedom::Any
Amrex() = new() Amrex() = new()
end end
""" """
...@@ -16,15 +16,10 @@ end ...@@ -16,15 +16,10 @@ end
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1 https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
""" """
function init!(extractor::Amrex, outputPrefix::String) function init!(extractor::Amrex, outputPrefix::String)
extractor.app = "Amrex" extractor.app = "Amrex"
extractor.outputPrefix = outputPrefix extractor.outputPrefix = outputPrefix
extractor.degreesOfFreedom = [ extractor.degreesOfFreedom =
"max_step", ["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level"]
"amr.check_int",
"amr.plot_int",
"amr.n_cell",
"amr.max_level"
]
end end
""" """
...@@ -33,33 +28,32 @@ end ...@@ -33,33 +28,32 @@ end
- `extractor::AbstractAmrex` : input type extending AbstractAmrex - `extractor::AbstractAmrex` : input type extending AbstractAmrex
- `inputFile::String` : input file to be parsed, absolute path is preferred - `inputFile::String` : input file to be parsed, absolute path is preferred
""" """
function input_parser(extractor::AbstractAmrex, inputFile::String)::Dict{String,String} function input_parser(extractor::AbstractAmrex, inputFile::String)::Dict{String,String}
parameters = Dict{String,String}() parameters = Dict{String,String}()
# get file contents in a single iterable type, \n newline is removed # get file contents in a single iterable type, \n newline is removed
fileContents = readlines(inputFile) fileContents = readlines(inputFile)
# go through each line # go through each line
for line in fileContents for line in fileContents
if isempty(line)
if isempty(line) continue
continue end
end
# remove comments marked with #
# remove comments marked with # result = findfirst("#", line)
result = findfirst("#", line)
if isnothing(result) == false
if isnothing(result) == false line = SubString(line, 1, result[1] - 1)
line = SubString(line, 1, result[1]-1) if isempty(line)
if isempty(line) continue
continue end
end end
parameter = split(line, "=")
parameters[strip(parameter[1])] = strip(parameter[2])
end end
parameter = split(line,"=") return parameters
parameters[strip(parameter[1])] = strip(parameter[2]) end
end
return parameters
end
\ No newline at end of file
mutable struct AmrexCastro <: AbstractAmrex mutable struct AmrexCastro <: AbstractAmrex
app::String app::String
degreesOfFreedom degreesOfFreedom::Any
outputPrefix::String outputPrefix::String
AmrexCastro() = new() AmrexCastro() = new()
end end
""" """
...@@ -14,15 +14,15 @@ end ...@@ -14,15 +14,15 @@ end
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1 https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
""" """
function init!(extractor::AmrexCastro, outputPrefix::String) function init!(extractor::AmrexCastro, outputPrefix::String)
extractor.app = "AmrexCastro" extractor.app = "AmrexCastro"
extractor.degreesOfFreedom = [ extractor.degreesOfFreedom = [
"max_step", "max_step",
"amr.check_int", "amr.check_int",
"amr.plot_int", "amr.plot_int",
"amr.n_cell", "amr.n_cell",
"amr.max_level", "amr.max_level",
"castro.cfl", "castro.cfl",
"castro.max_grid_size" "castro.max_grid_size",
] ]
extractor.outputPrefix = outputPrefix extractor.outputPrefix = outputPrefix
end end
abstract type AbstractExtractor end
include("amrex.jl") abstract type AbstractExtractor end
include("amrexCastro.jl")
include("Amrex.jl")
include("AmrexCastro.jl")
...@@ -4,9 +4,9 @@ using Test, Base.Filesystem ...@@ -4,9 +4,9 @@ using Test, Base.Filesystem
import Exio import Exio
@testset "test_amrexCastro" begin @testset "test_amrexCastro" begin
include("test_amrexCastro.jl") include("test_AmrexCastro.jl")
end; end;
@testset "test_Exio.input_parser_docstring" begin @testset "test_Exio.input_parser_docstring" begin
@test println(@doc Exio.input_parser) === nothing @test println(@doc Exio.input_parser) === nothing
end; 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", ".")
@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
end
test_AmrexCastro()
exio = Exio.exio_init("AmrexCastro", ".")
@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
n = 0
for parameter in parameters
key = parameter[1]
value = parameter[2]
if isequal(key, "amr.regrid_int") global n += 1; @test isequal(value, "2")
elseif isequal(key, "amr.plot_file") global n += 1; @test isequal(value,"sedov_2d_cyl_in_cart_plt")
elseif isequal(key, "amr.max_level") global n += 1; @test isequal(value, "2")
elseif isequal(key, "amr.plot_int") global n += 1; @test isequal(value, "20")
elseif isequal(key, "amr.n_cell") global n += 1; @test isequal(value, "16 16")
end
println(parameter[1], "...", parameter[2])
end
# @test n == 5
\ No newline at end of file
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