LORENE
diff_dsdx2.C
1 /*
2  * Methods for the class Diff_dsdx2
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_dsdx2.C,v 1.4 2016/12/05 16:17:50 j_novak Exp $
32  * $Log: diff_dsdx2.C,v $
33  * Revision 1.4 2016/12/05 16:17:50 j_novak
34  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35  *
36  * Revision 1.3 2014/10/13 08:52:50 j_novak
37  * Lorene classes and functions now belong to the namespace Lorene.
38  *
39  * Revision 1.2 2014/10/06 15:13:04 j_novak
40  * Modified #include directives to use c++ syntax.
41  *
42  * Revision 1.1 2005/01/10 16:34:52 j_novak
43  * New class for 1D mono-domain differential operators.
44  *
45  *
46  * $Header: /cvsroot/Lorene/C++/Source/Diff/diff_dsdx2.C,v 1.4 2016/12/05 16:17:50 j_novak Exp $
47  *
48  */
49 
50 // C headers
51 #include <cassert>
52 #include <cstdlib>
53 
54 // Lorene headers
55 #include "diff.h"
56 #include "proto.h"
57 
58 namespace Lorene {
59 
60 namespace {
61  int nap = 0 ;
62  Matrice* tab[MAX_BASE*Diff::max_points] ;
63  int nr_done[Diff::max_points] ;
64 }
65 
66 Diff_dsdx2::Diff_dsdx2(int base_r, int nr) : Diff(base_r, nr) {
67  initialize() ;
68 }
69 
70 Diff_dsdx2::Diff_dsdx2(const Diff_dsdx2& diff_in) : Diff(diff_in) {
71  assert (nap != 0) ;
72 }
73 
75 
77  if (nap == 0) {
78  for (int i=0; i<max_points; i++) {
79  nr_done[i] = -1 ;
80  for (int j=0; j<MAX_BASE; j++)
81  tab[j*max_points+i] = 0x0 ;
82  }
83  nap = 1 ;
84  }
85  return ;
86 }
87 
88 void Diff_dsdx2::operator=(const Diff_dsdx2& diff_in) {
89  assert (nap != 0) ;
90  Diff::operator=(diff_in) ;
91 
92 }
93 
95 
96  bool done = false ;
97  int indice ;
98  for (indice =0; indice<max_points; indice++) {
99  if (nr_done[indice] == npoints) {
100  if (tab[base*max_points + indice] != 0x0) done = true ;
101  break ;
102  }
103  if (nr_done[indice] == -1)
104  break ;
105  }
106  if (!done) { //The computation must be done ...
107  if (indice == max_points) {
108  cerr << "Diff_dsdx2::get_matrice() : no space left!!" << '\n'
109  << "The value of Diff.max_points must be increased..." << endl ;
110  abort() ;
111  }
112  nr_done[indice] = npoints ;
113  tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
114  Matrice& resu = *tab[base*max_points + indice] ;
115  resu.set_etat_qcq() ;
116 
117  double* vect = new double[npoints] ;
118  for (int i=0; i<npoints; i++) {
119  for (int j=0; j<npoints; j++)
120  vect[j] = 0. ;
121  vect[i] = 1. ;
122  d2sdx2_1d(npoints, &vect, base << TRA_R) ;
123  for (int j=0; j<npoints; j++)
124  resu.set(j,i) = vect[j] ;
125  }
126  delete [] vect ;
127  }
128 
129  return *tab[base*max_points + indice] ;
130 }
131 
132 ostream& Diff_dsdx2::operator>>(ostream& ost) const {
133 
134  ost << " d2 / dx2 " << endl ;
135  return ost ;
136 
137 }
138 }
Class for the elementary differential operator (see the base class Diff ).
Definition: diff.h:172
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_dsdx2.C:132
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
void operator=(const Diff_dsdx2 &)
Assignment to another Diff_dsdx2.
Definition: diff_dsdx2.C:88
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_dsdx2()
Destructor.
Definition: diff_dsdx2.C:74
Matrix handling.
Definition: matrice.h:152
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_dsdx2.C:94
void operator=(const Diff &)
Assignment to another Diff.
Definition: diff.C:78
void initialize()
Initializes arrays.
Definition: diff_dsdx2.C:76
double & set(int j, int i)
Read/write of a particuliar element.
Definition: matrice.h:277
Diff_dsdx2(int base_r, int nr)
Standard constructor.
Definition: diff_dsdx2.C:66
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144