From 41f29cbf3076db51b96f240d27d432ef31b8aa71 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 14 Apr 2015 16:00:24 +0200 Subject: A major rewrite. Split the code into multiple files, drop the GSL dependency, introduce configurable logging, random cleanups. --- basis.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 basis.c (limited to 'basis.c') diff --git a/basis.c b/basis.c new file mode 100644 index 0000000..0735752 --- /dev/null +++ b/basis.c @@ -0,0 +1,74 @@ +/* + * Copyright 2014-2015 Anton Khirnov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * definitions of the basis functions for the spectral method + */ + +#include + +#include "internal.h" + +static double sb_even_eval(double coord, int idx, double sf) +{ + double val = atan2(sf, coord); + + idx *= 2; // even only + + return sin((idx + 1) * val); +} + +static double sb_even_eval_diff1(double coord, int idx, double sf) +{ + double val = atan2(sf, coord); + + idx *= 2; // even only + + return - sf * (idx + 1) * cos((idx + 1) * val) / (SQR(sf) + SQR(coord)); +} + +static double sb_even_eval_diff2(double coord, int idx, double sf) +{ + double val = atan2(sf, coord); + + idx *= 2; // even only + + return sf * (idx + 1) * (2 * coord * cos((idx + 1) * val) - sf * (idx + 1) * sin((idx + 1) * val)) / SQR(SQR(sf) + SQR(coord)); +} + +static double sb_even_colloc_point(int order, int idx, double sf) +{ + double t; + + idx = order - idx - 1; + + t = (idx + 2) * M_PI / (2 * order + 2); + return sf / tan(t); +} + +/* + * The basis of even (n = 2 * idx) SB functions (Boyd 2000, Ch 17.9) + * SB(x, n) = sin((n + 1) arccot(|x| / L)) + * They are symmetric wrt origin and decay as odd powers of x in infinity. + */ +const BasisSet bdi_sb_even_basis = { + .eval = sb_even_eval, + .eval_diff1 = sb_even_eval_diff1, + .eval_diff2 = sb_even_eval_diff2, + .colloc_point = sb_even_colloc_point, +}; -- cgit v1.2.3