Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capillary pressure models #1517

Merged
merged 9 commits into from
Nov 9, 2016
Merged

Capillary pressure models #1517

merged 9 commits into from
Nov 9, 2016

Conversation

wenqing
Copy link
Member

@wenqing wenqing commented Nov 3, 2016

This PR presents:

  • Base class for capillary pressure model
  • class for van Genuchten capillaryPressure model
  • class for BrookCoreyCapillaryPressure model
  • Creator for capillary pressure models
  • unit tests for these classes

@@ -120,6 +120,16 @@ inline double to_radians(double degrees) {
return degrees*boost::math::constants::pi<double>()/180.;
}

template<typename Type> Type limitValueInInterval(const Type variable,
const Type lower_bound,
const Type upper_bound)
Copy link
Member

@endJunction endJunction Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to pass the types by universal reference (Type&&) to avoid copies if the types are expensive to copy.
My bad. Not working this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type could be integer or real type.

double getCapillaryPressure(const double saturation) const override;

/// Get capillary pressure.
double getSturation(const double capillary_pressure) const override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment mentions pressure, but this is saturation.
Typo in saturation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrented.

* Note:
* \f[m=1/(1-n)\f]
*/
class BrookCoreyCapillaryPressure final : public CapillaryPressureSaturation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to call it BrookCoreyCapillaryPressureSaturation to reflect that it is having both p and s and also is derived from CapillaryPressureSaturation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name accordingly.

{
}

BrookCoreyCapillaryPressure(const BrookCoreyCapillaryPressure& orig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be shortened to

BrookCoreyCapillaryPressure(const BrookCoreyCapillaryPressure&) = default;

Also if copy constructor is present, add the move ctor, and maybe both assignments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the copy constructor because it is not used.

const double _mm; ///< Exponent (<=1.0), n=1/(1-mm).
const double _Pc_max; ///< Maximum capillaray pressure

const double _perturbation = std::numeric_limits<double>::epsilon();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short comment how the _perturbation is used.
From what I have seen in the code, maybe 'offset' would be a better name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name to _minor_offset

Copy link
Member

@endJunction endJunction left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes required. Looking good otherwise. I didn't check the formulae.

virtual double getCapillaryPressure(const double saturation) const = 0;

/// Get capillary pressure.
virtual double getSturation(const double capillary_ressure) const = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with comment and typo here.

*/
static std::unique_ptr<CapillaryPressureSaturation>
createBrookCoreyOrVanGenuchten(BaseLib::ConfigTree const& config,
const bool is_brook_corey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split it into two different create functions and avoid the boolean parameter.
Adding a third model here would be difficult.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split it.

@wenqing wenqing force-pushed the perm_Pc_S branch 2 times, most recently from c3c7931 to 4a7c08c Compare November 3, 2016 15:34
@wenqing
Copy link
Member Author

wenqing commented Nov 3, 2016

@endJunction Formulas are checked by the unit tests, which use the results from OGS5 as expected data for comparison.

@@ -89,9 +82,9 @@ class BrookCoreyCapillaryPressure final : public CapillaryPressureSaturation
const double _mm; ///< Exponent (<=1.0), n=1/(1-mm).
const double _Pc_max; ///< Maximum capillaray pressure

const double _perturbation = std::numeric_limits<double>::epsilon();
const double _minor_offset = std::numeric_limits<double>::epsilon();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs a description how it is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a description.

*/
static std::unique_ptr<CapillaryPressureSaturation>
createVanGenuchten(BaseLib::ConfigTree const& config,
const bool is_brook_corey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean is no longer needed, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@ogsbot
Copy link
Member

ogsbot commented Nov 3, 2016

Jenkins: OGS-6/Linux-PRs-dynamic failed: https://svn.ufz.de:8443/job/OGS-6/job/Linux-PRs-dynamic/1579/

Copy link
Collaborator

@chleh chleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments from my side.

const double saturation) const
{
const double S = MathLib::limitValueInInterval(
saturation, _Sr + _minor_offset, _Smax - _minor_offset);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any mathematical concerns here? p_C(S) is cut off at certain values, but the derivative does not take that into account.
Maybe that's common practice, though...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to avoid the overflow in std::pow(Se, -n) when S=0. When S=Smax, setting S=Smax - _minor_offset avoids Pc=0. Therefore, it is a numerical 'tricky' to keep computation run with a tiny losing in accuracy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation.

* [4] \f$ P_c^{\mbox{max}}\f$
*/
BrookCoreyCapillaryPressureSaturation(
std::array<double, 5> const& parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to pass the parameters individually rather than as array, because they all mean different things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

{
/**
\param config ConfigTree object which contains the input data
including <type>BrookCorey</type>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put a check that the type is really BrookCorey.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.


/**
\param config ConfigTree object which contains the input data
including <type>vanGenuchten</type>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise: I'd put a check to the function body.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{material_property__porous_medium__porous_medium__capillary_pressure__type}
auto const type = config.getConfigParameter<std::string>("type");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: If you'd add checks to the specific create functions, you'd switch to peek...() here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chleh Thanks for above comments. I will improve the classes in the Fluid directories according to these comments once the current work is finished.

* Created on October 28, 2016, 6:05 PM
*/

#include "vanGenuchtenCapillaryPressureSaturation.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all files start uppercase. Maybe we should stick to this convention as much as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

* [4] \f$ P_c^{\mbox{max}}\f$
*/
vanGenuchtenCapillaryPressureSaturation(
std::array<double, 5> const& parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before: I'd prefer no array to be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

for (std::size_t i = 0; i < S.size(); i++)
{
ASSERT_NEAR(pc[i], pc_model->getCapillaryPressure(S[i]), 1.e-5);
ASSERT_NEAR(S[i], pc_model->getSaturation(pc[i]), 1.e-5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem too strict, since S is on the order of 0.1...1
Or is it impossible to decrease this tolerance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decreased the tolerance for S to 1e-14.

for (std::size_t i = 0; i < S.size(); i++)
{
ASSERT_NEAR(pc[i], pc_model->getCapillaryPressure(S[i]), 1.e-5);
ASSERT_NEAR(S[i], pc_model->getSaturation(pc[i]), 1.e-5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's possible to make the tolerance a bit stricter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decreased the tolerance for S to 1e-14.

* as
* \f[p_b=\rho g/\alpha\f]
*/
class vanGenuchtenCapillaryPressureSaturation final
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class names should start uppercase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

@wenqing wenqing force-pushed the perm_Pc_S branch 2 times, most recently from b7979cf to 76faead Compare November 8, 2016 15:42
added model type check in the function body according to the comments by Christoph
//! \ogs_file_param{material_property__porous_medium__porous_medium__capillary_pressure__type}
config.checkConfigParameter("type", "BrookCorey");

//! \ogs_file_param{material_property__porous_medium__porous_medium__capillary_pressure__type__pd}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken the type in the string must be BrookCorey because it is specific for that model.
@chleh Please correct me if I'm talking garbage.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The line must be
//! \ogs_file_param{material_property__porous_medium__porous_medium__capillary_pressure__BrookCorey__pd}
same for the other doxygen comments.
IMHO since documenting input file parameters is somewhat tricky, it could be fixed when writing documentation. But in order to write documentation it is better to first have test case where this material model is acutally used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

@endJunction
Copy link
Member

Merge if the config parameter documentation strings are correct.

@wenqing wenqing merged commit 3b3bfca into ufz:master Nov 9, 2016
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants