Skip to content

Commit

Permalink
Merge pull request #11 from sintefmath/skip_kw
Browse files Browse the repository at this point in the history
Allow runtime customization of skipped records
  • Loading branch information
moyner authored Jun 25, 2024
2 parents 78b873b + 66aa992 commit 43fefa2
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoEnergyIO"
uuid = "3b1dd628-313a-45bb-9d8d-8f3c48dcb5d4"
authors = ["Olav Møyner <olav.moyner@gmail.com> and contributors"]
version = "1.1.2"
version = "1.1.3"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
27 changes: 27 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ spe1_pth = GeoEnergyIO.test_input_file_path("SPE1", "SPE1.DATA")
spe1 = parse_data_file(spe1_pth)
```

### Handling unsupported keywords

Not all keywords are supported by the parser, but not all keywords are important. The input format is such that it is difficult to automatically skip keywords, but you an manually add keywords to the skip list:

```@docs
GeoEnergyIO.InputParser.skip_kw!
```

Adding keywords to the skip list is not persistent across Julia sessions and can be added to the top of your script. Contributions to the global skip list defined in the `__init__` function of the parser are welcome.

```@example
using GeoEnergyIO
# Skip keyword without data
GeoEnergyIO.InputParser.skip_kw!(:MY_KW, 0)
# Keyword with a single record of data, e.g.
# MY_DATA_KW
# "some data" 1 2 3 /
GeoEnergyIO.InputParser.skip_kw!(:MY_DATA_KW, 1)
# Keyword with many records, terminated by empty record:
# MY_LONG_DATA_KW
# "some data" 1 2 3 /
# "more data" 4 5 6 /
# "even more data" 1 9 /
# /
GeoEnergyIO.InputParser.skip_kw!(:MY_LONG_DATA_KW, Inf)
```

## Parsing and processing of corner-point grids

Corner-point meshes are the de-facto standard format for simulation of subsurface flow. These meshes are semi-structured, but can have quite complex structure in practice due to eroded and collapsed cells and the presence of faults. This module includes a processor to convert the input format into a mesh that can be used for simulation. Converting the corner-points into a mesh with a connected topology is non-trivial, but the included algorithm has been verified on a number of real-field assets.
Expand Down
63 changes: 63 additions & 0 deletions src/InputParser/InputParser.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,72 @@
module InputParser
using Parsers, DelimitedFiles, Jutul, OrderedCollections, Dates, LinearAlgebra
export parse_data_file
@enum PARSER_WARNING PARSER_MISSING_SUPPORT PARSER_JUTULDARCY_MISSING_SUPPORT PARSER_JUTULDARCY_PARTIAL_SUPPORT PARSER_PARTIAL_SUPPORT
const KEYWORD_SKIP_LIST = Tuple{Symbol, Union{Float64, Int}, Union{PARSER_WARNING, Nothing}}[]

include("parser.jl")
include("units.jl")
include("utils.jl")
include("keywords/keywords.jl")

function __init__()
# Keywords with a single line
skip_kw!(:PETOPTS, 1)
skip_kw!(:PARALLEL, 1)
skip_kw!(:MULTSAVE, 1)
skip_kw!(:VECTABLE, 1)
skip_kw!(:MULTSAVE, 1)
skip_kw!(:MEMORY, 1)
skip_kw!(:OPTIONS3, 1)
skip_kw!(:TSCRIT, 1, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:CVCRIT, 1, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:RPTPRINT, 1)
# Keywords without data (i.e. just the name)
skip_kw!(:MULTOUT, 0)
skip_kw!(:NOSIM, 0)
skip_kw!(:NOINSPEC, 0)
skip_kw!(:NORSSPEC, 0)
skip_kw!(:NOWARN, 0)
skip_kw!(:NOWARNEP, 0)
skip_kw!(:NOHYKR, 0)
skip_kw!(:NOMIX, 0)
skip_kw!(:FILLEPS, 0)
skip_kw!(:NPROCX, 0)
skip_kw!(:NPROCY, 0)
skip_kw!(:NONNC, 0)
skip_kw!(:NEWTRAN, 0)
skip_kw!(:CO2STORE, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:CO2STOR, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:DIFFUSE, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:OLDTRAN, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:UNIFSAVE, 0)
skip_kw!(:SATOPTS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:EQLOPTS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:TRACERS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:PIMTDIMS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:FLUXNUM, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:OPTIONS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:EHYSTR, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:ZIPPY2, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:DRSDT, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:WPAVE, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:VAPPARS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:RESTART, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:NETBALAN, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:JFUNC, 1, PARSER_MISSING_SUPPORT)
# Keywords with any number of records, terminated by empty records
skip_kw!(:PSPLITX, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PSPLITY, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PSPLITZ, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:COMPLUMP, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:AQUNUM, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:TRACER, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:THPRES, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PIMULTAB, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:VFPPROD, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:VFPINJ, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:WTRACER, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:GCONINJE, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:WTEST, Inf, PARSER_MISSING_SUPPORT)
end
end
25 changes: 23 additions & 2 deletions src/InputParser/parser.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
"""
skip_kw!(kw, num, msg = nothing)
Add a keyword to list of records that will be skipped on parsing.
`kw` is the symbol (usually capitalized) of the keyword to skip, num is the
number of expected records:
- 0 means that the keyword to skip has no data (for example "WATER" with no
data to follow)
- 1 means that the keyword has a single record terminated by `/`
- Any other number means a fixed number of lines, without termination by empty
record.
- Inf means that the keyword has any number of records, terminated by a record
without entries.
"""
function skip_kw!(kw::Symbol, num = 0, msg = nothing)
push!(KEYWORD_SKIP_LIST, (kw, num, msg))
end

function skip_kw!(kw::AbstractString, num, msg = nothing)
skip_kw!(Symbol(kw), num, msg)
end

Base.@kwdef struct ParserVerbosityConfig
silent::Bool = false
verbose::Bool = true
Expand All @@ -7,8 +30,6 @@ Base.@kwdef struct ParserVerbosityConfig
warn_count::Dict{String, Int} = Dict{String, Int}()
end

@enum PARSER_WARNING PARSER_MISSING_SUPPORT PARSER_JUTULDARCY_MISSING_SUPPORT PARSER_JUTULDARCY_PARTIAL_SUPPORT PARSER_PARTIAL_SUPPORT

function keyword_header(current_data, keyword)
if haskey(current_data, "CURRENT_SECTION")
section = current_data["CURRENT_SECTION"]
Expand Down
73 changes: 1 addition & 72 deletions src/InputParser/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,79 +400,8 @@ end

function parse_keyword!(data, outer_data, units, cfg, f, v::Val{T}) where T
# Keywords where we read a single record and don't do anything proper

skip_kw_with_warn = Symbol[
:SATOPTS,
:EQLOPTS,
:TRACERS,
:PIMTDIMS,
:OPTIONS
]

skip_list = []
function skip_kw!(kw, num, msg = nothing)
push!(skip_list, (kw, num, msg))
end
skip_kw!(:PETOPTS, 1)
skip_kw!(:PARALLEL, 1)
skip_kw!(:MULTSAVE, 1)
skip_kw!(:VECTABLE, 1)
skip_kw!(:MULTSAVE, 1)
skip_kw!(:MEMORY, 1)
skip_kw!(:OPTIONS3, 1)
skip_kw!(:TSCRIT, 1, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:CVCRIT, 1, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:RPTPRINT, 1)

skip_kw!(:MULTOUT, 0)
skip_kw!(:NOSIM, 0)
skip_kw!(:NOINSPEC, 0)
skip_kw!(:NORSSPEC, 0)
skip_kw!(:NOWARN, 0)
skip_kw!(:NOWARNEP, 0)
skip_kw!(:NOHYKR, 0)
skip_kw!(:NOMIX, 0)
skip_kw!(:FILLEPS, 0)
skip_kw!(:NPROCX, 0)
skip_kw!(:NPROCY, 0)
skip_kw!(:NONNC, 0)
skip_kw!(:NEWTRAN, 0)
skip_kw!(:CO2STORE, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:CO2STOR, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:DIFFUSE, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:OLDTRAN, 0, PARSER_JUTULDARCY_MISSING_SUPPORT)
skip_kw!(:UNIFSAVE, 0)
skip_kw!(:SATOPTS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:EQLOPTS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:TRACERS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:PIMTDIMS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:FLUXNUM, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:OPTIONS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:EHYSTR, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:ZIPPY2, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:DRSDT, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:WPAVE, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:VAPPARS, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:RESTART, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:NETBALAN, 1, PARSER_MISSING_SUPPORT)
skip_kw!(:JFUNC, 1, PARSER_MISSING_SUPPORT)

skip_kw!(:PSPLITX, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PSPLITY, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PSPLITZ, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:COMPLUMP, Inf, PARSER_MISSING_SUPPORT)

skip_kw!(:TRACER, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:THPRES, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:PIMULTAB, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:VFPPROD, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:VFPINJ, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:WTRACER, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:GCONINJE, Inf, PARSER_MISSING_SUPPORT)
skip_kw!(:WTEST, Inf, PARSER_MISSING_SUPPORT)

found = false
for (kw, num, msg) in skip_list
for (kw, num, msg) in KEYWORD_SKIP_LIST
if kw != T
continue
end
Expand Down

4 comments on commit 43fefa2

@moyner
Copy link
Member Author

@moyner moyner commented on 43fefa2 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/109723

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.3 -m "<description of version>" 43fefa251acaa60aac56132bc57fd4e81d054a0d
git push origin v1.1.3

@moyner
Copy link
Member Author

@moyner moyner commented on 43fefa2 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Changes

  • Greatly improved parser performance
  • Improved WELTARG support
  • Allow runtime customization of skipped records

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/109723

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.3 -m "<description of version>" 43fefa251acaa60aac56132bc57fd4e81d054a0d
git push origin v1.1.3

Please sign in to comment.