1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
|
/*
Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
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/>.
*/
#include <config.h>
#include "TestTypeTag.hpp"
#include <opm/common/utility/Serializer.hpp>
#include <opm/input/eclipse/Schedule/Action/State.hpp>
#include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQState.hpp>
#include <opm/output/eclipse/Inplace.hpp>
#include <opm/input/eclipse/EclipseState/WagHysteresisConfig.hpp>
#include <opm/material/fluidmatrixinteractions/EclHysteresisTwoPhaseLawParams.hpp>
#include <opm/models/blackoil/blackoilprimaryvariables.hh>
#include <opm/simulators/flow/FemCpGridCompat.hpp>
#include <opm/simulators/flow/FlowGenericVanguard.hpp>
#include <opm/simulators/flow/FlowProblemBlackoil.hpp>
#include <opm/simulators/timestepping/AdaptiveTimeStepping.hpp>
#include <opm/simulators/timestepping/SimulatorReport.hpp>
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
#include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/utils/SerializationPackers.hpp>
#include <opm/simulators/wells/ALQState.hpp>
#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
#include <opm/simulators/wells/GroupState.hpp>
#include <opm/simulators/wells/PerfData.hpp>
#include <opm/simulators/wells/SegmentState.hpp>
#include <opm/simulators/wells/SingleWellState.hpp>
#define BOOST_TEST_MODULE TestRestartSerialization
#define BOOST_TEST_NO_MAIN
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/test/unit_test.hpp>
#include <algorithm>
namespace Opm::Properties {
namespace TTag {
struct TestRestartTypeTag {
using InheritsFrom = std::tuple<TestTypeTag>;
};
}
template<>
struct LinearSolverBackend<TTag::TestRestartTypeTag, TTag::FlowIstlSolverParams> {
using type = ISTLSolver<TTag::TestRestartTypeTag>;
};
}
template<class T>
std::tuple<T,int,int> PackUnpack(T& in)
{
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(in);
const size_t pos1 = ser.position();
T out{};
ser.unpack(out);
const size_t pos2 = ser.position();
return std::make_tuple(std::move(out), pos1, pos2);
}
#define TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, OBJ) \
BOOST_AUTO_TEST_CASE(NAME) \
{ \
auto val1 = Opm::TYPE::OBJ(); \
auto val2 = PackUnpack(val1); \
BOOST_CHECK_MESSAGE(std::get<1>(val2) == std::get<2>(val2), "Packed size differ from unpack size for " #TYPE); \
BOOST_CHECK_MESSAGE(val1 == std::get<0>(val2), "Deserialized " #TYPE " differ"); \
}
#define TEST_FOR_TYPE_NAMED(TYPE, NAME) \
TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, serializationTestObject)
#define TEST_FOR_TYPE(TYPE) \
TEST_FOR_TYPE_NAMED(TYPE, TYPE)
namespace Opm { using ALQS = ALQState<double>; }
TEST_FOR_TYPE_NAMED(ALQS, ALQState)
namespace Opm { using GroupS = GroupState<double>; }
TEST_FOR_TYPE_NAMED(GroupS, GroupState)
TEST_FOR_TYPE(HardcodedTimeStepControl)
TEST_FOR_TYPE(Inplace)
namespace Opm { using PerfD = PerfData<double>; }
TEST_FOR_TYPE_NAMED(PerfD, PerfData)
TEST_FOR_TYPE(PIDAndIterationCountTimeStepControl)
TEST_FOR_TYPE(PIDTimeStepControl)
namespace Opm { using SegmState = SegmentState<double>; }
TEST_FOR_TYPE_NAMED(SegmState, SegmentState)
TEST_FOR_TYPE(SimpleIterationCountTimeStepControl)
TEST_FOR_TYPE(SimulatorReport)
TEST_FOR_TYPE(SimulatorReportSingle)
TEST_FOR_TYPE(SimulatorTimer)
namespace Opm { using ATS = AdaptiveTimeStepping<Properties::TTag::TestTypeTag>; }
TEST_FOR_TYPE_NAMED_OBJ(ATS, AdaptiveTimeSteppingHardcoded, serializationTestObjectHardcoded)
TEST_FOR_TYPE_NAMED_OBJ(ATS, AdaptiveTimeSteppingPID, serializationTestObjectPID)
TEST_FOR_TYPE_NAMED_OBJ(ATS, AdaptiveTimeSteppingPIDIt, serializationTestObjectPIDIt)
TEST_FOR_TYPE_NAMED_OBJ(ATS, AdaptiveTimeSteppingSimple, serializationTestObjectSimple)
TEST_FOR_TYPE_NAMED_OBJ(ATS, AdaptiveTimeStepping3rdOrder, serializationTestObject3rdOrder)
namespace Opm { using BPV = BlackOilPrimaryVariables<Properties::TTag::TestTypeTag>; }
TEST_FOR_TYPE_NAMED(BPV, BlackoilPrimaryVariables)
namespace Opm {
struct DummyMaterial {
struct Params {
struct Traits {
using Scalar = double;
};
};
};
using HystParam = EclHysteresisTwoPhaseLawParams<DummyMaterial>;
}
TEST_FOR_TYPE_NAMED(HystParam, EclHysteresisTwoPhaseLawParams)
namespace Opm {
using Disc = Opm::FvBaseDiscretization<Opm::Properties::TTag::TestTypeTag>;
using BVec = typename Disc::BlockVectorWrapper;
}
TEST_FOR_TYPE_NAMED(BVec, BlockVectorWrapper)
BOOST_AUTO_TEST_CASE(SingleWellState)
{
Opm::ParallelWellInfo<double> dummy;
using IndexTraits = Opm::BlackOilDefaultFluidSystemIndices;
using PhaseUsage = Opm::PhaseUsageInfo<IndexTraits>;
auto data_out = Opm::SingleWellState<double, IndexTraits>::serializationTestObject(dummy);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in("", dummy, PhaseUsage{}, false, 0.0, {}, 0.0);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for SingleWellState");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized SingleWellState differ");
}
BOOST_AUTO_TEST_CASE(WellContainer)
{
auto data_out = Opm::WellContainer<double>::serializationTestObject(1.0);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in;
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for WellContainer");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized WellContainer differ");
}
BOOST_AUTO_TEST_CASE(WellState)
{
Opm::ParallelWellInfo<double> dummy;
using IndexTraits = Opm::BlackOilDefaultFluidSystemIndices;
auto data_out = Opm::WellState<double, IndexTraits>::serializationTestObject(dummy);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(dummy);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for WellState");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized WellState differ");
}
BOOST_AUTO_TEST_CASE(WGState)
{
Opm::ParallelWellInfo<double> dummy;
using IndexTraits = Opm::BlackOilDefaultFluidSystemIndices;
using PhaseUsage = Opm::PhaseUsageInfo<IndexTraits>;
auto data_out = Opm::WGState<double, IndexTraits>::serializationTestObject(dummy);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(PhaseUsage{});
data_in.well_state = Opm::WellState<double, IndexTraits>(dummy);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for WGState");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized WGState differ");
}
BOOST_AUTO_TEST_CASE(FlowGenericVanguard)
{
auto in_params = Opm::FlowGenericVanguard::serializationTestParams();
Opm::FlowGenericVanguard val1(std::move(in_params));
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(val1);
const size_t pos1 = ser.position();
Opm::FlowGenericVanguard::SimulationModelParams out_params;
out_params.setupTime_ = 0.0;
out_params.actionState_ = std::make_unique<Opm::Action::State>();
out_params.udqState_ = std::make_unique<Opm::UDQState>();
out_params.eclSchedule_ = std::make_shared<Opm::Schedule>();
out_params.summaryState_ = std::make_unique<Opm::SummaryState>();
Opm::FlowGenericVanguard val2(std::move(out_params));
ser.unpack(val2);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for FlowGenericVanguard");
BOOST_CHECK_MESSAGE(val1 == val2, "Deserialized FlowGenericVanguard differ");
}
BOOST_AUTO_TEST_CASE(FlowGenericProblem)
{
Opm::EclipseState eclState;
Opm::Schedule schedule;
Dune::CpGrid grid;
using GridView = Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>;
auto gridView = grid.leafGridView();
auto data_out
= Opm::FlowGenericProblem<GridView, Opm::BlackOilFluidSystem<double, Opm::BlackOilDefaultFluidSystemIndices>>::
serializationTestObject(eclState, schedule, gridView);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(eclState, schedule, gridView);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for FlowGenericProblem");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized FlowGenericProblem differ");
}
BOOST_AUTO_TEST_CASE(MixingRateControls)
{
Opm::Schedule schedule;
using FS = Opm::BlackOilFluidSystem<double, Opm::BlackOilDefaultFluidSystemIndices>;
auto data_out = Opm::MixingRateControls<FS>::serializationTestObject(schedule);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(schedule);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for MixingRateControls");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized MixingRateControls differ");
}
#if HAVE_DUNE_FEM
BOOST_AUTO_TEST_CASE(FlowGenericProblemFem)
{
Opm::EclipseState eclState;
Opm::Schedule schedule;
Dune::CpGrid grid;
using GridPart = Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>;
using GridView = GridPart::GridViewType;
auto gridPart = GridPart(grid);
auto gridView = gridPart.gridView();
auto data_out
= Opm::FlowGenericProblem<GridView, Opm::BlackOilFluidSystem<double, Opm::BlackOilDefaultFluidSystemIndices>>::
serializationTestObject(eclState, schedule, gridView);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(eclState, schedule, gridView);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for EclGenericProblem");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem differ");
}
#endif // HAVE_DUNE_FEM
namespace Opm {
using IndexTraits = Opm::BlackOilDefaultFluidSystemIndices;
using PhaseUsage = Opm::PhaseUsageInfo<IndexTraits>;
class BlackoilWellModelGenericTest : public BlackoilWellModelGeneric<double, IndexTraits>
{
public:
BlackoilWellModelGenericTest(Schedule& schedule,
BlackoilWellModelGasLiftGeneric<double, IndexTraits>& gaslift,
const SummaryState& summaryState,
const EclipseState& eclState,
const PhaseUsage& phase_usage,
const Parallel::Communication& comm,
bool deserialize)
: BlackoilWellModelGeneric<double, IndexTraits>(schedule, gaslift, summaryState,
eclState, phase_usage, comm)
{
if (deserialize) {
active_wgstate_.well_state = WellState<double, IndexTraits>(dummy);
last_valid_wgstate_.well_state = WellState<double, IndexTraits>(dummy);
nupcol_wgstate_.well_state = WellState<double, IndexTraits>(dummy);
}
}
void setSerializationTestData()
{
initial_step_ = true;
report_step_starts_ = true;
last_run_wellpi_ = 1;
local_shut_wells_ = {2, 3};
closed_this_step_ = {"test1", "test2"};
guideRate_.setSerializationTestData();
node_pressures_ = {{"test3", 4.0}};
active_wgstate_ = WGState<double, IndexTraits>::serializationTestObject(dummy);
last_valid_wgstate_ = WGState<double, IndexTraits>::serializationTestObject(dummy);
nupcol_wgstate_ = WGState<double, IndexTraits>::serializationTestObject(dummy);
switched_prod_groups_ = {{"test4", {Group::ProductionCMode::NONE, Group::ProductionCMode::ORAT}}};
const auto controls = {Group::InjectionCMode::NONE, Group::InjectionCMode::RATE, Group::InjectionCMode::RATE };
switched_inj_groups_ = {{"test4", {controls, {}, controls} }};
closed_offending_wells_ = {{"test4", {"test5", "test6"}}};
}
void calcResvCoeff(const int, const int, const std::vector<double>&, std::vector<double>&) override
{}
void calcInjResvCoeff(const int, const int, std::vector<double>&) override
{}
void computePotentials(const std::size_t,
const WellState<double, IndexTraits>&,
std::string&,
ExceptionType::ExcEnum&,
DeferredLogger&) override
{}
void createWellContainer(const int) override
{}
void initWellContainer(const int) override
{}
void calculateProductivityIndexValuesShutWells(const int,
DeferredLogger&) override
{}
void calculateProductivityIndexValues(DeferredLogger&) override
{}
int compressedIndexForInterior(int) const override
{
return 0;
}
private:
ParallelWellInfo<double> dummy;
};
class BlackoilWellModelGasLiftGenericTest : public BlackoilWellModelGasLiftGeneric<double, IndexTraits>
{
public:
BlackoilWellModelGasLiftGenericTest()
: BlackoilWellModelGasLiftGeneric<double, IndexTraits>(false)
{
this->last_glift_opt_time_ = 1234.5;
}
};
}
BOOST_AUTO_TEST_CASE(BlackoilWellModelGeneric)
{
Opm::Schedule schedule{};
Opm::SummaryState summaryState{};
Opm::EclipseState eclState{};
Opm::PhaseUsage phase_usage{};
Opm::Parallel::Communication comm{};
Opm::BlackoilWellModelGasLiftGenericTest gaslift;
Opm::BlackoilWellModelGenericTest data_out(schedule, gaslift, summaryState,
eclState, phase_usage, comm, false);
data_out.setSerializationTestData();
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
Opm::BlackoilWellModelGenericTest data_in(schedule, gaslift, summaryState,
eclState, phase_usage, comm, true);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for BlackoilWellModelGeneric");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized BlackoilWellModelGeneric differ");
}
template<class Grid, class GridView, class DofMapper, class Stencil, class FluidSystem, class Scalar>
class GenericTracerModelTest : public Opm::GenericTracerModel<Grid,GridView,DofMapper,Stencil,FluidSystem,Scalar>
{
using Base = Opm::GenericTracerModel<Grid,GridView,DofMapper,Stencil,FluidSystem,Scalar>;
public:
GenericTracerModelTest(const GridView& gridView,
const Opm::EclipseState& eclState,
const Dune::CartesianIndexMapper<Grid>& cartMapper,
const DofMapper& dofMapper,
const std::function<std::array<double,Grid::dimensionworld>(int)> centroids) :
Base(gridView, eclState, cartMapper, dofMapper, centroids)
{}
static GenericTracerModelTest
serializationTestObject(const GridView& gridView,
const Opm::EclipseState& eclState,
const Dune::CartesianIndexMapper<Grid>& cartMapper,
const DofMapper& dofMapper,
const std::function<std::array<double,Grid::dimensionworld>(int)> centroids)
{
GenericTracerModelTest result(gridView, eclState, cartMapper, dofMapper, centroids);
result.tracerConcentration_ = {{{1.0, 2.0}}, {{3.0, 4.0}}, {{5.0, 6.0}}};
result.wellTracerRate_.emplace(1, std::vector{Opm::WellTracerRate<double>{"foo", 4.0}});
return result;
}
bool operator==(const GenericTracerModelTest& rhs) const
{
if (this->tracerConcentration_.size() != rhs.tracerConcentration_.size()) {
return false;
}
for (size_t i = 0; i < this->tracerConcentration_.size(); ++i) {
if (!std::equal(this->tracerConcentration_[i].begin(),
this->tracerConcentration_[i].end(),
rhs.tracerConcentration_[i].begin(),
rhs.tracerConcentration_[i].end())) {
return false;
}
}
return this->wellTracerRate_ == rhs.wellTracerRate_;
}
};
BOOST_AUTO_TEST_CASE(FlowGenericTracerModel)
{
Dune::CpGrid grid;
Opm::EclipseState eclState;
Dune::CartesianIndexMapper<Dune::CpGrid> mapper(grid);
auto centroids = [](int) { return std::array<double,Dune::CpGrid::dimensionworld>{}; };
using GridView = Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>;
auto gridView = grid.leafGridView();
Dune::MultipleCodimMultipleGeomTypeMapper<GridView> dofMapper(gridView, Dune::mcmgElementLayout());
auto data_out = GenericTracerModelTest<Dune::CpGrid,
GridView,
Dune::MultipleCodimMultipleGeomTypeMapper<GridView>,
Opm::EcfvStencil<double, GridView, false, false>,
Opm::BlackOilFluidSystem<double, Opm::BlackOilDefaultFluidSystemIndices>,
double>
::serializationTestObject(gridView, eclState, mapper, dofMapper, centroids);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(gridView, eclState, mapper, dofMapper, centroids);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for EclGenericTracerModel");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericTracerModel differ");
}
#if HAVE_DUNE_FEM
BOOST_AUTO_TEST_CASE(FlowGenericTracerModelFem)
{
Dune::CpGrid grid;
Opm::EclipseState eclState;
Dune::CartesianIndexMapper<Dune::CpGrid> mapper(grid);
auto centroids = [](int) { return std::array<double,Dune::CpGrid::dimensionworld>{}; };
using GridPart = Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>;
using GridView = GridPart::GridViewType;
auto gridPart = GridPart(grid);
auto gridView = gridPart.gridView();
Dune::MultipleCodimMultipleGeomTypeMapper<GridView> dofMapper(gridView, Dune::mcmgElementLayout());
auto data_out = GenericTracerModelTest<Dune::CpGrid,
GridView,
Dune::MultipleCodimMultipleGeomTypeMapper<GridView>,
Opm::EcfvStencil<double, GridView, false, false>,
Opm::BlackOilFluidSystem<double, Opm::BlackOilDefaultFluidSystemIndices>,
double>
::serializationTestObject(gridView, eclState, mapper, dofMapper, centroids);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(gridView, eclState, mapper, dofMapper, centroids);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for EclGenericTracerModel");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericTracerModel differ");
}
#endif // HAVE_DUNE_FEM
namespace Opm {
class TBatchExport : public TracerModel<Properties::TTag::TestTypeTag> {
public:
using TBatch = TracerBatch<double>;
};
}
TEST_FOR_TYPE_NAMED(TBatchExport::TBatch, TracerBatch)
namespace {
struct AquiferFixture {
AquiferFixture() {
using namespace Opm;
using TT = Properties::TTag::TestRestartTypeTag;
const char* argv[] = {
"test_RestartSerialization",
"--ecl-deck-file-name=GLIFT1.DATA"
};
// Since this parameter is registered in opm/models/nonlinear/newtonmethodparams.cpp but not accessed here
Parameters::Register<Parameters::NewtonMaxIterations>("The maximum number of Newton iterations per time step");
Opm::ThreadManager::registerParameters();
AdaptiveTimeStepping<TT>::registerParameters();
BlackoilModelParameters<double>::registerParameters();
Parameters::Register<Parameters::EnableTerminalOutput>("Do *NOT* use!");
setupParameters_<TT>(2, argv, /*registerParams=*/true, false, true, 0);
Opm::FlowGenericVanguard::setCommunication(std::make_unique<Opm::Parallel::Communication>());
}
};
}
BOOST_GLOBAL_FIXTURE(AquiferFixture);
#define TEST_FOR_AQUIFER(TYPE) \
BOOST_AUTO_TEST_CASE(TYPE) \
{ \
using TT = Opm::Properties::TTag::TestRestartTypeTag; \
Opm::FlowGenericVanguard::readDeck("GLIFT1.DATA"); \
using Simulator = Opm::GetPropType<TT, Opm::Properties::Simulator>; \
Simulator sim; \
auto data_out = Opm::TYPE<TT>::serializationTestObject(sim); \
Opm::Serialization::MemPacker packer; \
Opm::Serializer ser(packer); \
ser.pack(data_out); \
const size_t pos1 = ser.position(); \
decltype(data_out) data_in({}, sim, {}); \
ser.unpack(data_in); \
const size_t pos2 = ser.position(); \
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for " #TYPE); \
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized " #TYPE " differ"); \
}
TEST_FOR_AQUIFER(AquiferCarterTracy)
TEST_FOR_AQUIFER(AquiferFetkovich)
BOOST_AUTO_TEST_CASE(AquiferNumerical)
{
using TT = Opm::Properties::TTag::TestRestartTypeTag;
Opm::FlowGenericVanguard::readDeck("GLIFT1.DATA");
using Simulator = Opm::GetPropType<TT, Opm::Properties::Simulator>;
Simulator sim;
auto data_out = Opm::AquiferNumerical<TT>::serializationTestObject(sim);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in({}, sim);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for AquiferNumerical");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized AquiferNumerical differ");
}
BOOST_AUTO_TEST_CASE(AquiferConstantFlux)
{
using TT = Opm::Properties::TTag::TestRestartTypeTag;
Opm::FlowGenericVanguard::readDeck("GLIFT1.DATA");
using Simulator = Opm::GetPropType<TT, Opm::Properties::Simulator>;
Simulator sim;
auto data_out = Opm::AquiferConstantFlux<TT>::serializationTestObject(sim);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in({}, sim, {});
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for AquiferConstantFlux");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized AquiferConstantFlux differ");
}
bool init_unit_test_func()
{
return true;
}
int main(int argc, char** argv)
{
// MPI setup.
int argcDummy = 1;
const char *tmp[] = {"test_RestartSerialization"};
char **argvDummy = const_cast<char**>(tmp);
#if HAVE_DUNE_FEM
Dune::Fem::MPIManager::initialize(argcDummy, argvDummy);
#else
Dune::MPIHelper::instance(argcDummy, argvDummy);
#endif
return boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
}
|