2
Copyright 2013 Thibaut Paumard
4
This file is part of Gyoto.
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.
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.
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/>.
20
#include "../ygyoto.h"
22
#include <GyotoStarTrace.h>
23
#ifdef GYOTO_USE_XERCES
24
#include <GyotoFactory.h>
31
using namespace Gyoto;
32
using namespace Gyoto::Astrobj;
37
void ygyoto_StarTrace_eval(SmartPointer<Astrobj::Generic>* ao_, int argc) {
41
static char const * knames[]={
43
"radius", "metric", "initcoord", "spectrum", "opacity", "delta", "adaptive",
44
"deltamaxoverradius", "deltamaxoverdistance", "tmin", "tmax",
45
"maxiter", "reset", "xfill",
46
YGYOTO_ASTROBJ_GENERIC_KW,
47
"get_skypos", "get_txyz", "get_prime", "get_coord", "get_cartesian",
52
YGYOTO_WORKER_INIT(Astrobj, StarTrace, knames, YGYOTO_ASTROBJ_GENERIC_KW_N+21);
54
YGYOTO_WORKER_SET_UNIT;
55
YGYOTO_WORKER_GETSET_DOUBLE2_UNIT(radius);
56
YGYOTO_WORKER_GETSET_OBJECT2(metric,Metric);
59
if ((iarg=kiargs[++k])>=0) { //initcoord
62
if ((*rvset)++) y_error(rmsg);
64
double *coord = ypush_d(dims);
65
(*ao)->getInitialCoord(coord);
68
double *pos=ygeta_d(iarg, &ptot, 0);
69
if (ptot<4) y_error("POS should have at least 4 elements");
72
for (n=0; n<4; ++n) coord[n]=pos[n];
74
double *v=NULL, tdot0;
76
if (yarg_number(piargs[0]+*rvset)) {
77
if ((*paUsed)++) y_error(pmsg);
78
v=ygeta_d(piargs[0]+*rvset, &vtot, 0);
79
if (vtot!=3) y_error("V should have 3 elements");
81
y_error("Please set metric before setting initial condition");
82
tdot0=(*ao)->metric()->SysPrimeToTdot(pos, v);
84
for (n=0; n<3; ++n) coord[5+n]=v[n]*tdot0;
86
for (n=4; n<8; ++n) coord[n]=pos[n];
89
tdot0=(*ao)->metric()->SysPrimeToTdot(pos, v);
91
for (n=0; n<3; ++n) coord[5+n]=v[n]*tdot0;
92
} else y_error("Not enough information to set initial condition");
94
(*ao)->setInitialCondition(coord);
98
YGYOTO_WORKER_GETSET_OBJECT2(spectrum,Spectrum);
99
YGYOTO_WORKER_GETSET_OBJECT2(opacity,Spectrum);
100
YGYOTO_WORKER_GETSET_DOUBLE2_UNIT(delta);
101
YGYOTO_WORKER_GETSET_LONG2(adaptive);
102
YGYOTO_WORKER_GETSET_DOUBLE2(deltaMaxOverRadius);
103
YGYOTO_WORKER_GETSET_DOUBLE2(deltaMaxOverDistance);
104
YGYOTO_WORKER_GETSET_DOUBLE2(TMin);
105
YGYOTO_WORKER_GETSET_DOUBLE2(TMax);
106
YGYOTO_WORKER_GETSET_LONG2( maxiter );
107
YGYOTO_WORKER_RUN( reset() );
108
YGYOTO_WORKER_RUN( xFill(ygets_d(iarg+*rvset)) );
110
YGYOTO_WORKER_CALL_GENERIC(Astrobj);
112
k += YGYOTO_ASTROBJ_GENERIC_KW_N;
114
// SPECIFIC GET KEYWORDS
115
if ((iarg=kiargs[++k])>=0) { // get skypos
116
if ((*rvset)++) y_error(rmsg);
117
if ((*paUsed)++) y_error(pmsg);
119
if (!yarg_Screen(iarg)) y_error("Expecting gyoto_Screen argument");
120
SmartPointer<Screen> *screen = yget_Screen(iarg);
122
int nel =(*ao)->get_nelements();
123
long dims[] = {2, nel, 3};
124
double * data=ypush_d(dims);
126
(*ao)->getSkyPos(*screen, data, data+nel, data+2*nel);
129
if ((iarg=kiargs[++k])>=0) { // get_txyz
130
if ((*rvset)++) y_error(rmsg);
131
int nel =(*ao)->get_nelements();
133
long dims[] = {2, nel, 4};
134
double * data=ypush_d(dims);
137
(*ao)->get_xyz(data+nel, data+2*nel, data+3*nel);
140
if ((iarg=kiargs[++k])>=0) { // get_prime
141
if ((*rvset)++) y_error(rmsg);
142
int nel =(*ao)->get_nelements();
144
long dims[] = {2, nel, 3};
145
double * data=ypush_d(dims);
147
(*ao)->get_prime(data, data+nel, data+2*nel);
150
if ((iarg=kiargs[++k])>=0) { // get_coord
151
if ((*rvset)++) y_error(rmsg);
152
// Two cases : get_coord=1 or get_coord=dates.
153
// We will recognize the first case if the parameter is the
154
// integer scalar 1, any other type or value is a date
156
int argt = yarg_number(iarg);
158
long dims[Y_DIMSIZE];
159
double* dates = NULL;
160
double dummy[]= {1.};
161
if (yarg_nil(iarg)) {
162
// void is same as 1 in this context
167
} else dates = ygeta_d(iarg, ntot, dims);
170
cerr << "DEBUG: gyoto_StarTrace(get_coord=array("
171
<< (argt==1?"long":"double")
173
<< ") (rank=" << dims[0]
174
<< ", dates[0]=" << dates[0] << ")" << endl;
176
if (dims[0] == 0 && argt == 1 && dates[0] == 1) {
178
cerr << "DEBUG: retrieving all already computed coordinates" << endl;
179
int nel =(*ao)->get_nelements();
180
long ddims[] = {2, nel, 8};
181
double * data = ypush_d(ddims);
183
(*ao)->getCoord(data, data+nel, data+2*nel, data+3*nel);
184
(*ao)->get_dot(data+4*nel, data+5*nel, data+6*nel, data+7*nel);
187
cerr << "DEBUG: retrieving coordinates for specified date(s)"<< endl;
188
if (dims[0] > Y_DIMSIZE-2)
189
y_errorn("gyoto_StarTrace(get_coord=dates): DATES must have at most %ld "
190
"dimensions", Y_DIMSIZE-2);
193
double * data = ypush_d(dims);
195
(*ao) -> getCoord(dates, nel,
196
data, data+ nel,data+2* nel,data+3* nel,
197
data+4* nel, data+5* nel, data+6* nel);
200
if ((iarg=kiargs[++k])>=0) { // get_cartesian
201
if ((*rvset)++) y_error(rmsg);
203
long dims[Y_DIMSIZE];
204
double* dates = ygeta_d(iarg, ntot, dims);
206
cerr << "DEBUG: gyoto_StarTrace(get_cartesian=dates)"<< endl;
207
if (dims[0] > Y_DIMSIZE-2)
208
y_errorn("gyoto_StarTrace(get_cartesian=dates): DATES must have at most %ld "
209
"dimensions", Y_DIMSIZE-2);
212
double * data = ypush_d(dims);
214
(*ao) -> getCartesian(dates, nel,
215
data, data + nel, data + 2*nel,
216
data + 3*nel, data + 4*nel, data + 5*nel);
220
if ((iarg=kiargs[++k])>=0) { // star
221
if ((*rvset)++) y_error(rmsg);
222
*ypush_Astrobj() = new Star (**ao);
230
void Y__gyoto_StarTrace_register_as_Astrobj(){
231
ygyoto_Astrobj_register("StarTrace",&ygyoto_StarTrace_eval);
234
// Generic constructor/accessor
236
Y_gyoto_StarTrace(int argc)
239
YGYOTO_CONSTRUCTOR_INIT2(Astrobj, Astrobj::Generic, StarTrace, astrobj);
240
if ((*ao)->kind().compare("StarTrace"))
241
y_error("Expecting Astrobj of kind StarTrace");
242
ygyoto_StarTrace_eval(ao, argc);