Skip to content
Snippets Groups Projects
Commit 76ab964c authored by wenqing's avatar wenqing
Browse files

[FL] Added composite fluid property classes

parent b760757b
No related branches found
No related tags found
No related merge requests found
/**
* \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 */
/**
* \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
/**
* \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 */
......@@ -15,22 +15,12 @@
#include <array>
#include <string>
#include "PropertyVariableType.h"
namespace MaterialLib
{
namespace Fluid
{
/// Variable that determine the property.
enum class PropertyVariableType
{
T = 0, ///< temperature.
p = 1, ///< pressure.
rho = p, ///< density. For some models, rho substitutes p
number_of_variables = 2 ///< Number of property variables.
};
const unsigned PropertyVariableNumber =
static_cast<unsigned>(PropertyVariableType::number_of_variables);
/// Base class of fluid density properties
class FluidProperty
{
......
/**
* \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 PropertyVariableType.h
*
* Created on November 29, 2016, 2:28 PM
*/
#ifndef OGS_PROPERTY_VARIABLE_TYPE_H
#define OGS_PROPERTY_VARIABLE_TYPE_H
namespace MaterialLib
{
namespace Fluid
{
/// Variable that determine the property.
enum class PropertyVariableType
{
T = 0, ///< temperature.
p = 1, ///< pressure.
rho = p, ///< density. For some models, rho substitutes p
number_of_variables = 2 ///< Number of property variables.
};
const unsigned PropertyVariableNumber =
static_cast<unsigned>(PropertyVariableType::number_of_variables);
} // end namespace
} // end namespace
#endif /* OGS_PROPERTY_VARIABLE_TYPE_H */
/**
* \brief Test Composite density viscosity models
*
* \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 TestCompositeDensityViscosityModel.cpp
*
*/
#include <gtest/gtest.h>
#include <memory>
#include <cmath>
#include "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"
using namespace MaterialLib;
using namespace MaterialLib::Fluid;
using ArrayType = MaterialLib::Fluid::FluidProperty::ArrayType;
template <typename F>
std::unique_ptr<FluidProperty> createTestModel(const char xml[], F func,
const std::string& key)
{
auto const ptree = readXml(xml);
BaseLib::ConfigTree conf(ptree, "", BaseLib::ConfigTree::onerror,
BaseLib::ConfigTree::onwarning);
auto const& sub_config = conf.getConfigSubtree(key);
return func(sub_config);
}
TEST(MaterialFluidModel, checkCompositeDensityViscosityModel)
{
const char xml_d[] =
"<density>"
" <type>TemperatureDependent</type>"
" <temperature0> 293.0 </temperature0> "
" <beta> 4.3e-4 </beta> "
" <rho0>1000.</rho0>"
"</density>";
auto rho = createTestModel(xml_d, createFluidDensityModel, "density");
const char xml_v[] =
"<viscosity>"
" <type>TemperatureDependent</type>"
" <mu0>1.e-3 </mu0>"
" <tc>293.</tc>"
" <tv>368.</tv>"
"</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)));
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),
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),
1.e-10);
ASSERT_NEAR(1000.0 * 4.3e-4, composite_fluid_model->getdValue(
PropertyType::Density, vars,
Fluid::PropertyVariableType::T),
1.e-10);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment