diff --git a/MaterialLib/CMakeLists.txt b/MaterialLib/CMakeLists.txt index 9030788b9736d9f31f66128f0d669fa11b2217bd..2789b878330cb32555f909d482ff218f69af9462 100644 --- a/MaterialLib/CMakeLists.txt +++ b/MaterialLib/CMakeLists.txt @@ -8,6 +8,7 @@ append_source_files(SOURCES Fluid) append_source_files(SOURCES Fluid/Density) append_source_files(SOURCES Fluid/Viscosity) append_source_files(SOURCES Fluid/GibbsFreeEnergy) +append_source_files(SOURCES Fluid/FluidProperties) append_source_files(SOURCES PorousMedium/Porosity) append_source_files(SOURCES PorousMedium/Storage) diff --git a/MaterialLib/Fluid/CompositeFluidProperty.h b/MaterialLib/Fluid/CompositeFluidProperty.h deleted file mode 100644 index 26a48f23d636fef12ef539efa07e95e7f91a046d..0000000000000000000000000000000000000000 --- a/MaterialLib/Fluid/CompositeFluidProperty.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \copyright - * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * \file CompositeFluidProperty.h - * - * Created on November 29, 2016, 2:23 PM - */ - -#ifndef OGS_COMPOSITE_FLUID_PROPERTY_H -#define OGS_COMPOSITE_FLUID_PROPERTY_H - -#include <array> - -#include "PropertyVariableType.h" - -namespace MaterialLib -{ -namespace Fluid -{ -/// Property type. -enum class PropertyType -{ - Density, - Vicosity, - HeatCapacity, - ThermalConductivity -}; - -class CompositeFluidProperty -{ -public: - typedef std::array<double, PropertyVariableNumber> ArrayType; - - virtual ~CompositeFluidProperty(){}; - - /** - * Get the value of a Property. - * \param property_type Property type. - * \param variable_values An array of variables. The order of its elements - * is given in enum class PropertyVariableType. - */ - virtual double getValue(const PropertyType property_type, - const ArrayType& variable_values) const = 0; - - /** - * Get the partial differential of a property. - * \param property_type Property type. - * \param variable_values An array of variables. The order of its elements - * is given in enum class PropertyVariableType. - * \param variable_type Variable type - */ - virtual double getdValue( - const PropertyType property_type, - const ArrayType& variable_values, - const PropertyVariableType variable_type) const = 0; -}; - -} // end namespace -} // end namespace -#endif /* OGS_COMPOSITE_FLUID_PROPERTY_H */ diff --git a/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.cpp b/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.cpp deleted file mode 100644 index 5e2f095f123955946adeee3be995f1869d2898e2..0000000000000000000000000000000000000000 --- a/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \copyright - * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * \file CompositeDensityViscosityModel.cpp - * - * Created on November 29, 2016, 3:19 PM - */ - -#include "CompositeDensityViscosityModel.h" - -#include "MaterialLib/Fluid/FluidProperty.h" - -namespace MaterialLib -{ -namespace Fluid -{ -CompositeDensityViscosityModel::CompositeDensityViscosityModel( - std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& density, - std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& viscosity) - : _density(std::move(density)), _viscosity(std::move(viscosity)) -{ -} - -inline double CompositeDensityViscosityModel::getValue( - const PropertyType property_type, const ArrayType& variable_values) const -{ - switch (property_type) - { - case PropertyType::Density: - return _density->getValue(variable_values); - case PropertyType::Vicosity: - return _viscosity->getValue(variable_values); - default: - return 0.; - } -} - -inline double CompositeDensityViscosityModel::getdValue( - const PropertyType property_type, - const ArrayType& variable_values, - const PropertyVariableType variable_type) const -{ - switch (property_type) - { - case PropertyType::Density: - return _density->getdValue(variable_values, variable_type); - case PropertyType::Vicosity: - return _viscosity->getdValue(variable_values, variable_type); - default: - return 0.; - } -} - -} // end namespace -} // end namespace diff --git a/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.h b/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.h deleted file mode 100644 index 527cfd819f0a351df5068c099e6d2a5755da278a..0000000000000000000000000000000000000000 --- a/MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * \copyright - * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * \file CompositeDensityViscosityModel.h - * - * Created on November 29, 2016, 3:19 PM - */ - -#ifndef OGS_COMPOSITE_DENSITY_VISCOSITY_MODEL_H -#define OGS_COMPOSITE_DENSITY_VISCOSITY_MODEL_H - -#include <memory> - -#include "MaterialLib/Fluid/CompositeFluidProperty.h" - -namespace MaterialLib -{ -namespace Fluid -{ -class FluidProperty; - -/// A class contains density and viscosity model. -class CompositeDensityViscosityModel final : public CompositeFluidProperty -{ -public: - CompositeDensityViscosityModel( - std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& density, - std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& viscosity); - - /** - * Get the value of a Property. - * \param property_type Property type. - * \param variable_values An array of variables. The order of its elements - * is given in enum class PropertyVariableType. - */ - double getValue(const PropertyType property_type, - const ArrayType& variable_values) const override; - - /** - * Get the partial differential of a property. - * \param property_type Property type. - * \param variable_values An array of variables. The order of its elements - * is given in enum class PropertyVariableType. - * \param variable_type Variable type - */ - double getdValue(const PropertyType property_type, - const ArrayType& variable_values, - const PropertyVariableType variable_type) const override; - -private: - std::unique_ptr<MaterialLib::Fluid::FluidProperty> _density; - std::unique_ptr<MaterialLib::Fluid::FluidProperty> _viscosity; -}; - -} // end namespace -} // end namespace -#endif /* OGS_COMPOSITE_DENSITY_VISCOSITY_MODEL_H */ diff --git a/MaterialLib/Fluid/FluidProperties/FluidProperties.h b/MaterialLib/Fluid/FluidProperties/FluidProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..3bbef0353778ff9ecead4a0065493a877d805647 --- /dev/null +++ b/MaterialLib/Fluid/FluidProperties/FluidProperties.h @@ -0,0 +1,96 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * \file FluidProperties.h + * + * Created on November 29, 2016, 2:23 PM + */ + +#ifndef OGS_FLUID_PROPERTIES_H +#define OGS_FLUID_PROPERTIES_H + +#include <array> +#include <memory> + +#include "MaterialLib/Fluid/FluidProperty.h" +#include "MaterialLib/Fluid/PropertyVariableType.h" + +namespace MaterialLib +{ +namespace Fluid +{ +/// Fluid property type. +enum class FluidPropertyType +{ + Density = 0, + Vicosity = 1, + HeatCapacity = 2, + ThermalConductivity = 3, + number_of_property_types = 4 ///< Number of property types. +}; + +const unsigned FluidPropertyTypeNumber = + static_cast<unsigned>(FluidPropertyType::number_of_property_types); + +/// Base class of fluid properties. +class FluidProperties +{ +public: + typedef std::array<double, PropertyVariableNumber> ArrayType; + + FluidProperties( + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& density, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& viscosity, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& heat_capacity, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& + thermal_conductivity) + : _property_models{{std::move(density), std::move(viscosity), + std::move(heat_capacity), + std::move(thermal_conductivity)}} + { + } + virtual ~FluidProperties(){}; + + /** + * Get the value of a Property. + * \param property_type Property type. + * \param variable_values An array of variables. The order of its elements + * is temperature, pressure, concentration, which is + * defined in enum class PropertyVariableType. + */ + virtual double getValue(const FluidPropertyType property_type, + const ArrayType& variable_values) const = 0; + + /** + * Get the partial differential of a property. + * \param property_type Property type. + * \param variable_values An array of variables. The order of its elements + * is temperature, pressure, concentration, which is + * defined in enum class PropertyVariableType. + * \param variable_type Variable type + */ + virtual double getdValue( + const FluidPropertyType property_type, + const ArrayType& variable_values, + const PropertyVariableType variable_type) const = 0; + +protected: + /** Fluid property models. + * 0: density; + * 1: viscosity; + * 2: specific heat capacity; + * 3: thermal conductivity + * + * The index is specified via enum class PropertyType. + */ + std::array<std::unique_ptr<FluidProperty>, FluidPropertyTypeNumber> + _property_models; +}; + +} // end namespace +} // end namespace +#endif /* OGS_FLUID_PROPERTIES_H */ diff --git a/MaterialLib/Fluid/FluidProperties/TemperaturePressureConcentrationDependentFluidProperties.h b/MaterialLib/Fluid/FluidProperties/TemperaturePressureConcentrationDependentFluidProperties.h new file mode 100644 index 0000000000000000000000000000000000000000..883fc09c4926bb94bc9e797103331abc4593a528 --- /dev/null +++ b/MaterialLib/Fluid/FluidProperties/TemperaturePressureConcentrationDependentFluidProperties.h @@ -0,0 +1,77 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * \file TemperaturePressureConcentrationDependentFluidProperties.h + * + * Created on November 29, 2016, 3:19 PM + */ + +#ifndef OGS_TEMPERATURE_PRESSURE_CONCENTRATION_DEPENDENT_FLUID_PROPERTIES_H +#define OGS_TEMPERATURE_PRESSURE_CONCENTRATION_DEPENDENT_FLUID_PROPERTIES_H + +#include "FluidProperties.h" +#include "MaterialLib/Fluid/FluidProperty.h" + +namespace MaterialLib +{ +namespace Fluid +{ +class FluidProperty; + +/// A class contains density, viscosity, heat_capacity and thermal_conductivity +/// models, which are all functions of temperature, pressure and concentration. +class TemperaturePressureConcentrationDependentFluidProperties final + : public FluidProperties +{ +public: + TemperaturePressureConcentrationDependentFluidProperties( + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& density, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& viscosity, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& heat_capacity, + std::unique_ptr<MaterialLib::Fluid::FluidProperty>&& + thermal_conductivity) + : FluidProperties(std::move(density), std::move(viscosity), + std::move(heat_capacity), + std::move(thermal_conductivity)) + { + } + + /** + * Get the value of a Property. + * \param property_type Property type. + * \param variable_values An array of variables. The order of its elements + * is temperature, pressure, concentration, which is + * defined in enum class PropertyVariableType. + */ + double getValue(const FluidPropertyType property_type, + const ArrayType& variable_values) const override + { + return _property_models[static_cast<unsigned>(property_type)]->getValue( + variable_values); + } + + /** + * Get the partial differential of a property. + * \param property_type Property type. + * \param variable_values An array of variables. The order of its elements + * is temperature, pressure, concentration, which is + * defined in enum class PropertyVariableType. + * \param variable_type Variable type + */ + double getdValue(const FluidPropertyType property_type, + const ArrayType& variable_values, + const PropertyVariableType variable_type) const override + { + return _property_models[static_cast<unsigned>(property_type)] + ->getdValue(variable_values, variable_type); + } +}; + +} // end namespace +} // end namespace +#endif /* OGS_TEMPERATURE_PRESSURE_CONCENTRATION_DEPENDENT_FLUID_PROPERTIES_H \ + */ diff --git a/Tests/MaterialLib/TestCompositeDensityViscosityModel.cpp b/Tests/MaterialLib/TestFluidProperties.cpp similarity index 67% rename from Tests/MaterialLib/TestCompositeDensityViscosityModel.cpp rename to Tests/MaterialLib/TestFluidProperties.cpp index e23f41fe312127778d9cafdb733cfa8492c95d11..3d766f463ea758fdda0aee20d4eda8974ea236e9 100644 --- a/Tests/MaterialLib/TestCompositeDensityViscosityModel.cpp +++ b/Tests/MaterialLib/TestFluidProperties.cpp @@ -7,7 +7,7 @@ * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * - * \file TestCompositeDensityViscosityModel.cpp + * \file TestFluidProperties.cpp * */ @@ -16,12 +16,12 @@ #include <memory> #include <cmath> -#include "TestTools.h" +#include "Tests/TestTools.h" #include "MaterialLib/Fluid/Density/createFluidDensityModel.h" #include "MaterialLib/Fluid/Viscosity/createViscosityModel.h" -#include "MaterialLib/Fluid/CompositeFluidProperty.h" -#include "MaterialLib/Fluid/CompositeFluidProperty/CompositeDensityViscosityModel.h" +#include "MaterialLib/Fluid/FluidProperties/FluidProperties.h" +#include "MaterialLib/Fluid/FluidProperties/TemperaturePressureConcentrationDependentFluidProperties.h" using namespace MaterialLib; using namespace MaterialLib::Fluid; @@ -59,28 +59,29 @@ TEST(MaterialFluidModel, checkCompositeDensityViscosityModel) "</viscosity>"; auto mu = createTestModel(xml_v, createViscosityModel, "viscosity"); - std::unique_ptr<CompositeFluidProperty> composite_fluid_model = - std::unique_ptr<CompositeFluidProperty>( - new CompositeDensityViscosityModel(std::move(rho), std::move(mu))); + std::unique_ptr<FluidProperties> fluid_model = + std::unique_ptr<FluidProperties>( + new TemperaturePressureConcentrationDependentFluidProperties( + std::move(rho), std::move(mu), nullptr, nullptr)); ArrayType vars; vars[0] = 350.0; const double mu_expected = 1.e-3 * std::exp(-(vars[0] - 293) / 368); ASSERT_NEAR(mu_expected, - composite_fluid_model->getValue(PropertyType::Vicosity, vars), - 1.e-10); - ASSERT_NEAR(-mu_expected, - composite_fluid_model->getdValue( - PropertyType::Vicosity, vars, - MaterialLib::Fluid::PropertyVariableType::T), + fluid_model->getValue(FluidPropertyType::Vicosity, vars), 1.e-10); + ASSERT_NEAR( + -mu_expected, + fluid_model->getdValue(FluidPropertyType::Vicosity, vars, + MaterialLib::Fluid::PropertyVariableType::T), + 1.e-10); vars[0] = 273.1; ASSERT_NEAR(1000.0 * (1 + 4.3e-4 * (vars[0] - 293.0)), - composite_fluid_model->getValue(PropertyType::Density, vars), + fluid_model->getValue(FluidPropertyType::Density, vars), 1.e-10); - ASSERT_NEAR(1000.0 * 4.3e-4, composite_fluid_model->getdValue( - PropertyType::Density, vars, - Fluid::PropertyVariableType::T), + ASSERT_NEAR(1000.0 * 4.3e-4, + fluid_model->getdValue(FluidPropertyType::Density, vars, + Fluid::PropertyVariableType::T), 1.e-10); }