FICompositionalModel.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 Copyright 2026, SINTEF Digital
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
26#ifndef OPM_FI_COMPOSITIONAL_MODEL_HPP
27#define OPM_FI_COMPOSITIONAL_MODEL_HPP
28
31
32#include <exception>
33#include <mutex>
34
35namespace Opm {
36
41template <class TypeTag>
42class FICompositionalModel : public FlashModel<TypeTag>
43{
44 using ParentType = FlashModel<TypeTag>;
47
48public:
49 explicit FICompositionalModel(Simulator& simulator)
50 : ParentType(simulator)
51 {}
52
53 void invalidateAndUpdateIntensiveQuantities(unsigned timeIdx) const
54 {
55 if (!this->storeIntensiveQuantities() ||
56 timeIdx >= this->cachedIntensiveQuantityHistorySize()) {
57 ParentType::invalidateAndUpdateIntensiveQuantities(timeIdx);
58 return;
59 }
60
61 this->invalidateIntensiveQuantitiesCache(timeIdx);
62
63 const auto& problem = this->simulator_.problem();
64 const auto& solution = this->solution(timeIdx);
65 const unsigned numDof = this->numGridDof();
66 const auto flashSettings = IntensiveQuantities::FlashSettings::fromParameters();
67
68 // An exception must not escape the parallel loop, which would call
69 // std::terminate(); rethrow it afterwards, so that a failed flash
70 // chops the time step.
71 std::mutex exceptionLock;
72 std::exception_ptr exceptionPtr = nullptr;
73
74 // dynamic scheduling, since the flash costs more in two-phase cells
75#ifdef _OPENMP
76#pragma omp parallel for schedule(dynamic, 64)
77#endif
78 for (unsigned globalIdx = 0; globalIdx < numDof; ++globalIdx) {
79 try {
80 this->intensiveQuantityCache_[timeIdx][globalIdx]
81 .update(problem, solution[globalIdx], globalIdx, timeIdx, flashSettings);
82 this->setIntensiveQuantitiesCacheEntryValidity(globalIdx, timeIdx, true);
83 }
84 catch (...) {
85 const std::lock_guard lock(exceptionLock);
86 exceptionPtr = std::current_exception();
87 }
88 }
89
90 if (exceptionPtr) {
91 std::rethrow_exception(exceptionPtr);
92 }
93 }
94};
95
96} // namespace Opm
97
98#endif // OPM_FI_COMPOSITIONAL_MODEL_HPP
PT-flash model that updates the cached intensive quantities cell by cell, without element contexts.
Definition: FICompositionalModel.hpp:43
FICompositionalModel(Simulator &simulator)
Definition: FICompositionalModel.hpp:49
void invalidateAndUpdateIntensiveQuantities(unsigned timeIdx) const
Definition: FICompositionalModel.hpp:53
A compositional multi-phase model based on flash-calculations.
Definition: ptflash/flashmodel.hh:195
Definition: blackoilbioeffectsmodules.hh:45
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
The Opm property system, traits with inheritance.