LORENE
diff_xdsdx.C
1/*
2 * Methods for the class Diff_xdsdx
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
28char diff_xdsdx_C[] = "$Header: /cvsroot/Lorene/C++/Source/Diff/diff_xdsdx.C,v 1.5 2014/10/13 08:52:51 j_novak Exp $" ;
29
30/*
31 * $Id: diff_xdsdx.C,v 1.5 2014/10/13 08:52:51 j_novak Exp $
32 * $Log: diff_xdsdx.C,v $
33 * Revision 1.5 2014/10/13 08:52:51 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.4 2014/10/06 15:13:05 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.3 2007/12/11 15:28:11 jl_cornou
40 * Jacobi(0,2) polynomials partially implemented
41 *
42 * Revision 1.2 2005/01/11 15:16:10 j_novak
43 * More Diff operators.
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_xdsdx.C,v 1.5 2014/10/13 08:52:51 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
61namespace Lorene {
62void xpundsdx_1d(int, double**, int) ;
63
64namespace {
65 int nap = 0 ;
66 Matrice* tab[MAX_BASE*Diff::max_points] ;
67 int nr_done[Diff::max_points] ;
68}
69
70Diff_xdsdx::Diff_xdsdx(int base_r, int nr) : Diff(base_r, nr) {
71 initialize() ;
72}
73
74Diff_xdsdx::Diff_xdsdx(const Diff_xdsdx& diff_in) : Diff(diff_in) {
75 assert (nap != 0) ;
76}
77
79
81 if (nap == 0) {
82 for (int i=0; i<max_points; i++) {
83 nr_done[i] = -1 ;
84 for (int j=0; j<MAX_BASE; j++)
85 tab[j*max_points+i] = 0x0 ;
86 }
87 nap = 1 ;
88 }
89 return ;
90}
91
92void Diff_xdsdx::operator=(const Diff_xdsdx& diff_in) {
93 assert (nap != 0) ;
94 Diff::operator=(diff_in) ;
95
96}
97
99
100 bool done = false ;
101 int indice ;
102 for (indice =0; indice<max_points; indice++) {
103 if (nr_done[indice] == npoints) {
104 if (tab[base*max_points + indice] != 0x0) done = true ;
105 break ;
106 }
107 if (nr_done[indice] == -1)
108 break ;
109 }
110 if (!done) { //The computation must be done ...
111 if (indice == max_points) {
112 cerr << "Diff_xdsdx::get_matrice() : no space left!!" << '\n'
113 << "The value of Diff.max_points must be increased..." << endl ;
114 abort() ;
115 }
116 nr_done[indice] = npoints ;
117 tab[base*max_points + indice] = new Matrice(npoints, npoints) ;
118 Matrice& resu = *tab[base*max_points + indice] ;
119 resu.set_etat_qcq() ;
120
121 double* vect = new double[npoints] ;
122 double* cres = new double[npoints] ;
123 for (int i=0; i<npoints; i++) {
124 for (int j=0; j<npoints; j++)
125 vect[j] = 0. ;
126 vect[i] = 1. ;
127
128 switch (base) {
129
130 case R_JACO02 : {
131 xpundsdx_1d(npoints, &vect, base << TRA_R) ;
132 for (int j=0 ; j<npoints; j++)
133 resu.set(j,i) = vect[j] ;
134 }
135 break ;
136
137 case R_CHEBU : {
138 dsdx_1d(npoints, &vect, R_CHEBU) ;
139 mult_xm1_1d_cheb(npoints, vect, cres) ;
140 for (int j=0; j<npoints; j++)
141 resu.set(j,i) = cres[j] ;
142 }
143 break ;
144
145 default : {
146 xdsdx_1d(npoints, &vect, base << TRA_R) ;
147 for (int j=0; j<npoints; j++)
148 resu.set(j,i) = vect[j] ;
149 }
150 break ;
151 }
152 }
153 delete [] vect ;
154 delete [] cres ;
155 }
156
157 return *tab[base*max_points + indice] ;
158}
159
160ostream& Diff_xdsdx::operator>>(ostream& ost) const {
161
162 ost << " xi * d / dx " << endl ;
163 return ost ;
164
165}
166}
Class for the elementary differential operator (see the base class Diff ).
Definition diff.h:409
Diff_xdsdx(int base_r, int nr)
Standard constructor.
Definition diff_xdsdx.C:70
void initialize()
Initializes arrays.
Definition diff_xdsdx.C:80
virtual const Matrice & get_matrice() const
Returns the matrix associated with the operator.
Definition diff_xdsdx.C:98
virtual ~Diff_xdsdx()
Destructor.
Definition diff_xdsdx.C:78
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition diff_xdsdx.C:160
void operator=(const Diff_xdsdx &)
Assignment to another Diff_xdsdx.
Definition diff_xdsdx.C:92
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.
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Lorene prototypes.
Definition app_hor.h:64