MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
heaviside_filter.hpp
Go to the documentation of this file.
1 /*
2 * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3 * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #ifndef __mast_simp_heaviside_filter_h__
21 #define __mast_simp_heaviside_filter_h__
22 
23 // MAST includes
25 #include <mast/base/exceptions.hpp>
26 
27 namespace MAST {
28 namespace Optimization {
29 namespace Topology {
30 namespace SIMP {
31 
36 template <typename ScalarType, typename FieldType>
38 
39 public:
40 
42  _beta (0.),
43  _eta (0.),
44  _v (nullptr)
45  { }
46 
47  virtual ~HeavisideFilter() {}
48 
49  inline void set_field(const FieldType& v) { _v = &v;}
50 
51  inline void set_parameters(const real_t beta, const real_t eta) {
52 
53  _beta = beta;
54  _eta = eta;
55  }
56 
60  inline ScalarType filter(ScalarType s) const {
61 
62  return ((tanh(_beta*_eta)+tanh(_beta*(s-_eta))) /
63  (tanh(_beta*_eta)+tanh(_beta*(1.-_eta))));
64  }
65 
66 
70  inline ScalarType filter_derivative(ScalarType s,
71  ScalarType ds) const {
72 
73  return ((1.-pow(tanh(_beta*(s-_eta)),2))* _beta * ds /
74  (tanh(_beta*_eta)+tanh(_beta*(1.-_eta))));
75  }
76 
81  template <typename ContextType>
82  inline ScalarType value(const ContextType& c) const {
83 
84  Assert0(_v, "Scalar field not initialized");
85 
86  return ((tanh(_beta*_eta)+tanh(_beta*(_v->value(c)-_eta))) /
87  (tanh(_beta*_eta)+tanh(_beta*(1.-_eta))));
88  }
89 
93  template <typename ContextType, typename ScalarFieldType>
94  inline ScalarType derivative(const ContextType& c,
95  const ScalarFieldType& f) const {
96 
97  Assert0(_v, "Scalar field not initialized");
98 
99  return ((1.-pow(tanh(_beta*(_v->value(c)-_eta)),2))*
100  _beta*_v->derivative(c, f) /
101  (tanh(_beta*_eta)+tanh(_beta*(1.-_eta))));
102  }
103 
104 
105 private:
106 
109  const FieldType *_v;
110 };
111 } // namespace SIMP
112 } // namespace Topology
113 } // namespace Optimization
114 } // namespace MAST
115 
116 #endif // __mast_simp_heaviside_filter_h__
ScalarType value(const ContextType &c) const
This class implements the Heaviside filter defined as .
ScalarType filter_derivative(ScalarType s, ScalarType ds) const
a function to compute the filtered value for given scalar s
ScalarType filter(ScalarType s) const
a function to compute the filtered value for given scalar s
ScalarType derivative(const ContextType &c, const ScalarFieldType &f) const
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
void set_parameters(const real_t beta, const real_t eta)
double real_t