serial/testftns.hpp
00001 /* testftns.hpp
00002  * 
00003  * Some original functions used for testing the adaptive routines, 
00004  * now in their own header file (as templates) for house keeping. 
00005  */
00006 
00007 #ifndef MULTIQUAD_TESTFTNS_HPP
00008 #define MULTIQUAD_TESTFTNS_HPP
00009 
00010 #include <cmath>
00011 
00012 /* Defines tensor product of functions f(t) = cos(omega_j * t).
00013  * Paramteter: omega = (omega_1,..., omega_d).
00014  */
00015 template <typename FP>
00016 FP prod_cos(unsigned int dim, const FP* x, void* params)
00017 {
00018     FP* omega = (FP*)params;
00019     FP p = 1;
00020     for (size_t j = 0; j < dim; ++j) {
00021         p *= cos(omega[j] * x[j]);
00022     }
00023     return p;
00024 }
00025 
00026 /* Defines f(x) = cos(omega * |x|) for single parameter omega.
00027  */
00028 template <typename FP>
00029 FP radial_cos(unsigned int dim, const FP* x, void* params)
00030 {
00031     FP* omega = (FP*)params;
00032     FP r2 = 0;
00033     for (size_t j = 0; j < dim; ++j) {
00034         r2 += x[j] * x[j];
00035     }
00036     return cos(omega[0] * sqrt(r2));
00037 }
00038 
00039 /* Defines tensor product of 1-dimensional f(t) = 1 - t^{alpha_j}.
00040  * Parameter: alpha = (alpha_1,..., alpha_d).
00041  */
00042 template <typename FP>
00043 FP prod_bell(unsigned int dim, const FP* x, void* params)
00044 {
00045     FP* alpha = (FP*)params;
00046     FP p = 1;
00047     for (size_t j = 0; j < dim; ++j) {
00048         p *= 1 - pow(x[j], alpha[j]);
00049     }
00050     return p;
00051 }
00052 
00053 /* Defines f(x) = 1 - |x|^alpha, 0 ≤ |x| ≤ 1, and zero otherwise. 
00054  */
00055 template <typename FP>
00056 FP radial_bell(unsigned int dim, const FP* x, void* params)
00057 {
00058     FP* alpha = (FP*)params;
00059     FP r2 = 0;
00060     for (size_t j = 0; j < dim; ++j) {
00061         r2 += x[j] * x[j];
00062     }
00063     return (r2 < 1) ? 1 - pow(r2, alpha[0]/2) : 0;
00064 }
00065 
00066 /* Defines f(x) = |x|^alpha.
00067  */
00068 template <typename FP>
00069 FP radial_power(unsigned int dim, const FP* x, void* params)
00070 {
00071     FP* alpha = (FP*)params;
00072     FP r2 = 0;
00073     for (size_t j = 0; j < dim; ++j) {
00074         r2 += x[j] * x[j];
00075     }
00076     return pow(r2, alpha[0]/2); 
00077 }
00078 
00079 #endif // MULTIQUAD_TESTFTNS_HPP
 All Classes Functions Variables