# Need Gibbs Seawater (GSW) Equation of State to be ported to Julia

**URL:** <https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476>\
**Category:** Geo\
**Created:** [October 30, 2019, 3:40am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476 "2019-10-30T03:40:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![truedichotomy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/truedichotomy/32/11076_2.png) [@truedichotomy](https://discourse.julialang.org/u/truedichotomy)\
**Post date:** [October 30, 2019, 3:40am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/1 "2019-10-30T03:40:49Z")

</div>

The [Gibb Seawater Equation of State (GSW)](http://www.teos-10.org/software.htm) is what oceanographers use to calculate fundamental properties of seawater. Currently there are a couple implementation of the C version of the library in Julia but none of them are working with macOS. If someone can help me develop a version fo macOS, it would be very appreciate. Thanks!

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 30, 2019, 3:52am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/2 "2019-10-30T03:52:38Z")

</div>

im working with Helmholtz EOS, I have the IAPWS95-2018 (just water) and the GERG2008 (natural gas) implemented. (working on a PT solver too). i can help you.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 30, 2019, 3:57am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/3 "2019-10-30T03:57:25Z")

</div>

looking at [this paper](http://www.teos-10.org/pubs/SIA_Paper_1.pdf). a lot of implementations use the IAPWS95 + a correction term. so implementing the correction terms is whats missing

---

<div class="post-metadata">

**Author:** ![truedichotomy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/truedichotomy/32/11076_2.png) [@truedichotomy](https://discourse.julialang.org/u/truedichotomy)\
**Post date:** [October 31, 2019, 12:39am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/4 "2019-10-31T00:39:20Z")

</div>

Sounds like you are doing a Julia native implementation?

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 31, 2019, 1:05am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/5 "2019-10-31T01:05:05Z")

</div>

Always wanted to see an implementation of GERG! Any chance you could share?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 31, 2019, 1:05am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/6 "2019-10-31T01:05:09Z")

</div>

of helmholtz EOS, mainly. the idea i have is an agnostic EOS system. the derivatives are calculated via ForwardDiff and i’m working on a PT solver (multicomponent, i haven’t did anything with monocomponent, like IAPWS95), there are good tools to work on that

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 31, 2019, 1:08am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/7 "2019-10-31T01:08:34Z")

</div>

of course, check this:  
[https://github.com/longemen3000/LavoisierCore.jl/blob/master/src/gerg2008.jl](https://github.com/longemen3000/LavoisierCore.jl/blob/master/src/gerg2008.jl)  
my idea is that the EOS is a struct, and you pass the struct to calculate a property: for example:

```julia
mymodel = GERG2008(:CH4,:H2O,:CO2)
pressure(mymodel,2u"kg/m^3",300u"K",[0.1,0.2,0.7])

```

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 31, 2019, 1:10am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/8 "2019-10-31T01:10:42Z")

</div>

Wow! I admire your tenacity thank you. I will have to fork this and play with it a bit.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [October 31, 2019, 1:13am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/9 "2019-10-31T01:13:16Z")

</div>

for all 21 compunds, it takes around 121 μs per helmholtz evaluation, a binary one takes around 4μs (IAPWS95 takes around the same as a binary GERG). if you need properties, you just differenciate the helmholtz function with ForwardDiff (zygote is too slow in this case)

---

<div class="post-metadata">

**Author:** ![kouketsu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kouketsu/32/8643_2.png) [@kouketsu](https://discourse.julialang.org/u/kouketsu)\
**Post date:** [November 1, 2019, 3:20am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/10 "2019-11-01T03:20:31Z")

</div>

Could you try [this](https://github.com/kouketsu/GSW.jl) ?  
This is just a wrapper and I don’t have an OSX environment, but it seem to be successful to build on the travis (osx) now.

---

<div class="post-metadata">

**Author:** ![truedichotomy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/truedichotomy/32/11076_2.png) [@truedichotomy](https://discourse.julialang.org/u/truedichotomy)\
**Post date:** [November 5, 2019, 9:28pm UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/12 "2019-11-05T21:28:52Z")

</div>

Thanks @kouketsu!!! I just installed your GSW.jl package and it works! The installation went without a hitch on a new macOS machine but on my old machine I had to manually remove a previous non-working installation to make it precompile correctly. Thanks again!

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 5, 2019, 11:20pm UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/13 "2019-11-05T23:20:58Z")

</div>

Longeman I really love the scope your package is aiming for but I tried to use it with a GERG mixture of 2 components and got an array out of bounds error.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [November 6, 2019, 12:10am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/14 "2019-11-06T00:10:50Z")

</div>

how you are calling it?  
when you call `model = GERG2008()` , you call it with all 21 compounds in the order of the kunst paper. if you want a custom order, you can call `GERG2008(compounds...)`, where the list of accepted compounds are:

```julia
symvalues = [:CH4, :N2, :CO2, :C2, :C3, :nC4, :iC4, :nC5, :iC5, :C6, :C7, :C8, :C9, :C10, 
    :H2, :O2, :CO, :H2O, :H2S, :He, :Ar]

```

for example: a water-H2S mixture can be called via:

```julia
model = GERG2008(:H2O,:H2S)
core_pressure(model,0.01,373,[0.9,0.1])

```

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 6, 2019, 12:15am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/15 "2019-11-06T00:15:50Z")

</div>

I don’t have the code right now, I think I ran it like this,

```nohighlight
m = GERG2008(:CH4, :C3)
density(m,2u"kg/m^3",300u"K",[0.1,0.2])

```

and it gave me an array out of bounds error, something like “tried to access index 3 of a 2 index array”

Maybe I cloned master at an inopportune time though

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [November 6, 2019, 12:17am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/16 "2019-11-06T00:17:43Z")

</div>

I have density? I dont remember coding that lol

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [November 6, 2019, 12:19am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/17 "2019-11-06T00:19:31Z")

</div>

Give me a moment and i will give you proper `molar_density` and `mass_density`

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 6, 2019, 12:19am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/18 "2019-11-06T00:19:49Z")

</div>

😆 Think I meant pressure sorry! Density would be awesome though!

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [November 6, 2019, 12:22am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/19 "2019-11-06T00:22:13Z")

</div>

You can check how many compounds yor model have with `length(model) `

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 6, 2019, 12:23am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/20 "2019-11-06T00:23:10Z")

</div>

let me try again I cannot find where I cloned it to!

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 6, 2019, 12:28am UTC](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476/21 "2019-11-06T00:28:14Z")

</div>

```nohighlight
julia> pressure(m,2u"kg/m^3",300u"K",[0.1,0.2])
ERROR: BoundsError: attempt to access 2-element Array{Float64,1} at index [6]
Stacktrace:
 [1] getindex at ./array.jl:731 [inlined]
 [2] _fr2(::GERG2008, ::ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2}, ::ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2}, ::Array{Float64,1}) at /home/caseykneale/try/LavoisierCore.jl/src/gerg2008.jl:626
 [3] core_helmholtz(::GERG2008, ::ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2}, ::ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2}, ::Array{Float64,1}) at /home/caseykneale/try/LavoisierCore.jl/src/gerg2008.jl:671
 [4] vector_mode_gradient(::getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}}, ::Array{Float64,1}, ::ForwardDiff.GradientConfig{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2,Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2},1}}) at /home/caseykneale/try/LavoisierCore.jl/src/core.jl:74
 [5] gradient(::Function, ::Array{Float64,1}, ::ForwardDiff.GradientConfig{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2,Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2},1}}, ::Val{true}) at /home/caseykneale/.julia/packages/ForwardDiff/N0wMF/src/gradient.jl:17
 [6] gradient(::Function, ::Array{Float64,1}, ::ForwardDiff.GradientConfig{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2,Array{ForwardDiff.Dual{ForwardDiff.Tag{getfield(LavoisierCore, Symbol("##37#38")){GERG2008,Array{Float64,1}},Float64},Float64,2},1}}) at /home/caseykneale/.julia/packages/ForwardDiff/N0wMF/src/gradient.jl:15 (repeats 2 times)
 [7] core_grad_vt at /home/caseykneale/try/LavoisierCore.jl/src/core.jl:75 [inlined]
 [8] core_pressure(::GERG2008, ::Float64, ::Int64, ::Array{Float64,1}) at /home/caseykneale/try/LavoisierCore.jl/src/core.jl:161
 [9] pressure(::GERG2008, ::Quantity{Int64,𝐌*𝐋^-3,Unitful.FreeUnits{(kg, m^-3),𝐌*𝐋^-3,nothing}}, ::Quantity{Int64,𝚯,Unitful.FreeUnits{(K,),𝚯,nothing}}, ::Array{Float64,1}) at /home/caseykneale/try/LavoisierCore.jl/src/core.jl:170
 [10] top-level scope at none:0

julia> length(m)
2

```

[Next page](https://discourse.julialang.org/t/need-gibbs-seawater-gsw-equation-of-state-to-be-ported-to-julia/30476.md?page=2)
