FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
function_traits.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
8#include <kernel/analytic/common.hpp>
9#include <kernel/util/tiny_algebra.hpp>
10
11#include <deque>
12namespace FEAT
13{
14 namespace Solver
15 {
28 template<typename DT_, typename Function_>
29#ifndef DOXYGEN
30 struct OptimizationTestTraits;
31#else
33 {
35 typedef Function_ FunctionType;
39 typedef typename FunctionType::template Evaluator<FuncEvalTraits> EvalType;
41 typedef typename EvalType::ValueType ValueType;
43 typedef typename EvalType::PointType PointType;
44
52 static void get_starting_point(PointType& start)
53 {
54 }
55
63 static void get_minimal_points(std::deque<PointType>& min_points)
64 {
65 }
66
83 template<int sn_>
84 static void get_domain_bounds(Tiny::Vector<DT_, 2, sn_>& domain, int dim)
85 {
86 }
87
93 static String name()
94 {
95 }
96 };
97#endif
98
100 template<typename DT_>
101 struct OptimizationTestTraits<DT_, Analytic::Common::BazaraaShettyFunction>
102 {
103 public:
106 typedef typename FunctionType::template Evaluator<FuncEvalTraits> EvalType;
107 typedef typename EvalType::ValueType ValueType;
108 typedef typename EvalType::PointType PointType;
109
110 static void get_starting_point(PointType& start)
111 {
112 start(0) = DT_(4);
113 start(1) = DT_(2);
114 }
115
116 static void get_minimal_points(std::deque<PointType>& min_points)
117 {
118 min_points.clear();
119 PointType tmp(DT_(0));
120 tmp(0) = DT_(2);
121 tmp(1) = DT_(1);
122 min_points.push_back(tmp);
123 }
124
125 template<int sn_>
126 static void get_domain_bounds(Tiny::Vector<DT_, 2, sn_>& domain, int dim)
127 {
128 XASSERTM((dim >= 0) && (dim <= 2), "get_domain_bounds defined up to dim = 2, but got "+stringify(dim));
129
130 domain(0) = -DT_(0.5);
131 domain(1) = DT_(4.5);
132 }
133
134 static String name()
135 {
136 return "BazaraaShettyFunction";
137 }
138 };
139
140 template<typename DT_>
141 struct OptimizationTestTraits<DT_, Analytic::Common::GoldsteinPriceFunction>
142 {
143 public:
145 typedef Analytic::EvalTraits<DT_, FunctionType> FuncEvalTraits;
146 typedef typename FunctionType::template Evaluator<FuncEvalTraits> EvalType;
147 typedef typename EvalType::ValueType ValueType;
148 typedef typename EvalType::PointType PointType;
149
150 static void get_starting_point(PointType& start)
151 {
152 // This is a nice starting point
153 //start(0) = -DT_(0.5);
154 //start(1) = DT_(0.25);
155
156 // Is is a hard starting point
157 start(0) = DT_(1.5);
158 start(1) = DT_(1.17);
159 }
160
161 static void get_minimal_points(std::deque<PointType>& min_points)
162 {
163 min_points.clear();
164 PointType tmp(DT_(0));
165
166 tmp(0) = DT_(0);
167 tmp(1) = -DT_(1);
168 min_points.push_back(tmp);
169
170 tmp(0) = -DT_(0.6);
171 tmp(1) = -DT_(0.4);
172 min_points.push_back(tmp);
173
174 tmp(0) = DT_(1.2);
175 tmp(1) = DT_(0.8);
176 min_points.push_back(tmp);
177
178 tmp(0) = DT_(1.8);
179 tmp(1) = DT_(0.2);
180 min_points.push_back(tmp);
181 }
182
183 template<int sn_>
184 static void get_domain_bounds(Tiny::Vector<DT_, 2, sn_>& domain, int dim)
185 {
186 XASSERTM((dim >= 0) && (dim <= 2), "get_domain_bounds defined up to dim = 2, but got "+stringify(dim));
187
188 domain(0) = -DT_(0.2);
189 domain(1) = DT_(0.2);
190 }
191
192 static String name()
193 {
194 return "GoldsteinPriceFunction";
195 }
196 };
197
198 template<typename DT_>
199 struct OptimizationTestTraits<DT_, Analytic::Common::HimmelblauFunction>
200 {
201 public:
203 typedef Analytic::EvalTraits<DT_, FunctionType> FuncEvalTraits;
204 typedef typename FunctionType::template Evaluator<FuncEvalTraits> EvalType;
205 typedef typename EvalType::ValueType ValueType;
206 typedef typename EvalType::PointType PointType;
207
208 static void get_starting_point(PointType& start)
209 {
210 start(0) = DT_(1.5);
211 start(1) = DT_(4);
212 }
213
214 static void get_minimal_points(std::deque<PointType>& min_points)
215 {
216 min_points.clear();
217
218 PointType tmp(DT_(0));
219
220 tmp(0) = -DT_(3.77931025337774689189076584129);
221 tmp(1) = -DT_(3.28318599128616941226600051437);
222 min_points.push_back(tmp);
223
224 tmp(0) = -DT_(2.80511808695274485305357239809);
225 tmp(1) = DT_(3.13131251825057296580430072341);
226 min_points.push_back(tmp);
227
228 tmp(0) = DT_(3);
229 tmp(1) = DT_(2);
230 min_points.push_back(tmp);
231
232 tmp(0) = DT_(3.58442834033049174494433823938);
233 tmp(1) = -DT_(1.84812652696440355353830020904);
234 min_points.push_back(tmp);
235 }
236
237 template<int sn_>
238 static void get_domain_bounds(Tiny::Vector<DT_, 2, sn_>& domain, int dim)
239 {
240 XASSERTM((dim >= 0) && (dim <= 2), "get_domain_bounds defined up to dim = 2, but got "+stringify(dim));
241
242 domain(0) = DT_(1);
243 domain(1) = DT_(4.5);
244 }
245
246 static String name()
247 {
248 return "HimmelblauFunction";
249 }
250 };
251
252 template<typename DT_>
253 struct OptimizationTestTraits<DT_, Analytic::Common::RosenbrockFunction>
254 {
255 public:
257 typedef Analytic::EvalTraits<DT_, FunctionType> FuncEvalTraits;
258 typedef typename FunctionType::template Evaluator<FuncEvalTraits> EvalType;
259 typedef typename EvalType::ValueType ValueType;
260 typedef typename EvalType::PointType PointType;
261
262 static void get_starting_point(PointType& start)
263 {
264 start(0) = -DT_(1.9);
265 start(1) = DT_(2);
266 }
267
268 static void get_minimal_points(std::deque<PointType>& min_points)
269 {
270 min_points.clear();
271 min_points.push_back(PointType(DT_(1)));
272 }
273
274 template<int sn_>
275 static void get_domain_bounds(Tiny::Vector<DT_, 2, sn_>& domain, int dim)
276 {
277 if(dim == 0)
278 {
279 domain(0) = -DT_(3);
280 domain(1) = DT_(2);
281 }
282 else if(dim == 1)
283 {
284 domain(0) = -DT_(0.5);
285 domain(1) = DT_(3.5);
286 }
287 else
288 XABORTM("get_domain_bounds defined up to dim = 2, but got "+stringify(dim));
289 }
290
291 static String name()
292 {
293 return "RosenbrockFunction";
294 }
295 };
296
298 } // namespace Solver
299} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
StaticFunction wrapper class template for Analytic::Function interface.
String class implementation.
Definition: string.hpp:46
Tiny Vector class template.
StaticWrapperFunction< 2, GoldsteinPriceStatic, true, true, true > GoldsteinPriceFunction
*‍/
Definition: common.hpp:1527
StaticWrapperFunction< 2, HimmelblauStatic, true, true, true > HimmelblauFunction
*‍/
Definition: common.hpp:1639
StaticWrapperFunction< 2, RosenbrockStatic, true, true, true > RosenbrockFunction
*‍/
Definition: common.hpp:1705
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
Class holding additional information about certain AnalyticFunction used for optimization tests.
static String name()
Returns the name of the AnalyticFunction.
FunctionType::template Evaluator< FuncEvalTraits > EvalType
Type of the evaluator.
EvalType::ValueType ValueType
Type the function maps to.
static void get_domain_bounds(Tiny::Vector< DT_, 2, sn_ > &domain, int dim)
Gets the domain bounds.
static void get_starting_point(PointType &start)
Gets an initial guess to start from.
Analytic::EvalTraits< DT_, FunctionType > FuncEvalTraits
The evaluation traits for this function.
Function_ FunctionType
The AnalyticFunction i.e. from FEAT::Analytic::Common.
EvalType::PointType PointType
Type the function maps from.
static void get_minimal_points(std::deque< PointType > &min_points)
Gets a list of all minimal points.