LORENE
diff_id.C
1 /*
2  * Methods for the class Diff_id
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_id.C,v 1.4 2016/12/05 16:17:50 j_novak Exp $
32  * $Log: diff_id.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:05 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_id.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_id::Diff_id(int base_r, int nr) : Diff(base_r, nr) {
67  initialize() ;
68 }
69 
70 Diff_id::Diff_id(const Diff_id& 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_id::operator=(const Diff_id& diff_in) {
89  assert (nap != 0) ;
90  Diff::operator=(diff_in) ;
91 
92 }
93 
94 const Matrice& Diff_id::get_matrice() const {
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_id::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  for (int i=0; i<npoints; i++) {
118  for (int j=0; j<npoints; j++)
119  resu.set(i,j) = 0. ;
120  resu.set(i,i) = 1. ;
121  }
122  }
123  return *tab[base*max_points + indice] ;
124 }
125 
126 ostream& Diff_id::operator>>(ostream& ost) const {
127 
128  ost << " Identity " << endl ;
129 
130  return ost ;
131 
132 }
133 }
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_id.C:126
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 ~Diff_id()
Destructor.
Definition: diff_id.C:74
int npoints
Number of coefficients.
Definition: diff.h:75
Class for the elementary differential operator Identity (see the base class Diff ).
Definition: diff.h:210
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_id.C:76
Diff_id(int base_r, int nr)
Standard constructor.
Definition: diff_id.C:66
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_id.C:94
void operator=(const Diff_id &)
Assignment to another Diff_id.
Definition: diff_id.C:88
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144