/* * Functions for spectral summation to a Valencia-type grid (see grille_val.h) * */ /* * Copyright (c) 2001 and 2004 Jerome Novak * * This file is part of LORENE. * * LORENE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * LORENE 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 LORENE; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ char gval_from_spectral_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/gval_from_spectral.C,v 1.14 2014/10/13 08:53:48 j_novak Exp $" ; /* * $Id: gval_from_spectral.C,v 1.14 2014/10/13 08:53:48 j_novak Exp $ * $Log: gval_from_spectral.C,v $ * Revision 1.14 2014/10/13 08:53:48 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.13 2014/10/06 15:13:22 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.12 2009/10/28 13:40:23 j_novak * General case for the theta symmetry (now should work). * * Revision 1.11 2009/10/21 13:19:04 j_novak * Going back (temporary) to previous version. * * Revision 1.9 2007/12/21 10:46:29 j_novak * In "from_spectral..." functions: better treatment of ETATZERO case. * * Revision 1.8 2007/11/02 16:49:12 j_novak * Suppression of intermediate array for spectral summation. * * Revision 1.7 2006/10/02 07:41:03 j_novak * Corrected an error in the case r=0, when exporting to a cartesian grid. * * Revision 1.6 2005/06/23 13:44:18 j_novak * Removed some old comments. * * Revision 1.5 2005/06/23 13:40:08 j_novak * The tests on the number of dimensions have been changed to handle better the * axisymmetric case. * * Revision 1.4 2005/06/22 09:11:17 lm_lin * * Grid wedding: convert from the old C++ object "Cmp" to "Scalar". * * Revision 1.3 2004/12/17 13:35:04 m_forot * Add the case T_LEG * * Revision 1.2 2004/05/07 13:19:24 j_novak * Prevention of warnings * * Revision 1.1 2004/05/07 12:32:13 j_novak * New summation from spectral to FD grid. Much faster! * * * $Header: /cvsroot/Lorene/C++/Source/Valencia/gval_from_spectral.C,v 1.14 2014/10/13 08:53:48 j_novak Exp $ * */ #include // Lorene headers #include "grille_val.h" #include "proto_f77.h" //-------------------------------------- // Sommation depuis une grille spectrale //-------------------------------------- namespace Lorene { void Grille_val::somme_spectrale1(const Scalar& meudon, double* resu, int taille_in) const { int taille = dim.dim[0]+2*nfantome ; if (taille != taille_in) { cout << "Gval_spher::somme_spectral2():\n" ; cout << "grid size incompatible with array size... exiting!" << endl ; abort() ; } int nrv = dim.dim[0]+nfantome ; const Map& mp = meudon.get_mp() ; int l ; double xi ; for (int i=0; it[i],0.,0.,l,xi) ; resu[i] = meudon.get_spectral_va().val_point_jk(l, xi, 0, 0) ; } for (int i=nrv; it[ix])*(x->t[ix]) ; for (int iz=nfantome; izt[iz])*(zr->t[iz]) + xx2) ; theta = (rr != 0. ? acos((zr->t[iz])/rr) : 0) ; mp.val_lx(rr, theta, phi, l, xi0) ; resu[inum] = meudon.get_spectral_va().val_point(l, xi0, theta, phi) ; inum++ ; } for (int iz=nzv; izt[iy] ; double yy2 = yy*yy ; for (int ix=0; ixt[ix] ; double xx2 = xx*xx ; for (int iz=nfantome; izt[iz])*(zr->t[iz]) + xx2 + yy2) ; theta = (rr != 0. ? acos((zr->t[iz])/rr) : 0. ); phi = (rr != 0. ? atan2(yy, xx) : 0. ) ; // return value in [-M_PI,M_PI], should work mp.val_lx(rr, theta, phi, l, xi0) ; resu[inum] = meudon.get_spectral_va().val_point(l, xi0, theta, phi) ; inum++ ; } for (int iz=nzv; iz=2) ; int nrv = dim.dim[0] + nfantome ; int ntv = dim.dim[1] + nfantome ; int nrv2 = dim.dim[0] + 2*nfantome ; int ntv2 = dim.dim[1] + 2*nfantome ; int taille = ntv2*nrv2 ; if (taille != taille_in) { cout << "Gval_spher::somme_spectral2():\n" ; cout << "grid size incompatible with array size... exiting!" << endl ; abort() ; } const Map& mp = meudon.get_mp() ; int l ; double xi, rr, theta ; double phi0 = 0 ; int inum = 0 ; for (int it=0; itt[it] ; for (int ir=nfantome; irt[ir] ; mp.val_lx(rr, theta, phi0, l, xi) ; resu[inum] = meudon.get_spectral_va().val_point(l, xi, theta, phi0) ; inum++ ; } for (int ir=nrv; irt[it] ; for (int ir=nfantome; irt[ir] ; mp.val_lx(rr, theta, phi0, l, xi) ; resu[inum] = meudon.get_spectral_va().val_point(l, xi, theta, phi0) ; inum++ ; } for (int ir=nrv; irt[it] ; for (int ir=nfantome; irt[ir] ; mp.val_lx(rr, theta, phi0, l, xi) ; resu[inum] = meudon.get_spectral_va().val_point(l, xi, theta, phi0) ; inum++ ; } for (int ir=nrv; ir(&mp) ; assert(mpaff != 0x0) ; #endif const Mg3d* mg = mp.get_mg() ; int ntm = mg->get_nt(0) ; int npm = mg->get_np(0) ; int nz = mg->get_nzone() ; #ifndef NDEBUG for (int lz=1; lzget_nt(lz)) ; //Same angular grids in all domains... assert (npm == mg->get_np(lz)) ; } #endif //Intermediate quantities //----------------------- double* alpha = new double[nrv0*(npm+2)*ntm] ; double* p_coef = alpha ; double* chebnri = 0x0 ; //size ~ nrv0 * (npm+2) * nr ... int* idom = 0x0 ; initialize_spectral_r(mp, meudon.get_spectral_va().get_base(), idom, chebnri) ; double* p_func = chebnri ; Mtbl_cf& mtbcf = *meudon.get_spectral_va().c_cf ; double** coefm = new double*[nz] ; for (int lz=0; lzget_etat() != ETATNONDEF) ; coefm[lz] = (mtbcf.t[lz])->t ; if (coefm[lz] == 0x0) { int sizem = mg->get_nr(lz)*ntm*(npm+2) ; coefm[lz] = new double[sizem] ; double* pcf = coefm[lz] ; for (int i=0; iget_nr(lz) ; for (int mpm=0; mpmt == 0x0) delete [] coefm[lz] ; } delete [] coefm ; delete [] chebnri ; delete [] idom ; double* beta = new double[ntv0*nrv0*(npm+2)] ; p_coef = beta ; double* tetlj = 0x0 ; initialize_spectral_theta(mp, meudon.get_spectral_va().get_base(), tetlj) ; p_func = tetlj ; double* p_interm = alpha ; //Second partial summation //------------------------ for (int jtv=0; jtvget_np(0) ; int ntm = mg->get_nt(0) ; assert (idom == 0x0) ; idom = new int[nrv0] ; double* xi = new double[nrv0] ; int nrmax = 0 ; for (int i=0; it[i+nfantome], 0., 0., idom[i], xi[i]) ; nrmax += mg->get_nr(idom[i]) ; } assert (chebnri == 0x0) ; chebnri = new double[(npm+2)*ntm*nrmax] ; double* p_out = chebnri ; for (int irv=0; irvget_type_r(idom[irv]) == RARE) ; int nmax = (nucleus ? 2*mg->get_nr(idom[irv]) + 1 : mg->get_nr(idom[irv])) ; double* cheb = new double[nmax] ; cheb[0] = 1. ; cheb[1] = xi[irv] ; for (int ir=2; irget_nr(idom[irv]); ir++) { *p_out = cheb[fact*ir+par] ; p_out++ ; } } // Loop on it } // Loop on ip delete [] cheb ; }// Loop on irv delete [] xi ; } void Gval_spher::initialize_spectral_theta(const Map& mp, const Base_val& base, double*& tetlj) const { int ntv0 = dim.dim[1] ; const Mg3d* mg = mp.get_mg() ; int npm = mg->get_np(0) ; int ntm = mg->get_nt(0) ; int base_t = base.get_base_t(0) ; assert (tetlj == 0x0) ; tetlj = new double[(npm+2)*ntv0*ntm] ; double* p_out = tetlj ; for (int jtv=0; jtvt[jtv+nfantome] ; for (int mpm=0; mpm < npm+2; mpm++) { for (int ltm=0; ltmget_np(0) ; int base_p = base.get_base_p(0) ; assert (expmk == 0x0) ; expmk = new double[(npm+2)*npv0] ; double* p_out = expmk ; for (int kpv=0; kpvt[kpv+nfantome] ; for (int mpm=0; mpm < npm+2; mpm++) { switch (base_p) { //## One should use array of functions... case P_COSSIN : { int m = mpm / 2 ; *p_out = ( (mpm%2 == 0) ? cos(m*fi) : sin(m*fi) ) ; break ; } case P_COSSIN_P : { int m = mpm / 2 ; *p_out = ( (mpm%2 == 0) ? cos(2*m*fi) : sin(2*m*fi) ) ; break ; } case P_COSSIN_I : { int m = mpm / 2 ; *p_out = ( (mpm%2 == 0) ? cos((2*m+1)*fi) : sin((2*m+1)*fi) ) ; break ; } default : { cout << "Gval_spher::initialize_spectral_phi : " << '\n' << "Unexpected phi base !" << '\n' << "Base : " << base_p << endl ; abort() ; break ; } } p_out++ ; } //Loop on mpm } //Loop on kpv } }