LORENE
diff_dsdx.C
1 /*
2  * Methods for the class Diff_dsdx
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_dsdx.C,v 1.5 2016/12/05 16:17:50 j_novak Exp $
32  * $Log: diff_dsdx.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:50 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 2006/04/10 15:20:52 j_novak
43  * Operators dsdx and sx can now be used in the nucleus.
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_dsdx.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 
63 namespace {
64  int nap = 0 ;
65  Matrice* tab[MAX_BASE*Diff::max_points] ;
66  int nr_done[Diff::max_points] ;
67 }
68 
69 Diff_dsdx::Diff_dsdx(int base_r, int nr) : Diff(base_r, nr) {
70  initialize() ;
71 }
72 
73 Diff_dsdx::Diff_dsdx(const Diff_dsdx& diff_in) : Diff(diff_in) {
74  assert (nap != 0) ;
75 }
76 
78 
80  if (nap == 0) {
81  for (int i=0; i<max_points; i++) {
82  nr_done[i] = -1 ;
83  for (int j=0; j<MAX_BASE; j++)
84  tab[j*max_points+i] = 0x0 ;
85  }
86  nap = 1 ;
87  }
88  return ;
89 }
90 
91 void Diff_dsdx::operator=(const Diff_dsdx& diff_in) {
92  assert (nap != 0) ;
93  Diff::operator=(diff_in) ;
94 
95 }
96 
98 
99  bool done = false ;
100  int indice ;
101  for (indice =0; indice<max_points; indice++) {
102  if (nr_done[indice] == npoints) {
103  if (tab[base*max_points + indice] != 0x0) done = true ;
104  break ;
105  }
106  if (nr_done[indice] == -1)
107  break ;
108  }
109  if (!done) { //The computation must be done ...
110  if (indice == max_points) {
111  cerr << "Diff_dsdx::get_matrice() : no space left!!" << '\n'
112  << "The value of Diff.max_points must be increased..." << endl ;
113  abort() ;
114  }
115  nr_done[indice] = npoints ;
116  tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
117  Matrice& resu = *tab[base*max_points + indice] ;
118  resu.set_etat_qcq() ;
119 
120  double* vect = new double[npoints] ;
121  for (int i=0; i<npoints; i++) {
122  for (int j=0; j<npoints; j++)
123  vect[j] = 0. ;
124  vect[i] = 1. ;
125  dsdx_1d(npoints, &vect, base << TRA_R) ;
126  for (int j=0; j<npoints; j++)
127  resu.set(j,i) = vect[j] ;
128  }
129  delete [] vect ;
130  }
131  return *tab[base*max_points + indice] ;
132 }
133 
134 ostream& Diff_dsdx::operator>>(ostream& ost) const {
135 
136  ost << " d / dx " << endl ;
137 
138  return ost ;
139 
140 }
141 }
virtual ~Diff_dsdx()
Destructor.
Definition: diff_dsdx.C:77
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 const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_dsdx.C:97
Class for the elementary differential operator (see the base class Diff ).
Definition: diff.h:129
void operator=(const Diff_dsdx &)
Assignment to another Diff_dsdx.
Definition: diff_dsdx.C:91
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
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 initialize()
Initializes arrays.
Definition: diff_dsdx.C:79
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_dsdx.C:134
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
Diff_dsdx(int base_r, int nr)
Standard constructor, the base is that of the functions the operator is acting on (starting base)...
Definition: diff_dsdx.C:69
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144