Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Godoy, William
jexio
Commits
b9141834
Commit
b9141834
authored
Jun 09, 2020
by
William F Godoy
Browse files
Adding test
parent
bf05d689
Changes
8
Hide whitespace changes
Inline
Side-by-side
Project.toml
View file @
b9141834
...
...
@@ -2,6 +2,11 @@
name
=
"Exio"
uuid
=
"0525473d-17b7-4fd3-beb1-bf17216ddbac"
version
=
"0.0.1"
[deps]
Test
Filesystem
[compat]
julia
=
"1"
...
...
@@ -12,3 +17,5 @@ Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56"
test
=
["Test"]
README.md
View file @
b9141834
# jexio
Run tests:
`> julia --project=. test/runtests.jl`
src/Exio.jl
View file @
b9141834
module
Exio
export
ExioH
,
exio_init
export
ExioH
,
exio_init
,
input_parser
include
(
"extractor/extractor.jl"
)
...
...
@@ -11,13 +11,13 @@ mutable struct ExioH
end
function
exio_init
(
app
::
String
,
outputPrefix
::
String
)
function
exio_init
(
app
::
String
,
outputPrefix
::
String
)
::
ExioH
exioH
=
ExioH
()
if
app
==
"AmrexCastro"
println
(
"Hello AmrexCastro"
)
exioH
.
extractor
=
AmrexCastro
()
init
(
exioH
.
extractor
,
outputPrefix
)
init
!
(
exioH
.
extractor
,
outputPrefix
)
end
return
exioH
...
...
src/extractor/amrex.jl
View file @
b9141834
...
...
@@ -9,7 +9,13 @@ mutable struct Amrex <: AbstractAmrex
Amrex
()
=
new
()
end
function
init
(
extractor
::
Amrex
,
outputPrefix
::
String
)
"""
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
=
[
...
...
@@ -21,12 +27,39 @@ function init(extractor::Amrex, outputPrefix::String)
]
end
function
input_parser
(
inputFile
::
String
)
parameters
=
Dict
{
String
,
String
}()
"""
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
)
print
(
fileContents
)
# 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
\ No newline at end of file
src/extractor/amrexCastro.jl
View file @
b9141834
...
...
@@ -7,7 +7,13 @@ mutable struct AmrexCastro <: AbstractAmrex
AmrexCastro
()
=
new
()
end
function
init
(
extractor
::
AmrexCastro
,
outputPrefix
::
String
)
"""
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"
,
...
...
test/data/amrexCastro/test_data_
a
mrex
_c
astro_inputs.2d.cyl_in_cartcoords
→
test/data/amrexCastro/test_data_
A
mrex
C
astro_inputs.2d.cyl_in_cartcoords
View file @
b9141834
File moved
test/runtests.jl
View file @
b9141834
using
Test
using
Test
,
Base
.
Filesystem
import
Exio
@testset
"test_amrexCastro"
begin
include
(
"test_amrexCastro.jl"
)
include
(
"test_amrexCastro.jl"
)
end
;
@testset
"test_Exio.input_parser_docstring"
begin
@test
println
(
@doc
Exio
.
input_parser
)
===
nothing
end
;
test/test_amrexCastro.jl
View file @
b9141834
...
...
@@ -2,4 +2,31 @@
exio
=
Exio
.
exio_init
(
"AmrexCastro"
,
"."
)
@test
typeof
(
exio
)
==
Exio
.
ExioH
\ No newline at end of file
@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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment