source: issm/trunk/src/c/ModelProcessorx/Model.cpp@ 358

Last change on this file since 358 was 358, checked in by Eric.Larour, 16 years ago

New slope extrude module. New slope computation in Penta and Tria

File size: 12.8 KB
RevLine 
[1]1/*! \file Model.cpp
2 * \brief Model structure that mirrors the matlab workspace structure. Servers for the serial
3 * and parallel runs.
4 */
5
6#ifdef HAVE_CONFIG_H
7 #include "config.h"
8#else
9#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
10#endif
11
12#include "../shared/shared.h"
13#include "../io/io.h"
14#include "../include/globals.h"
15#include "../include/macros.h"
16
17#include <string.h>
18#include "stdio.h"
19
[117]20#include "./Model.h"
[1]21
22
23/*!--------------------------------------------------
24 NewModel
25 --------------------------------------------------*/
26
27Model* NewModel(void) {
28 /*! create a new Model object */
29 Model* model=NULL;
30
31 model=(Model*)xmalloc(sizeof(Model));
32
33 /*!initialize all pointers to 0: */
34
35
36 model->repository=NULL;
37 model->meshtype=NULL;
38 model->analysis_type=NULL;
39 model->numberofelements=0;
40 model->numberofnodes=0;
41 model->x=NULL;
42 model->y=NULL;
43 model->z=NULL;
44 model->elements=NULL;
45 model->elements_type=NULL;
46 model->numberofnodes2d=0;
47 model->elements2d=NULL;
[88]48 model->deadgrids=NULL;
[1]49 model->numlayers=0;
[88]50 model->uppernodes=NULL;
[308]51 model->gridonhutter=NULL;
[1]52
53 model->vx_obs=NULL;
54 model->vy_obs=NULL;
55 model->vx=NULL;
56 model->vy=NULL;
57 model->vz=NULL;
58 model->pressure=NULL;
59 model->elementonbed=NULL;
60 model->elementonsurface=NULL;
61 model->gridonbed=NULL;
62 model->gridonsurface=NULL;
63 model->thickness=NULL;
64 model->surface=NULL;
65 model->bed=NULL;
66 model->elementoniceshelf=NULL;
67
68 model->drag_type=0;
69 model->drag=NULL;
70 model->p=NULL;
71
72
73 model->numberofsegs_diag=0;
74 model->segmentonneumann_diag=NULL;
75 model-> neumannvalues_diag=NULL;
76 model-> gridondirichlet_diag=NULL;
77 model-> dirichletvalues_diag=NULL;
78 //prognostic
79 model-> segmentonneumann_prog=NULL;
80 model-> neumannvalues_prog=NULL;
81 model-> gridondirichlet_prog=NULL;
82 model-> dirichletvalues_prog=NULL;
83 //prognostic2
84 model-> segmentonneumann_prog2=NULL;
85 model-> neumannvalues_prog2=NULL;
86 //thermal
87 model-> gridondirichlet_thermal=NULL;
88 model-> dirichletvalues_thermal=NULL;
89 model-> geothermalflux=NULL;
90
91 /*!materials: */
92 model->rho_water=0;
93 model->rho_ice=0;
94 model->g=0;
95 model->n=0;
96 model->B=NULL;
97
98 /*!control methods: */
99 model->control_type=NULL;
100
101 /*!solution parameters: */
102 model->fit=NULL;
103 model->meanvel=0;
104 model->epsvel=0;
105 model->artificial_diffusivity=0;
106 model->nsteps=0;
107 model->tolx=0;
108 model->maxiter=NULL;
109 model->mincontrolconstraint=0;
110 model->maxcontrolconstraint=0;
111 model->debug=0;
112 model->plot=0;
113 model->eps_rel=0;
114 model->eps_abs=0;
115 model->dt=0;
116 model->ndt=0;
117 model->penalty_offset=0;
118 model->penalty_melting=0;
119 model->penalty_lock=0;
120 model->sparsity=0;
121 model->connectivity=0;
122 model->lowmem=0;
123 model->optscal=NULL;
124 model->yts=0;
125 model->viscosity_overshoot=0;
126 model->waitonlock=0;
127
128 /*!thermal parameters: */
129 model->beta=0;
130 model->meltingpoint=0;
131 model->latentheat=0;
132 model->heatcapacity=0;
133 model->thermalconductivity=0;
134 model->min_thermal_constraints=0;
135 model->mixed_layer_capacity=0;
136 model->thermal_exchange_velocity=0;
137
138
139 model->numrifts=0;
140 model->riftsnumpenaltypairs=NULL;
141 model->riftspenaltypairs=NULL;
142 model->riftsfill=NULL;
143 model->riftsfriction=NULL;
144
145 /*!penalties: */
146 model->numpenalties=0;
147 model->penalties=NULL;
148 model->penaltypartitioning=NULL;
149
150 /*!basal: */
151 model->melting=NULL;
152 model->accumulation=NULL;
153
[300]154 /*elements type: */
155 model->ishutter=0;
156 model->ismacayealpattyn=0;
157 model->isstokes=0;
158
[1]159 return model;
160}
161
162
163/*!--------------------------------------------------
164 DeleteModel
165 --------------------------------------------------*/
166
167void DeleteModel(Model** pmodel){
168
169 /*!Recover structure: */
170 Model* model = *pmodel;
171
172 int i;
173
174 /*!Two cases here:
175 * - serial mode: matlab's memory manager will take care of delete model when returning from Imp. Do nothing here, so as not to confuse
176 * the memory manager.
177 * - in parallel, anything the io layer does (FetchData) did needs to be erased explicitely in the model.
178 */
179
180 #ifdef _PARALLEL_
181 xfree((void**)&model->x);
182 xfree((void**)&model->y);
183 xfree((void**)&model->z);
184 xfree((void**)&model->elements);
185 xfree((void**)&model->elements_type);
[308]186 xfree((void**)&model->gridonhutter);
[1]187 if (strcmp(model->meshtype,"3d")==0){
188 xfree((void**)&model->elements2d);
189 xfree((void**)&model->deadgrids);
[88]190 xfree((void**)&model->uppernodes);
[1]191 }
192 xfree((void**)&model->solverstring);
193 xfree((void**)&model->elementonbed);
194 xfree((void**)&model->elementonsurface);
195 xfree((void**)&model->gridonbed);
196 xfree((void**)&model->gridonsurface);
197 xfree((void**)&model->thickness);
198 xfree((void**)&model->surface);
199 xfree((void**)&model->bed);
200 xfree((void**)&model->vx_obs);
201 xfree((void**)&model->vy_obs);
202 xfree((void**)&model->vx);
203 xfree((void**)&model->vy);
204 xfree((void**)&model->vz);
205 xfree((void**)&model->pressure);
206 xfree((void**)&model->drag);
207 xfree((void**)&model->p);
208 xfree((void**)&model->q);
209 xfree((void**)&model->elementoniceshelf);
210 xfree((void**)&model->segmentonneumann_diag);
211 xfree((void**)&model->neumannvalues_diag);
212 xfree((void**)&model->gridondirichlet_diag);
213 xfree((void**)&model->dirichletvalues_diag);
214 xfree((void**)&model->segmentonneumann_prog);
215 xfree((void**)&model->neumannvalues_prog);
216 xfree((void**)&model->gridondirichlet_prog);
217 xfree((void**)&model->dirichletvalues_prog);
218 xfree((void**)&model->segmentonneumann_prog2);
219 xfree((void**)&model->neumannvalues_prog2);
220 xfree((void**)&model->gridondirichlet_thermal);
221 xfree((void**)&model->dirichletvalues_thermal);
222 xfree((void**)&model->geothermalflux);
223 xfree((void**)&model->melting);
224 xfree((void**)&model->accumulation);
225 xfree((void**)&model->B);
226 xfree((void**)&model->n);
227 xfree((void**)&model->fit);
228 xfree((void**)&model->optscal);
229 xfree((void**)&model->maxiter);
230
231
232 /*!Delete structure fields: */
233 xfree((void**)&model->repository);
234 xfree((void**)&model->meshtype);
235 xfree((void**)&model->analysis_type);
236
237 if(model->numrifts){
238 for(i=0;i<model->numrifts;i++){
239 double* riftpenaltypairs=model->riftspenaltypairs[i];
240 xfree((void**)&riftpenaltypairs);
241 }
242 xfree((void**)&model->riftspenaltypairs);
243 xfree((void**)&model->riftsnumpenaltypairs);
244 xfree((void**)&model->riftsfill);
245 xfree((void**)&model->riftsfriction);
246 }
247
248 xfree((void**)&model->penalties);
249 xfree((void**)&model->penaltypartitioning);
250
251 xfree((void**)&model->control_type);
252
253 /*!Delete entire structure: */
254 xfree((void**)pmodel);
255 #endif
256}
257
258/*!--------------------------------------------------
259 ModelInit
260 --------------------------------------------------*/
261
262#undef __FUNCT__
263#define __FUNCT__ "ModelInit"
264
265int ModelInit(Model** pmodel,ConstDataHandle model_handle){
266
267 int i,j;
268
269 /*output: */
270 Model* model=NULL;
271
272 /*Allocate model: */
273 model=NewModel();
274
275 /*In ModelInit, we get all the data that is not difficult to get, and that is small: */
276 ModelFetchData((void**)&model->analysis_type,NULL,NULL,model_handle,"analysis_type","String",NULL);
277
278 ModelFetchData((void**)&model->meshtype,NULL,NULL,model_handle,"type","String",NULL);
279 /*!Get numberofelements and numberofnodes: */
280 ModelFetchData((void**)&model->numberofnodes,NULL,NULL,model_handle,"numberofgrids","Integer",NULL);
281 ModelFetchData((void**)&model->numberofelements,NULL,NULL,model_handle,"numberofelements","Integer",NULL);
282
283 /*!In case we are running 3d, we are going to need the collapsed and non-collapsed 2d meshes, from which the 3d mesh was extruded: */
284 if (strcmp(model->meshtype,"3d")==0){
285
286 /*!Deal with 2d mesh: */
287 ModelFetchData((void**)&model->numberofelements2d,NULL,NULL,model_handle,"numberofelements2d","Integer",NULL);
288 ModelFetchData((void**)&model->numberofnodes2d,NULL,NULL,model_handle,"numberofgrids2d","Integer",NULL);
289 ModelFetchData((void**)&model->numlayers,NULL,NULL,model_handle,"numlayers","Integer",NULL);
290 }
[300]291
292 /*elements type: */
293 ModelFetchData((void**)&model->ishutter,NULL,NULL,model_handle,"ishutter","Integer",NULL);
294 ModelFetchData((void**)&model->ismacayealpattyn,NULL,NULL,model_handle,"ismacayealpattyn","Integer",NULL);
295
[1]296 /*!Get drag_type, drag and p,q: */
297 ModelFetchData((void**)&model->drag_type,NULL,NULL,model_handle,"drag_type","Integer",NULL);
298
299 /*!Get materials: */
300 ModelFetchData((void**)&model->rho_water,NULL,NULL,model_handle,"rho_water","Scalar",NULL);
301 ModelFetchData((void**)&model->rho_ice,NULL,NULL,model_handle,"rho_ice","Scalar",NULL);
302 ModelFetchData((void**)&model->g,NULL,NULL,model_handle,"g","Scalar",NULL);
303
304 /*Get control parameters: */
305 ModelFetchData((void**)&model->control_type,NULL,NULL,model_handle,"control_type","String",NULL);
306
307 /*!Get solution parameters: */
308 ModelFetchData((void**)&model->yts,NULL,NULL,model_handle,"yts","Scalar",NULL);
309 ModelFetchData((void**)&model->meanvel,NULL,NULL,model_handle,"meanvel","Scalar",NULL);
310 ModelFetchData((void**)&model->epsvel,NULL,NULL,model_handle,"epsvel","Scalar",NULL);
311 ModelFetchData((void**)&model->debug,NULL,NULL,model_handle,"debug","Integer",NULL);
312 ModelFetchData((void**)&model->plot,NULL,NULL,model_handle,"plot","Integer",NULL);
313 ModelFetchData((void**)&model->artificial_diffusivity,NULL,NULL,model_handle,"artificial_diffusivity","Integer",NULL);
314 ModelFetchData((void**)&model->nsteps,NULL,NULL,model_handle,"nsteps","Integer",NULL);
315 ModelFetchData((void**)&model->tolx,NULL,NULL,model_handle,"tolx","Scalar",NULL);
316 ModelFetchData((void**)&model->mincontrolconstraint,NULL,NULL,model_handle,"mincontrolconstraint","Scalar",NULL);
317 ModelFetchData((void**)&model->maxcontrolconstraint,NULL,NULL,model_handle,"maxcontrolconstraint","Scalar",NULL);
318 ModelFetchData((void**)&model->eps_rel,NULL,NULL,model_handle,"eps_rel","Scalar",NULL);
319 ModelFetchData((void**)&model->eps_abs,NULL,NULL,model_handle,"eps_abs","Scalar",NULL);
320 ModelFetchData((void**)&model->dt,NULL,NULL,model_handle,"dt","Scalar",NULL);
321 ModelFetchData((void**)&model->ndt,NULL,NULL,model_handle,"ndt","Scalar",NULL);
322 ModelFetchData((void**)&model->penalty_offset,NULL,NULL,model_handle,"penalty_offset","Scalar",NULL);
323 ModelFetchData((void**)&model->penalty_melting,NULL,NULL,model_handle,"penalty_melting","Scalar",NULL);
324 ModelFetchData((void**)&model->penalty_lock,NULL,NULL,model_handle,"penalty_lock","Integer",NULL);
325 ModelFetchData((void**)&model->sparsity,NULL,NULL,model_handle,"sparsity","Scalar",NULL);
326 ModelFetchData((void**)&model->connectivity,NULL,NULL,model_handle,"connectivity","Integer",NULL);
327 ModelFetchData((void**)&model->lowmem,NULL,NULL,model_handle,"lowmem","Integer",NULL);
328 ModelFetchData((void**)&model->solverstring,NULL,NULL,model_handle,"solverstring","String",NULL);
329 ModelFetchData((void**)&model->viscosity_overshoot,NULL,NULL,model_handle,"viscosity_overshoot","Scalar",NULL);
330 ModelFetchData((void**)&model->waitonlock,NULL,NULL,model_handle,"waitonlock","Integer",NULL);
331
332 /*!Get thermal parameters: */
333 ModelFetchData((void**)&model->beta,NULL,NULL,model_handle,"beta","Scalar",NULL);
334 ModelFetchData((void**)&model->meltingpoint,NULL,NULL,model_handle,"meltingpoint","Scalar",NULL);
335 ModelFetchData((void**)&model->latentheat,NULL,NULL,model_handle,"latentheat","Scalar",NULL);
336 ModelFetchData((void**)&model->heatcapacity,NULL,NULL,model_handle,"heatcapacity","Scalar",NULL);
337 ModelFetchData((void**)&model->thermalconductivity,NULL,NULL,model_handle,"thermalconductivity","Scalar",NULL);
338 ModelFetchData((void**)&model->min_thermal_constraints,NULL,NULL,model_handle,"min_thermal_constraints","Integer",NULL);
339 ModelFetchData((void**)&model->mixed_layer_capacity,NULL,NULL,model_handle,"mixed_layer_capacity","Scalar",NULL);
340 ModelFetchData((void**)&model->thermal_exchange_velocity,NULL,NULL,model_handle,"thermal_exchange_velocity","Scalar",NULL);
[358]341
[1]342 /*rifts: */
343 ModelFetchData((void**)&model->numrifts,NULL,NULL,model_handle,"numrifts","Integer",NULL);
344
345 /*Assign output pointers: */
346 *pmodel=model;
347
348 return 1;
349}
350
351/*!--------------------------------------------------
352 ModelEcho
353 --------------------------------------------------*/
354void ModelEcho(Model* model,int which_part,int rank) {
355
356 //which_part determines what gets echoed, otherwise, we'll get too much output.
357 //1-> penalties
358
359 int i,j;
360
361 if(which_part==1 && my_rank==rank && (strcmp(model->meshtype,"3d")==0)){
362 printf("Model penalties: \n");
363 printf(" number of penalties: %i\n",model->numpenalties);
364 printf(" grids: \n");
365
366 for(i=0;i<model->numpenalties;i++){
367 for(j=0;j<model->numlayers;j++){
368 printf("%i ",(int)*(model->penalties+model->numlayers*i+j));
369 }
370 printf("\n");
371 }
372 }
373
374 if(which_part==2 && my_rank==rank){
375 printf("Model rifts: \n");
376 printf(" number of rifts: %i\n",model->numrifts);
377 for(i=0;i<model->numrifts;i++){
378 double* penaltypairs=model->riftspenaltypairs[i];
379 printf(" rift #%i\n",i);
380 for (j=0;j<model->riftsnumpenaltypairs[i];j++){
381 printf(" grids %g %g elements %g %g normal [%g,%g] length %g\n",*(penaltypairs+7*j+0),*(penaltypairs+7*j+1),*(penaltypairs+7*j+2),*(penaltypairs+7*j+3),
382 *(penaltypairs+7*j+4),*(penaltypairs+7*j+5),*(penaltypairs+7*j+6));
383 }
384 printf(" friction %g fill %i\n",model->riftsfriction[i],model->riftsfill[i]);
385 }
386 }
387 cleanup_and_return:
388 return;
389}
Note: See TracBrowser for help on using the repository browser.