Loading...
Searching...
No Matches
DatumDepth.hpp
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
Copyright 2024 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATUM_DEPTH_HPP_INCLUDED
#define DATUM_DEPTH_HPP_INCLUDED
#include <cassert>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
namespace Opm {
class SOLUTIONSection;
} // namespace Opm
namespace Opm {
class DatumDepth
{
public:
DatumDepth() = default;
explicit DatumDepth(const SOLUTIONSection& soln);
static DatumDepth serializationTestObjectZero();
static DatumDepth serializationTestObjectGlobal();
static DatumDepth serializationTestObjectDefaultRegion();
static DatumDepth serializationTestObjectUserDefined();
double operator()(const int region) const
{
return (*this)("FIPNUM", region);
}
double operator()(std::string_view rset, const int region) const
{
return std::visit([rset, region](const auto& datumDepthImpl)
{ return datumDepthImpl(rset, region); }, this->datum_);
}
bool operator==(const DatumDepth& that) const
{
return this->datum_ == that.datum_;
}
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->datum_);
}
private:
class Zero
{
public:
double operator()([[maybe_unused]] std::string_view rset,
[[maybe_unused]] const int region) const
{
return 0.0;
}
static Zero serializationTestObject() { return {}; }
bool operator==(const Zero&) const { return true; }
template <class Serializer>
void serializeOp([[maybe_unused]] Serializer& serializer)
{} // Nothing to do
};
class Global
{
public:
Global() = default;
explicit Global(const SOLUTIONSection& soln);
double operator()([[maybe_unused]] std::string_view rset,
[[maybe_unused]] const int region) const
{
return this->depth_;
}
static Global serializationTestObject();
bool operator==(const Global& that) const
{
return this->depth_ == that.depth_;
}
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->depth_);
}
private:
double depth_{};
};
class DefaultRegion
{
public:
DefaultRegion() = default;
explicit DefaultRegion(const SOLUTIONSection& soln);
static DefaultRegion serializationTestObject();
double operator()([[maybe_unused]] std::string_view rset,
const int region) const
{
assert (! this->depth_.empty());
// Note: depth_.back() is intentional for region >= size().
// If the input supplies fewer depth values than there are
// regions, then the remaining regions implicitly have the
// same datum depth as the last fully specified region.
return (region < static_cast<int>(this->depth_.size()))
? this->depth_[region] : this->depth_.back();
}
bool operator==(const DefaultRegion& that) const
{
return this->depth_ == that.depth_;
}
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->depth_);
}
private:
std::vector<double> depth_{};
};
class UserDefined
{
public:
UserDefined() = default;
explicit UserDefined(const SOLUTIONSection& soln);
static UserDefined serializationTestObject();
double operator()(std::string_view rset, const int region) const;
bool operator==(const UserDefined& that) const
{
return (this->rsetNames_ == that.rsetNames_)
&& (this->rsetStart_ == that.rsetStart_)
&& (this->depth_ == that.depth_)
&& (this->default_ == that.default_)
&& (this->rsetIndex_ == that.rsetIndex_)
;
}
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->rsetNames_);
serializer(this->rsetStart_);
serializer(this->depth_);
serializer(this->default_);
serializer(this->rsetIndex_);
}
private:
std::vector<std::string> rsetNames_{};
std::vector<std::vector<double>::size_type> rsetStart_{};
std::vector<double> depth_{};
std::vector<double> default_{};
std::vector<std::vector<std::string>::size_type> rsetIndex_{};
double depthValue(std::string_view rset,
std::vector<double>::const_iterator begin,
std::vector<double>::const_iterator end,
std::vector<double>::difference_type ix) const;
};
std::variant<Zero, Global, DefaultRegion, UserDefined> datum_{};
};
} // namespace Opm
#endif // DATUM_DEPTH_HPP_INCLUDED
Opm::SOLUTIONSection
Definition DeckSection.hpp:135
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30