LORENE
diff_mx.C
1 /*
2  * Methods for the class Diff_mx
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 char diff_mx_C[] = "$Header: /cvsroot/Lorene/C++/Source/Diff/diff_mx.C,v 1.4 2014/10/13 08:52:50 j_novak Exp $" ;
29 
30 /*
31  * $Id: diff_mx.C,v 1.4 2014/10/13 08:52:50 j_novak Exp $
32  * $Log: diff_mx.C,v $
33  * Revision 1.4 2014/10/13 08:52:50 j_novak
34  * Lorene classes and functions now belong to the namespace Lorene.
35  *
36  * Revision 1.3 2014/10/06 15:13:05 j_novak
37  * Modified #include directives to use c++ syntax.
38  *
39  * Revision 1.2 2007/12/11 15:28:11 jl_cornou
40  * Jacobi(0,2) polynomials partially implemented
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_mx.C,v 1.4 2014/10/13 08:52: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_mx::Diff_mx(int base_r, int nr) : Diff(base_r, nr) {
67  initialize() ;
68  assert ((base != R_CHEBP)&&(base != R_CHEBI)) ;
69 }
70 
71 Diff_mx::Diff_mx(const Diff_mx& diff_in) : Diff(diff_in) {
72  assert (nap != 0) ;
73  assert ((base != R_CHEBP)&&(base != R_CHEBI)) ;
74 }
75 
77 
79  if (nap == 0) {
80  for (int i=0; i<max_points; i++) {
81  nr_done[i] = -1 ;
82  for (int j=0; j<MAX_BASE; j++)
83  tab[j*max_points+i] = 0x0 ;
84  }
85  nap = 1 ;
86  }
87  return ;
88 }
89 
90 void Diff_mx::operator=(const Diff_mx& diff_in) {
91  assert (nap != 0) ;
92  Diff::operator=(diff_in) ;
93 
94 }
95 
96 const Matrice& Diff_mx::get_matrice() const {
97 
98  bool done = false ;
99  int indice ;
100  for (indice =0; indice<max_points; indice++) {
101  if (nr_done[indice] == npoints) {
102  if (tab[base*max_points + indice] != 0x0) done = true ;
103  break ;
104  }
105  if (nr_done[indice] == -1)
106  break ;
107  }
108  if (!done) { //The computation must be done ...
109  if (indice == max_points) {
110  cerr << "Diff_mx::get_matrice() : no space left!!" << '\n'
111  << "The value of Diff.max_points must be increased..." << endl ;
112  abort() ;
113  }
114  nr_done[indice] = npoints ;
115  tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
116  Matrice& resu = *tab[base*max_points + indice] ;
117  resu.set_etat_qcq() ;
118 
119  double* vect = new double[npoints] ;
120  double* cres = 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  if (base == R_CHEBU) {
126  mult_xm1_1d_cheb(npoints, vect, cres) ;
127  for (int j=0; j<npoints; j++)
128  resu.set(j,i) = cres[j] ;
129  }
130  else if (base == R_JACO02) {
131  multxpun_1d(npoints, &vect, base << TRA_R) ;
132  for (int j =0; j<npoints; j++)
133  resu.set(j,i) = vect[j] ;
134  }
135  else {
136  multx_1d(npoints, &vect, base << TRA_R) ;
137  for (int j=0; j<npoints; j++)
138  resu.set(j,i) = vect[j] ;
139  }
140  }
141  delete [] vect ;
142  delete [] cres ;
143  }
144  return *tab[base*max_points + indice] ;
145 }
146 
147 ostream& Diff_mx::operator>>(ostream& ost) const {
148 
149  ost << " Multiplication by x " << endl ;
150 
151  return ost ;
152 
153 }
154 }
Class for the elementary differential operator multiplication by (see the base class Diff ).
Definition: diff.h:250
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition: diff_mx.C:96
virtual ~Diff_mx()
Destructor.
Definition: diff_mx.C:76
void initialize()
Initializes arrays.
Definition: diff_mx.C:78
void operator=(const Diff_mx &)
Assignment to another Diff_mx.
Definition: diff_mx.C:90
Diff_mx(int base_r, int nr)
Standard constructor.
Definition: diff_mx.C:66
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: diff_mx.C:147
Base (abstract) class for 1D spectral differential operators in one domain.
Definition: diff.h:65
int npoints
Number of coefficients.
Definition: diff.h:75
void operator=(const Diff &)
Assignment to another Diff.
Definition: diff.C:75
static const int max_points
Maximal number of matrices stored per base.
Definition: diff.h:71
int base
Base in radial direction.
Definition: diff.h:74
Matrix handling.
Definition: matrice.h:152
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:175
double & set(int j, int i)
Read/write of a particuliar element.
Definition: matrice.h:277
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
Definition: type_parite.h:188
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
Lorene prototypes.
Definition: app_hor.h:64