LORENE
des_profile_log.C
1/*
2 * Draws the profile of a {\tt Scalar} along radial axis directions, with a
3 * log-scale in the y-axis.
4 */
5
6/*
7 * Copyright (c) 2022 Jerome Novak
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28
29
30
31/*
32 * $Id: des_profile_log.C,v 1.1 2022/02/10 16:33:53 j_novak Exp $
33 * $Log: des_profile_log.C,v $
34 * Revision 1.1 2022/02/10 16:33:53 j_novak
35 * New drawing functions with logscale in y : des_profile_log, des_meridian_log.
36 *
37 *
38 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_profile_log.C,v 1.1 2022/02/10 16:33:53 j_novak Exp $
39 *
40 */
41
42// Header Lorene
43#include "scalar.h"
44#include "graphique.h"
45
46namespace Lorene {
47
48
49 //*****************************************************************************
50
51 void des_profile_log(const Scalar& uu, double r_min, double r_max,
52 double theta, double phi, double pzero, const char* nomy,
53 const char* title, bool draw_bound) {
54
55 const int npt = 400 ; // Number of points along the axis
56
57 float uutab[npt] ; // Value of uu at the npt points
58
59 double hr = (r_max - r_min) / double(npt-1) ;
60
61 for (int i=0; i<npt; i++) {
62
63 double r = hr * i + r_min ;
64
65 double tmp_val = fabs(uu.val_point(r, theta, phi)) ;
66 if (tmp_val < pzero) tmp_val = pzero ;
67 uutab[i] = float(log10(tmp_val)) ;
68 }
69
70 float xmin = float(r_min) ;
71 float xmax = float(r_max) ;
72
73 const char* nomx = "r" ;
74
75 if (title == 0x0) {
76 title = "" ;
77 }
78
79 if (nomy == 0x0) {
80 nomy = "" ;
81 }
82
83 // Preparations for the drawing of boundaries
84 // ------------------------------------------
85 const Map& mp = uu.get_mp() ;
86 int nz = mp.get_mg()->get_nzone() ;
87 int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ;
88
89 float* xbound = new float[l_max+1] ;
90 int nbound = 0 ;
91
92 if (draw_bound) {
93 const double xi_max = 1. ;
94 for (int l=0; l<=l_max; l++) {
95
96 double rb = mp.val_r(l, xi_max, theta, phi) ;
97
98 if ((rb >= r_min) && (rb <= r_max)) {
99 xbound[nbound] = float(rb) ;
100 nbound++ ;
101 }
102 }
103 }
104
105 des_profile(uutab, npt, xmin, xmax, nomx, nomy, title, 0x0,
106 nbound, xbound, true) ;
107
108 delete [] xbound ;
109
110 }
111
112
113 //******************************************************************************
114
115 void des_prof_mult_log(const Scalar** uu, int nprof, double r_min, double r_max,
116 const double* theta, const double* phi, double pzero,
117 double radial_scale, bool closeit, const char* nomy,
118 const char* title, int ngraph, const char* nomx,
119 const int* line_style, const char* device,
120 bool draw_bound) {
121
122 // Special case of no graphical output:
123 if (device != 0x0) {
124 if ((device[0] == '/') && (device[1] == 'n')) return ;
125 }
126
127 const int npt = 400 ; // Number of points along the axis
128 double rr[npt] ;
129
130 float* uutab = new float[npt*nprof] ; // Value of uu at the npt points
131 // for each of the nprof profiles
132
133 double hr = (r_max - r_min) / double(npt-1) ;
134
135 for (int i=0; i<npt; i++) {
136 rr[i] = hr * i + r_min ;
137 }
138
139
140 for (int j=0; j<nprof; j++) {
141
142 const Scalar& vv = *(uu[j]) ;
143
144 for (int i=0; i<npt; i++) {
145 double tmp_val = fabs(vv.val_point(rr[i], theta[j], phi[j])) ;
146 if (tmp_val < pzero) tmp_val = pzero ;
147 uutab[j*npt+i] = float(log10(tmp_val)) ;
148 }
149 }
150
151
152 float xmin = float(radial_scale * r_min) ;
153 float xmax = float(radial_scale * r_max) ;
154
155 if (nomx == 0x0) nomx = "r" ;
156
157 if (nomy == 0x0) nomy = "" ;
158
159 if (title == 0x0) title = "" ;
160
161 // Preparations for the drawing of boundaries
162 // ------------------------------------------
163
164 int nbound_max = 100 * nprof ;
165 float* xbound = new float[nbound_max] ;
166 int nbound = 0 ;
167
168 if (draw_bound) {
169 const double xi_max = 1. ;
170 for (int j=0; j<nprof; j++) {
171
172 const Map& mp = uu[j]->get_mp() ;
173 int nz = mp.get_mg()->get_nzone() ;
174 int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ;
175
176 for (int l=0; l<=l_max; l++) {
177
178 double rb = mp.val_r(l, xi_max, theta[j], phi[j]) ;
179
180 if ((rb >= r_min) && (rb <= r_max)) {
181 xbound[nbound] = float(rb * radial_scale) ;
182 nbound++ ;
183 if (nbound > nbound_max-1) {
184 cout << "des_profile_mult : nbound too large !" << endl ;
185 abort() ;
186 }
187 }
188 }
189 }
190 }
191
192 // Call to the low level routine
193 // -----------------------------
194
195 des_profile_mult(uutab, nprof, npt, xmin, xmax, nomx, nomy, title,
196 line_style, ngraph, closeit, device, nbound, xbound, true) ;
197
198
199 delete [] uutab ;
200 delete [] xbound ;
201
202 }
203
204 //******************************************************************************
205
206 void des_meridian_log(const Scalar& uu, double r_min, double r_max,
207 const char* nomy, int ngraph, double pzero,
208 const char* device,
209 bool closeit, bool draw_bound) {
210
211 // Special case of no graphical output:
212 if (device != 0x0) {
213 if ((device[0] == '/') && (device[1] == 'n')) return ;
214 }
215
216 const Scalar* des[] = {&uu, &uu, &uu, &uu, &uu} ;
217 double phi1[] = {0., 0., 0., 0.25*M_PI, 0.25*M_PI} ;
218 double theta1[] = {0., 0.25*M_PI, 0.5*M_PI, 0., 0.25*M_PI} ;
219
220 des_prof_mult_log(des, 5, r_min, r_max, theta1, phi1, pzero, 1., closeit,
221 nomy, "phi=0: th=0, pi/4, pi/2, phi=pi/4: th=0, pi/4",
222 ngraph, 0x0, 0x0, device, draw_bound) ;
223
224 }
225
226} // end of namespace Lorene
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
Cmp log10(const Cmp &)
Basis 10 logarithm.
Definition cmp_math.C:325
Lorene prototypes.
Definition app_hor.h:67
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Definition map.C:142
Coord phi
coordinate centered on the grid
Definition map.h:732
Coord r
r coordinate centered on the grid
Definition map.h:730