1 | #include "../../c/main/issm.h"
|
---|
2 | #include <cstddef>
|
---|
3 | #include <stdio.h>
|
---|
4 |
|
---|
5 | //Android specific header includes:
|
---|
6 | #include <jni.h>
|
---|
7 | #include <android/log.h>
|
---|
8 | #include <android/log.h>
|
---|
9 |
|
---|
10 | //iOS specific header includes:
|
---|
11 |
|
---|
12 | namespace gov_nasa_jpl_issm
|
---|
13 | {
|
---|
14 | /*Global variables{{{*/
|
---|
15 | FemModel *fm;
|
---|
16 | double* xyz; /*keep vertices information here*/
|
---|
17 | /*}}}*/
|
---|
18 | jint Initialize(JNIEnv *env, jclass clazz, jstring jsolution_type, jstring jabsfile, jstring jrelfile) /*{{{*/
|
---|
19 | {
|
---|
20 |
|
---|
21 | /*arguments to constructor: */
|
---|
22 | int argc; //arguments to constructor.
|
---|
23 | char** argv = NULL;
|
---|
24 | const char* issmname = "issm.exe";
|
---|
25 | char *solution_type = NULL;
|
---|
26 | char *absfile = NULL;
|
---|
27 | char *relfile = NULL;
|
---|
28 | ISSM_MPI_Comm comm=1;
|
---|
29 |
|
---|
30 | /*log:*/
|
---|
31 | __android_log_print(ANDROID_LOG_INFO, "Native","Initializing FemModel");
|
---|
32 |
|
---|
33 | /*retrieve from java machine: */
|
---|
34 | solution_type = (char*)env->GetStringUTFChars(jsolution_type,0);
|
---|
35 | absfile = (char*)env->GetStringUTFChars(jabsfile,0);
|
---|
36 | relfile = (char*)env->GetStringUTFChars(jrelfile,0);
|
---|
37 |
|
---|
38 | /*creat arguments to call constructor for FemModel: */
|
---|
39 | argc=4;
|
---|
40 | argv=(char**)malloc(argc*sizeof(char*));
|
---|
41 | argv[0]=(char*)issmname;
|
---|
42 | argv[1]=solution_type;
|
---|
43 | argv[2]=absfile;
|
---|
44 | argv[3]=relfile;
|
---|
45 |
|
---|
46 | /*call Model constructor passing in infile as File Descriptor parameter.*/
|
---|
47 | fm = new FemModel(argc,argv,comm);
|
---|
48 |
|
---|
49 | /*we'll need the toolkits activated right away to use matrices: */
|
---|
50 | ToolkitsOptionsFromAnalysis(fm->parameters,NoneAnalysisEnum);
|
---|
51 |
|
---|
52 | /*release strings: */
|
---|
53 | env->ReleaseStringUTFChars(jsolution_type, solution_type); //must realease the char*
|
---|
54 | env->ReleaseStringUTFChars(jabsfile, absfile); //must realease the char*
|
---|
55 | env->ReleaseStringUTFChars(jrelfile, relfile); //must realease the char*
|
---|
56 |
|
---|
57 | /*figure out size of solution: */
|
---|
58 | __android_log_print(ANDROID_LOG_INFO, "Native","Number of elements");
|
---|
59 | jint size = (jint) fm->elements->NumberOfElements();
|
---|
60 |
|
---|
61 | /*retrieve vertices x,y and z coordinates: */
|
---|
62 | __android_log_print(ANDROID_LOG_INFO, "Native","Retrieving vertices");
|
---|
63 | xyz=fm->vertices->ToXYZ();
|
---|
64 |
|
---|
65 | /*log: */
|
---|
66 | __android_log_print(ANDROID_LOG_INFO, "Native","Done Initializing FemModel");
|
---|
67 |
|
---|
68 | return size;
|
---|
69 |
|
---|
70 | }
|
---|
71 | /*}}}*/
|
---|
72 | void Solve(JNIEnv *env, jclass clazz , jdouble alpha, jobject buf){ /*{{{*/
|
---|
73 |
|
---|
74 | int i,count;
|
---|
75 | double x1,y1,z1,vel1;
|
---|
76 | double x2,y2,z2,vel2;
|
---|
77 | double x3,y3,z3,vel3;
|
---|
78 | int v1,v2,v3,eid;
|
---|
79 | Patch* patch=NULL;
|
---|
80 |
|
---|
81 | /*log:*/
|
---|
82 | __android_log_print(ANDROID_LOG_INFO, "Native","Solving ");
|
---|
83 |
|
---|
84 | /*retrieve buffer: */
|
---|
85 | jdouble *dBuf = (jdouble *)env->GetDirectBufferAddress(buf);
|
---|
86 |
|
---|
87 | /*reset basal friction to what it was before: */
|
---|
88 | __android_log_print(ANDROID_LOG_INFO, "Native","alpha %g ",alpha);
|
---|
89 |
|
---|
90 | __android_log_print(ANDROID_LOG_INFO, "Native","ok-1");
|
---|
91 |
|
---|
92 | InputDuplicatex(fm->elements,fm->nodes,fm->vertices,fm->loads,fm->materials,fm->parameters,AndroidFrictionCoefficientEnum,FrictionCoefficientEnum);
|
---|
93 | __android_log_print(ANDROID_LOG_INFO, "Native","ok0");
|
---|
94 |
|
---|
95 | /*now scale friction by alpha: */
|
---|
96 | InputScalex(fm->elements,fm->nodes,fm->vertices,fm->loads,fm->materials,fm->parameters,FrictionCoefficientEnum,alpha/100);
|
---|
97 | __android_log_print(ANDROID_LOG_INFO, "Native","ok1");
|
---|
98 |
|
---|
99 | /*solve: */
|
---|
100 | fm -> Solve();
|
---|
101 | __android_log_print(ANDROID_LOG_INFO, "Native","ok2");
|
---|
102 |
|
---|
103 | /*retrieve results: */
|
---|
104 | __android_log_print(ANDROID_LOG_INFO, "Native","Retrieving results ");
|
---|
105 | //fm->elements->ProcessResultsUnits(); we are now in SI units
|
---|
106 | patch=fm->elements->ResultsToPatch();
|
---|
107 |
|
---|
108 | /*sort out the velocities: */
|
---|
109 | for(i=0;i<patch->numrows;i++){
|
---|
110 | if ((patch->values[i*patch->numcols+0])==VelEnum){
|
---|
111 |
|
---|
112 | /*Each row of the Patch object is made of the following information:
|
---|
113 | - the result enum_type,
|
---|
114 | - the step and time,
|
---|
115 | - the id of the element,
|
---|
116 | - the interpolation type,
|
---|
117 | - the vertices ids,
|
---|
118 | - and the values at the nodes (could be different from the vertices)
|
---|
119 | */
|
---|
120 | eid=(int)patch->values[i*patch->numcols+3]-1;
|
---|
121 | v1=(int)patch->values[i*patch->numcols+5];
|
---|
122 | x1=xyz[3*(v1-1)+0]; y1=xyz[3*(v1-1)+1]; z1=xyz[3*(v1-1)+2];
|
---|
123 |
|
---|
124 | v2=(int)patch->values[i*patch->numcols+6];
|
---|
125 | x2=xyz[3*(v2-1)+0]; y2=xyz[3*(v2-1)+1]; z2=xyz[3*(v2-1)+2];
|
---|
126 |
|
---|
127 | v3=(int)patch->values[i*patch->numcols+7];
|
---|
128 | x3=xyz[3*(v3-1)+0]; y3=xyz[3*(v3-1)+1]; z3=xyz[3*(v3-1)+2];
|
---|
129 |
|
---|
130 | vel1=patch->values[i*patch->numcols+8];
|
---|
131 | vel2=patch->values[i*patch->numcols+9];
|
---|
132 | vel3=patch->values[i*patch->numcols+10];
|
---|
133 |
|
---|
134 | /*plug into dBuf: */
|
---|
135 | /*vertex 1: */
|
---|
136 | dBuf[12*eid+0]=x1;
|
---|
137 | dBuf[12*eid+1]=y1;
|
---|
138 | dBuf[12*eid+2]=z1;
|
---|
139 |
|
---|
140 | /*vertex 2: */
|
---|
141 | dBuf[12*eid+3]=x2;
|
---|
142 | dBuf[12*eid+4]=y2;
|
---|
143 | dBuf[12*eid+5]=z2;
|
---|
144 |
|
---|
145 | /*vertex 3: */
|
---|
146 | dBuf[12*eid+6]=x3;
|
---|
147 | dBuf[12*eid+7]=y3;
|
---|
148 | dBuf[12*eid+8]=z3;
|
---|
149 |
|
---|
150 | /*values at 3 vertices: */
|
---|
151 | dBuf[12*eid+9]=vel1;
|
---|
152 | dBuf[12*eid+10]=vel2;
|
---|
153 | dBuf[12*eid+11]=vel3;
|
---|
154 |
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | /*for(i=0;i<148;i++){
|
---|
159 | __android_log_print(ANDROID_LOG_INFO, "Native","%g %g %g | %g %g %g | %g %g %g | %g %g %g\n",
|
---|
160 | dBuf[12*i+0],dBuf[12*i+1],dBuf[12*i+2],
|
---|
161 | dBuf[12*i+3],dBuf[12*i+4],dBuf[12*i+5],
|
---|
162 | dBuf[12*i+6],dBuf[12*i+7],dBuf[12*i+8],
|
---|
163 | dBuf[12*i+9],dBuf[12*i+10],dBuf[12*i+11]);
|
---|
164 | }*/
|
---|
165 |
|
---|
166 | /*delete temporary data:*/
|
---|
167 | delete patch;
|
---|
168 |
|
---|
169 | }/*}}}*/
|
---|
170 | static JNINativeMethod method_table[] = /*{{{*/
|
---|
171 | {
|
---|
172 | {"createISSMModel" ,"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I" , (void *) Initialize},
|
---|
173 | {"solveISSMModel", "(DLjava/nio/DoubleBuffer;)V", (void *) Solve}
|
---|
174 | };
|
---|
175 | /*}}}*/
|
---|
176 | }
|
---|
177 |
|
---|
178 | using namespace gov_nasa_jpl_issm;
|
---|
179 | extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) /*{{{*/
|
---|
180 | {
|
---|
181 | JNIEnv* env;
|
---|
182 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
---|
183 | return -1;
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | jclass clazz = env->FindClass("gov/nasa/jpl/issm/IssmJni");
|
---|
188 | if(clazz)
|
---|
189 | {
|
---|
190 | env->RegisterNatives(clazz, method_table, 3);
|
---|
191 | env->DeleteLocalRef(clazz);
|
---|
192 | return JNI_VERSION_1_6;
|
---|
193 | }
|
---|
194 | else return -1;
|
---|
195 | }
|
---|
196 | }
|
---|
197 | /*}}}*/
|
---|