{"action":"created","comment":{"url":"https://api.github.com/repos/OPM/opm-core/pulls/comments/43727224","id":43727224,"diff_hunk":"@@ -57,7 +68,167 @@ namespace Opm\n             std::shared_ptr<GridProperty<int>> eqlnum = eclipseState->getIntGridProperty(\"EQLNUM\");\n             auto eqlnumData = eqlnum->getData();\n \n-            // Set values for each face.\n+            int numPhases = initialState.numPhases();\n+            int numCells = UgGridHelpers::numCells(grid);\n+            int numPvtRegions = deck->getKeyword(\"TABDIMS\")->getRecord(0)->getItem(\"NTPVT\")->getInt(0);\n+\n+            // retrieve the surface densities\n+            std::vector<std::vector<double> > surfaceDensity(numPvtRegions);\n+            Opm::DeckKeywordConstPtr densityKw = deck->getKeyword(\"DENSITY\");\n+            for (int regionIdx = 0; regionIdx < numPvtRegions; ++regionIdx) {\n+                surfaceDensity[regionIdx].resize(numPhases);\n+\n+                if (pu.phase_used[BlackoilPhases::Aqua]) {\n+                    int wpos = pu.phase_pos[BlackoilPhases::Aqua];\n+                    surfaceDensity[regionIdx][wpos] =\n+                        densityKw->getRecord(regionIdx)->getItem(\"WATER\")->getSIDouble(0);\n+                }\n+\n+                if (pu.phase_used[BlackoilPhases::Liquid]) {\n+                    int opos = pu.phase_pos[BlackoilPhases::Liquid];\n+                    surfaceDensity[regionIdx][opos] =\n+                        densityKw->getRecord(regionIdx)->getItem(\"OIL\")->getSIDouble(0);\n+                }\n+\n+                if (pu.phase_used[BlackoilPhases::Vapour]) {\n+                    int gpos = pu.phase_pos[BlackoilPhases::Vapour];\n+                    surfaceDensity[regionIdx][gpos] =\n+                        densityKw->getRecord(regionIdx)->getItem(\"GAS\")->getSIDouble(0);\n+                }\n+            }\n+\n+            // retrieve the PVT region of each cell. note that we need c++ instead of\n+            // Fortran indices.\n+            std::vector<int> pvtRegion = eclipseState->getIntGridProperty(\"PVTNUM\")->getData();\n+            for (auto it = pvtRegion.begin(); it != pvtRegion.end(); ++ it) {\n+                *it = std::max(0, *it - 1);\n+            }\n+\n+            // compute the initial \"phase presence\" of each cell (required to calculate\n+            // the inverse formation volume factors\n+            std::vector<PhasePresence> cond(numCells);\n+            for (int cellIdx = 0; cellIdx < numCells; ++cellIdx) {\n+                if (pu.phase_used[BlackoilPhases::Aqua] && initialState.saturation()[numPhases*cellIdx + pu.phase_pos[BlackoilPhases::Aqua]] > 0.0) {\n+                    cond[cellIdx].setFreeWater();\n+                }\n+\n+                if (pu.phase_used[BlackoilPhases::Liquid] && initialState.saturation()[numPhases*cellIdx + pu.phase_pos[BlackoilPhases::Liquid]] > 0.0) {\n+                    cond[cellIdx].setFreeOil();\n+                }\n+\n+                if (pu.phase_used[BlackoilPhases::Vapour] && initialState.saturation()[numPhases*cellIdx + pu.phase_pos[BlackoilPhases::Vapour]] > 0.0) {\n+                    cond[cellIdx].setFreeGas();\n+                }\n+            }\n+\n+            // calculate the initial fluid densities for the gravity correction.\n+            std::vector<double> b(numCells);\n+\n+            std::vector<std::vector<double>> rho(numPhases);\n+            for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {\n+                rho[phaseIdx].resize(numCells);\n+            }\n+\n+            // compute the capillary pressures of the active phases\n+            std::vector<double> capPress(numCells*numPhases);\n+            std::vector<int> cellIdxArray(numCells);\n+            for (int cellIdx = 0; cellIdx < numCells; ++ cellIdx) {\n+                cellIdxArray[cellIdx] = cellIdx;\n+            }\n+            props.capPress(numCells, initialState.saturation().data(), cellIdxArray.data(), capPress.data(), NULL);\n+\n+            // compute the absolute pressure of each active phase\n+            std::vector<std::vector<double> > phasePressure(numPhases);\n+            for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {\n+                phasePressure[phaseIdx].resize(numCells);\n+            }\n+\n+            for (int cellIdx = 0; cellIdx < numCells; ++ cellIdx) {\n+                assert(pu.phase_used[BlackoilPhases::Liquid]); // we currently hard-code the oil phase as the reference phase!\n+                int opos = pu.phase_pos[BlackoilPhases::Liquid];\n+                phasePressure[opos][cellIdx] = initialState.pressure()[cellIdx];\n+\n+                if (pu.phase_used[BlackoilPhases::Aqua]) {\n+                    int wpos = pu.phase_pos[BlackoilPhases::Aqua];\n+                    phasePressure[wpos][cellIdx] = initialState.pressure()[cellIdx] + (capPress[cellIdx*numPhases + opos] - capPress[cellIdx*numPhases + wpos]);\n+                }\n+\n+                if (pu.phase_used[BlackoilPhases::Vapour]) {\n+                    int gpos = pu.phase_pos[BlackoilPhases::Vapour];\n+                    phasePressure[gpos][cellIdx] = initialState.pressure()[cellIdx] + (capPress[cellIdx*numPhases + gpos] - capPress[cellIdx*numPhases + opos]);\n+                }\n+            }\n+\n+            // calculate the inverse formation volume factors for the active phases and each cell\n+            if (pu.phase_used[BlackoilPhases::Aqua]) {\n+                std::vector<double> dummy(numCells*BlackoilPhases::MaxNumPhases);\n+                int wpos = pu.phase_pos[BlackoilPhases::Aqua];\n+                const PvtInterface& pvtw = props.pvt(wpos);\n+                pvtw.b(numCells,\n+                       pvtRegion.data(),\n+                       phasePressure[wpos].data(),\n+                       initialState.temperature().data(),\n+                       initialState.gasoilratio().data(),\n+                       cond.data(),\n+                       b.data(),\n+                       dummy.data(),\n+                       dummy.data());\n+                for (int cellIdx = 0; cellIdx < numCells; ++ cellIdx) {\n+                    rho[wpos][cellIdx] = surfaceDensity[pvtRegion[cellIdx]][wpos]*b[cellIdx];\n+                }\n+            }\n+\n+            if (pu.phase_used[BlackoilPhases::Liquid]) {\n+                std::vector<double> dummy(numCells*BlackoilPhases::MaxNumPhases);\n+                int opos = pu.phase_pos[BlackoilPhases::Liquid];\n+                const PvtInterface& pvto = props.pvt(opos);\n+                pvto.b(numCells,\n+                       pvtRegion.data(),\n+                       phasePressure[opos].data(),\n+                       initialState.temperature().data(),\n+                       initialState.gasoilratio().data(),\n+                       cond.data(),\n+                       b.data(),\n+                       dummy.data(),\n+                       dummy.data());\n+                for (int cellIdx = 0; cellIdx < numCells; ++ cellIdx) {\n+                    rho[opos][cellIdx] = surfaceDensity[pvtRegion[cellIdx]][opos]*b[cellIdx];\n+\n+                    if (pu.phase_used[BlackoilPhases::Vapour]) {\n+                        int gpos = pu.phase_pos[BlackoilPhases::Vapour];\n+                        rho[opos][cellIdx] +=\n+                            surfaceDensity[pvtRegion[cellIdx]][gpos]*initialState.surfacevol()[cellIdx]*b[cellIdx];","path":"opm/core/utility/thresholdPressures.hpp","position":167,"original_position":167,"commit_id":"7d17969ac988f7c1fe633fbf78b13c4887a6c869","original_commit_id":"7d17969ac988f7c1fe633fbf78b13c4887a6c869","user":{"login":"totto82","id":3223024,"avatar_url":"https://avatars.githubusercontent.com/u/3223024?v=3","gravatar_id":"","url":"https://api.github.com/users/totto82","html_url":"https://github.com/totto82","followers_url":"https://api.github.com/users/totto82/followers","following_url":"https://api.github.com/users/totto82/following{/other_user}","gists_url":"https://api.github.com/users/totto82/gists{/gist_id}","starred_url":"https://api.github.com/users/totto82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/totto82/subscriptions","organizations_url":"https://api.github.com/users/totto82/orgs","repos_url":"https://api.github.com/users/totto82/repos","events_url":"https://api.github.com/users/totto82/events{/privacy}","received_events_url":"https://api.github.com/users/totto82/received_events","type":"User","site_admin":false},"body":"This is still wrong.","created_at":"2015-11-03T09:14:52Z","updated_at":"2015-11-03T09:14:52Z","html_url":"https://github.com/OPM/opm-core/pull/907#discussion_r43727224","pull_request_url":"https://api.github.com/repos/OPM/opm-core/pulls/907","_links":{"self":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/comments/43727224"},"html":{"href":"https://github.com/OPM/opm-core/pull/907#discussion_r43727224"},"pull_request":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/907"}}},"pull_request":{"url":"https://api.github.com/repos/OPM/opm-core/pulls/907","id":48190643,"html_url":"https://github.com/OPM/opm-core/pull/907","diff_url":"https://github.com/OPM/opm-core/pull/907.diff","patch_url":"https://github.com/OPM/opm-core/pull/907.patch","issue_url":"https://api.github.com/repos/OPM/opm-core/issues/907","number":907,"state":"open","locked":false,"title":"implement determining the threshold pressure from the initial condition","user":{"login":"andlaus","id":1837735,"avatar_url":"https://avatars.githubusercontent.com/u/1837735?v=3","gravatar_id":"","url":"https://api.github.com/users/andlaus","html_url":"https://github.com/andlaus","followers_url":"https://api.github.com/users/andlaus/followers","following_url":"https://api.github.com/users/andlaus/following{/other_user}","gists_url":"https://api.github.com/users/andlaus/gists{/gist_id}","starred_url":"https://api.github.com/users/andlaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andlaus/subscriptions","organizations_url":"https://api.github.com/users/andlaus/orgs","repos_url":"https://api.github.com/users/andlaus/repos","events_url":"https://api.github.com/users/andlaus/events{/privacy}","received_events_url":"https://api.github.com/users/andlaus/received_events","type":"User","site_admin":false},"body":"This needs to be done if a equilibration region transition is\r\nmentioned by the THPRES keyword, but no value is given for this record\r\nin the third item. (it seems that this is used quite frequently.)\r\n\r\nAlso, the approach taken by this patch also does not collide with the\r\nrestart machinery as far as I can see. This is because the initial\r\ncondition is applied by the simulator before the state at the restart\r\ntime is loaded. (I interpreted the code that way, but I could be\r\nwrong, could anyone verify this?)\r\n\r\nsince it is pretty elaborate to calculate initial condition, this\r\npatch is pretty messy. I also do not know if Eclipse does include\r\ncapillary pressure in this calculation or not (this patch does) and\r\nthere may be other bugs lurking. happy testing!","created_at":"2015-10-20T11:58:57Z","updated_at":"2015-11-03T09:14:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8259b135fdb7c16ef68ce9ace1c6e2e2a11bcb12","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OPM/opm-core/pulls/907/commits","review_comments_url":"https://api.github.com/repos/OPM/opm-core/pulls/907/comments","review_comment_url":"https://api.github.com/repos/OPM/opm-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OPM/opm-core/issues/907/comments","statuses_url":"https://api.github.com/repos/OPM/opm-core/statuses/7d17969ac988f7c1fe633fbf78b13c4887a6c869","head":{"label":"andlaus:thpress_from_initial","ref":"thpress_from_initial","sha":"7d17969ac988f7c1fe633fbf78b13c4887a6c869","user":{"login":"andlaus","id":1837735,"avatar_url":"https://avatars.githubusercontent.com/u/1837735?v=3","gravatar_id":"","url":"https://api.github.com/users/andlaus","html_url":"https://github.com/andlaus","followers_url":"https://api.github.com/users/andlaus/followers","following_url":"https://api.github.com/users/andlaus/following{/other_user}","gists_url":"https://api.github.com/users/andlaus/gists{/gist_id}","starred_url":"https://api.github.com/users/andlaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andlaus/subscriptions","organizations_url":"https://api.github.com/users/andlaus/orgs","repos_url":"https://api.github.com/users/andlaus/repos","events_url":"https://api.github.com/users/andlaus/events{/privacy}","received_events_url":"https://api.github.com/users/andlaus/received_events","type":"User","site_admin":false},"repo":{"id":4860076,"name":"opm-core","full_name":"andlaus/opm-core","owner":{"login":"andlaus","id":1837735,"avatar_url":"https://avatars.githubusercontent.com/u/1837735?v=3","gravatar_id":"","url":"https://api.github.com/users/andlaus","html_url":"https://github.com/andlaus","followers_url":"https://api.github.com/users/andlaus/followers","following_url":"https://api.github.com/users/andlaus/following{/other_user}","gists_url":"https://api.github.com/users/andlaus/gists{/gist_id}","starred_url":"https://api.github.com/users/andlaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andlaus/subscriptions","organizations_url":"https://api.github.com/users/andlaus/orgs","repos_url":"https://api.github.com/users/andlaus/repos","events_url":"https://api.github.com/users/andlaus/events{/privacy}","received_events_url":"https://api.github.com/users/andlaus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andlaus/opm-core","description":"Open Porous Media Core Library","fork":true,"url":"https://api.github.com/repos/andlaus/opm-core","forks_url":"https://api.github.com/repos/andlaus/opm-core/forks","keys_url":"https://api.github.com/repos/andlaus/opm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andlaus/opm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andlaus/opm-core/teams","hooks_url":"https://api.github.com/repos/andlaus/opm-core/hooks","issue_events_url":"https://api.github.com/repos/andlaus/opm-core/issues/events{/number}","events_url":"https://api.github.com/repos/andlaus/opm-core/events","assignees_url":"https://api.github.com/repos/andlaus/opm-core/assignees{/user}","branches_url":"https://api.github.com/repos/andlaus/opm-core/branches{/branch}","tags_url":"https://api.github.com/repos/andlaus/opm-core/tags","blobs_url":"https://api.github.com/repos/andlaus/opm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andlaus/opm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andlaus/opm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/andlaus/opm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andlaus/opm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/andlaus/opm-core/languages","stargazers_url":"https://api.github.com/repos/andlaus/opm-core/stargazers","contributors_url":"https://api.github.com/repos/andlaus/opm-core/contributors","subscribers_url":"https://api.github.com/repos/andlaus/opm-core/subscribers","subscription_url":"https://api.github.com/repos/andlaus/opm-core/subscription","commits_url":"https://api.github.com/repos/andlaus/opm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/andlaus/opm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/andlaus/opm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/andlaus/opm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/andlaus/opm-core/contents/{+path}","compare_url":"https://api.github.com/repos/andlaus/opm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andlaus/opm-core/merges","archive_url":"https://api.github.com/repos/andlaus/opm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andlaus/opm-core/downloads","issues_url":"https://api.github.com/repos/andlaus/opm-core/issues{/number}","pulls_url":"https://api.github.com/repos/andlaus/opm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/andlaus/opm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/andlaus/opm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andlaus/opm-core/labels{/name}","releases_url":"https://api.github.com/repos/andlaus/opm-core/releases{/id}","created_at":"2012-07-02T13:28:32Z","updated_at":"2014-06-25T08:42:33Z","pushed_at":"2015-10-29T16:45:39Z","git_url":"git://github.com/andlaus/opm-core.git","ssh_url":"git@github.com:andlaus/opm-core.git","clone_url":"https://github.com/andlaus/opm-core.git","svn_url":"https://github.com/andlaus/opm-core","homepage":"http://www.opm-project.org","size":12936,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"OPM:master","ref":"master","sha":"0cd08a1f12b936b3c1ccdae86425cd9b26fc6fc1","user":{"login":"OPM","id":1827197,"avatar_url":"https://avatars.githubusercontent.com/u/1827197?v=3","gravatar_id":"","url":"https://api.github.com/users/OPM","html_url":"https://github.com/OPM","followers_url":"https://api.github.com/users/OPM/followers","following_url":"https://api.github.com/users/OPM/following{/other_user}","gists_url":"https://api.github.com/users/OPM/gists{/gist_id}","starred_url":"https://api.github.com/users/OPM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OPM/subscriptions","organizations_url":"https://api.github.com/users/OPM/orgs","repos_url":"https://api.github.com/users/OPM/repos","events_url":"https://api.github.com/users/OPM/events{/privacy}","received_events_url":"https://api.github.com/users/OPM/received_events","type":"Organization","site_admin":false},"repo":{"id":4787500,"name":"opm-core","full_name":"OPM/opm-core","owner":{"login":"OPM","id":1827197,"avatar_url":"https://avatars.githubusercontent.com/u/1827197?v=3","gravatar_id":"","url":"https://api.github.com/users/OPM","html_url":"https://github.com/OPM","followers_url":"https://api.github.com/users/OPM/followers","following_url":"https://api.github.com/users/OPM/following{/other_user}","gists_url":"https://api.github.com/users/OPM/gists{/gist_id}","starred_url":"https://api.github.com/users/OPM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OPM/subscriptions","organizations_url":"https://api.github.com/users/OPM/orgs","repos_url":"https://api.github.com/users/OPM/repos","events_url":"https://api.github.com/users/OPM/events{/privacy}","received_events_url":"https://api.github.com/users/OPM/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OPM/opm-core","description":"Open Porous Media Core Library","fork":false,"url":"https://api.github.com/repos/OPM/opm-core","forks_url":"https://api.github.com/repos/OPM/opm-core/forks","keys_url":"https://api.github.com/repos/OPM/opm-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OPM/opm-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OPM/opm-core/teams","hooks_url":"https://api.github.com/repos/OPM/opm-core/hooks","issue_events_url":"https://api.github.com/repos/OPM/opm-core/issues/events{/number}","events_url":"https://api.github.com/repos/OPM/opm-core/events","assignees_url":"https://api.github.com/repos/OPM/opm-core/assignees{/user}","branches_url":"https://api.github.com/repos/OPM/opm-core/branches{/branch}","tags_url":"https://api.github.com/repos/OPM/opm-core/tags","blobs_url":"https://api.github.com/repos/OPM/opm-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OPM/opm-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OPM/opm-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/OPM/opm-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OPM/opm-core/statuses/{sha}","languages_url":"https://api.github.com/repos/OPM/opm-core/languages","stargazers_url":"https://api.github.com/repos/OPM/opm-core/stargazers","contributors_url":"https://api.github.com/repos/OPM/opm-core/contributors","subscribers_url":"https://api.github.com/repos/OPM/opm-core/subscribers","subscription_url":"https://api.github.com/repos/OPM/opm-core/subscription","commits_url":"https://api.github.com/repos/OPM/opm-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/OPM/opm-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/OPM/opm-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/OPM/opm-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/OPM/opm-core/contents/{+path}","compare_url":"https://api.github.com/repos/OPM/opm-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OPM/opm-core/merges","archive_url":"https://api.github.com/repos/OPM/opm-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OPM/opm-core/downloads","issues_url":"https://api.github.com/repos/OPM/opm-core/issues{/number}","pulls_url":"https://api.github.com/repos/OPM/opm-core/pulls{/number}","milestones_url":"https://api.github.com/repos/OPM/opm-core/milestones{/number}","notifications_url":"https://api.github.com/repos/OPM/opm-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OPM/opm-core/labels{/name}","releases_url":"https://api.github.com/repos/OPM/opm-core/releases{/id}","created_at":"2012-06-25T21:14:06Z","updated_at":"2015-09-02T05:40:29Z","pushed_at":"2015-11-02T14:20:24Z","git_url":"git://github.com/OPM/opm-core.git","ssh_url":"git@github.com:OPM/opm-core.git","clone_url":"https://github.com/OPM/opm-core.git","svn_url":"https://github.com/OPM/opm-core","homepage":"http://www.opm-project.org","size":16865,"stargazers_count":21,"watchers_count":21,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":19,"forks":42,"open_issues":19,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/907"},"html":{"href":"https://github.com/OPM/opm-core/pull/907"},"issue":{"href":"https://api.github.com/repos/OPM/opm-core/issues/907"},"comments":{"href":"https://api.github.com/repos/OPM/opm-core/issues/907/comments"},"review_comments":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/907/comments"},"review_comment":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OPM/opm-core/pulls/907/commits"},"statuses":{"href":"https://api.github.com/repos/OPM/opm-core/statuses/7d17969ac988f7c1fe633fbf78b13c4887a6c869"}}}}