From 0cccd275b0798d43316ca2394305254d41b9412c Mon Sep 17 00:00:00 2001 From: Braam van Dyk Date: Sat, 13 Jul 2024 19:43:42 +0200 Subject: [PATCH] Remove file access from tests --- corrected.csv | 28 ++++++++++++ streamhistories/C2.csv | 54 +++++++++++------------ streamhistories/FeedStream.csv | 28 ++++++++++++ streamhistories/ProdStream.csv | 28 ++++++++++++ test/components/Ethane.comp | 7 --- test/components/Ethylene.comp | 7 --- test/components/Hydrogen.comp | 5 --- test/components/argon.comp | 5 --- test/components/nitrogen.comp | 5 --- test/runtests.jl | 73 ++++++++++++++++++++----------- test/streamhistories/C2.csv | 28 ------------ test/streamhistories/Hydrogen.csv | 28 ------------ test/streamhistories/Product.csv | 28 ------------ 13 files changed, 158 insertions(+), 166 deletions(-) create mode 100644 corrected.csv create mode 100644 streamhistories/FeedStream.csv create mode 100644 streamhistories/ProdStream.csv delete mode 100644 test/components/Ethane.comp delete mode 100644 test/components/Ethylene.comp delete mode 100644 test/components/Hydrogen.comp delete mode 100644 test/components/argon.comp delete mode 100644 test/components/nitrogen.comp delete mode 100644 test/streamhistories/C2.csv delete mode 100644 test/streamhistories/Hydrogen.csv delete mode 100644 test/streamhistories/Product.csv diff --git a/corrected.csv b/corrected.csv new file mode 100644 index 0000000..e126530 --- /dev/null +++ b/corrected.csv @@ -0,0 +1,28 @@ +Timestamp,Ethylene,Ethane,Hydrogen,Nitrogen,Argon +2020/01/01 00:00,3.0083766913264873,26.835736901945783,0.0,0.0,0.0 +2020/01/01 06:00,3.0122752167551723,26.963791743045917,0.0,0.0,0.0 +2020/01/02 00:00,2.585930742198797,29.632356832198965,0.0,0.0,0.0 +2020/01/02 06:00,2.9761703603631293,29.182702913216673,0.0,0.0,0.0 +2020/01/03 00:00,2.9015044671522725,27.762081372179146,0.0,0.0,0.0 +2020/01/03 06:00,2.874294992678864,28.53658904603999,0.0,0.0,0.0 +2020/01/04 00:00,3.081113015029097,26.62348193331089,0.0,0.0,0.0 +2020/01/04 06:00,3.049341758044824,27.193173419142095,0.0,0.0,0.0 +2020/01/05 00:00,2.740714769461643,24.972745338141674,0.0,0.0,0.0 +2020/01/05 06:00,2.886997138662742,29.430553417668566,0.0,0.0,0.0 +2020/01/06 00:00,2.9150167837800343,26.17109933085312,0.0,0.0,0.0 +2020/01/06 06:00,2.9643963478886994,26.113797068074483,0.0,0.0,0.0 +2020/01/07 00:00,2.8012284010056714,24.825791865256555,0.0,0.0,0.0 +2020/01/07 06:00,2.8073907754922063,27.751932941648906,0.0,0.0,0.0 +2020/01/08 00:00,2.663511819024626,24.835621085404465,0.0,0.0,0.0 +2020/01/08 06:00,2.698683941215198,29.69750257156399,0.0,0.0,0.0 +2020/01/09 00:00,2.5848739576307316,26.734676897482224,0.0,0.0,0.0 +2020/01/09 06:00,2.692180161717027,28.973112942338556,0.0,0.0,0.0 +2020/01/10 00:00,3.0510497369050102,29.105783314192017,0.0,0.0,0.0 +2020/01/10 06:00,2.7201007797438446,27.989192493038836,0.0,0.0,0.0 +2020/01/11 00:00,2.6801400104303212,24.79772964635246,0.0,0.0,0.0 +2020/01/11 06:00,2.8586606349089316,28.30425813181928,0.0,0.0,0.0 +2020/01/12 00:00,3.0121363263515066,28.109514811425118,0.0,0.0,0.0 +2020/01/12 06:00,2.8788586827937364,24.554236532004648,0.0,0.0,0.0 +2020/01/13 00:00,2.7358116660981437,24.46065833659935,0.0,0.0,0.0 +2020/01/13 06:00,3.058238037659462,25.23085988766036,0.0,0.0,0.0 +2020/01/14 00:00,2.9887658768934973,25.705164750239195,0.0,0.0,0.0 diff --git a/streamhistories/C2.csv b/streamhistories/C2.csv index 1ebb40f..97eebc1 100644 --- a/streamhistories/C2.csv +++ b/streamhistories/C2.csv @@ -1,28 +1,28 @@ TimeStamp,Ethylene,Ethane, -2020/01/01 00:00,0.107239036,0.89247781,0.999716846 -2020/01/01 06:00,0.107378006,0.896736538,1.004114544 -2020/01/02 00:00,0.092180185,0.985485177,1.077665362 -2020/01/02 06:00,0.106090983,0.970531008,1.076621991 -2020/01/03 00:00,0.103429382,0.923285307,1.026714689 -2020/01/03 06:00,0.102459451,0.949043158,1.051502609 -2020/01/04 00:00,0.109831854,0.885418833,0.995250687 -2020/01/04 06:00,0.10869931,0.904365099,1.013064409 -2020/01/05 00:00,0.097697742,0.830520181,0.928217923 -2020/01/05 06:00,0.102912242,0.978773788,1.08168603 -2020/01/06 00:00,0.103911053,0.870373916,0.974284969 -2020/01/06 06:00,0.105671277,0.868468211,0.974139488 -2020/01/07 00:00,0.09985486,0.82563294,0.9254878 -2020/01/07 06:00,0.100074529,0.9229478,1.023022329 -2020/01/08 00:00,0.094945703,0.825959831,0.920905534 -2020/01/08 06:00,0.096199477,0.987651733,1.08385121 -2020/01/09 00:00,0.092142514,0.889116851,0.981259365 -2020/01/09 06:00,0.095967638,0.963560661,1.059528299 -2020/01/10 00:00,0.108760194,0.967972888,1.076733082 -2020/01/10 06:00,0.096962919,0.930838356,1.027801275 -2020/01/11 00:00,0.095538445,0.824699673,0.920238118 -2020/01/11 06:00,0.101902136,0.941316514,1.04321865 -2020/01/12 00:00,0.107373055,0.934839923,1.042212978 -2020/01/12 06:00,0.102622132,0.816601807,0.919223939 -2020/01/13 00:00,0.097522962,0.813489671,0.911012633 -2020/01/13 06:00,0.109016434,0.839104313,0.948120747 -2020/01/14 00:00,0.106539973,0.8548783,0.961418273 +2020/01/01 00:00,0.107239036,0.89247781 +2020/01/01 06:00,0.107378006,0.896736538 +2020/01/02 00:00,0.092180185,0.985485177 +2020/01/02 06:00,0.106090983,0.970531008 +2020/01/03 00:00,0.103429382,0.923285307 +2020/01/03 06:00,0.102459451,0.949043158 +2020/01/04 00:00,0.109831854,0.885418833 +2020/01/04 06:00,0.10869931,0.904365099 +2020/01/05 00:00,0.097697742,0.830520181 +2020/01/05 06:00,0.102912242,0.978773788 +2020/01/06 00:00,0.103911053,0.870373916 +2020/01/06 06:00,0.105671277,0.868468211 +2020/01/07 00:00,0.09985486,0.82563294 +2020/01/07 06:00,0.100074529,0.9229478 +2020/01/08 00:00,0.094945703,0.825959831 +2020/01/08 06:00,0.096199477,0.987651733 +2020/01/09 00:00,0.092142514,0.889116851 +2020/01/09 06:00,0.095967638,0.963560661 +2020/01/10 00:00,0.108760194,0.967972888 +2020/01/10 06:00,0.096962919,0.930838356 +2020/01/11 00:00,0.095538445,0.824699673 +2020/01/11 06:00,0.101902136,0.941316514 +2020/01/12 00:00,0.107373055,0.934839923 +2020/01/12 06:00,0.102622132,0.816601807 +2020/01/13 00:00,0.097522962,0.813489671 +2020/01/13 06:00,0.109016434,0.839104313 +2020/01/14 00:00,0.106539973,0.8548783 diff --git a/streamhistories/FeedStream.csv b/streamhistories/FeedStream.csv new file mode 100644 index 0000000..e34b589 --- /dev/null +++ b/streamhistories/FeedStream.csv @@ -0,0 +1,28 @@ +TimeStamp,Ethylene,Ethane,Hydrogen +2020/01/01 00:00,2.106769468,1.003401256,1.982216977 +2020/01/01 06:00,2.131540904,1.013929486,2.060710012 +2020/01/02 00:00,2.185135078,0.900772132,2.089783814 +2020/01/02 06:00,2.121437851,0.996612314,1.949841967 +2020/01/03 00:00,1.870060192,0.908472049,2.133315741 +2020/01/03 06:00,2.162483792,1.017292333,1.981289862 +2020/01/04 00:00,1.874144316,1.016528818,1.869917964 +2020/01/04 06:00,1.930813671,0.987594037,2.057931188 +2020/01/05 00:00,2.12724289,0.923263342,1.942614287 +2020/01/05 06:00,2.166490061,1.09140564,2.103809748 +2020/01/06 00:00,2.171592849,0.938031976,2.082197957 +2020/01/06 06:00,1.804783711,1.009065835,2.174490206 +2020/01/07 00:00,1.957542321,0.968165676,2.0137447 +2020/01/07 06:00,2.090437725,0.959660933,1.981954587 +2020/01/08 00:00,1.826464608,1.032311353,1.970649718 +2020/01/08 06:00,2.0636046,0.929639599,1.981938883 +2020/01/09 00:00,1.939313926,1.021765505,1.83542421 +2020/01/09 06:00,1.812793332,1.014771253,2.025132329 +2020/01/10 00:00,2.154109894,0.94432342,1.807169447 +2020/01/10 06:00,2.046941449,1.072374428,2.04317426 +2020/01/11 00:00,2.123098553,1.039538123,2.153854047 +2020/01/11 06:00,2.164622176,0.924480721,1.844844328 +2020/01/12 00:00,2.029604398,1.096570384,2.008174739 +2020/01/12 06:00,1.812750071,0.93871181,2.080720078 +2020/01/13 00:00,2.040306101,1.054645559,1.832314174 +2020/01/13 06:00,1.825082427,1.086792417,1.870012827 +2020/01/14 00:00,2.071117783,0.923618539,1.946087723 diff --git a/streamhistories/ProdStream.csv b/streamhistories/ProdStream.csv new file mode 100644 index 0000000..820ea2f --- /dev/null +++ b/streamhistories/ProdStream.csv @@ -0,0 +1,28 @@ +TimeStamp,Ethylene,Ethane,Hydrogen +2020/01/01 00:00,0.094847475,2.824195924,0.107086839 +2020/01/01 06:00,0.106695391,3.105880258,0.096251326 +2020/01/02 00:00,0.102286352,2.930281896,0.092709887 +2020/01/02 06:00,0.106366777,2.937360623,0.099469173 +2020/01/03 00:00,0.10739573,3.079427009,0.107948161 +2020/01/03 06:00,0.107216832,2.681132673,0.096722099 +2020/01/04 00:00,0.108440593,3.147213457,0.09484186 +2020/01/04 06:00,0.095783328,2.941535492,0.09831654 +2020/01/05 00:00,0.096754576,2.859088923,0.101727602 +2020/01/05 06:00,0.103450933,3.152374747,0.105715784 +2020/01/06 00:00,0.103721975,3.165819875,0.108245492 +2020/01/06 06:00,0.109647132,2.715473397,0.098381232 +2020/01/07 00:00,0.097842428,2.974938255,0.097679239 +2020/01/07 06:00,0.094613655,2.745158433,0.092714496 +2020/01/08 00:00,0.105486247,3.046699336,0.102787767 +2020/01/08 06:00,0.097740302,3.088488562,0.102170201 +2020/01/09 00:00,0.109665602,3.150692658,0.099799808 +2020/01/09 06:00,0.101942625,3.048766159,0.105441331 +2020/01/10 00:00,0.097207081,2.850987559,0.098853211 +2020/01/10 06:00,0.096770733,2.773339542,0.109027659 +2020/01/11 00:00,0.109821635,2.941705012,0.090958608 +2020/01/11 06:00,0.098911185,2.750565883,0.106860639 +2020/01/12 00:00,0.106685906,2.89196396,0.093979461 +2020/01/12 06:00,0.092178675,2.838049488,0.108714181 +2020/01/13 00:00,0.09246444,3.08225984,0.104577241 +2020/01/13 06:00,0.107521724,2.942532641,0.091441559 +2020/01/14 00:00,0.105880929,2.76768405,0.100651375 diff --git a/test/components/Ethane.comp b/test/components/Ethane.comp deleted file mode 100644 index 46293b4..0000000 --- a/test/components/Ethane.comp +++ /dev/null @@ -1,7 +0,0 @@ -Ethane -2 -C -H -2 -6 -30.0688 \ No newline at end of file diff --git a/test/components/Ethylene.comp b/test/components/Ethylene.comp deleted file mode 100644 index dfb1924..0000000 --- a/test/components/Ethylene.comp +++ /dev/null @@ -1,7 +0,0 @@ -Ethylene -2 -C -H -2 -4 -28.053 \ No newline at end of file diff --git a/test/components/Hydrogen.comp b/test/components/Hydrogen.comp deleted file mode 100644 index 9958609..0000000 --- a/test/components/Hydrogen.comp +++ /dev/null @@ -1,5 +0,0 @@ -Hydrogen -1 -H -2 -2.0158 \ No newline at end of file diff --git a/test/components/argon.comp b/test/components/argon.comp deleted file mode 100644 index f6e1f13..0000000 --- a/test/components/argon.comp +++ /dev/null @@ -1,5 +0,0 @@ -Argon -1 -Ar -1 -39.948 \ No newline at end of file diff --git a/test/components/nitrogen.comp b/test/components/nitrogen.comp deleted file mode 100644 index 36596ee..0000000 --- a/test/components/nitrogen.comp +++ /dev/null @@ -1,5 +0,0 @@ -Nitrogen -1 -N -2 -28.0134 \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index acb3752..f23808e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,44 +1,36 @@ using FlowsheetTools using Test -@testset "Streams" begin +@testset "Components and Streams" begin fs = Flowsheet() @comp begin "C" --> 2 "H" --> 4 end "Ethylene" fs - dummy = writecomponent(joinpath(@__DIR__, "components", "Ethylene.comp"), fs.comps["Ethylene"]) - @test dummy == 25 @comp begin "C" --> 2 "H" --> 6 end "Ethane" fs - dummy = writecomponent(joinpath(@__DIR__, "components", "Ethane.comp"), fs.comps["Ethane"]) - @test dummy == 24 @comp begin "H" --> 2 end "Hydrogen" fs - dummy = writecomponent(joinpath(@__DIR__, "components", "Hydrogen.comp"), fs.comps["Hydrogen"]) - @test dummy == 21 @comp begin "N" --> 2 end "Nitrogen" fs - dummy = writecomponent(joinpath(@__DIR__, "components", "Nitrogen.comp"), fs.comps["Nitrogen"]) - @test dummy == 22 @comp begin "Ar" --> 1 end "Argon" fs - dummy = writecomponent(joinpath(@__DIR__, "components", "Argon.comp"), fs.comps["Argon"]) - @test dummy == 19 - count = readcomponentlist!(fs, joinpath(@__DIR__, "components"), ["Ethylene", "Ethane", "Hydrogen"]) - @test count == 3 @test fs.comps["Ethylene"].Mr ≈ 28.053 + @test fs.comps["Ethane"].Mr ≈ 30.0688 + @test fs.comps["Hydrogen"].Mr ≈ 2.0158 + @test fs.comps["Nitrogen"].Mr ≈ 28.0134 + @test fs.comps["Argon"].Mr ≈ 39.948 @stream mass begin @@ -67,7 +59,7 @@ using Test @test all(values(fs.streams["Prod2"].totalmassflow .≈ 2.0 .* fs.streams["Product"].totalmassflow)) end -@testset "UnitOps and Boundaries" begin +@testset "Simple UnitOps and Boundaries" begin fs = Flowsheet() @comp begin @@ -142,15 +134,46 @@ end @test molar_selectivity(fs.boundaries["B"], "Ethylene", "Ethane") ≈ 1.0 end -@testset "Corrections and Closure" begin +@testset "Active UnitOps and Closures" begin fs = Flowsheet() - count = readcomponentlist!(fs, joinpath(@__DIR__, "components"), ["Ethylene", "Ethane", "Hydrogen", "Nitrogen", "Argon"]) - @test count ==5 + @comp begin + "C" --> 2 + "H" --> 4 + end "Ethylene" fs + + @comp begin + "C" --> 2 + "H" --> 6 + end "Ethane" fs + + @comp begin + "H" --> 2 + end "Hydrogen" fs + + @comp begin + "N" --> 2 + end "Nitrogen" fs + + @comp begin + "Ar" --> 1 + end "Argon" fs + + @stream mole begin + "Ethylene" --> 0.1 + "Ethane" --> 0.9 + end "C2" fs + + @stream mole begin + "Hydrogen" --> 1.1 + end "H2" fs + + @stream mole begin + "Ethylene" --> 0.0 + "Ethane" --> 1.0 + "Hydrogen" --> 1.0 + end "Product" fs - readstreamhistory!(fs, "C2", joinpath(@__DIR__, "streamhistories", "C2.csv"); ismoleflow=true) - readstreamhistory!(fs, "H2", joinpath(@__DIR__, "streamhistories", "Hydrogen.csv"); ismoleflow=true) - readstreamhistory!(fs, "Product", joinpath(@__DIR__, "streamhistories", "Product.csv"); ismoleflow=true) addemptystream!(fs, "Mixed"); addemptystream!(fs, "Product1"); addemptystream!(fs, "Product1a"); @@ -219,13 +242,11 @@ end end "Reactor2" fs fs.unitops["Reactor2"]() - a = values(fs.streams["Product4"].moleflows[Symbol("Ethylene")] .≈ fs.streams["Product4"].moleflows[Symbol("Ethane")]) - @test findall(<(1), a) == [9, 13, 14, 18] + @test all(values(fs.streams["Product4"].moleflows[Symbol("Ethylene")] .≈ fs.streams["Product4"].moleflows[Symbol("Ethane")])) + fs.streams["Mixed"] = 1.1*fs.streams["Mixed"] - - @boundary begin unitops --> ["Mixer"] end "B1" fs @@ -242,6 +263,6 @@ end closemb!(fs, corrections) - sum(values(fs.boundaries["B1"].closure)) ≈ 27 - sum(values(fs.boundaries["B2"].closure)) ≈ 27 + @test all(values(fs.boundaries["B1"].closure) .≈ 1) + @test all(values(fs.boundaries["B2"].closure) .≈ 1) end \ No newline at end of file diff --git a/test/streamhistories/C2.csv b/test/streamhistories/C2.csv deleted file mode 100644 index 1ebb40f..0000000 --- a/test/streamhistories/C2.csv +++ /dev/null @@ -1,28 +0,0 @@ -TimeStamp,Ethylene,Ethane, -2020/01/01 00:00,0.107239036,0.89247781,0.999716846 -2020/01/01 06:00,0.107378006,0.896736538,1.004114544 -2020/01/02 00:00,0.092180185,0.985485177,1.077665362 -2020/01/02 06:00,0.106090983,0.970531008,1.076621991 -2020/01/03 00:00,0.103429382,0.923285307,1.026714689 -2020/01/03 06:00,0.102459451,0.949043158,1.051502609 -2020/01/04 00:00,0.109831854,0.885418833,0.995250687 -2020/01/04 06:00,0.10869931,0.904365099,1.013064409 -2020/01/05 00:00,0.097697742,0.830520181,0.928217923 -2020/01/05 06:00,0.102912242,0.978773788,1.08168603 -2020/01/06 00:00,0.103911053,0.870373916,0.974284969 -2020/01/06 06:00,0.105671277,0.868468211,0.974139488 -2020/01/07 00:00,0.09985486,0.82563294,0.9254878 -2020/01/07 06:00,0.100074529,0.9229478,1.023022329 -2020/01/08 00:00,0.094945703,0.825959831,0.920905534 -2020/01/08 06:00,0.096199477,0.987651733,1.08385121 -2020/01/09 00:00,0.092142514,0.889116851,0.981259365 -2020/01/09 06:00,0.095967638,0.963560661,1.059528299 -2020/01/10 00:00,0.108760194,0.967972888,1.076733082 -2020/01/10 06:00,0.096962919,0.930838356,1.027801275 -2020/01/11 00:00,0.095538445,0.824699673,0.920238118 -2020/01/11 06:00,0.101902136,0.941316514,1.04321865 -2020/01/12 00:00,0.107373055,0.934839923,1.042212978 -2020/01/12 06:00,0.102622132,0.816601807,0.919223939 -2020/01/13 00:00,0.097522962,0.813489671,0.911012633 -2020/01/13 06:00,0.109016434,0.839104313,0.948120747 -2020/01/14 00:00,0.106539973,0.8548783,0.961418273 diff --git a/test/streamhistories/Hydrogen.csv b/test/streamhistories/Hydrogen.csv deleted file mode 100644 index b3372b7..0000000 --- a/test/streamhistories/Hydrogen.csv +++ /dev/null @@ -1,28 +0,0 @@ -TimeStamp,Hydrogen -2020/01/01 00:00,1.117239036 -2020/01/01 06:00,1.097378006 -2020/01/02 00:00,1.102180185 -2020/01/02 06:00,1.096090983 -2020/01/03 00:00,1.113429382 -2020/01/03 06:00,1.092459451 -2020/01/04 00:00,1.119831854 -2020/01/04 06:00,1.09869931 -2020/01/05 00:00,1.107697742 -2020/01/05 06:00,1.092912242 -2020/01/06 00:00,1.113911053 -2020/01/06 06:00,1.095671277 -2020/01/07 00:00,1.10985486 -2020/01/07 06:00,1.090074529 -2020/01/08 00:00,1.104945703 -2020/01/08 06:00,1.086199477 -2020/01/09 00:00,1.102142514 -2020/01/09 06:00,1.085967638 -2020/01/10 00:00,1.118760194 -2020/01/10 06:00,1.086962919 -2020/01/11 00:00,1.105538445 -2020/01/11 06:00,1.091902136 -2020/01/12 00:00,1.117373055 -2020/01/12 06:00,1.092622132 -2020/01/13 00:00,1.107522962 -2020/01/13 06:00,1.099016434 -2020/01/14 00:00,1.116539973 diff --git a/test/streamhistories/Product.csv b/test/streamhistories/Product.csv deleted file mode 100644 index c5207b3..0000000 --- a/test/streamhistories/Product.csv +++ /dev/null @@ -1,28 +0,0 @@ -TimeStamp,Ethylene,Ethane,Hydrogen -2020/01/01 00:00,0,0.999716846,1.01 -2020/01/01 06:00,0,1.004114544,0.99 -2020/01/02 00:00,0,1.077665362,1.01 -2020/01/02 06:00,0,1.076621991,0.99 -2020/01/03 00:00,0,1.026714689,1.01 -2020/01/03 06:00,0,1.051502609,0.99 -2020/01/04 00:00,0,0.995250687,1.01 -2020/01/04 06:00,0,1.013064409,0.99 -2020/01/05 00:00,0.001,0.927217923,1.011 -2020/01/05 06:00,0,1.08168603,0.99 -2020/01/06 00:00,0,0.974284969,1.01 -2020/01/06 06:00,0,0.974139488,0.99 -2020/01/07 00:00,0.002,0.9234878,1.012 -2020/01/07 06:00,0.00001,1.023012329,0.99001 -2020/01/08 00:00,0,0.920905534,1.01 -2020/01/08 06:00,0,1.08385121,0.99 -2020/01/09 00:00,0,0.981259365,1.01 -2020/01/09 06:00,0.00003,1.059498299,0.99003 -2020/01/10 00:00,0,1.076733082,1.01 -2020/01/10 06:00,0,1.027801275,0.99 -2020/01/11 00:00,0,0.920238118,1.01 -2020/01/11 06:00,0,1.04321865,0.99 -2020/01/12 00:00,0,1.042212978,1.01 -2020/01/12 06:00,0,0.919223939,0.99 -2020/01/13 00:00,0,0.911012633,1.01 -2020/01/13 06:00,0,0.948120747,0.99 -2020/01/14 00:00,0,0.961418273,1.01