src/test_lapl.cpp
author Alexey Ozeritsky <aozeritsky@gmail.com>
Fri Jun 11 21:50:18 2010 +0400 (20 months ago)
changeset 142 2aa3b89e9ccc
parent 1122c23436cf99b
child 175c295a4e9c9e5
permissions -rw-r--r--
fix
     1 #include <math.h>
     2 #include <stdlib.h>
     3 #include <stdio.h>
     4 
     5 #include <vector>
     6 
     7 #include "lapl.h"
     8 #include "linal.h"
     9 
    10 #ifdef max
    11 #undef max
    12 #endif
    13 
    14 using namespace std;
    15 using namespace linal;
    16 
    17 static inline double max(double a, double b)
    18 {
    19 	return (a > b) ? a : b;
    20 }
    21 
    22 
    23 double rp(double x, double y) {
    24 	return -6.0 * sin(y) * sin(2.0 * x);
    25 }
    26 
    27 double ans(double x, double y) {
    28 	return sin(y) * sin(2.0 * x);
    29 }
    30 
    31 double ans2(double x, double y, double t)
    32 {
    33 	return x*sin(y+t)*ipow(cos(x),4);
    34 }
    35 
    36 double rp2(double x, double y, double t, double mu, double sigma)
    37 {
    38 	return sin(y+t)*ipow(cos(x),2)*(9*mu*sin(x)*cos(x)+20*mu*x*ipow(cos(x),2)+sigma*x*ipow(cos(x),2)-15*mu*x);
    39 }
    40 
    41 void solve()
    42 {
    43 	long nlat = 3*19, nlon = 3*36;
    44 	double dlat = M_PI / (nlat-1);
    45 	double dlon = 2. * M_PI /nlon;
    46 	int i, j;
    47 
    48 	double mu    = -0.5;
    49 	double sigma = 1000;
    50 
    51 	vector < double > u(nlat * nlon);
    52 	vector < double > v(nlat * nlon);
    53 	vector < double > r(nlat * nlon);
    54 
    55 	SphereOperator op(nlat, nlon, 0);
    56 	SphereLaplace lapl(op);
    57 
    58 	double nev1 = 0;
    59 
    60 	for (i = 0; i < nlat; ++i) {
    61 		for (j = 0; j < nlon; ++j) {
    62 			double phi    = -0.5 * M_PI + i * dlat;
    63 			double lambda = j * dlon;
    64 
    65 			r[i * nlon + j] = rp2(phi, lambda, 0, mu, sigma);
    66 		}
    67 	}
    68 
    69 	lapl.solve(&u[0], &r[0], -mu, sigma);
    70 
    71 	for (i = 0; i < nlat; ++i) {
    72 		for (j = 0; j < nlon; ++j) {
    73 			double phi    = -0.5 * M_PI + i * dlat;
    74 			double lambda = j * dlon;
    75 
    76 			nev1 = max(nev1, fabs(u[i * nlon + j] - ans2(phi, lambda, 0)));
    77 		}
    78 	}
    79 
    80 	fprintf(stderr, "nev1=%.16le \n", nev1);
    81 
    82 	lapl.calc(&v[0], &u[0]);
    83 	nev1 = 0.0;
    84 
    85 	for (i = 0; i < nlat; ++i) {
    86 		for (j = 0; j < nlon; ++j) {
    87 			double phi    = -0.5 * M_PI + i * dlat;
    88 			double lambda = j * dlon;
    89 
    90 			nev1 = max(nev1, fabs(5 * v[i * nlon + j] - r[i * nlon + j]));
    91 		}
    92 	}
    93 
    94 	fprintf(stderr, "nev1=%.16le \n", nev1);
    95 }
    96 
    97 int main(int argc, char * argv[])
    98 {
    99 	solve();
   100 }
   101