|
PISM, A Parallel Ice Sheet Model
stable v0.5
|
00001 /* Copyright (C) 2004-2009 Ed Bueler 00002 00003 This file is part of PISM. 00004 00005 PISM is free software; you can redistribute it and/or modify it under the 00006 terms of the GNU General Public License as published by the Free Software 00007 Foundation; either version 2 of the License, or (at your option) any later 00008 version. 00009 00010 PISM is distributed in the hope that it will be useful, but WITHOUT ANY 00011 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00013 details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with PISM; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #include <math.h> 00021 #include <gsl/gsl_spline.h> 00022 #include <petscvec.h> 00023 #include "cubature.h" 00024 00025 00026 PetscErrorCode conv2_same(Vec vA, int mA, int nA, Vec vB, int mB, int nB, 00027 Vec &vresult) { 00028 PetscErrorCode ierr; 00029 double sum, **A, **B, **result; 00030 int i,j,r,s; 00031 00032 ierr = VecGetArray2d(vA, mA, nA, 0, 0, &A); CHKERRQ(ierr); 00033 ierr = VecGetArray2d(vB, mB, nB, 0, 0, &B); CHKERRQ(ierr); 00034 ierr = VecGetArray2d(vresult, mA, nA, 0, 0, &result); CHKERRQ(ierr); 00035 for (i=0; i < mA; i++) { 00036 for (j=0; j < nA; j++) { 00037 sum = 0.0; 00038 for (r = PetscMax(0, i - mB + 1); r < PetscMin(mA, i); r++) { 00039 for (s = PetscMax(0, j - nB + 1); s < PetscMin(nA, j); s++) { 00040 sum += A[r][s] * B[i - r][j - s]; 00041 } 00042 } 00043 result[i][j] = sum; 00044 } 00045 } 00046 ierr = VecRestoreArray2d(vA, mA, nA, 0, 0, &A); CHKERRQ(ierr); 00047 ierr = VecRestoreArray2d(vB, mB, nB, 0, 0, &B); CHKERRQ(ierr); 00048 ierr = VecRestoreArray2d(vresult, mA, nA, 0, 0, &result); CHKERRQ(ierr); 00049 return 0; 00050 } 00051 00052 00053 double interp1_linear(double* x, double* Y, int N, double xi) { 00054 00055 gsl_interp_accel* acc = gsl_interp_accel_alloc(); 00056 gsl_spline* spline = gsl_spline_alloc(gsl_interp_linear,N); 00057 gsl_spline_init(spline,x,Y,N); 00058 00059 double result = gsl_spline_eval(spline,xi,acc); 00060 00061 gsl_spline_free(spline); 00062 gsl_interp_accel_free(acc); 00063 return result; 00064 } 00065 00066 00067 double dblquad_cubature(integrand f, double ax, double bx, double ay, double by, 00068 double reqRelError, void *fdata) { 00069 00070 double xmin[2] = {ax, ay}; 00071 double xmax[2] = {bx, by}; 00072 unsigned maxEval = 5000; 00073 double val, estimated_error; 00074 00075 /* see cubature.h: */ 00076 adapt_integrate(f, fdata, 2, xmin, xmax, 00077 maxEval, 0.0, reqRelError, &val, &estimated_error); 00078 return val; 00079 } 00080
1.7.5.1