// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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 .
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
/*!
* \file
*
* \brief This file tests the properties system.
*
* We define a few type tags and property tags, then we attach values
* to (TypeTag, PropertyTag) tuples and finally we use them in the
* main function and print some diagnostic messages.
*/
#include "config.h"
#include
#include
namespace Opm::Properties {
///////////////////
// Define some hierarchy of type tags:
//
// Vehicle -- CompactCar -- Sedan -_
// \ \.
// \ +- Pickup ---_
// \ / \.
// +-- Truck ---------------^ \.
// \ \.
// +- Tank ----------------------------------+- HummerH1
///////////////////
namespace TTag {
struct Vehicle {};
struct CompactCar { using InheritsFrom = std::tuple; };
struct Truck { using InheritsFrom = std::tuple; };
struct Tank { using InheritsFrom = std::tuple; };
struct Sedan { using InheritsFrom = std::tuple; };
struct Pickup { using InheritsFrom = std::tuple; };
struct HummerH1 { using InheritsFrom = std::tuple; };
} // end namespace TTag
///////////////////
// Define the property tags:
// TopSpeed, NumSeats, CanonCaliber, GasUsage, AutomaticTransmission, Payload
///////////////////
template
struct TopSpeed { using type = UndefinedProperty; }; // [km/h]
template
struct NumSeats { using type = UndefinedProperty; }; // []
template
struct CanonCaliber { using type = UndefinedProperty; }; // [mm]
template
struct GasUsage { using type = UndefinedProperty; }; // [l/100km]
template
struct AutomaticTransmission { using type = UndefinedProperty; }; // true/false
template
struct Payload { using type = UndefinedProperty; }; // [t]
///////////////////
// Make the AutomaticTransmission default to false
template
struct AutomaticTransmission { static constexpr bool value = false; };
///////////////////
// Define some values for the properties on the type tags:
//
// (CompactCar, TopSpeed) = GasUsage*35
// (CompactCar, NumSeats) = 5
// (CompactCar, GasUsage) = 4
//
// (Truck, TopSpeed) = 100
// (Truck, NumSeats) = 2
// (Truck, GasUsage) = 12
// (Truck, Payload) = 35
//
// (Tank, TopSpeed) = 60
// (Tank, GasUsage) = 65
// (Tank, CanonCaliber) = 120
//
// (Sedan, GasUsage) = 7
// (Sedan, AutomaticTransmission) = true
//
// (Pickup, TopSpeed) = 120
// (Pickup, Payload) = 5
//
// (HummmerH1, TopSpeed) = (Pickup, TopSpeed)
///////////////////
template
struct TopSpeed { static constexpr int value = getPropValue() * 30; };
template
struct NumSeats { static constexpr int value = 5; };
template
struct GasUsage { static constexpr int value = 4; };
template
struct TopSpeed { static constexpr int value = 100; };
template
struct NumSeats { static constexpr int value = 2; };
template
struct GasUsage { static constexpr int value = 12; };
template
struct Payload { static constexpr int value = 35; };
template
struct TopSpeed { static constexpr int value = 60; };
template
struct GasUsage { static constexpr int value = 65; };
template
struct CanonCaliber { static constexpr int value = 120; };
template
struct GasUsage { static constexpr int value = 7; };
template
struct AutomaticTransmission { static constexpr bool value = true; };
template
struct TopSpeed { static constexpr int value = 120; };
template
struct Payload { static constexpr int value = 5; };
template
struct TopSpeed { static constexpr int value = getPropValue(); };
} // namespace Opm::Properties
int main()
{
using namespace Opm;
using namespace Opm::Properties;
// print all properties for all type tags
std::cout << "---------------------------------------\n";
std::cout << "-- Property values\n";
std::cout << "---------------------------------------\n";
std::cout << "---------- Values for CompactCar ----------\n";
std::cout << "(CompactCar, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(CompactCar, NumSeats) = " << getPropValue() << "\n";
std::cout << "(CompactCar, GasUsage) = " << getPropValue() << "\n";
std::cout << "(CompactCar, AutomaticTransmission) = " << getPropValue() << "\n";
std::cout << "---------- Values for Truck ----------\n";
std::cout << "(Truck, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(Truck, NumSeats) = " << getPropValue() << "\n";
std::cout << "(Truck, GasUsage) = " << getPropValue() << "\n";
std::cout << "(Truck, Payload) = " << getPropValue() << "\n";
std::cout << "(Truck, AutomaticTransmission) = " << getPropValue() << "\n";
std::cout << "---------- Values for Tank ----------\n";
std::cout << "(Tank, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(Tank, GasUsage) = " << getPropValue() << "\n";
std::cout << "(Tank, AutomaticTransmission) = " << getPropValue() << "\n";
std::cout << "(Tank, CanonCaliber) = " << getPropValue() << "\n";
std::cout << "---------- Values for Sedan ----------\n";
std::cout << "(Sedan, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(Sedan, NumSeats) = " << getPropValue() << "\n";
std::cout << "(Sedan, GasUsage) = " << getPropValue() << "\n";
std::cout << "(Sedan, AutomaticTransmission) = " << getPropValue() << "\n";
std::cout << "---------- Values for Pickup ----------\n";
std::cout << "(Pickup, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(Pickup, NumSeats) = " << getPropValue() << "\n";
std::cout << "(Pickup, GasUsage) = " << getPropValue() << "\n";
std::cout << "(Pickup, Payload) = " << getPropValue() << "\n";
std::cout << "(Pickup, AutomaticTransmission) = " << getPropValue() << "\n";
std::cout << "---------- Values for HummerH1 ----------\n";
std::cout << "(HummerH1, TopSpeed) = " << getPropValue() << "\n";
std::cout << "(HummerH1, NumSeats) = " << getPropValue() << "\n";
std::cout << "(HummerH1, GasUsage) = " << getPropValue() << "\n";
std::cout << "(HummerH1, Payload) = " << getPropValue() << "\n";
std::cout << "(HummerH1, AutomaticTransmission) = " << getPropValue() << "\n";
return 0;
}