QUGaR 0.0.4
Loading...
Searching...
No Matches
impl_funcs_lib_macros.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------
2//
3// Copyright (C) 2025-present by Pablo Antolin
4//
5// This file is part of the QUGaR library.
6//
7// SPDX-License-Identifier: MIT
8//
9// --------------------------------------------------------------------------
10
11#ifndef QUGAR_IMPL_FUNCS_LIB_MACROS_HPP
12#define QUGAR_IMPL_FUNCS_LIB_MACROS_HPP
13
20
21
22// NOLINTBEGIN (cppcoreguidelines-macro-usage, bugprone-macro-parentheses)
23#define declare_impl_func_virtual_interface \
24 template<typename T> using Hessian = ImplicitFunc<dim>::template Hessian<T>; \
25 \
26 [[nodiscard]] virtual real operator()(const Point<dim> &point) const final; \
27 \
28 [[nodiscard]] virtual ::algoim::Interval<dim> operator()(const Point<dim, ::algoim::Interval<dim>> &point) \
29 const final; \
30 \
31 [[nodiscard]] virtual Vector<real, dim> grad(const Point<dim> &point) const final; \
32 \
33 [[nodiscard]] virtual Vector<::algoim::Interval<dim>, dim> grad(const Point<dim, ::algoim::Interval<dim>> &point) \
34 const final; \
35 \
36 [[nodiscard]] Hessian<real> virtual hessian(const Point<dim> &point) const final; \
37 \
38private: \
39 template<typename T> [[nodiscard]] T eval_(const Point<dim, T> &point) const; \
40 \
41 template<typename T> [[nodiscard]] Vector<T, dim> grad_(const Point<dim, T> &point) const; \
42 \
43 template<typename T> [[nodiscard]] Hessian<T> hessian_(const Point<dim, T> &point) const
44
45#define declare_impl_func_virtual_interface_2D \
46 template<typename T> using Hessian = ImplicitFunc<2>::template Hessian<T>; \
47 \
48 [[nodiscard]] virtual real operator()(const Point<2> &point) const final; \
49 \
50 [[nodiscard]] virtual ::algoim::Interval<2> operator()(const Point<2, ::algoim::Interval<2>> &point) const final; \
51 \
52 [[nodiscard]] virtual Vector<real, 2> grad(const Point<2> &point) const final; \
53 \
54 [[nodiscard]] virtual Vector<::algoim::Interval<2>, 2> grad(const Point<2, ::algoim::Interval<2>> &point) \
55 const final; \
56 \
57 [[nodiscard]] Hessian<real> virtual hessian(const Point<2> &point) const final; \
58 \
59private: \
60 template<typename T> [[nodiscard]] T eval_(const Point<2, T> &point) const; \
61 \
62 template<typename T> [[nodiscard]] Vector<T, 2> grad_(const Point<2, T> &point) const; \
63 \
64 template<typename T> [[nodiscard]] Hessian<T> hessian_(const Point<2, T> &point) const
65
66
67#define declare_impl_func_virtual_interface_3D \
68 template<typename T> using Hessian = ImplicitFunc<3>::template Hessian<T>; \
69 \
70 [[nodiscard]] virtual real operator()(const Point<3> &point) const final; \
71 \
72 [[nodiscard]] virtual ::algoim::Interval<3> operator()(const Point<3, ::algoim::Interval<3>> &point) const final; \
73 \
74 [[nodiscard]] virtual Vector<real, 3> grad(const Point<3> &point) const final; \
75 \
76 [[nodiscard]] virtual Vector<::algoim::Interval<3>, 3> grad(const Point<3, ::algoim::Interval<3>> &point) \
77 const final; \
78 \
79 [[nodiscard]] Hessian<real> virtual hessian(const Point<3> &point) const final; \
80 \
81private: \
82 template<typename T> [[nodiscard]] T eval_(const Point<3, T> &point) const; \
83 \
84 template<typename T> [[nodiscard]] Vector<T, 3> grad_(const Point<3, T> &point) const; \
85 \
86 template<typename T> [[nodiscard]] Hessian<T> hessian_(const Point<3, T> &point) const
87
88
89#define implement_impl_func(FUNC_NAME) \
90 \
91 template<int dim> real FUNC_NAME<dim>::operator()(const Point<dim> &point) const \
92 { \
93 return this->eval_(point); \
94 } \
95 \
96 template<int dim> \
97 ::algoim::Interval<dim> FUNC_NAME<dim>::operator()(const Point<dim, ::algoim::Interval<dim>> &point) const \
98 { \
99 return this->eval_(point); \
100 } \
101 \
102 template<int dim> Vector<real, dim> FUNC_NAME<dim>::grad(const Point<dim> &point) const \
103 { \
104 return this->grad_(point); \
105 } \
106 \
107 template<int dim> \
108 Vector<::algoim::Interval<dim>, dim> FUNC_NAME<dim>::grad(const Point<dim, ::algoim::Interval<dim>> &point) const \
109 { \
110 return this->grad_(point); \
111 } \
112 \
113 template<int dim> auto FUNC_NAME<dim>::hessian(const Point<dim> &point) const -> Hessian<real> \
114 { \
115 return this->hessian_(point); \
116 }
117
118#define implement_impl_func_2D(FUNC_NAME) \
119 \
120 real FUNC_NAME::operator()(const Point<2> &point) const \
121 { \
122 return this->eval_(point); \
123 } \
124 \
125 ::algoim::Interval<2> FUNC_NAME::operator()(const Point<2, ::algoim::Interval<2>> &point) const \
126 { \
127 return this->eval_(point); \
128 } \
129 \
130 Vector<real, 2> FUNC_NAME::grad(const Point<2> &point) const \
131 { \
132 return this->grad_(point); \
133 } \
134 \
135 Vector<::algoim::Interval<2>, 2> FUNC_NAME::grad(const Point<2, ::algoim::Interval<2>> &point) const \
136 { \
137 return this->grad_(point); \
138 } \
139 \
140 auto FUNC_NAME::hessian(const Point<2> &point) const -> Hessian<real> \
141 { \
142 return this->hessian_(point); \
143 }
144
145#define implement_impl_func_3D(FUNC_NAME) \
146 \
147 real FUNC_NAME::operator()(const Point<3> &point) const \
148 { \
149 return this->eval_(point); \
150 } \
151 \
152 ::algoim::Interval<3> FUNC_NAME::operator()(const Point<3, ::algoim::Interval<3>> &point) const \
153 { \
154 return this->eval_(point); \
155 } \
156 \
157 Vector<real, 3> FUNC_NAME::grad(const Point<3> &point) const \
158 { \
159 return this->grad_(point); \
160 } \
161 \
162 Vector<::algoim::Interval<3>, 3> FUNC_NAME::grad(const Point<3, ::algoim::Interval<3>> &point) const \
163 { \
164 return this->grad_(point); \
165 } \
166 \
167 auto FUNC_NAME::hessian(const Point<3> &point) const -> Hessian<real> \
168 { \
169 return this->hessian_(point); \
170 }
171
172#define implement_impl_func_transf(FUNC_NAME) \
173 \
174 template<int dim> real FUNC_NAME<dim>::operator()(const Point<dim> &point) const \
175 { \
176 return this->eval_(this->transf_.transform_point(point)); \
177 } \
178 \
179 template<int dim> \
180 ::algoim::Interval<dim> FUNC_NAME<dim>::operator()(const Point<dim, ::algoim::Interval<dim>> &point) const \
181 { \
182 return this->eval_(this->transf_.transform_point(point)); \
183 } \
184 \
185 template<int dim> Vector<real, dim> FUNC_NAME<dim>::grad(const Point<dim> &point) const \
186 { \
187 return this->transf_.transform_vector(this->grad_(this->transf_.transform_point(point))); \
188 } \
189 \
190 template<int dim> \
191 Vector<::algoim::Interval<dim>, dim> FUNC_NAME<dim>::grad(const Point<dim, ::algoim::Interval<dim>> &point) const \
192 { \
193 return this->transf_.transform_vector(this->grad_(this->transf_.transform_point(point))); \
194 } \
195 \
196 template<int dim> auto FUNC_NAME<dim>::hessian(const Point<dim> &point) const -> Hessian<real> \
197 { \
198 return this->transf_.transform_tensor(this->hessian_(this->transf_.transform_point(point))); \
199 }
200// NOLINTEND (cppcoreguidelines-macro-usage, bugprone-macro-parentheses)
201
202
203#endif// QUGAR_IMPL_FUNCS_LIB_MACROS_HPP