LORENE
diff_xdsdx2.C
1 /*
2  * Methods for the class Diff_xdsdx2
3  *
4  * (see file diff.h for documentation).
5  *
6  */
7 
8 /*
9  * Copyright (c) 2005 Jerome Novak
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License version 2
15  * as published by the Free Software Foundation.
16  *
17  * LORENE is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with LORENE; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  */
27 
28 
29 
30 /*
31  * $Id: diff_xdsdx2.C,v 1.5 2016/12/05 16:17:50 j_novak Exp $
32  * $Log: diff_xdsdx2.C,v $
33  * Revision 1.5 2016/12/05 16:17:50 j_novak
34  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35  *
36  * Revision 1.4 2014/10/13 08:52:51 j_novak
37  * Lorene classes and functions now belong to the namespace Lorene.
38  *
39  * Revision 1.3 2014/10/06 15:13:05 j_novak
40  * Modified #include directives to use c++ syntax.
41  *
42  * Revision 1.2 2007/12/11 15:28:11 jl_cornou
43  * Jacobi(0,2) polynomials partially implemented
44  *
45  * Revision 1.1 2005/01/10 16:34:52 j_novak
46  * New class for 1D mono-domain differential operators.
47  *
48  *
49  * $Header: /cvsroot/Lorene/C++/Source/Diff/diff_xdsdx2.C,v 1.5 2016/12/05 16:17:50 j_novak Exp $
50  *
51  */
52 
53 // C headers
54 #include <cassert>
55 #include <cstdlib>
56 
57 // Lorene headers
58 #include "diff.h"
59 #include "proto.h"
60 
61 namespace Lorene {
62 void multxpun_1d(int, double**, int) ;
63 
64 namespace {
65  int nap = 0 ;
66  Matrice* tab[MAX_BASE*Diff::max_points] ;
67  int nr_done[Diff::max_points] ;
68 }
69 
70 Diff_xdsdx2::Diff_xdsdx2(int base_r, int nr) : Diff(base_r, nr) {
71  initialize() ;
72  assert ((base != R_CHEBP)&&(base != R_CHEBI)) ;
73 }
74 
75 Diff_xdsdx2::Diff_xdsdx2(const Diff_xdsdx2& diff_in) : Diff(diff_in) {
76  assert (nap != 0) ;
77  assert ((base != R_CHEBP)&&(base != R_CHEBI)) ;
78 }
79 
81 
83  if (nap == 0) {
84  for (int i=0; i<max_points; i++) {
85  nr_done[i] = -1 ;
86  for (int j=0; j<MAX_BASE; j++)
87  tab[j*max_points+i] = 0x0 ;
88  }
89  nap = 1 ;
90  }
91  return ;
92 }
93 
94 void Diff_xdsdx2::operator=(const Diff_xdsdx2& diff_in) {
95  assert (nap != 0) ;
96  Diff::operator=(diff_in) ;
97 
98 }
99 
101 
102  bool done = false ;
103  int indice ;
104  for (indice =0; indice<max_points; indice++) {
105  if (nr_done[indice] == npoints) {
106  if (tab[base*max_points + indice] != 0x0) done = true ;
107  break ;
108  }
109  if (nr_done[indice] == -1)
110  break ;
111  }
112  if (!done) { //The computation must be done ...
113  if (indice == max_points) {
114  cerr << "Diff_xdsdx2::get_matrice() : no space left!!" << '\n'
115  << "The value of Diff.max_points must be increased..." << endl ;
116  abort() ;
117  }
118  nr_done[indice] = npoints ;
119  tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
120  Matrice& resu = *tab[base*max_points + indice] ;
121  resu.set_etat_qcq() ;
122 
123  double* vect = new double[npoints] ;
124  double* cres = new double[npoints] ;
125  for (int i=0; i<npoints; i++) {
126  for (int j=0; j<npoints; j++)
127  vect[j] = 0. ;
128  vect[i] = 1. ;
129  d2sdx2_1d(npoints, &vect, base << TRA_R) ;
130  if (base == R_CHEBU) {
131  mult_xm1_1d_cheb(npoints, vect, cres) ;
132  for (int j=0; j<npoints; j++)
133  resu.set(j,i) = cres[j] ;
134  }
135  else if (base == R_JACO02) {
136  multxpun_1d(npoints, &vect, base << TRA_R) ;
137  for (int j=0; j<npoints; j++)
138  resu.set(j,i) = vect[j] ;
139  }
140  else {
141  multx_1d(npoints, &vect, base << TRA_R) ;
142  for (int j=0; j<npoints; j++)
143  resu.set(j,i) = vect[j] ;
144  }
145  }
146  delete [] vect ;
147  delete [] cres ;
148  }
149  return *tab[base*max_points + indice] ;
150 }
151 
152 ostream& Diff_xdsdx2::operator>>(ostream& ost) const {
153 
154  ost << " x d2 / dx2 " << endl ;
155 
156  return ost ;
157 
158 }
159 }
Base (abstract) class for 1D spectral differential operators in one domain.
Definition: diff.h:65
Lorene prototypes.
Definition: app_hor.h:67
static const int max_points
Maximal number of matrices stored per base.
Definition: diff.h:71
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_xdsdx2.C:152
void initialize()
Initializes arrays.
Definition: diff_xdsdx2.C:82
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
virtual ~Diff_xdsdx2()
Destructor.
Definition: diff_xdsdx2.C:80
Diff_xdsdx2(int base_r, int nr)
Standard constructor.
Definition: diff_xdsdx2.C:70
int npoints
Number of coefficients.
Definition: diff.h:75
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_xdsdx2.C:100
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
int base
Base in radial direction.
Definition: diff.h:74
Matrix handling.
Definition: matrice.h:152
void operator=(const Diff_xdsdx2 &)
Assignment to another Diff_xdsdx2.
Definition: diff_xdsdx2.C:94
void operator=(const Diff &)
Assignment to another Diff.
Definition: diff.C:78
double & set(int j, int i)
Read/write of a particuliar element.
Definition: matrice.h:277
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
Class for the elementary differential operator (see the base class Diff ).
Definition: diff.h:531
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144