Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cahn_hilliard_filter.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_cahn_hilliard_filter_h
5#define lethe_cahn_hilliard_filter_h
6
8
9/**
10 * @brief Filter phase fraction according to the selected filtering method.
11 */
13{
14public:
16
17 /**
18 * @brief Default destructor.
19 */
20 virtual ~CahnHilliardFilterBase() = default;
21
22 /**
23 * @brief Instantiate and return a pointer to a CahnHilliardFilterBase
24 * object by casting it to the proper child class.
25 *
26 * @param[in] cahn_hilliard_parameters CahnHilliard model parameters.
27 */
28 static std::shared_ptr<CahnHilliardFilterBase>
29 model_cast(const Parameters::CahnHilliard &cahn_hilliard_parameters);
30
31 /**
32 * @brief Calculate the value of the filtered phase fraction.
33 * @param[in] unfiltered_phase Value of the phase fraction before applying
34 * the filter.
35 * @return Value of the phase fraction after applying the filter.
36 */
37 virtual double
38 filter_phase(const double &unfiltered_phase) = 0;
39};
40
41/**
42 * @brief Used as a default when no filter is applied to the phase fraction.
43 *
44 */
46{
47public:
49
50 /**
51 * @brief Return the phase fraction with no modification.
52 */
53 virtual double
54 filter_phase(const double &unfiltered_phase) override
55 {
56 return unfiltered_phase;
57 }
58};
59
60/**
61 * @brief Calculate a filtered phase fraction for Cahn-Hilliard simulations.
62 * In this case, a simple clamping is performed on the phase fraction parameter
63 * for it to remain in the [-1,1] interval.
64 */
66{
67public:
69
70 /**
71 * @brief Calculate the value of the filtered phase fraction.
72 * @param[in] unfiltered_phase Value of the phase fraction before applying the
73 * filter.
74 * @return Value of the phase fraction after applying the filter.
75 */
76 virtual double
77 filter_phase(const double &unfiltered_phase) override
78 {
79 return (std::abs(unfiltered_phase) < 1) ? unfiltered_phase :
80 sgn(unfiltered_phase);
81 }
82};
83
84/**
85 * @brief Calculate a filtered phase fraction for Cahn-Hilliard simulations.
86 *
87 * The filtered phase is defined as \f$\phi_f = \tanh(\beta \phi)\f$ with
88 * \f$ \phi \f$ the unfiltered phase field.
89 */
91{
92public:
94 : beta(beta)
95 {}
96
97 /**
98 * @brief Calculate the value of the filtered phase fraction.
99 * @param[in] unfiltered_phase Value of the phase fraction before applying the
100 * filter.
101 * @return Value of the phase fraction after applying the filter.
102 */
103 virtual double
104 filter_phase(const double &unfiltered_phase) override
105 {
106 return tanh(beta * unfiltered_phase);
107 }
108
109private:
110 /**
111 * User-defined parameter that influences how sharp the filtering is.
112 */
113 const double beta;
114};
115
116#endif
virtual double filter_phase(const double &unfiltered_phase) override
Calculate the value of the filtered phase fraction.
CahnHilliardClipFilter()=default
virtual double filter_phase(const double &unfiltered_phase)=0
Calculate the value of the filtered phase fraction.
static std::shared_ptr< CahnHilliardFilterBase > model_cast(const Parameters::CahnHilliard &cahn_hilliard_parameters)
Instantiate and return a pointer to a CahnHilliardFilterBase object by casting it to the proper child...
CahnHilliardFilterBase()=default
virtual ~CahnHilliardFilterBase()=default
Default destructor.
CahnHilliardNoFilter()=default
virtual double filter_phase(const double &unfiltered_phase) override
Return the phase fraction with no modification.
CahnHilliardTanhFilter(const double beta)
virtual double filter_phase(const double &unfiltered_phase) override
Calculate the value of the filtered phase fraction.
constexpr int sgn(const T val) noexcept
Retrieve the sign of a value.
Definition utilities.h:344