00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 char diff_xdsdx_C[] = "$Header: /cvsroot/Lorene/C++/Source/Diff/diff_xdsdx.C,v 1.3 2007/12/11 15:28:11 jl_cornou Exp $" ;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include <assert.h>
00049 #include <stdlib.h>
00050
00051
00052 #include "diff.h"
00053 #include "proto.h"
00054
00055 void xpundsdx_1d(int, double**, int) ;
00056
00057 namespace {
00058 int nap = 0 ;
00059 Matrice* tab[MAX_BASE*Diff::max_points] ;
00060 int nr_done[Diff::max_points] ;
00061 }
00062
00063 Diff_xdsdx::Diff_xdsdx(int base_r, int nr) : Diff(base_r, nr) {
00064 initialize() ;
00065 }
00066
00067 Diff_xdsdx::Diff_xdsdx(const Diff_xdsdx& diff_in) : Diff(diff_in) {
00068 assert (nap != 0) ;
00069 }
00070
00071 Diff_xdsdx::~Diff_xdsdx() {}
00072
00073 void Diff_xdsdx::initialize() {
00074 if (nap == 0) {
00075 for (int i=0; i<max_points; i++) {
00076 nr_done[i] = -1 ;
00077 for (int j=0; j<MAX_BASE; j++)
00078 tab[j*max_points+i] = 0x0 ;
00079 }
00080 nap = 1 ;
00081 }
00082 return ;
00083 }
00084
00085 void Diff_xdsdx::operator=(const Diff_xdsdx& diff_in) {
00086 assert (nap != 0) ;
00087 Diff::operator=(diff_in) ;
00088
00089 }
00090
00091 const Matrice& Diff_xdsdx::get_matrice() const {
00092
00093 bool done = false ;
00094 int indice ;
00095 for (indice =0; indice<max_points; indice++) {
00096 if (nr_done[indice] == npoints) {
00097 if (tab[base*max_points + indice] != 0x0) done = true ;
00098 break ;
00099 }
00100 if (nr_done[indice] == -1)
00101 break ;
00102 }
00103 if (!done) {
00104 if (indice == max_points) {
00105 cerr << "Diff_xdsdx::get_matrice() : no space left!!" << '\n'
00106 << "The value of Diff.max_points must be increased..." << endl ;
00107 abort() ;
00108 }
00109 nr_done[indice] = npoints ;
00110 tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
00111 Matrice& resu = *tab[base*max_points + indice] ;
00112 resu.set_etat_qcq() ;
00113
00114 double* vect = new double[npoints] ;
00115 double* cres = new double[npoints] ;
00116 for (int i=0; i<npoints; i++) {
00117 for (int j=0; j<npoints; j++)
00118 vect[j] = 0. ;
00119 vect[i] = 1. ;
00120
00121 switch (base) {
00122
00123 case R_JACO02 : {
00124 xpundsdx_1d(npoints, &vect, base << TRA_R) ;
00125 for (int j=0 ; j<npoints; j++)
00126 resu.set(j,i) = vect[j] ;
00127 }
00128 break ;
00129
00130 case R_CHEBU : {
00131 dsdx_1d(npoints, &vect, R_CHEBU) ;
00132 mult_xm1_1d_cheb(npoints, vect, cres) ;
00133 for (int j=0; j<npoints; j++)
00134 resu.set(j,i) = cres[j] ;
00135 }
00136 break ;
00137
00138 default : {
00139 xdsdx_1d(npoints, &vect, base << TRA_R) ;
00140 for (int j=0; j<npoints; j++)
00141 resu.set(j,i) = vect[j] ;
00142 }
00143 break ;
00144 }
00145 }
00146 delete [] vect ;
00147 delete [] cres ;
00148 }
00149
00150 return *tab[base*max_points + indice] ;
00151 }
00152
00153 ostream& Diff_xdsdx::operator>>(ostream& ost) const {
00154
00155 ost << " xi * d / dx " << endl ;
00156 return ost ;
00157
00158 }