Ice Sheet System Model  4.18
Code documentation
InterpFromMesh2dx.cpp
Go to the documentation of this file.
1 
5 #include "./InterpFromMesh2dx.h"
6 #include "../../shared/shared.h"
7 #include "../../toolkits/toolkits.h"
8 #include "../../classes/classes.h"
9 #include "../ContourToNodesx/ContourToNodesx.h"
10 
12  int* index_data, double* x_data, double* y_data, int nods_data,int nels_data, double* data, int data_length,
13  double* x_prime, double* y_prime, int nods_prime,
14  double* default_values,int num_default_values,Contour<IssmPDouble>** contours,int numcontours){
15 
16  /*Output*/
17  IssmSeqVec<IssmPDouble>* data_prime=NULL;
18 
19  /*Intermediary*/
20  int i;
21  int interpolation_type;
22  bool debug;
23  double xmin,xmax;
24  double ymin,ymax;
25 
26  /*contours: */
27  double *incontour = NULL;
28 
29  /*some checks*/
30  if (nels_data<1 || nods_data<3 || nods_prime==0){
31  _error_("nothing to be done according to the mesh given in input");
32  }
33 
34  /*Set debug to 1 if there are lots of elements*/
35  debug=(bool)((double)nels_data*(double)nods_prime >= pow((double)10,(double)9));
36 
37  /*figure out what kind of interpolation is needed*/
38  if (data_length==nods_data){
39  interpolation_type=1;
40  }
41  else if (data_length==nels_data){
42  interpolation_type=2;
43  }
44  else{
45  _error_("length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!");
46  }
47 
48  if((numcontours) && (interpolation_type==2)){
49  _error_("element interpolation_type with contours not supported yet!");
50  }
51 
52  /*Get prime mesh extrema coordinates*/
53  xmin=x_prime[0]; xmax=x_prime[0];ymin=y_prime[0]; ymax=y_prime[0];
54  for (i=1;i<nods_prime;i++){
55  if (x_prime[i]<xmin) xmin=x_prime[i];
56  if (x_prime[i]>xmax) xmax=x_prime[i];
57  if (y_prime[i]<ymin) ymin=y_prime[i];
58  if (y_prime[i]>ymax) ymax=y_prime[i];
59  }
60 
61  /*Initialize output*/
62  data_prime=new IssmSeqVec<IssmPDouble>(nods_prime);
63  if(num_default_values){
64  if(num_default_values==1)for (i=0;i<nods_prime;i++) data_prime->SetValue(i,default_values[0],INS_VAL);
65  else for (i=0;i<nods_prime;i++) data_prime->SetValue(i,default_values[i],INS_VAL);
66  }
67 
68  /*Build indices of contour: */
69  if(numcontours){
70  ContourToNodesx( &incontour,x_prime,y_prime,nods_prime,contours,numcontours,1);
71  }
72  else{
73  incontour=xNew<double>(nods_prime);
74  for (i=0;i<nods_prime;i++) incontour[i]=1.0;
75  }
76 
77  /*initialize thread parameters: */
79  gate.interpolation_type = interpolation_type;
80  gate.debug = debug;
81  gate.nels_data = nels_data;
82  gate.index_data = index_data;
83  gate.x_data = x_data;
84  gate.y_data = y_data;
85  gate.data = data;
86  gate.xmin = xmin;
87  gate.xmax = xmax;
88  gate.ymin = ymin;
89  gate.ymax = ymax;
90  gate.nods_prime = nods_prime;
91  gate.data_prime = data_prime;
92  gate.x_prime = x_prime;
93  gate.y_prime = y_prime;
94  gate.default_values = default_values;
95  gate.num_default_values = num_default_values;
96  gate.incontour = incontour;
97 
98  /*launch the thread manager with InterpFromGridToMeshxt as a core: */
99  LaunchThread(InterpFromMesh2dxt,(void*)&gate,_NUMTHREADS_);
100 
101  /*Assign output pointers:*/
102  xDelete<double>(incontour);
103  *pdata_prime=data_prime;
104  return 1;
105 }
InterpFromMesh2dxThreadStruct
Definition: InterpFromMesh2dx.h:12
InterpFromMesh2dxThreadStruct::ymin
double ymin
Definition: InterpFromMesh2dx.h:22
InterpFromMesh2dxThreadStruct::y_prime
double * y_prime
Definition: InterpFromMesh2dx.h:26
InterpFromMesh2dxThreadStruct::x_prime
double * x_prime
Definition: InterpFromMesh2dx.h:25
LaunchThread
void LaunchThread(void *function(void *), void *gate, int num_threads)
Definition: LaunchThread.cpp:25
InterpFromMesh2dxThreadStruct::default_values
double * default_values
Definition: InterpFromMesh2dx.h:27
InterpFromMesh2dxThreadStruct::nods_prime
int nods_prime
Definition: InterpFromMesh2dx.h:23
IssmSeqVec< IssmPDouble >
Contour
Definition: Contour.h:15
InterpFromMesh2dxThreadStruct::interpolation_type
int interpolation_type
Definition: InterpFromMesh2dx.h:14
ContourToNodesx
int ContourToNodesx(IssmPDouble **pflags, double *x, double *y, int nods, Contour< IssmPDouble > **contours, int numcontours, int edgevalue)
Definition: ContourToNodesx.cpp:6
IssmSeqVec::SetValue
void SetValue(int dof, doubletype value, InsMode mode)
Definition: IssmSeqVec.h:115
InterpFromMesh2dxThreadStruct::incontour
double * incontour
Definition: InterpFromMesh2dx.h:29
InterpFromMesh2dxThreadStruct::nels_data
int nels_data
Definition: InterpFromMesh2dx.h:16
InterpFromMesh2dxThreadStruct::xmin
double xmin
Definition: InterpFromMesh2dx.h:21
INS_VAL
@ INS_VAL
Definition: toolkitsenums.h:14
InterpFromMesh2dxThreadStruct::data_prime
IssmSeqVec< IssmPDouble > * data_prime
Definition: InterpFromMesh2dx.h:24
InterpFromMesh2dxThreadStruct::ymax
double ymax
Definition: InterpFromMesh2dx.h:22
InterpFromMesh2dx
int InterpFromMesh2dx(IssmSeqVec< IssmPDouble > **pdata_prime, int *index_data, double *x_data, double *y_data, int nods_data, int nels_data, double *data, int data_length, double *x_prime, double *y_prime, int nods_prime, double *default_values, int num_default_values, Contour< IssmPDouble > **contours, int numcontours)
Definition: InterpFromMesh2dx.cpp:11
InterpFromMesh2dxThreadStruct::data
double * data
Definition: InterpFromMesh2dx.h:20
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
InterpFromMesh2dxThreadStruct::xmax
double xmax
Definition: InterpFromMesh2dx.h:21
InterpFromMesh2dx.h
: header file for Data interpolation routines.
InterpFromMesh2dxThreadStruct::debug
bool debug
Definition: InterpFromMesh2dx.h:15
InterpFromMesh2dxThreadStruct::index_data
int * index_data
Definition: InterpFromMesh2dx.h:17
InterpFromMesh2dxThreadStruct::y_data
double * y_data
Definition: InterpFromMesh2dx.h:19
InterpFromMesh2dxThreadStruct::x_data
double * x_data
Definition: InterpFromMesh2dx.h:18
InterpFromMesh2dxThreadStruct::num_default_values
int num_default_values
Definition: InterpFromMesh2dx.h:28
InterpFromMesh2dxt
void * InterpFromMesh2dxt(void *vInterpFromMesh2dxThreadStruct)
Definition: InterpFromMesh2dxt.cpp:8