Ice Sheet System Model  4.18
Code documentation
FetchJavascriptData.cpp
Go to the documentation of this file.
1 /*\file FetchData.cpp:
2  * \brief: general I/O interface to fetch data in javascript
3  */
4 
5 #ifdef HAVE_CONFIG_H
6  #include <config.h>
7 #else
8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9 #endif
10 
11 #include "./javascriptio.h"
12 #include <cstring>
13 
14 /*Primitive data types*/
15 /*FUNCTION FetchData(char** pstring, char* string){{{*/
16 void FetchData(char** pstring, char* stringin){
17  char* string=NULL;
18 
19  string=xNew<char>(strlen(stringin)+1); xMemCpy<char>(string,stringin,strlen(stringin)+1);
20 
21  *pstring=string;
22 }
23 /*}}}*/
24 /*FUNCTION FetchData(int* pinteger, int integer){{{*/
25 void FetchData(int* pinteger, int integer){
26  *pinteger=integer;
27 }
28 /*}}}*/
29 /*FUNCTION FetchData(double* pscalar, double scalar){{{*/
30 void FetchData(double* pscalar, double scalar){
31  *pscalar=scalar;
32 }
33 /*}}}*/
34 /*FUNCTION FetchData(double **pvector, double* vectorin, int nods){{{*/
35 void FetchData(double** pvector, double* vectorin, int nods){
36  double* vector=NULL;
37 
38  vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods);
39 
40  *pvector=vector;
41 }
42 /*}}}*/
43 /*FUNCTION FetchData(double **pvector, int* pnods, double* vectorin, int nods){{{*/
44 void FetchData(double** pvector, int* pnods, double* vectorin, int nods){
45  double* vector=NULL;
46 
47  vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods);
48 
49  *pvector=vector;
50  *pnods=nods;
51 }
52 /*}}}*/
53 /*FUNCTION FetchData(double **pmatrix, int* pM, int* pN, int* matrix, int M, int N){{{*/
54 void FetchData(double **pmatrix, int* pM, int* pN, int* matrixin, int M, int N){
55  double* outmatrix=NULL;
56  int outmatrix_rows, outmatrix_cols;
57 
58  if(M == 0 || N == 0){
59  /*Nothing to pick up. Just initialize matrix pointer to NULL: */
60  outmatrix_rows=0;
61  outmatrix_cols=0;
62  outmatrix=NULL;
63  }
64  else if (pmatrix && matrixin){
65  outmatrix_rows=M;
66  outmatrix_cols=N;
67  outmatrix=xNew<IssmPDouble>(M*N);
68  for(int i=0;i<M*N;i++){outmatrix[i]=(IssmPDouble)matrixin[i];}
69  }
70 
71  /*Assign output pointers:*/
72  *pmatrix=outmatrix;
73  if (pM){*pM=outmatrix_rows;}
74  if (pN){*pN=outmatrix_cols;}
75 }
76 /*}}}*/
77 /*FUNCTION FetchData(double **pmatrix, int* pM, int* pN, double* matrix, int M, int N){{{*/
78 void FetchData(double **pmatrix, int* pM, int* pN, double* matrixin, int M, int N){
79  double* outmatrix=NULL;
80  int outmatrix_rows, outmatrix_cols;
81 
82  if(M == 0 || N == 0){
83  /*Nothing to pick up. Just initialize matrix pointer to NULL: */
84  outmatrix_rows=0;
85  outmatrix_cols=0;
86  outmatrix=NULL;
87  }
88  else if (pmatrix && matrixin){
89  outmatrix_rows=M;
90  outmatrix_cols=N;
91  outmatrix=xNew<IssmPDouble>(M*N); xMemCpy<IssmPDouble>(outmatrix,matrixin,M*N);
92  }
93 
94  /*Assign output pointers:*/
95  *pmatrix=outmatrix;
96  if (pM){*pM=outmatrix_rows;}
97  if (pN){*pN=outmatrix_cols;}
98 }
99 /*}}}*/
100 /*FUNCTION FetchData(int **pmatrix, int* pM, int* pN, int* matrix, int M, int N){{{*/
101 void FetchData(int **pmatrix, int* pM, int* pN, int* matrixin, int M, int N){
102  int* outmatrix=NULL;
103  int outmatrix_rows, outmatrix_cols;
104 
105  if(M == 0 || N == 0){
106  /*Nothing to pick up. Just initialize matrix pointer to NULL: */
107  outmatrix_rows=0;
108  outmatrix_cols=0;
109  outmatrix=NULL;
110  }
111  else if (pmatrix && matrixin){
112  outmatrix_rows=M;
113  outmatrix_cols=N;
114  outmatrix=xNew<int>(M*N); xMemCpy<int>(outmatrix,matrixin,M*N);
115  }
116 
117  /*Assign output pointers:*/
118  *pmatrix=outmatrix;
119  if (pM){*pM=outmatrix_rows;}
120  if (pN){*pN=outmatrix_cols;}
121 }
122 /*}}}*/
123 /*ISSM objects*/
124 /*FUNCTION FetchData(Contours** pcontours, double* x, double* y, int nods){{{*/
125 void FetchData(Contours** pcontours, double* x, double* y, int nods){
126  int numcontours, index, test1, test2;
127  char *contourname = NULL;
128  Contours *contours = NULL;
129  Contour<double> *contouri = NULL;
130 
131  /*only 1 contour for now: */
132  contours=new Contours();
133 
134  if (nods){
135  contouri=new Contour<double>();
136  contouri->nods=nods;
137  contouri->x=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(contouri->x,x,nods);
138  contouri->y=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(contouri->y,y,nods);
139  contours->AddObject(contouri);
140  }
141 
142  *pcontours=contours;
143 }
144 /*}}}*/
145 /*FUNCTION FetchData(BamgGeom** pbamggeom, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* CornersSize, double* Corners, int* RequiredVerticesSize, double* RequiredVertices, int* RequiredEdgesSize, double* RequiredEdges, int* CrackedEdgesSize, double* CrackedEdges, int* SubDomainsSize, double* SubDomains){{{*/
146 void FetchData(BamgGeom** pbamggeom, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* CornersSize, double* Corners, int* RequiredVerticesSize, double* RequiredVertices, int* RequiredEdgesSize, double* RequiredEdges, int* CrackedEdgesSize, double* CrackedEdges, int* SubDomainsSize, double* SubDomains){
147 
148  /*Initialize output*/
149  BamgGeom* bamggeom=new BamgGeom();
150 
151  /*Fetch all fields*/
152  FetchData(&bamggeom->Vertices, &bamggeom->VerticesSize[0], &bamggeom->VerticesSize[1], Vertices, VerticesSize[0], VerticesSize[1]);
153  FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], Edges, EdgesSize[0], EdgesSize[1]);
154  FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], Corners, CornersSize[0], CornersSize[1]);
155  FetchData(&bamggeom->RequiredVertices, &bamggeom->RequiredVerticesSize[0], &bamggeom->RequiredVerticesSize[1], RequiredVertices, RequiredVerticesSize[0], RequiredVerticesSize[1]);
156  FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], RequiredEdges, RequiredEdgesSize[0], RequiredEdgesSize[1]);
157  FetchData(&bamggeom->CrackedEdges, &bamggeom->CrackedEdgesSize[0], &bamggeom->CrackedEdgesSize[1], CrackedEdges, CrackedEdgesSize[0], CrackedEdgesSize[1]);
158  FetchData(&bamggeom->SubDomains, &bamggeom->SubDomainsSize[0], &bamggeom->SubDomainsSize[1], SubDomains, SubDomainsSize[0], SubDomainsSize[1]);
159 
160  /*Assign output pointers:*/
161  *pbamggeom=bamggeom;
162 }
163 /*}}}*/
164 /*FUNCTION FetchData(BamgMesh** pbamgmesh, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* TrianglesSize, double* Triangles, int* CrackedEdgesSize, double* CrackedEdges, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomEdge, int* VerticesOnGeomVertexSize, double* VerticesOnGeomVertex, int* EdgesOnGeomEdgeSize, double* EdgesOnGeomEdge, int* IssmSegmentsSize, double* IssmSegments){{{*/
165 void FetchData(BamgMesh** pbamgmesh, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* TrianglesSize, double* Triangles, int* CrackedEdgesSize, double* CrackedEdges, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomEdge, int* VerticesOnGeomVertexSize, double* VerticesOnGeomVertex, int* EdgesOnGeomEdgeSize, double* EdgesOnGeomEdge, int* IssmSegmentsSize, double* IssmSegments){
166 
167  /*Initialize output*/
168  BamgMesh* bamgmesh=new BamgMesh();
169 
170  /*Fetch all fields*/
171  FetchData(&bamgmesh->Vertices, &bamgmesh->VerticesSize[0], &bamgmesh->VerticesSize[1], Vertices, VerticesSize[0], VerticesSize[1]);
172  FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], Edges, EdgesSize[0], EdgesSize[1]);
173  FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], Triangles, TrianglesSize[0], TrianglesSize[1]);
174  FetchData(&bamgmesh->CrackedEdges, &bamgmesh->CrackedEdgesSize[0], &bamgmesh->CrackedEdgesSize[1], CrackedEdges, CrackedEdgesSize[0], CrackedEdgesSize[1]);
175  FetchData(&bamgmesh->VerticesOnGeomEdge, &bamgmesh->VerticesOnGeomEdgeSize[0], &bamgmesh->VerticesOnGeomEdgeSize[1], VerticesOnGeomEdge, VerticesOnGeomEdgeSize[0], VerticesOnGeomEdgeSize[1]);
176  FetchData(&bamgmesh->VerticesOnGeomVertex, &bamgmesh->VerticesOnGeomVertexSize[0], &bamgmesh->VerticesOnGeomVertexSize[1], VerticesOnGeomVertex, VerticesOnGeomVertexSize[0], VerticesOnGeomVertexSize[1]);
177  FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], EdgesOnGeomEdge, EdgesOnGeomEdgeSize[0], EdgesOnGeomEdgeSize[1]);
178  FetchData(&bamgmesh->IssmSegments, &bamgmesh->IssmSegmentsSize[0], &bamgmesh->IssmSegmentsSize[1], IssmSegments, IssmSegmentsSize[0], IssmSegmentsSize[1]);
179 
180  /*Assign output pointers:*/
181  *pbamgmesh=bamgmesh;
182 }
183 /*}}}*/
184 /*FUNCTION FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int hVerticesLength, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){{{*/
185 void FetchData(BamgOpts** pbamgopts, double anisomax, double coeff, double cutoff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int hVerticesLength, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){
186 
187  BamgOpts *bamgopts = new BamgOpts();
188 
189  /*Parameters*/
190  bamgopts->anisomax = anisomax;
191  bamgopts->coeff = coeff;
192  bamgopts->cutoff = cutoff;
193  bamgopts->errg = errg;
194  bamgopts->gradation = gradation;
195  bamgopts->Hessiantype = Hessiantype;
196  bamgopts->maxnbv = maxnbv;
197  bamgopts->maxsubdiv = maxsubdiv;
198  bamgopts->Metrictype = Metrictype;
199  bamgopts->nbjacobi = nbjacobi;
200  bamgopts->nbsmooth = nbsmooth;
201  bamgopts->omega = omega;
202  bamgopts->power = power;
203  bamgopts->verbose = verbose;
204 
205  /*Flags*/
206  bamgopts->Crack = Crack;
207  bamgopts->KeepVertices = KeepVertices;
208  bamgopts->splitcorners = splitcorners;
209 
210  /*Metric related*/
211  bamgopts->hmin = hmin;
212  bamgopts->hmax = hmax;
213  FetchData(&bamgopts->hminVertices, &bamgopts->hminVerticesSize[0], &bamgopts->hminVerticesSize[1], hminVertices, hminVerticesSize[0], hminVerticesSize[1]);
214  FetchData(&bamgopts->hmaxVertices, &bamgopts->hmaxVerticesSize[0], &bamgopts->hmaxVerticesSize[1], hmaxVertices, hmaxVerticesSize[0], hmaxVerticesSize[1]);
215  FetchData(&bamgopts->hVertices, &bamgopts->hVerticesLength, hVertices, hVerticesLength);
216  FetchData(&bamgopts->field, &bamgopts->fieldSize[0], &bamgopts->fieldSize[1], field, fieldSize[0], fieldSize[1]);
217  FetchData(&bamgopts->metric, &bamgopts->metricSize[0], &bamgopts->metricSize[1], metric, metricSize[0], metricSize[1]);
218  FetchData(&bamgopts->err, &bamgopts->errSize[0], &bamgopts->errSize[1], err, errSize[0], errSize[1]);
219 
220  /*Additional checks*/
221  bamgopts->Check();
222 
223  /*Assign output pointers:*/
224  *pbamgopts=bamgopts;
225 }
226 /*}}}*/
227 /*FUNCTION FetchData(Options** poptions, int NRHS, int nrhs, const char* optionname, double optionvalue){{{*/
228 void FetchData(Options** poptions, int NRHS, int nrhs, const char* optionname, double optionvalue){
229 
230  /*Initialize output*/
231  Options* options=new Options();
232 
233  /*check and parse the name */
235  odouble=new GenericOption<double>();
236  odouble->name=xNew<char>(strlen(optionname)+1);
237  memcpy(odouble->name,optionname,(strlen(optionname)+1)*sizeof(char));
238  odouble->value=optionvalue;
239  odouble->size[0]=1;
240  odouble->size[1]=1;
241  options->AddOption((Option*)odouble);
242 
243  /*Assign output pointers:*/
244  *poptions=options;
245 }
246 /*}}}*/
BamgGeom::RequiredVertices
double * RequiredVertices
Definition: BamgGeom.h:19
BamgOpts::cutoff
double cutoff
Definition: BamgOpts.h:14
BamgGeom::Edges
double * Edges
Definition: BamgGeom.h:13
GenericOption::size
int size[2]
Definition: GenericOption.h:27
Vertices
Declaration of Vertices class.
Definition: Vertices.h:15
BamgGeom::CrackedEdges
double * CrackedEdges
Definition: BamgGeom.h:23
Options
Definition: Options.h:9
BamgOpts::power
double power
Definition: BamgOpts.h:25
BamgGeom::CornersSize
int CornersSize[2]
Definition: BamgGeom.h:16
BamgMesh::VerticesOnGeomVertexSize
int VerticesOnGeomVertexSize[2]
Definition: BamgMesh.h:19
BamgOpts::err
double * err
Definition: BamgOpts.h:47
BamgMesh::EdgesOnGeomEdge
double * EdgesOnGeomEdge
Definition: BamgMesh.h:24
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
GenericOption::name
char * name
Definition: GenericOption.h:25
BamgOpts::maxsubdiv
double maxsubdiv
Definition: BamgOpts.h:20
NRHS
#define NRHS
Definition: BamgConvertMesh.h:52
BamgGeom::Corners
double * Corners
Definition: BamgGeom.h:17
BamgMesh::VerticesOnGeomEdgeSize
int VerticesOnGeomEdgeSize[2]
Definition: BamgMesh.h:21
BamgGeom::RequiredEdgesSize
int RequiredEdgesSize[2]
Definition: BamgGeom.h:20
BamgOpts::verbose
int verbose
Definition: BamgOpts.h:26
BamgOpts::Crack
int Crack
Definition: BamgOpts.h:29
BamgMesh::Vertices
double * Vertices
Definition: BamgMesh.h:12
Contours
Declaration of Contours class.
Definition: Contours.h:10
BamgOpts::field
double * field
Definition: BamgOpts.h:45
BamgOpts::Hessiantype
int Hessiantype
Definition: BamgOpts.h:18
Contour
Definition: Contour.h:15
BamgMesh
Definition: BamgMesh.h:7
BamgGeom::SubDomainsSize
int SubDomainsSize[2]
Definition: BamgGeom.h:24
BamgOpts::coeff
double coeff
Definition: BamgOpts.h:15
GenericOption::value
OptionType value
Definition: GenericOption.h:26
BamgOpts::nbjacobi
int nbjacobi
Definition: BamgOpts.h:22
BamgOpts::omega
double omega
Definition: BamgOpts.h:24
BamgOpts::metricSize
int metricSize[2]
Definition: BamgOpts.h:42
BamgGeom::SubDomains
double * SubDomains
Definition: BamgGeom.h:25
BamgOpts::hVertices
double * hVertices
Definition: BamgOpts.h:41
BamgOpts::KeepVertices
int KeepVertices
Definition: BamgOpts.h:30
BamgMesh::EdgesOnGeomEdgeSize
int EdgesOnGeomEdgeSize[2]
Definition: BamgMesh.h:23
BamgOpts::gradation
double gradation
Definition: BamgOpts.h:17
BamgMesh::VerticesSize
int VerticesSize[2]
Definition: BamgMesh.h:11
FetchData
void FetchData(char **pstring, char *stringin)
Definition: FetchJavascriptData.cpp:16
BamgOpts::nbsmooth
int nbsmooth
Definition: BamgOpts.h:23
BamgGeom::CrackedEdgesSize
int CrackedEdgesSize[2]
Definition: BamgGeom.h:22
BamgMesh::VerticesOnGeomEdge
double * VerticesOnGeomEdge
Definition: BamgMesh.h:22
BamgOpts::fieldSize
int fieldSize[2]
Definition: BamgOpts.h:44
BamgMesh::EdgesSize
int EdgesSize[2]
Definition: BamgMesh.h:14
BamgOpts::hmaxVerticesSize
int hmaxVerticesSize[2]
Definition: BamgOpts.h:38
BamgGeom::RequiredVerticesSize
int RequiredVerticesSize[2]
Definition: BamgGeom.h:18
BamgOpts::hmaxVertices
double * hmaxVertices
Definition: BamgOpts.h:39
BamgOpts::hmax
double hmax
Definition: BamgOpts.h:35
BamgOpts
Definition: BamgOpts.h:8
BamgMesh::Edges
double * Edges
Definition: BamgMesh.h:15
BamgOpts::errSize
int errSize[2]
Definition: BamgOpts.h:46
Contour::nods
int nods
Definition: Contour.h:20
BamgOpts::splitcorners
int splitcorners
Definition: BamgOpts.h:31
BamgMesh::IssmSegmentsSize
int IssmSegmentsSize[2]
Definition: BamgMesh.h:38
BamgOpts::maxnbv
int maxnbv
Definition: BamgOpts.h:19
BamgOpts::metric
double * metric
Definition: BamgOpts.h:43
Option
Definition: Option.h:13
BamgGeom::VerticesSize
int VerticesSize[2]
Definition: BamgGeom.h:10
BamgMesh::TrianglesSize
int TrianglesSize[2]
Definition: BamgMesh.h:16
BamgGeom::EdgesSize
int EdgesSize[2]
Definition: BamgGeom.h:12
BamgGeom
Definition: BamgGeom.h:7
BamgMesh::VerticesOnGeomVertex
double * VerticesOnGeomVertex
Definition: BamgMesh.h:20
Contour::y
doubletype * y
Definition: Contour.h:22
BamgOpts::hmin
double hmin
Definition: BamgOpts.h:34
javascriptio.h
BamgOpts::Check
void Check(void)
Definition: BamgOpts.cpp:50
Contour::x
doubletype * x
Definition: Contour.h:21
BamgOpts::errg
double errg
Definition: BamgOpts.h:16
BamgGeom::Vertices
double * Vertices
Definition: BamgGeom.h:11
BamgOpts::hVerticesLength
int hVerticesLength
Definition: BamgOpts.h:40
BamgGeom::RequiredEdges
double * RequiredEdges
Definition: BamgGeom.h:21
BamgOpts::anisomax
double anisomax
Definition: BamgOpts.h:13
BamgOpts::Metrictype
int Metrictype
Definition: BamgOpts.h:21
BamgMesh::IssmSegments
double * IssmSegments
Definition: BamgMesh.h:39
IssmPDouble
IssmDouble IssmPDouble
Definition: types.h:38
BamgMesh::CrackedEdges
double * CrackedEdges
Definition: BamgMesh.h:33
Options::AddOption
int AddOption(Option *in_oobject)
Definition: Options.cpp:33
BamgOpts::hminVerticesSize
int hminVerticesSize[2]
Definition: BamgOpts.h:36
BamgMesh::Triangles
double * Triangles
Definition: BamgMesh.h:17
BamgMesh::CrackedEdgesSize
int CrackedEdgesSize[2]
Definition: BamgMesh.h:32
GenericOption
Definition: GenericOption.h:22
BamgOpts::hminVertices
double * hminVertices
Definition: BamgOpts.h:37