Use Uppercase Exponents in UDQDefine::input_string

Needed for compatibility reasons.
This commit is contained in:
Bård Skaflestad 2022-03-11 09:48:52 +01:00
parent a0d9a04470
commit d08b7292bf
2 changed files with 33 additions and 10 deletions

View File

@ -16,20 +16,25 @@
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fmt/format.h>
#include <numeric>
#include <opm/input/eclipse/Schedule/UDQ/UDQToken.hpp>
namespace Opm {
#include <numeric>
#include <string>
#include <variant>
#include <vector>
#include <fmt/format.h>
namespace {
std::string format_double(double d) {
return fmt::format("{:g}", d);
}
}
std::string format_double(const double d)
{
// Use uppercase exponents for restart file compatibility.
return fmt::format("{:G}", d);
}
} // namespace anonymous
namespace Opm {
UDQToken::UDQToken(const std::string& string_token, UDQTokenType token_type_) :
token_type(token_type_)
@ -74,5 +79,4 @@ std::string UDQToken::str() const {
return format_double(std::get<double>(this->m_value));
}
}
} // namespace Opm

View File

@ -1290,6 +1290,25 @@ BOOST_AUTO_TEST_CASE(UDQPARSE_TEST1) {
BOOST_CHECK_EQUAL( def2.input_string() , "2 * (1 + WBHP)");
}
BOOST_AUTO_TEST_CASE(INPUT_STRING_SCIENTIFIC_NOTATION) {
const auto schedule = make_schedule(R"(
SCHEDULE
UDQ
DEFINE FU_THREE (3000000 + FU_ONE*1500000 + 1000000*FU_TWO)/365 /
/
)");
const auto& udq = schedule.getUDQConfig(0);
const auto def = udq.definitions();
BOOST_CHECK_EQUAL(def.size(), 1ULL);
const auto expect_input_string = std::string {
"(3E+06 + FU_ONE * 1.5E+06 + 1E+06 * FU_TWO) / 365"
};
BOOST_CHECK_EQUAL(def[0].input_string(), expect_input_string);
}
BOOST_AUTO_TEST_CASE(UDQ_PARSE_ERROR) {
UDQParams udqp;