2013-05-06 09:48:29 +02:00
|
|
|
/*
|
2013-09-12 10:58:44 +02:00
|
|
|
Copyright 2013 Statoil ASA.
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
This file is part of the Open Porous Media project (OPM).
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
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.
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
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.
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-06 12:13:49 +02:00
|
|
|
*/
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-08-01 09:31:27 +02:00
|
|
|
#include <opm/json/JsonObject.hpp>
|
|
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
|
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
2013-10-16 14:57:01 +02:00
|
|
|
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
2013-08-01 09:31:27 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/DeckDoubleItem.hpp>
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
namespace Opm
|
|
|
|
|
{
|
2013-05-06 09:48:29 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
ParserDoubleItem::ParserDoubleItem(const std::string& itemName,
|
2014-05-08 16:25:34 +02:00
|
|
|
ParserItemSizeEnum sizeType_) :
|
|
|
|
|
ParserItem(itemName, sizeType_)
|
2013-09-12 10:58:44 +02:00
|
|
|
{
|
2014-09-12 12:23:37 +02:00
|
|
|
// use NaN as 'default default'. (Keep in mind that in the deck it can be queried
|
|
|
|
|
// using deckItem->defaultApplied(idx) if an item was defaulted or not...
|
|
|
|
|
m_default = std::numeric_limits<double>::quiet_NaN();
|
2013-08-01 09:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 15:26:18 +01:00
|
|
|
ParserDoubleItem::ParserDoubleItem(const std::string& itemName)
|
|
|
|
|
: ParserItem(itemName)
|
2013-09-17 22:27:53 +02:00
|
|
|
{
|
2014-09-12 12:23:37 +02:00
|
|
|
m_default = std::numeric_limits<double>::quiet_NaN();
|
2014-11-11 15:26:18 +01:00
|
|
|
m_defaultSet = false;
|
2013-09-17 22:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-11 15:26:18 +01:00
|
|
|
ParserDoubleItem::ParserDoubleItem(const std::string& itemName, double defaultValue)
|
|
|
|
|
: ParserItem(itemName)
|
2013-09-18 07:16:09 +02:00
|
|
|
{
|
|
|
|
|
setDefault( defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-11 15:26:18 +01:00
|
|
|
ParserDoubleItem::ParserDoubleItem(const std::string& itemName, ParserItemSizeEnum sizeType, double defaultValue)
|
|
|
|
|
: ParserItem(itemName, sizeType)
|
2013-09-12 10:58:44 +02:00
|
|
|
{
|
2013-09-17 22:27:53 +02:00
|
|
|
setDefault( defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 07:16:09 +02:00
|
|
|
|
2013-12-09 20:33:38 +01:00
|
|
|
double ParserDoubleItem::getDefault() const {
|
2014-11-11 15:26:18 +01:00
|
|
|
if (hasDefault())
|
|
|
|
|
return m_default;
|
|
|
|
|
|
|
|
|
|
if (sizeType() == Opm::ALL)
|
|
|
|
|
return std::numeric_limits<double>::quiet_NaN();
|
|
|
|
|
|
|
|
|
|
throw std::invalid_argument("No default value available for item "+name());
|
2013-12-09 20:33:38 +01:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2013-12-09 20:33:38 +01:00
|
|
|
|
2013-09-17 22:27:53 +02:00
|
|
|
void ParserDoubleItem::setDefault(double defaultValue) {
|
2013-08-01 09:31:27 +02:00
|
|
|
m_default = defaultValue;
|
2013-09-12 12:13:32 +02:00
|
|
|
m_defaultSet = true;
|
2013-08-01 09:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 15:26:18 +01:00
|
|
|
bool ParserDoubleItem::hasDefault() const {
|
|
|
|
|
return m_defaultSet;
|
|
|
|
|
}
|
2013-09-17 22:27:53 +02:00
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
ParserDoubleItem::ParserDoubleItem(const Json::JsonObject& jsonConfig) :
|
|
|
|
|
ParserItem(jsonConfig)
|
|
|
|
|
{
|
2014-09-12 12:23:37 +02:00
|
|
|
m_default = std::numeric_limits<double>::quiet_NaN();
|
2014-12-08 16:34:28 +01:00
|
|
|
if (jsonConfig.has_item("default"))
|
2013-09-17 22:27:53 +02:00
|
|
|
setDefault( jsonConfig.get_double("default") );
|
2013-08-01 09:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-13 11:02:23 +02:00
|
|
|
bool ParserDoubleItem::equal(const ParserItem& other) const {
|
|
|
|
|
return parserRawItemEqual<ParserDoubleItem>(other) && equalDimensions(other);
|
|
|
|
|
}
|
2013-09-12 10:58:44 +02:00
|
|
|
|
2013-12-11 13:25:42 +01:00
|
|
|
|
|
|
|
|
bool ParserDoubleItem::equalDimensions(const ParserItem& other) const {
|
2014-05-08 16:25:34 +02:00
|
|
|
bool equal_=false;
|
2013-12-11 13:25:42 +01:00
|
|
|
if (other.numDimensions() == numDimensions()) {
|
2014-05-08 16:25:34 +02:00
|
|
|
equal_ = true;
|
2013-12-11 13:25:42 +01:00
|
|
|
for (size_t idim=0; idim < numDimensions(); idim++) {
|
|
|
|
|
if (other.getDimension(idim) != getDimension(idim))
|
2014-05-08 16:25:34 +02:00
|
|
|
equal_ = false;
|
2013-12-11 13:25:42 +01:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
}
|
2014-05-08 16:25:34 +02:00
|
|
|
return equal_;
|
2013-12-11 13:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-09 21:12:27 +01:00
|
|
|
void ParserDoubleItem::push_backDimension(const std::string& dimension) {
|
|
|
|
|
if ((sizeType() == SINGLE) && (m_dimensions.size() > 0))
|
2014-10-22 13:21:22 +02:00
|
|
|
throw std::invalid_argument("Internal error: cannot add more than one dimension to an item of size 1");
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2013-12-09 21:12:27 +01:00
|
|
|
m_dimensions.push_back( dimension );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ParserDoubleItem::hasDimension() const {
|
|
|
|
|
return (m_dimensions.size() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 17:34:52 +01:00
|
|
|
size_t ParserDoubleItem::numDimensions() const {
|
|
|
|
|
return m_dimensions.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& ParserDoubleItem::getDimension(size_t index) const {
|
|
|
|
|
if (index < m_dimensions.size())
|
|
|
|
|
return m_dimensions[index];
|
|
|
|
|
else
|
|
|
|
|
throw std::invalid_argument("Invalid index ");
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 21:12:27 +01:00
|
|
|
|
2013-12-14 10:11:59 +01:00
|
|
|
DeckItemPtr ParserDoubleItem::scan(RawRecordPtr rawRecord) const {
|
2014-08-21 14:41:49 +02:00
|
|
|
return ParserItemScan<ParserDoubleItem,DeckDoubleItem,double>(this , rawRecord);
|
2013-10-16 14:57:01 +02:00
|
|
|
}
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-08-21 14:41:49 +02:00
|
|
|
void ParserDoubleItem::inlineNew(std::ostream& os) const {
|
2013-09-12 23:50:16 +02:00
|
|
|
os << "new ParserDoubleItem(" << "\"" << name() << "\"" << "," << ParserItemSizeEnum2String( sizeType() );
|
|
|
|
|
if (m_defaultSet)
|
|
|
|
|
os << "," << getDefault();
|
|
|
|
|
os << ")";
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 10:58:44 +02:00
|
|
|
}
|
2013-08-01 09:31:27 +02:00
|
|
|
|