LORENE
diff_sx.C
1 /*
2  * Methods for the class Diff_sx
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_sx.C,v 1.6 2016/12/05 16:17:50 j_novak Exp $
32  * $Log: diff_sx.C,v $
33  * Revision 1.6 2016/12/05 16:17:50 j_novak
34  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35  *
36  * Revision 1.5 2014/10/13 08:52:51 j_novak
37  * Lorene classes and functions now belong to the namespace Lorene.
38  *
39  * Revision 1.4 2014/10/06 15:13:05 j_novak
40  * Modified #include directives to use c++ syntax.
41  *
42  * Revision 1.3 2007/12/11 15:28:11 jl_cornou
43  * Jacobi(0,2) polynomials partially implemented
44  *
45  * Revision 1.2 2006/04/10 15:20:52 j_novak
46  * Operators dsdx and sx can now be used in the nucleus.
47  *
48  * Revision 1.1 2005/01/10 16:34:52 j_novak
49  * New class for 1D mono-domain differential operators.
50  *
51  *
52  * $Header: /cvsroot/Lorene/C++/Source/Diff/diff_sx.C,v 1.6 2016/12/05 16:17:50 j_novak Exp $
53  *
54  */
55 
56 // C headers
57 #include <cassert>
58 #include <cstdlib>
59 
60 // Lorene headers
61 #include "diff.h"
62 #include "proto.h"
63 
64 namespace Lorene {
65 void sxpun_1d(int, double**, int) ;
66 
67 namespace {
68  int nap = 0 ;
69  Matrice* tab[MAX_BASE*Diff::max_points] ;
70  int nr_done[Diff::max_points] ;
71 }
72 
73 Diff_sx::Diff_sx(int base_r, int nr) : Diff(base_r, nr) {
74  initialize() ;
75  assert(base != R_CHEB) ;
76 }
77 
78 Diff_sx::Diff_sx(const Diff_sx& diff_in) : Diff(diff_in) {
79  assert (nap != 0) ;
80  assert(base != R_CHEB) ;
81 }
82 
84 
86  if (nap == 0) {
87  for (int i=0; i<max_points; i++) {
88  nr_done[i] = -1 ;
89  for (int j=0; j<MAX_BASE; j++)
90  tab[j*max_points+i] = 0x0 ;
91  }
92  nap = 1 ;
93  }
94  return ;
95 }
96 
97 void Diff_sx::operator=(const Diff_sx& diff_in) {
98  assert (nap != 0) ;
99  Diff::operator=(diff_in) ;
100 
101 }
102 
104 
105  bool done = false ;
106  int indice ;
107  for (indice =0; indice<max_points; indice++) {
108  if (nr_done[indice] == npoints) {
109  if (tab[base*max_points + indice] != 0x0) done = true ;
110  break ;
111  }
112  if (nr_done[indice] == -1)
113  break ;
114  }
115  if (!done) { //The computation must be done ...
116  if (indice == max_points) {
117  cerr << "Diff_sx::get_matrice() : no space left!!" << '\n'
118  << "The value of Diff.max_points must be increased..." << endl ;
119  abort() ;
120  }
121  nr_done[indice] = npoints ;
122  tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
123  Matrice& resu = *tab[base*max_points + indice] ;
124  resu.set_etat_qcq() ;
125 
126  double* vect = new double[npoints] ;
127  for (int i=0; i<npoints; i++) {
128  for (int j=0; j<npoints; j++)
129  vect[j] = 0. ;
130  vect[i] = 1. ;
131  if (base == R_JACO02) {
132  sxpun_1d(npoints, &vect, base << TRA_R) ;
133  for (int j=0; j<npoints; j++)
134  resu.set(j,i)=vect[j];
135  }
136  else {
137  sx_1d(npoints, &vect, base << TRA_R) ;
138  for (int j=0; j<npoints; j++)
139  resu.set(j,i) = vect[j] ;
140  }
141  }
142  delete [] vect ;
143  }
144  return *tab[base*max_points + indice] ;
145 }
146 
147 ostream& Diff_sx::operator>>(ostream& ost) const {
148 
149  ost << " Division by x " << endl ;
150 
151  return ost ;
152 
153 }
154 }
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_sx.C:147
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_sx.C:103
Base (abstract) class for 1D spectral differential operators in one domain.
Definition: diff.h:65
void initialize()
Initializes arrays.
Definition: diff_sx.C:85
Lorene prototypes.
Definition: app_hor.h:67
static const int max_points
Maximal number of matrices stored per base.
Definition: diff.h:71
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
Diff_sx(int base_r, int nr)
Standard constructor.
Definition: diff_sx.C:73
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
int base
Base in radial direction.
Definition: diff.h:74
virtual ~Diff_sx()
Destructor.
Definition: diff_sx.C:83
Matrix handling.
Definition: matrice.h:152
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 operator=(const Diff_sx &)
Assignment to another Diff_sx.
Definition: diff_sx.C:97
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
Class for the elementary differential operator division by (see the base class Diff )...
Definition: diff.h:329
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166