Debian Codegraph @

yorick/gyoto_Metric.C

raw symbols SCIP
1 /*
2 Copyright 2011, 2013 Thibaut Paumard
3
4 This file is part of Gyoto.
5
6 Gyoto is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Gyoto is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "ygyoto.h"cxx . . $ `<file>/yorick/ygyoto.h`/
21 #include "ygyoto_private.h"cxx . . $ `<file>/yorick/ygyoto_private.h`/
22 #include "ygyoto_idx.h"cxx . . $ `<file>/yorick/ygyoto_idx.h`/
23 #include "yapi.h"
24 #include "pstdlib.h"
25 #ifdef GYOTO_USE_XERCEScxx . . $ `include/GyotoConfig.h:161:9`!
26 #include <GyotoFactory.h>cxx . . $ `<file>/include/GyotoFactory.h`/
27 #endif
28
29 #include <iostream>
30 #include <cstring>
31 using namespace std;
32 using namespace Gyoto;
33 using namespace YGyoto;
34
35
36 // Needed by the YGYOTO_WORKER_* macros
37
38 YGYOTO_YUSEROBJcxx . . $ `yorick/ygyoto_private.h:63:9`!(Metric, Metric::Generic)
39 YGYOTO_BASE_CONSTRUCTOR1cxx . . $ `yorick/ygyoto_private.h:237:9`!(Metric,metric)
40
41 static char ygyoto_Metric_namescxx . . $ ygyoto_Metric_names.[YGYOTO_TYPE_LENcxx . . $ `yorick/ygyoto.h:36:9`!][YGYOTO_MAX_REGISTEREDcxx . . $ `yorick/ygyoto.h:39:9`!]
42 ={{0}};
43 static ygyoto_Metric_eval_worker_tcxx . . $ ygyoto_Metric_eval_worker_t# *ygyoto_Metric_evalscxx . . $ ygyoto_Metric_evals.[YGYOTO_MAX_REGISTEREDcxx . . $ `yorick/ygyoto.h:39:9`!]
44 ={0};
45 static int ygyoto_Metric_countcxx . . $ ygyoto_Metric_count.=0;
46
47 extern "C" {
48 void gyoto_Metric_eval(void *obj, int argc) {
49 SmartPointercxx . . $ Gyoto/SmartPointer#<Metriccxx . . $ Gyoto/Metric/::Genericcxx . . $ Gyoto/Metric/Generic#> *OBJ_ = &((gyoto_Metric*)obj)->smptr;
50
51 // If no parameters, return pointer
52 if (argc==1 && yarg_nil(0)) {
53 ypush_long( (long) (*OBJ_)(cxx . . $ Gyoto/SmartPointer#`operator()`(1016ee5406d91ab9).) );
54 return;
55 }
56
57 // Try calling kind-specific worker
58 int n=0;
59 const stringcxx . . $ std/string# kind = (*OBJ_)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).kindcxx . . $ Gyoto/Object#kind(219584694fe2b248).();
60
61 while (n<ygyoto_Metric_countcxx . . $ ygyoto_Metric_count. && kind.comparecxx . . $ std/__cxx11/basic_string#compare(a291d14eafe45d05).(ygyoto_Metric_namescxx . . $ ygyoto_Metric_names.[n])) ++n;
62
63 if (n<ygyoto_Metric_countcxx . . $ ygyoto_Metric_count. && ygyoto_Metric_evalscxx . . $ ygyoto_Metric_evals.[n]) {
64 (*ygyoto_Metric_evalscxx . . $ ygyoto_Metric_evals.[n])(OBJ_, argc);
65 return;
66 }
67
68 // Fall-back to generic worker
69 static char const * knames[]={
70 "unit",
71 YGYOTO_METRIC_GENERIC_KWcxx . . $ `yorick/ygyoto.h:139:9`!, 0
72 };
73
74 YGYOTO_WORKER_INITcxx . . $ `yorick/ygyoto.h:254:9`!(Metric, Generic, knames, YGYOTO_METRIC_GENERIC_KW_Ncxx . . $ `yorick/ygyoto.h:145:9`!+1);
75
76 YGYOTO_WORKER_SET_UNITcxx . . $ `yorick/ygyoto.h:439:9`!;
77
78 YGYOTO_WORKER_CALL_GENERICcxx . . $ `yorick/ygyoto.h:493:9`!(Metric);
79
80 }
81 }
82
83 void ygyoto_Metric_registercxx . . $ ygyoto_Metric_register(58f3e85fe3544e93).(char const*const name, ygyoto_Metric_eval_worker_tcxx . . $ ygyoto_Metric_eval_worker_t#* on_eval){
84 int n;
85 if (ygyoto_Metric_countcxx . . $ ygyoto_Metric_count.==YGYOTO_MAX_REGISTEREDcxx . . $ `yorick/ygyoto.h:39:9`!)
86 y_error("Too many Metrics registered");
87 for (n=0; n<ygyoto_Metric_countcxx . . $ ygyoto_Metric_count.; ++n)
88 if (!strcmp(ygyoto_Metric_namescxx . . $ ygyoto_Metric_names.[n], name))
89 return;
90
91 strcpy(ygyoto_Metric_namescxx . . $ ygyoto_Metric_names.[ygyoto_Metric_countcxx . . $ ygyoto_Metric_count.], name);
92 ygyoto_Metric_evalscxx . . $ ygyoto_Metric_evals.[ygyoto_Metric_countcxx . . $ ygyoto_Metric_count.++]=on_eval;
93 //if ((ygyoto_Metric_count) < YGYOTO_METRIC_MAX_REGISTERED)
94 // strcpy(ygyoto_Metric_names[ygyoto_Metric_count], "");
95 }
96
97 void ygyoto_Metric_generic_evalcxx . . $ ygyoto_Metric_generic_eval(3a49bfe9aeadf44).(SmartPointercxx . . $ Gyoto/SmartPointer#<Metriccxx . . $ Gyoto/Metric/::Genericcxx . . $ Gyoto/Metric/Generic#>*OBJ,
98 int *kiargs, int *piargs,
99 int *rvset, int *paUsed, char * unit) {
100 int k=-1, iarg=-1;
101 char const * rmsg="Cannot set return value more than once";
102 char const * pmsg="Cannot use positional argument more than once";
103 long ntot, dims[Y_DIMSIZEcxx . . $ `<external>/13312585737040429147/yapi.h:133:9`!];
104
105 /* METHODS */
106 if ((iarg=kiargs[++k])>=0) { // get_tdot
107 if (debugcxx . . $ Gyoto/debug(b126dc7c1de90089).()) cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "In get_tdot" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
108 if ((*rvset)++) y_error(rmsg);
109 if ((*paUsed)++) y_error(pmsg);
110 double * pos=ygeta_d(iarg,&ntot,0);
111 if (ntot!=4) y_error("POS must have 4 elements");
112 double * vel=ygeta_d(piargs[0],&ntot,0);
113 if (ntot!=3) y_error("VEL must have 3 elements");
114 ypush_double((*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).SysPrimeToTdotcxx . . $ Gyoto/Metric/Generic#SysPrimeToTdot(7f599912affaf447).(pos, vel));
115 }
116
117 if ((iarg=kiargs[++k])>=0) { // nullifycoord
118 if (debugcxx . . $ Gyoto/debug(b126dc7c1de90089).()) cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "In nullifycoord" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
119 if ((*rvset)++) y_error(rmsg);
120 if ((*paUsed)++) y_error(pmsg);
121 double * pos=ygeta_d(iarg,&ntot,0);
122 if (ntot!=4) y_error("POS must have 4 elements");
123 double * vel=ygeta_d(piargs[0],&ntot,0);
124 if (ntot!=3) y_error("VEL must have 3 elements");
125 dims[0]=1; dims[1]=8;
126 double *coord = ypush_d(dims);
127 for (int i=0; i<4; ++i) coord[i]=pos[i];
128 for (int i=0; i<3; ++i) coord[i+5]=vel[i];
129 (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).nullifyCoordcxx . . $ Gyoto/Metric/Generic#nullifyCoord(b0764271c3b728b7).(coord);
130 }
131
132 // kind
133 if ((iarg=kiargs[++k])>=0) {
134 if ((*rvset)++) y_error(rmsg);
135 if (!yarg_nil(iarg)) y_error("KIND is readonly");
136 char ** kind = ypush_q(0);
137 *kind = p_strcpy((*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).kindcxx . . $ Gyoto/Object#kind(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
138 }
139
140 // coordkind
141 if ((iarg=kiargs[++k])>=0) {
142 if ((*rvset)++) y_error(rmsg);
143 if (!yarg_nil(iarg)) y_error("COORDKIND is readonly");
144 ypush_long((*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).coordKindcxx . . $ Gyoto/Metric/Generic#coordKind(455f465bc33b4cdf).());
145 }
146
147 YGYOTO_WORKER_SETPARAMETERcxx . . $ `yorick/ygyoto.h:446:9`!;
148
149 // ScalarProd
150 if ((iarg=kiargs[++k])>=0) {
151 if ((*rvset)++) y_error(rmsg);
152 if ((*paUsed)++) y_error(pmsg);
153 ntot=0;
154 double * pos = ygeta_d(iarg, &ntot, dims);
155 if (!dims[0] || dims[1]<4)
156 y_error("scalarprod: pos must be at least 4 elements long");
157 double * u1 = ygeta_d(piargs[0], &ntot, dims);
158 if (!dims[0] || dims[1]<4)
159 y_error("scalarprod: u1 must be at least 4 elements long");
160 double * u2 = ygeta_d(piargs[1], &ntot, dims);
161 if (!dims[0] || dims[1]<4)
162 y_error("scalarprod: u2 must be at least 4 elements long");
163 ypush_double((*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).ScalarProdcxx . . $ Gyoto/Metric/Generic#ScalarProd(75a2f40855971097).(pos, u1, u2));
164 }
165
166 YGYOTO_WORKER_GETSET_DOUBLE2_UNITcxx . . $ `yorick/ygyoto.h:342:9`!(mass);
167
168 YGYOTO_WORKER_GETSET_DOUBLE2cxx . . $ `yorick/ygyoto.h:372:9`!(deltaMin);
169 YGYOTO_WORKER_GETSET_DOUBLE2cxx . . $ `yorick/ygyoto.h:372:9`!(deltaMax);
170 YGYOTO_WORKER_GETSET_LONG2cxx . . $ `yorick/ygyoto.h:402:9`!(keplerian);
171
172 // Unit length
173 if ((iarg=kiargs[++k])>=0) { // unitLength()
174 if ((*rvset)++) y_error(rmsg);
175 if (!yarg_nil(iarg)) y_error("UNITLENGTH is readonly");
176 ypush_double((*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).unitLengthcxx . . $ Gyoto/Metric/Generic#unitLength(fbb5c2857318795a).(unitcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).?unit:""));
177 }
178
179 // circularvelocity
180 if ((iarg=kiargs[++k])>=0) {
181 if ((*rvset)++) y_error(rmsg);
182 if ((*paUsed)++) y_error(pmsg);
183 double * coords = ygeta_d(iarg, &ntot, dims);
184 if (!dims[0] || dims[1]<4)
185 y_error("syntax: circularvelocity=array(double, 4 ...)");
186 double dir =1;
187 if (piargs[0] >= 0) dir = ygets_d(piargs[0]) >= 0 ? 1 : -1;
188 long d1 = dims[1];
189 long npoints=ntot/d1;
190 dims[1]=4;
191 double * vels = ypush_d(dims);
192 for (long i=0; i<npoints; ++i, coords+=d1, vels+=4)
193 (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).circularVelocitycxx . . $ Gyoto/Metric/Generic#circularVelocity(38d15db0cf94146e).(coords, vels, dir);
194 }
195
196 // christoffel
197 if ((iarg=kiargs[++k])>=0) {
198 if ((*rvset)++) y_error(rmsg);
199 if ((*paUsed)++) y_error(pmsg);
200 double * coords = ygeta_d(iarg, &ntot, dims);
201 if (!dims[0] || dims[1]<4)
202 y_error("syntax: christoffel=array(double, 4)");
203
204 Idxcxx . . $ YGyoto/Idx# i_idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868). (piargs[0], 4);
205 if (i_idx.isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).()) return;
206 Idxcxx . . $ YGyoto/Idx# j_idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868). (piargs[1], 4);
207 if (j_idx.isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).()) return;
208 Idxcxx . . $ YGyoto/Idx# a_idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868). (piargs[2], 4);
209 if (a_idx.isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).()) return;
210 long ni=i_idx.getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).();
211 long nj=j_idx.getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).();
212 long na=a_idx.getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).();
213
214 dims[0]=i_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()+j_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()+a_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).();
215 size_t offset=0;
216 if (i_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()) dims[++offset]=ni;
217 if (j_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()) dims[++offset]=nj;
218 if (a_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()) dims[++offset]=na;
219 double * data=ypush_d(dims);
220 double dst[4][4][4];
221
222 if (dims[0]==3 && dims[1]==4 && dims[2]==4 && dims[3]==4) {
223 (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).christoffelcxx . . $ Gyoto/Metric/Generic#christoffel(5f571a8c1ccb248f).(dst, coords);
224 memcpy(data, &dst[0][0], 4*4*4*sizeof(double));
225 } else {
226 size_t i, j, a;
227 for ( a=a_idx.firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() ; a_idx.validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() ; a=a_idx.nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() )
228 for ( i=i_idx.firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() ; i_idx.validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() ; i=i_idx.nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() )
229 for ( j=j_idx.firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() ; j_idx.validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() ; j=j_idx.nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() )
230 *(data++) = (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).christoffelcxx . . $ Gyoto/Metric/Generic#christoffel(9e4c9f8de0307d32).(coords, int(a-1), int(i-1), int(j-1));
231 }
232
233 }
234
235 YGYOTO_WORKER_XMLWRITEcxx . . $ `yorick/ygyoto.h:459:10`!;
236 YGYOTO_WORKER_CLONEcxx . . $ `yorick/ygyoto.h:472:9`!(Metric);
237 YGYOTO_WORKER_HELPcxx . . $ `yorick/ygyoto.h:485:9`!;
238
239 if (*rvset || *paUsed || piargs[0]<0 || !yarg_number(piargs[0])) return;
240 //else /* GET G MU NU */
241
242 if (debugcxx . . $ Gyoto/debug(b126dc7c1de90089).()) cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "DEBUG: gyoto_Metric_generic_eval: getting gmunu\n";
243 double *x = ygeta_d(piargs[0], &ntot, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
244 if (ntot<4) y_error("X must have at least four elements");
245
246 Idxcxx . . $ YGyoto/Idx# i_idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868). (piargs[1], 4);
247 if (i_idx.isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).()) return;
248 Idxcxx . . $ YGyoto/Idx# j_idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868). (piargs[2], 4);
249 if (j_idx.isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).()) return;
250 long ni=i_idx.getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).();
251 long nj=j_idx.getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).();
252
253 dims[0]=i_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()+j_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).();
254 size_t offset=0;
255 if (i_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()) dims[++offset]=ni;
256 if (j_idx.getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).()) dims[++offset]=nj;
257 double * data=ypush_d(dims);
258 double dst[4][4];
259
260 if (dims[0]==2 && dims[1]==4 && dims[2]==4) {
261 (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).gmunucxx . . $ Gyoto/Metric/Generic#gmunu(14776f52c3e6dde3).(dst, x);
262 memcpy(data, &dst[0][0], 4*4*sizeof(double));
263 return;
264 }
265
266 size_t i, j;
267 for ( j=j_idx.firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() ; j_idx.validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() ; j=j_idx.nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() )
268 for ( i=i_idx.firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() ; i_idx.validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() ; i=i_idx.nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() )
269 *(data++) = (*OBJ)->cxx . . $ Gyoto/SmartPointer#`operator->`(155dc7f103cdb9db).gmunucxx . . $ Gyoto/Metric/Generic#gmunu(bd501205b20a58fa).(x, int(i-1), int(j-1));
270
271 }