scalar_exp_filter.C

00001 /*
00002  *  Function applying an exponential filter to a Scalar: 
00003  *  sigma(n/N) = exp(alpha*(n/N)^(2p)). See scalar.h for documentation.
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2007  Jerome Novak
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License version 2
00013  *   as published by the Free Software Foundation.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 char scalar_exp_filter_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_exp_filter.C,v 1.3 2012/01/17 10:29:27 j_penner Exp $" ;
00027 
00028 /*
00029  * $Id: scalar_exp_filter.C,v 1.3 2012/01/17 10:29:27 j_penner Exp $
00030  * $Log: scalar_exp_filter.C,v $
00031  * Revision 1.3  2012/01/17 10:29:27  j_penner
00032  * added two routines to handle generalized exponential filtering
00033  *
00034  * Revision 1.2  2007/10/31 10:50:16  j_novak
00035  * Testing whether the coefficients are zero in a given domain.
00036  *
00037  * Revision 1.1  2007/10/31 10:33:13  j_novak
00038  * Added exponential filters to smooth Gibbs-type phenomena.
00039  *
00040  *
00041  * $Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_exp_filter.C,v 1.3 2012/01/17 10:29:27 j_penner Exp $
00042  *
00043  */
00044 
00045 // C headers
00046 #include <assert.h>
00047 #include <math.h>
00048 
00049 // Lorene headers
00050 #include "tensor.h"
00051 #include "proto.h"
00052 
00053 void Scalar::exponential_filter_r(int lzmin, int lzmax, int p, 
00054               double alpha) {
00055     assert(lzmin >= 0) ;
00056     const Mg3d& mgrid = *mp->get_mg() ;
00057 #ifndef NDEBUG
00058     int nz = mgrid.get_nzone() ;
00059 #endif
00060     assert(lzmax < nz) ;
00061     assert(etat != ETATNONDEF) ;
00062     if (etat == ETATZERO) return ;
00063     va.coef() ;
00064     assert(va.c_cf != 0x0) ;
00065     assert(alpha < 0.) ;
00066     double alp = log(pow(10., alpha)) ;
00067     
00068     for (int lz=lzmin; lz<=lzmax; lz++) {
00069     if ((*va.c_cf)(lz).get_etat() == ETATQCQ) 
00070         for (int k=0; k<mgrid.get_np(lz); k++) 
00071         for (int j=0; j<mgrid.get_nt(lz); j++) {
00072             int nr = mgrid.get_nr(lz) ;
00073             for (int i=0; i<nr; i++) {
00074             double eta = double(i)/double(nr) ;
00075             va.c_cf->set(lz, k, j, i) *= exp(alp*pow(eta, 2*p)) ;
00076             }
00077         }
00078     }
00079      if (va.c != 0x0) {
00080     delete va.c ;
00081     va.c = 0x0 ;
00082      }
00083      va.del_deriv() ;
00084      del_deriv() ;
00085     
00086     return ;
00087 }
00088 
00089 void Scalar::sarra_filter_r(int lzmin, int lzmax, double p, 
00090               double alpha) {
00091     assert(lzmin >= 0) ;
00092     const Mg3d& mgrid = *mp->get_mg() ;
00093 #ifndef NDEBUG
00094     int nz = mgrid.get_nzone() ;
00095 #endif
00096     assert(lzmax < nz) ;
00097     assert(etat != ETATNONDEF) ;
00098     if (etat == ETATZERO) return ;
00099     va.coef() ;
00100     assert(va.c_cf != 0x0) ;
00101     assert(alpha < 0.) ;
00102     
00103     for (int lz=lzmin; lz<=lzmax; lz++) {
00104     if ((*va.c_cf)(lz).get_etat() == ETATQCQ) 
00105         for (int k=0; k<mgrid.get_np(lz); k++) 
00106         for (int j=0; j<mgrid.get_nt(lz); j++) {
00107             int nr = mgrid.get_nr(lz) ;
00108             for (int i=0; i<nr; i++) {
00109             double eta = double(i)/double(nr) ;
00110             va.c_cf->set(lz, k, j, i) *= exp(alpha*pow(eta, p)) ;
00111             }
00112         }
00113     }
00114      if (va.c != 0x0) {
00115     delete va.c ;
00116     va.c = 0x0 ;
00117      }
00118      va.del_deriv() ;
00119      del_deriv() ;
00120     
00121     return ;
00122 }
00123 void exp_filter_r_all_domains( Scalar& ss, int p, double alpha ) {
00124     int nz = ss.get_mp().get_mg()->get_nzone() ;
00125     ss.exponential_filter_r(0, nz-1, p, alpha) ;
00126     return ;
00127 }
00128 
00129 void Scalar::sarra_filter_r_all_domains( double p, double alpha ) {
00130     int nz = get_mp().get_mg()->get_nzone() ;
00131     sarra_filter_r(0, nz-1, p, alpha) ;
00132     return ;
00133 }
00134 
00135 void Scalar::exponential_filter_ylm(int lzmin, int lzmax, int p, 
00136               double alpha) {
00137     assert(lzmin >= 0) ;
00138     const Mg3d& mgrid = *mp->get_mg() ;
00139 #ifndef NDEBUG
00140     int nz = mgrid.get_nzone() ;
00141 #endif
00142     assert(lzmax < nz) ;
00143     assert(etat != ETATNONDEF) ;
00144     if (etat == ETATZERO) return ;
00145     double alp = log(pow(10., alpha)) ;
00146     va.ylm() ;
00147     assert(va.c_cf != 0x0) ;
00148     const Base_val& base = va.base ;
00149     int l_q, m_q, base_r ;
00150     
00151     for (int lz=lzmin; lz<=lzmax; lz++) 
00152     if ((*va.c_cf)(lz).get_etat() == ETATQCQ) {
00153         int np = mgrid.get_np(lz) ;
00154         int nt = mgrid.get_nt(lz) ;
00155         int nr = mgrid.get_nr(lz) ;
00156         int lmax = base.give_lmax(mgrid, lz) ; 
00157         for (int k=0; k<np; k++) 
00158         for (int j=0; j<nt; j++) {
00159             base.give_quant_numbers(lz, k, j, m_q, l_q, base_r) ;
00160             if (nullite_plm(j, nt, k, np, base) == 1 ) {
00161             double eta = double(l_q) / double(lmax) ;
00162             double sigma = exp(alp*pow(eta, 2*p)) ;
00163             for (int i=0; i<nr; i++) 
00164                 va.c_cf->set(lz, k, j, i) *= sigma ;
00165             }
00166         }
00167     }
00168     
00169     va.ylm_i() ;
00170     if (va.c != 0x0) {
00171     delete va.c ;
00172     va.c = 0x0 ;
00173     }
00174     va.del_deriv() ;
00175     del_deriv() ;
00176     return ;
00177 }
00178 
00179 void exp_filter_ylm_all_domains(Scalar& ss, int p, double alpha ) {
00180     int nz = ss.get_mp().get_mg()->get_nzone() ;
00181     ss.exponential_filter_ylm(0, nz-1, p, alpha) ;
00182     return ;
00183 }
00184 

Generated on Tue Feb 7 01:35:19 2012 for LORENE by  doxygen 1.4.6