27 #ifndef OPM_OUTPUT_EXTRACTORS_HPP 28 #define OPM_OUTPUT_EXTRACTORS_HPP 30 #include <opm/common/OpmLog/OpmLog.hpp> 31 #include <opm/common/utility/Visitor.hpp> 33 #include <opm/material/common/Valgrind.hpp> 43 #include <unordered_map> 48 #include <fmt/format.h> 53 template<
class TypeTag>
58 using FluidState =
typename IntensiveQuantities::FluidState;
60 static constexpr
int numPhases = FluidSystem::numPhases;
89 using ScalarFunc = std::function<Scalar(const Context&)>;
115 std::variant<AssignFunc, ScalarEntry, PhaseEntry>
data;
120 template<std::
size_t size>
124 std::vector<Entry> filtered_extractors;
125 filtered_extractors.reserve(input.size());
126 std::copy_if(std::move_iterator(input.begin()),
127 std::move_iterator(input.end()),
128 std::back_inserter(filtered_extractors),
134 return std::visit(VisitorOverloadSet{
141 return !v.data->empty();
145 return std::ranges::any_of(*v.data,
147 { return !ve.empty(); });
152 return filtered_extractors;
159 const std::vector<Entry>& extractors)
161 std::ranges::for_each(extractors,
162 [&ectx](
const auto& entry)
164 std::visit(VisitorOverloadSet{
167 auto& array = *v.data;
173 std::ranges::for_each(*v.data,
174 [phaseIdx = 0, &ectx, &v](
auto& array)
mutable 176 if (!array.empty()) {
177 array[ectx.globalDofIdx] = v.extract(phaseIdx, ectx);
178 Valgrind::CheckDefined(array[ectx.globalDofIdx]);
191 template<
class TypeTag>
197 using FluidState =
typename IntensiveQuantities::FluidState;
199 static constexpr
int numPhases = FluidSystem::numPhases;
200 static constexpr
int oilPhaseIdx = FluidSystem::oilPhaseIdx;
201 static constexpr
int gasPhaseIdx = FluidSystem::gasPhaseIdx;
202 static constexpr
int waterPhaseIdx = FluidSystem::waterPhaseIdx;
209 const FluidState&
fs;
211 const ElementContext& elemCtx;
228 std::variant<std::string_view, std::vector<std::string_view>>
kw;
237 std::variant<std::array<std::string_view, numPhases>,
238 std::array<std::array<std::string_view, numPhases>, 2>>
kw;
245 using Entry = std::variant<ScalarEntry, PhaseEntry>;
252 : data(d), extract(std::move(e))
260 using ExecMap = std::unordered_map<int, std::vector<Exec>>;
270 template<std::
size_t size>
271 static std::optional<ScalarFunc>
273 const std::array<Entry,size>& handlers)
275 using PhaseViewArray = std::array<std::string_view, numPhases>;
276 using StringViewVec = std::vector<std::string_view>;
279 const auto handler_info =
280 std::ranges::find_if(
282 [&base_kw, &phase](
const auto& handler)
285 const auto gen_handlers =
286 std::visit(VisitorOverloadSet{
289 return std::visit(VisitorOverloadSet{
290 [](
const std::string_view& kw) -> StringViewVec
294 [](
const StringViewVec& kws) -> StringViewVec
300 return std::visit(VisitorOverloadSet{
301 [](
const PhaseViewArray& data)
303 return StringViewVec{data.begin(), data.end()};
305 [](
const std::array<PhaseViewArray,2>& data)
308 res.reserve(2*numPhases);
309 res.insert(res.end(),
312 res.insert(res.end(),
321 const auto found_handler =
322 std::ranges::find(gen_handlers, base_kw);
323 if (found_handler != gen_handlers.end()) {
324 phase = std::distance(gen_handlers.begin(), found_handler) % numPhases;
326 return found_handler != gen_handlers.end();
330 if (handler_info == handlers.end()) {
334 return std::visit(VisitorOverloadSet{
341 return [phase, extract = e.extract]
344 static constexpr
auto phaseMap = std::array{
349 return extract(phaseMap[phase], ectx);
356 template<std::
size_t size>
358 const std::array<Entry,size>& handlers)
362 std::ranges::for_each(
364 [&handlers, &extractors](
auto& bd_info)
366 const auto& [key, cell] = bd_info.first;
367 if (
auto extract = makeExtractor(std::string_view{key}, handlers)) {
368 extractors[cell - 1].emplace_back(&bd_info.second, std::move(*extract));
371 OpmLog::warning(
"Unhandled output keyword",
372 fmt::format(
"Keyword '{}' is unhandled for output " 373 "to summary file.", key));
382 static void process(
const std::vector<Exec>& blockExtractors,
385 std::ranges::for_each(blockExtractors,
387 { *bdata.data = bdata.extract(ectx); });
397 using LgrExecMap = std::unordered_map<int,
398 std::unordered_map<int,
410 template<std::
size_t size>
412 double>& lgrBlockData,
413 const std::array<Entry,size>& handlers)
417 std::ranges::for_each(
419 [&handlers, &extractors](
auto& bd_info)
421 const auto& [lgr_kw, level, localCart] = bd_info.first;
424 const auto base_kw = std::string_view{lgr_kw}.substr(1);
425 if (
auto extract = makeExtractor(base_kw, handlers)) {
426 extractors[level][localCart].emplace_back(&bd_info.second, std::move(*extract));
429 OpmLog::warning(
"Unhandled LGR output keyword",
430 fmt::format(
"Keyword '{}' (LGR mirror of '{}') is " 431 "unhandled for output to summary file.",
443 #endif // OPM_OUTPUT_EXTRACTORS_HPP
Definition: alignedallocator.hh:32
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
Defines the common properties required by the porous medium multi-phase models.
Declare the properties used by the infrastructure code of the finite volume discretizations.
The Opm property system, traits with inheritance.
Defines a type tags and some fundamental properties all models.