39 #ifndef GETFEM_GLOBAL_FUNCTION_H__ 40 #define GETFEM_GLOBAL_FUNCTION_H__ 53 dim_type dim()
const {
return dim_; }
56 { GMM_ASSERT1(
false,
"this global_function has no value"); }
58 { GMM_ASSERT1(
false,
"this global_function has no gradient"); }
60 { GMM_ASSERT1(
false,
"this global_function has no hessian"); }
62 virtual bool is_in_support(
const base_node & )
const {
return true; }
63 virtual void bounding_box(base_node &bmin, base_node &bmax)
const {
64 GMM_ASSERT1(bmin.size() == dim_ && bmax.size() == dim_,
66 for (
auto&& xx : bmin) xx = -1e+25;
67 for (
auto&& xx : bmax) xx = 1e+25;
71 { DAL_STORED_OBJECT_DEBUG_CREATED(
this,
"Global function");}
73 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function"); }
76 typedef std::shared_ptr<const global_function> pglobal_function;
86 virtual scalar_type val(
const base_node &pt)
const = 0;
87 virtual void grad(
const base_node &pt, base_small_vector&)
const = 0;
88 virtual void hess(
const base_node &pt, base_matrix&)
const = 0;
91 { DAL_STORED_OBJECT_DEBUG_CREATED(
this,
"Global function simple");}
92 virtual ~global_function_simple()
93 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function simple"); }
96 class global_function_parser :
public global_function_simple {
98 ga_function f_val, f_grad, f_hess;
99 mutable model_real_plain_vector pt_;
101 virtual scalar_type val(
const base_node &pt)
const;
102 virtual const base_tensor &tensor_val(
const base_node &pt)
const;
103 virtual void grad(
const base_node &pt, base_small_vector &g)
const;
104 virtual void hess(
const base_node &pt, base_matrix &h)
const;
106 global_function_parser(dim_type dim_,
107 const std::string &sval,
108 const std::string &sgrad=
"",
109 const std::string &shess=
"");
110 virtual ~global_function_parser()
111 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function parser"); }
116 std::vector<pglobal_function> functions;
121 virtual bool is_in_support(
const base_node &p)
const;
122 virtual void bounding_box(base_node &bmin_, base_node &bmax_)
const;
123 global_function_sum(
const std::vector<pglobal_function> &funcs);
124 global_function_sum(pglobal_function f1, pglobal_function f2);
125 global_function_sum(pglobal_function f1, pglobal_function f2,
126 pglobal_function f3);
127 global_function_sum(pglobal_function f1, pglobal_function f2,
128 pglobal_function f3, pglobal_function f4);
129 virtual ~global_function_sum()
130 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function sum"); }
134 pglobal_function f1, f2;
139 virtual bool is_in_support(
const base_node &p)
const;
140 virtual void bounding_box(base_node &bmin_, base_node &bmax_)
const;
141 global_function_product(pglobal_function f1_, pglobal_function f2_);
142 virtual ~global_function_product()
143 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function product"); }
148 const base_node bmin, bmax;
152 mutable model_real_plain_vector pt_;
155 {
return f->val(c); }
161 virtual bool is_in_support(
const base_node &)
const;
162 virtual void bounding_box(base_node &bmin_, base_node &bmax_)
const {
168 global_function_bounded(pglobal_function f_,
169 const base_node &bmin_,
const base_node &bmax_,
170 const std::string &is_in_expr=
"");
171 virtual ~global_function_bounded()
172 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Global function bounded"); }
183 std::vector<scalar_type> U;
187 mutable bgeot::rtree::pbox_set boxlst;
192 const std::vector<scalar_type> &U_);
193 bool find_a_point(
const base_node &pt, base_node &ptr,
195 bool eval(
const base_node &pt, base_vector &val, base_matrix &grad)
const;
198 typedef std::shared_ptr<const interpolator_on_mesh_fem>
199 pinterpolator_on_mesh_fem;
206 virtual scalar_type val(scalar_type x, scalar_type y)
const = 0;
207 virtual base_small_vector grad(scalar_type x, scalar_type y)
const = 0;
208 virtual base_matrix hess(scalar_type x, scalar_type y)
const = 0;
212 typedef std::shared_ptr<const abstract_xy_function> pxy_function;
216 ga_function f_val, f_grad, f_hess;
217 mutable model_real_plain_vector ptx, pty, ptr, ptt;
219 virtual scalar_type val(scalar_type x, scalar_type y)
const;
220 virtual base_small_vector grad(scalar_type x, scalar_type y)
const;
221 virtual base_matrix hess(scalar_type x, scalar_type y)
const;
223 parser_xy_function(
const std::string &sval,
224 const std::string &sgrad=
"0;0;",
225 const std::string &shess=
"0;0;0;0;");
226 virtual ~parser_xy_function() {}
231 virtual scalar_type val(scalar_type x, scalar_type y)
const;
232 virtual base_small_vector grad(scalar_type x, scalar_type y)
const;
233 virtual base_matrix hess(scalar_type x, scalar_type y)
const;
234 crack_singular_xy_function(
unsigned l_) : l(l_) {}
235 virtual ~crack_singular_xy_function() {}
239 enum { NOCUTOFF = -1,
240 EXPONENTIAL_CUTOFF = 0,
241 POLYNOMIAL_CUTOFF = 1,
242 POLYNOMIAL2_CUTOFF=2 };
244 scalar_type a4, r1, r0;
245 virtual scalar_type val(scalar_type x, scalar_type y)
const;
246 virtual base_small_vector grad(scalar_type x, scalar_type y)
const;
247 virtual base_matrix hess(scalar_type x, scalar_type y)
const;
248 cutoff_xy_function(
int fun_num, scalar_type r,
249 scalar_type r1, scalar_type r0);
250 virtual ~cutoff_xy_function() {}
254 pinterpolator_on_mesh_fem itp;
256 virtual scalar_type val(scalar_type x, scalar_type y)
const {
257 base_vector v; base_matrix g;
258 itp->eval(base_node(x,y), v, g);
261 virtual base_small_vector grad(scalar_type x, scalar_type y)
const {
262 base_vector v; base_matrix g;
263 itp->eval(base_node(x,y), v, g);
264 return base_small_vector(g(component,0), g(component,1));
266 virtual base_matrix hess(scalar_type, scalar_type)
const 267 { GMM_ASSERT1(
false,
"Sorry, to be done ..."); }
268 interpolated_xy_function(
const pinterpolator_on_mesh_fem &itp_,
270 itp(itp_), component(c) {}
271 virtual ~interpolated_xy_function() {}
275 pxy_function fn1, fn2;
276 scalar_type val(scalar_type x, scalar_type y)
const {
277 return fn1->val(x,y) * fn2->val(x,y);
279 base_small_vector grad(scalar_type x, scalar_type y)
const {
280 return fn1->grad(x,y)*fn2->val(x,y) + fn1->val(x,y)*fn2->grad(x,y);
282 virtual base_matrix hess(scalar_type x, scalar_type y)
const {
283 base_matrix h = fn1->hess(x,y);
284 gmm::scale(h, fn2->val(x,y));
285 gmm::add(gmm::scaled(fn2->hess(x,y), fn1->val(x,y)), h);
286 gmm::rank_two_update(h, fn1->grad(x,y), fn2->grad(x,y));
289 product_of_xy_functions(pxy_function &fn1_, pxy_function &fn2_)
290 : fn1(fn1_), fn2(fn2_) {}
291 virtual ~product_of_xy_functions() {}
295 pxy_function fn1, fn2;
296 scalar_type val(scalar_type x, scalar_type y)
const {
297 return fn1->val(x,y) + fn2->val(x,y);
299 base_small_vector grad(scalar_type x, scalar_type y)
const {
300 return fn1->grad(x,y) + fn2->grad(x,y);
302 virtual base_matrix hess(scalar_type x, scalar_type y)
const {
303 base_matrix h = fn1->hess(x,y);
304 gmm::add(fn2->hess(x,y), h);
307 add_of_xy_functions(
const pxy_function &fn1_,
const pxy_function &fn2_)
308 : fn1(fn1_), fn2(fn2_) {}
309 virtual ~add_of_xy_functions() {}
317 global_function_on_level_set(
const level_set &ls,
const pxy_function &fn);
320 global_function_on_level_sets(
const std::vector<level_set> &lsets,
321 const pxy_function &fn);
base class for static stored objects
inherit from this class to define new global functions.
a general structure for interpolation of a function defined by a mesh_fem and a vector U at any point...
Define the getfem::mesh_fem class.
does the inversion of the geometric transformation for a given convex
size_t size_type
used as the common size type in the library
structure passed as the argument of fem interpolation functions.
below a list of simple functions of (x,y) used for building the crack singular functions ...
A langage for generic assembly of pde boundary value problems.
GEneric Tool for Finite Element Methods.
Describe a finite element method linked to a mesh.
Balanced tree of n-dimensional rectangles.
region-tree for window/point search on a set of rectangles.