Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
J
jexio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Godoy, William
jexio
Commits
7b4ab407
Commit
7b4ab407
authored
Jun 24, 2020
by
William F Godoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Setting linear models
parent
e9bec832
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
153 additions
and
92 deletions
+153
-92
.gitignore
.gitignore
+1
-0
README.md
README.md
+7
-6
scripts/requirements.jl
scripts/requirements.jl
+5
-0
src/Exio.jl
src/Exio.jl
+2
-4
src/extractor/Amrex.jl
src/extractor/Amrex.jl
+26
-24
src/extractor/AmrexCastro.jl
src/extractor/AmrexCastro.jl
+66
-28
src/helper/helperSystem.jl
src/helper/helperSystem.jl
+27
-8
test/runtests.jl
test/runtests.jl
+1
-1
test/test_AmrexCastro.jl
test/test_AmrexCastro.jl
+18
-21
No files found.
.gitignore
View file @
7b4ab407
.buildpath
.project
*.so
README.md
View file @
7b4ab407
...
...
@@ -9,15 +9,16 @@ Supported:
For simple usage see tests:
1.
Install requirements (run once):
`$ julia scripts/requirements.jl`
1.
Install requirements and precompile dependencies (run once). It takes time the first time,
generates
`jexio_deps.so`
:
-
`$ julia scripts/requirements.jl`
2.
Run tests:
`$ julia
--project=. test/runtests.jl`
Optionally,
when developing
run tests from the Julia REPL for preloading libraries,
-
`$ julia -Jjexio_deps.so
--project=. test/runtests.jl`
Optionally, run tests from the Julia REPL for preloading libraries,
as it results in faster runtimes after the first time.
`$ julia
--project=.`
`julia> include("test/runtests.jl")
-
`$ julia -Jjexio_deps.so
--project=.`
-
`julia> include("test/runtests.jl")
Formatting the code:
...
...
scripts/requirements.jl
View file @
7b4ab407
...
...
@@ -10,5 +10,10 @@ Pkg.add("Glob")
Pkg
.
add
(
"DataFrames"
)
Pkg
.
add
(
"GLM"
)
Pkg
.
add
(
"Plots"
)
Pkg
.
add
(
"PackageCompiler"
)
using
PackageCompiler
create_sysimage
([
:
Glob
,
:
Plots
,
:
GLM
,
:
DataFrames
],
sysimage_path
=
"jexio_deps.so"
)
exit
()
src/Exio.jl
View file @
7b4ab407
module
Exio
export
ExioH
,
exio_init
,
input_parser
export
ExioH
,
exio_init
include
(
"extractor/Extractor.jl"
)
mutable struct
ExioH
extractor
::
AbstractExtractor
ExioH
()
=
new
()
end
...
...
@@ -16,8 +15,7 @@ function exio_init(app::String, outputPrefix::String)::ExioH
exioH
=
ExioH
()
if
app
==
"AmrexCastro"
println
(
"Hello AmrexCastro"
)
exioH
.
extractor
=
AmrexCastro
()
init!
(
exioH
.
extractor
,
outputPrefix
)
exioH
.
extractor
=
AmrexCastro
(
outputPrefix
)
end
return
exioH
...
...
src/extractor/Amrex.jl
View file @
7b4ab407
...
...
@@ -4,23 +4,17 @@ abstract type AbstractAmrex <: AbstractExtractor end
mutable struct
Amrex
<:
AbstractAmrex
app
::
String
outputPrefix
::
String
degreesOfFreedom
::
Any
Amrex
()
=
new
()
inputs
::
Array
{
String
}
outputs
::
Array
{
String
}
Amrex
(
outputPrefix
::
String
)
=
new
(
"Amrex"
,
outputPrefix
,
[
"max_step"
,
"amr.check_int"
,
"amr.plot_int"
,
"amr.n_cell"
,
"amr.max_level"
],
[
"plots_size"
,
"checkpoints_size"
],
)
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
...
...
@@ -28,7 +22,7 @@ end
- `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
}
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
...
...
@@ -64,24 +58,25 @@ end
from input parameters
# Arguments
- `extractor::AbstractAmrex` : input type extending AbstractAmrex
- `parameters::Dict{
String,String
}` : input file to be parsed, absolute path is preferred
- `parameters::Dict{
Any,Any
}` : input file to be parsed, absolute path is preferred
"""
function
get_independent_variables
(
extractor
::
AbstractAmrex
,
parameters
)
::
Dict
function
_get_independent_variables
(
extractor
::
AbstractAmrex
,
parameters
)
::
Dict
{
String
,
Any
}
independentVariables
=
Dict
()
independentVariables
=
Dict
{
String
,
Any
}
()
# 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
# safe string conversion to a type
maxStep
=
parse
(
Int64
,
maxStepStr
)
plotIntStr
=
get
(
parameters
,
"amr.plot_int"
,
""
)
if
plotIntStr
!=
""
plotFrequency
=
parse
(
Int64
,
plotIntStr
)
independentVariables
[
"amr.plot_int"
]
=
plotFrequency
independentVariables
[
"amr.nplot_files"
]
=
floor
(
Int32
,
maxStep
/
plotFrequency
)
else
throw
(
NoSuchFieldException
(
"jexio Amrex: Can't find amr.plot_int"
))
...
...
@@ -90,7 +85,9 @@ function get_independent_variables(extractor::AbstractAmrex, parameters)::Dict
checkIntStr
=
get
(
parameters
,
"amr.check_int"
,
""
)
if
checkIntStr
!=
""
checkpointFrequency
=
parse
(
Int64
,
checkIntStr
)
independentVariables
[
"amr.ncheck_files"
]
=
floor
(
Int32
,
maxStep
/
checkpointFrequency
)
independentVariables
[
"amr.check_int"
]
=
checkpointFrequency
independentVariables
[
"amr.ncheck_files"
]
=
floor
(
Int32
,
maxStep
/
checkpointFrequency
)
else
throw
(
NoSuchFieldException
(
"jexio Amrex: Can't find amr.check_int"
))
end
...
...
@@ -109,10 +106,15 @@ function get_independent_variables(extractor::AbstractAmrex, parameters)::Dict
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
function
_get_inputs_X
(
extractor
::
AbstractAmrex
)
end
src/extractor/AmrexCastro.jl
View file @
7b4ab407
include
(
"../helper/helperSystem.jl"
)
mutable struct
AmrexCastro
<:
AbstractAmrex
@time
import
DataFrames
struct
AmrexCastro
<:
AbstractAmrex
app
::
String
degreesOfFreedom
::
Any
outputPrefix
::
String
inputs
::
Array
{
String
}
outputs
::
Dict
{
String
,
Array
{
String
}}
AmrexCastro
()
=
new
()
AmrexCastro
(
outputPrefix
::
String
)
=
new
(
"AmrexCastro"
,
outputPrefix
,
[
"max_step"
,
"amr.check_int"
,
"amr.plot_int"
,
"amr.n_cell"
,
"amr.max_level"
,
"castro.cfl"
,
"castro.max_grid_size"
,
],
Dict
{
String
,
Array
{
String
}}(
"plots_size"
=>
[
"max_step"
,
"amr.plot_int"
,
"amr.n_cell"
,
"amr.max_level"
])
)
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_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
)
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
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
]
# get relevant input parameters
parameters
=
_input_parser
(
extractor
,
inputFile
)
independent_variables
=
_get_independent_variables
(
extractor
,
parameters
)
if
!
isXInit
X
=
DataFrames
.
DataFrame
(
independent_variables
)
isXInit
=
true
else
DataFrames
.
push!
(
X
,
independent_variables
)
end
end
println
(
X
)
function
get_dependent_variable_datasize
(
extractor
::
AmrexCastro
)
outputDirs
=
helper_get_prefix_directories
(
extractor
.
outputPrefix
)
println
(
outputDirs
)
end
function
_get_outputs_Y
(
extractor
::
AmrexCastro
)
function
_get_outputs_Y_plots_size
(
extractor
::
AmrexCastro
)
maxStepStr
=
get
(
extractor
.
parameters
,
""
,
""
)
end
for
output
in
extractor
.
outputs
if
(
output
==
"plots_size"
)
_get_outputs_Y_plots_size
(
extractor
)
end
end
end
src/helper/helperSystem.jl
View file @
7b4ab407
...
...
@@ -3,11 +3,30 @@ import Glob
function
helper_get_prefix_directories
(
prefix
::
String
)
::
Array
{
String
}
findDelimiter
=
findlast
(
"/"
,
prefix
)
searchDirectory
=
prefix
[
1
:
findDelimiter
[
1
]
-
1
]
print
(
searchDirectory
)
pattern
=
string
(
prefix
[
findDelimiter
[
1
]
+
1
:
end
],
"*"
)
outputDirs
=
Glob
.
glob
(
pattern
,
searchDirectory
)
return
outputDirs
end
\ No newline at end of file
findDelimiter
=
findlast
(
"/"
,
prefix
)
searchDirectory
::
String
=
prefix
[
1
:
findDelimiter
[
1
]
-
1
]
#print(searchDirectory)
pattern
::
String
=
string
(
prefix
[
findDelimiter
[
1
]
+
1
:
end
],
"*"
)
outputDirs
=
Glob
.
glob
(
pattern
,
searchDirectory
)
return
outputDirs
end
"""
Gets the list of files inside a path that meet the prefix criteria.
Example:
path/prefix.*
path/
prefix.1
prefix.2
prefix.3
output: [ prefix.1, prefix.2, prefix.3 ]
"""
function
helper_get_prefix_files
(
prefix
::
String
,
path
::
String
)
::
Array
{
String
}
pattern
::
String
=
string
(
prefix
,
"*"
)
files
=
Glob
.
glob
(
pattern
,
path
)
end
test/runtests.jl
View file @
7b4ab407
...
...
@@ -8,5 +8,5 @@ import Exio
end
;
@testset
"test_Exio.input_parser_docstring"
begin
@test
println
(
@doc
Exio
.
input_parser
)
===
nothing
@test
println
(
@doc
Exio
.
_
input_parser
)
===
nothing
end
;
test/test_AmrexCastro.jl
View file @
7b4ab407
...
...
@@ -16,18 +16,22 @@ function test_value(
end
function
test_AmrexCastro
()
exio
=
Exio
.
exio_init
(
"AmrexCastro"
,
"./test/data/AmrexCastro/hydro_tests/Sedov/2d.cyl_in_cartcoords/case"
)
exio
=
Exio
.
exio_init
(
"AmrexCastro"
,
"./test/data/AmrexCastro/hydro_tests/Sedov/2d.cyl_in_cartcoords/case"
,
)
@test
typeof
(
exio
)
==
Exio
.
ExioH
println
(
"Current directory: "
,
Filesystem
.
pwd
())
inputFile
=
string
(
Filesystem
.
pwd
(),
"/"
,
inputFile
::
String
=
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
)
parameters
=
Exio
.
_
input_parser
(
exio
.
extractor
,
inputFile
)
# keys counter
counter
=
0
...
...
@@ -62,30 +66,23 @@ function test_AmrexCastro()
@test
counter
==
27
independent_variables
=
Exio
.
get_independent_variables
(
exio
.
extractor
,
parameters
)
independent_variables
=
Exio
.
_
get_independent_variables
(
exio
.
extractor
,
parameters
)
println
(
independent_variables
)
Exio
.
get_dependent_variable_datasize
(
exio
.
extractor
)
Exio
.
_get_linear_model
(
exio
.
extractor
)
end
test_AmrexCastro
()
@time
using
DataFrames
X
=
[
1
,
2
,
3
,
4
,
5
,
6
]
Y
=
[
2
,
4
,
7
,
9
,
11
,
13
]
data
=
DataFrames
.
DataFrame
(
X
=
X
,
Y
=
Y
)
println
(
data
)
@time
using
GLM
ols
=
GLM
.
lm
(
@formula
(
Y
~
X
),
data
)
println
(
ols
)
@time
using
Plots
display
(
plot
(
X
,
Y
))
X
=
[
1
,
2
,
3
,
4
,
5
,
6
]
Y
=
[
2
,
4
,
7
,
9
,
11
,
13
]
#@time import GLM
#ols = GLM.lm(GLM.@formula(Y ~ X), data)
# println(ols)
@time
import
Plots
display
(
Plots
.
plot
(
X
,
Y
))
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