source: issm/trunk-jpl/src/c/classes/Loads/Icefront.cpp@ 15564

Last change on this file since 15564 was 15564, checked in by Mathieu Morlighem, 12 years ago

CHG: hutter-> SIA macayeal->SSA pattyn->HO stokes->FS

File size: 29.2 KB
RevLine 
[3683]1/*!\file Icefront.c
2 * \brief: implementation of the Icefront object
3 */
4
5/*Headers:*/
[12365]6/*{{{*/
[3683]7#ifdef HAVE_CONFIG_H
[9320]8 #include <config.h>
[3683]9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
[15012]13#include "../classes.h"
14#include "shared/shared.h"
[3683]15/*}}}*/
16
[5701]17/*Load macros*/
18#define NUMVERTICESSEG 2
19#define NUMVERTICESQUA 4
20
[4248]21/*Icefront constructors and destructor*/
[12365]22/*FUNCTION Icefront::Icefront() {{{*/
[3683]23Icefront::Icefront(){
[5714]24
[3683]25 this->inputs=NULL;
26 this->parameters=NULL;
[5714]27
[4396]28 this->hnodes=NULL;
[5714]29 this->nodes= NULL;
[14761]30 this->hvertices=NULL;
31 this->vertices= NULL;
[4396]32 this->helement=NULL;
[5714]33 this->element= NULL;
[4396]34 this->hmatpar=NULL;
[5714]35 this->matpar= NULL;
[3683]36}
37/*}}}*/
[12365]38/*FUNCTION Icefront::Icefront(int id, int i, IoModel* iomodel,int analysis_type) {{{*/
[5136]39Icefront::Icefront(int icefront_id,int i, IoModel* iomodel,int in_icefront_type, int in_analysis_type){
[3683]40
41 int segment_width;
42 int element;
[15298]43 int numnodes;
44 int numvertices;
[3683]45
46 /*icefront constructor data: */
47 int icefront_eid;
48 int icefront_mparid;
49 int icefront_fill;
[15450]50 int *icefront_node_ids = NULL;
51 int *icefront_vertex_ids = NULL;
[13622]52
[3683]53 /*First, retrieve element index and element type: */
[15423]54 if(iomodel->dim==2){
[3683]55 segment_width=4;
56 }
57 else{
58 segment_width=6;
59 }
[9679]60 _assert_(iomodel->Data(DiagnosticIcefrontEnum));
[15450]61 element=reCast<int,IssmDouble>(iomodel->Data(DiagnosticIcefrontEnum)[segment_width*i+segment_width-2]-1);
[3683]62
63 /*Build ids for hook constructors: */
[15450]64 icefront_eid = reCast<int,IssmDouble>(iomodel->Data(DiagnosticIcefrontEnum)[segment_width*i+segment_width-2]); //matlab indexing
65 icefront_mparid = iomodel->numberofelements+1;
[3683]66
[5715]67 if (in_icefront_type==MacAyeal2dIceFrontEnum || in_icefront_type==MacAyeal3dIceFrontEnum){
[15450]68 numnodes = 2;
69 numvertices = 2;
70 icefront_node_ids = xNew<int>(numnodes);
71 icefront_vertex_ids = xNew<int>(numvertices);
[12557]72 icefront_node_ids[0]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
73 icefront_node_ids[1]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
[14761]74 icefront_vertex_ids[0]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
75 icefront_vertex_ids[1]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
[3683]76 }
[15564]77 else if (in_icefront_type==HOIceFrontEnum || in_icefront_type==FSIceFrontEnum){
[15450]78 numnodes = 4;
79 numvertices = 4;
80 icefront_node_ids = xNew<int>(numnodes);
81 icefront_vertex_ids = xNew<int>(numvertices);
[12557]82 icefront_node_ids[0]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
83 icefront_node_ids[1]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
84 icefront_node_ids[2]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+2));
85 icefront_node_ids[3]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+3));
[14761]86 icefront_vertex_ids[0]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
87 icefront_vertex_ids[1]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
88 icefront_vertex_ids[2]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+2));
89 icefront_vertex_ids[3]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+3));
[3683]90 }
[13036]91 else _error_("in_icefront_type " << EnumToStringx(in_icefront_type) << " not supported yet!");
[3683]92
[9465]93 /*Fill*/
[12557]94 icefront_fill=reCast<int>(iomodel->Data(DiagnosticIcefrontEnum)[segment_width*i+segment_width-1]);
[13622]95
[3683]96 /*Ok, we have everything to build the object: */
97 this->id=icefront_id;
[4003]98 this->analysis_type=in_analysis_type;
[3683]99
100 /*Hooks: */
[15298]101 this->hnodes=new Hook(icefront_node_ids,numnodes);
102 this->hvertices=new Hook(icefront_vertex_ids,numvertices);
[4396]103 this->helement=new Hook(&icefront_eid,1);
104 this->hmatpar=new Hook(&icefront_mparid,1);
[3683]105
106 //intialize and add as many inputs per element as requested:
107 this->inputs=new Inputs();
108 this->inputs->AddInput(new IntInput(FillEnum,icefront_fill));
[14688]109 this->inputs->AddInput(new IntInput(IceFrontTypeEnum,in_icefront_type));
[13622]110
[5714]111 //parameters and hooked fields: we still can't point to them, they may not even exist. Configure will handle this.
[14761]112 this->parameters = NULL;
113 this->nodes = NULL;
114 this->vertices = NULL;
115 this->element = NULL;
116 this->matpar = NULL;
[15450]117
118 /*Clean up*/
119 xDelete<int>(icefront_node_ids);
120 xDelete<int>(icefront_vertex_ids);
[3683]121}
122/*}}}*/
[15401]123/*FUNCTION Icefront::Icefront(const char* element_type_in,Inputs* inputs_in,Matpar* matpar_in, int icefront_type, int in_analysis_type) {{{*/
[15508]124Icefront::Icefront(int element_id, const char* element_type_in,Inputs* inputs_in,Matpar* matpar_in,int in_icefront_type, int in_analysis_type){
[15401]125
126 int segment_width;
127 int element;
128 int numnodes;
129 int numvertices;
130 int numberofelements;
131
132 /*icefront constructor data: */
133 int icefront_eid;
134 int icefront_mparid;
135 int icefront_node_ids[NUMVERTICESQUA]; //initialize with largest size
136 int icefront_vertex_ids[NUMVERTICESQUA]; //initialize with largest size
137
138// /*find parameters: */
139// iomodel->Constant(&numberofelements,MeshNumberofelementsEnum);
140//
141 /*First, retrieve element index and element type: */
142 if(strcmp(element_type_in,"2d")==0){
143 segment_width=4;
144 }
145 else{
146 segment_width=6;
147 }
[15508]148// element=element_number;
149
150 /*Build ids for hook constructors: */
[15401]151// icefront_eid=reCast<int,IssmDouble>( *(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+segment_width-2)); //matlab indexing
152// icefront_mparid=numberofelements+1; //matlab indexing
153//
154 if (in_icefront_type==MacAyeal2dIceFrontEnum || in_icefront_type==MacAyeal3dIceFrontEnum){
155// icefront_node_ids[0]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
156// icefront_node_ids[1]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
157// icefront_vertex_ids[0]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
158// icefront_vertex_ids[1]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
159 }
[15564]160 else if (in_icefront_type==HOIceFrontEnum || in_icefront_type==FSIceFrontEnum){
[15401]161// icefront_node_ids[0]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
162// icefront_node_ids[1]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
163// icefront_node_ids[2]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+2));
164// icefront_node_ids[3]=iomodel->nodecounter+reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+3));
165// icefront_vertex_ids[0]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+0));
166// icefront_vertex_ids[1]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+1));
167// icefront_vertex_ids[2]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+2));
168// icefront_vertex_ids[3]=reCast<int>(*(iomodel->Data(DiagnosticIcefrontEnum)+segment_width*i+3));
169 }
170 else _error_("in_icefront_type " << EnumToStringx(in_icefront_type) << " not supported yet!");
171
[15564]172 if (in_icefront_type==HOIceFrontEnum || in_icefront_type==FSIceFrontEnum){
[15401]173 numnodes=4;
174 numvertices=4;
175 }
176 else{
177 numnodes=2;
178 numvertices=2;
179 }
180
181 /*Ok, we have everything to build the object: */
182 this->id=1;
183 this->analysis_type=in_analysis_type;
184
185 /*Hooks: */
186 this->hnodes=new Hook(icefront_node_ids,numnodes);
187 this->hvertices=new Hook(icefront_vertex_ids,numvertices);
188 this->helement=new Hook(&icefront_eid,1);
189 this->hmatpar=new Hook(&icefront_mparid,1);
190
191 //intialize and add as many inputs per element as requested:
192 this->inputs=inputs_in;
193 this->inputs->AddInput(new IntInput(FillEnum,1)); //We always consider we have water, if above sea level, only air will be applied
194 this->inputs->AddInput(new IntInput(IceFrontTypeEnum,in_icefront_type));
195
196 //parameters and hooked fields: we still can't point to them, they may not even exist. Configure will handle this.
197 this->parameters = NULL;
198 this->nodes = NULL;
199 this->vertices = NULL;
200 this->element = NULL;
201 this->matpar = matpar_in;
202}
203
204/*}}}*/
[12365]205/*FUNCTION Icefront::~Icefront() {{{*/
[3683]206Icefront::~Icefront(){
207 delete inputs;
208 this->parameters=NULL;
[4396]209 delete hnodes;
[14761]210 delete hvertices;
[4396]211 delete helement;
212 delete hmatpar;
[3683]213}
214/*}}}*/
215
[4248]216/*Object virtual functions definitions:*/
[12365]217/*FUNCTION Icefront::Echo {{{*/
[4248]218void Icefront::Echo(void){
[15104]219 _printf_("Icefront:\n");
[15100]220 _printf_(" id: " << id << "\n");
221 _printf_(" analysis_type: " << EnumToStringx(analysis_type) << "\n");
[4396]222 hnodes->Echo();
[14761]223 hvertices->Echo();
[4396]224 helement->Echo();
225 hmatpar->Echo();
[15100]226 _printf_(" parameters: " << parameters << "\n");
[5161]227 if(parameters)parameters->Echo();
[15100]228 _printf_(" inputs: " << inputs << "\n");
[5161]229 if(inputs)inputs->Echo();
[3683]230}
231/*}}}*/
[12365]232/*FUNCTION Icefront::DeepEcho{{{*/
[3683]233void Icefront::DeepEcho(void){
234
[15104]235 _printf_("Icefront:\n");
[15100]236 _printf_(" id: " << id << "\n");
237 _printf_(" analysis_type: " << EnumToStringx(analysis_type) << "\n");
[4396]238 hnodes->DeepEcho();
[14761]239 hvertices->DeepEcho();
[4396]240 helement->DeepEcho();
241 hmatpar->DeepEcho();
[15100]242 _printf_(" parameters: " << parameters << "\n");
[5161]243 if(parameters)parameters->DeepEcho();
[15100]244 _printf_(" inputs: " << inputs << "\n");
[5161]245 if(inputs)inputs->DeepEcho();
[3683]246}
247/*}}}*/
[12365]248/*FUNCTION Icefront::Id {{{*/
[4248]249int Icefront::Id(void){ return id; }
[3683]250/*}}}*/
[12365]251/*FUNCTION Icefront::ObjectEnum{{{*/
[9883]252int Icefront::ObjectEnum(void){
[3683]253
[4248]254 return IcefrontEnum;
255
256}
257/*}}}*/
[12365]258/*FUNCTION Icefront::copy {{{*/
[4248]259Object* Icefront::copy() {
[13622]260
[4248]261 Icefront* icefront=NULL;
262
263 icefront=new Icefront();
264
265 /*copy fields: */
266 icefront->id=this->id;
267 icefront->analysis_type=this->analysis_type;
268 if(this->inputs){
269 icefront->inputs=(Inputs*)this->inputs->Copy();
270 }
271 else{
272 icefront->inputs=new Inputs();
273 }
274 /*point parameters: */
275 icefront->parameters=this->parameters;
276
277 /*now deal with hooks and objects: */
[14761]278 icefront->hnodes = (Hook*)this->hnodes->copy();
279 icefront->hvertices = (Hook*)this->hvertices->copy();
280 icefront->helement = (Hook*)this->helement->copy();
281 icefront->hmatpar = (Hook*)this->hmatpar->copy();
[4248]282
[5714]283 /*corresponding fields*/
[14761]284 icefront->nodes = (Node**)icefront->hnodes->deliverp();
285 icefront->vertices = (Vertex**)icefront->hvertices->deliverp();
286 icefront->element = (Element*)icefront->helement->delivers();
287 icefront->matpar = (Matpar*)icefront->hmatpar->delivers();
[5714]288
[4248]289 return icefront;
290
291}
292/*}}}*/
293
294/*Load virtual functions definitions:*/
[12365]295/*FUNCTION Icefront::Configure {{{*/
[4248]296void Icefront::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){
297
298 /*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective
299 * datasets, using internal ids and offsets hidden in hooks: */
[14975]300 hnodes->configure((DataSet*)nodesin);
301 hvertices->configure((DataSet*)verticesin);
302 helement->configure((DataSet*)elementsin);
303 hmatpar->configure((DataSet*)materialsin);
[4248]304
[5714]305 /*Initialize hooked fields*/
[14761]306 this->nodes = (Node**)hnodes->deliverp();
307 this->vertices = (Vertex**)hvertices->deliverp();
308 this->element = (Element*)helement->delivers();
309 this->matpar = (Matpar*)hmatpar->delivers();
[5714]310
[4248]311 /*point parameters to real dataset: */
312 this->parameters=parametersin;
313}
314/*}}}*/
[12365]315/*FUNCTION Icefront::SetCurrentConfiguration {{{*/
[4575]316void Icefront::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){
317}
318/*}}}*/
[12365]319/*FUNCTION Icefront::CreateKMatrix {{{*/
[13216]320void Icefront::CreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs){
[3683]321
322 /*No stiffness loads applied, do nothing: */
323 return;
324
325}
326/*}}}*/
[12365]327/*FUNCTION Icefront::CreatePVector {{{*/
[13216]328void Icefront::CreatePVector(Vector<IssmDouble>* pf){
[3683]329
[5714]330 /*Checks in debugging mode*/
[6412]331 _assert_(nodes);
332 _assert_(element);
333 _assert_(matpar);
[4043]334
335 /*Retrieve parameters: */
[5935]336 ElementVector* pe=NULL;
[5714]337 int analysis_type;
[4043]338 this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
339
[3683]340 /*Just branch to the correct element icefront vector generator, according to the type of analysis we are carrying out: */
[5935]341 switch(analysis_type){
[9785]342 #ifdef _HAVE_DIAGNOSTIC_
[5935]343 case DiagnosticHorizAnalysisEnum:
344 pe=CreatePVectorDiagnosticHoriz();
345 break;
[9785]346 #endif
347 #ifdef _HAVE_CONTROL_
[5935]348 case AdjointHorizAnalysisEnum:
349 pe=CreatePVectorAdjointHoriz();
350 break;
[9785]351 #endif
[5935]352 default:
[13036]353 _error_("analysis " << analysis_type << " (" << EnumToStringx(analysis_type) << ") not supported yet");
[3683]354 }
[5935]355
356 /*Add to global Vector*/
357 if(pe){
[8800]358 pe->AddToGlobal(pf);
[5935]359 delete pe;
[5425]360 }
[3683]361}
362/*}}}*/
[12365]363/*FUNCTION Icefront::CreateJacobianMatrix{{{*/
[13216]364void Icefront::CreateJacobianMatrix(Matrix<IssmDouble>* Jff){
[11332]365 this->CreateKMatrix(Jff,NULL);
366}
[12365]367/*}}}*/
[13915]368/*FUNCTION Icefront::GetNodesSidList{{{*/
369void Icefront::GetNodesSidList(int* sidlist){
370
371 int type;
[14688]372 inputs->GetInputValue(&type,IceFrontTypeEnum);
[13915]373 _assert_(sidlist);
374 _assert_(nodes);
375
376 switch(type){
377 case MacAyeal2dIceFrontEnum:
378 case MacAyeal3dIceFrontEnum:
379 for(int i=0;i<NUMVERTICESSEG;i++) sidlist[i]=nodes[i]->Sid();
380 return;
381#ifdef _HAVE_3D_
[15564]382 case HOIceFrontEnum:
383 case FSIceFrontEnum:
[13915]384 for(int i=0;i<NUMVERTICESQUA;i++) sidlist[i]=nodes[i]->Sid();
385 return;
386#endif
387 default:
388 _error_("Icefront type " << EnumToStringx(type) << " not supported yet");
389 }
390}
391/*}}}*/
392/*FUNCTION Icefront::GetNumberOfNodes{{{*/
393int Icefront::GetNumberOfNodes(void){
394
395 int type;
[14688]396 inputs->GetInputValue(&type,IceFrontTypeEnum);
[13915]397
398 switch(type){
399 case MacAyeal2dIceFrontEnum:
400 return NUMVERTICESSEG;
401#ifdef _HAVE_3D_
402 case MacAyeal3dIceFrontEnum:
403 return NUMVERTICESSEG;
[15564]404 case HOIceFrontEnum:
[13915]405 return NUMVERTICESQUA;
[15564]406 case FSIceFrontEnum:
[13915]407 return NUMVERTICESQUA;
408#endif
409 default:
410 _error_("Icefront type " << EnumToStringx(type) << " not supported yet");
411 }
412
413}
414/*}}}*/
[13925]415/*FUNCTION Icefront::IsPenalty{{{*/
416bool Icefront::IsPenalty(void){
417 return false;
418}
419/*}}}*/
[12365]420/*FUNCTION Icefront::PenaltyCreateKMatrix {{{*/
[13216]421void Icefront::PenaltyCreateKMatrix(Matrix<IssmDouble>* Kff, Matrix<IssmDouble>* Kfs, IssmDouble kmax){
[4248]422 /*do nothing: */
[5939]423 return;
[4248]424}
425/*}}}*/
[12365]426/*FUNCTION Icefront::PenaltyCreatePVector{{{*/
[13216]427void Icefront::PenaltyCreatePVector(Vector<IssmDouble>* pf,IssmDouble kmax){
[4248]428 /*do nothing: */
[5939]429 return;
[4248]430}
431/*}}}*/
[12365]432/*FUNCTION Icefront::PenaltyCreateJacobianMatrix{{{*/
[13216]433void Icefront::PenaltyCreateJacobianMatrix(Matrix<IssmDouble>* Jff,IssmDouble kmax){
[11332]434 this->PenaltyCreateKMatrix(Jff,NULL,kmax);
435}
[12365]436/*}}}*/
[13915]437/*FUNCTION Icefront::SetwiseNodeConnectivity{{{*/
438void Icefront::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int set1_enum,int set2_enum){
439
440 /*Output */
441 int d_nz = 0;
442 int o_nz = 0;
443
444 /*Loop over all nodes*/
445 for(int i=0;i<this->GetNumberOfNodes();i++){
446
447 if(!flags[this->nodes[i]->Sid()]){
448
449 /*flag current node so that no other element processes it*/
450 flags[this->nodes[i]->Sid()]=true;
451
452 /*if node is clone, we have an off-diagonal non-zero, else it is a diagonal non-zero*/
453 switch(set2_enum){
454 case FsetEnum:
455 if(nodes[i]->indexing.fsize){
456 if(this->nodes[i]->IsClone())
457 o_nz += 1;
458 else
459 d_nz += 1;
460 }
461 break;
462 case GsetEnum:
463 if(nodes[i]->indexing.gsize){
464 if(this->nodes[i]->IsClone())
465 o_nz += 1;
466 else
467 d_nz += 1;
468 }
469 break;
470 case SsetEnum:
471 if(nodes[i]->indexing.ssize){
472 if(this->nodes[i]->IsClone())
473 o_nz += 1;
474 else
475 d_nz += 1;
476 }
477 break;
478 default: _error_("not supported");
479 }
480 }
481 }
482
483 /*Assign output pointers: */
484 *pd_nz=d_nz;
485 *po_nz=o_nz;
486}
487/*}}}*/
[12365]488/*FUNCTION Icefront::InAnalysis{{{*/
[4248]489bool Icefront::InAnalysis(int in_analysis_type){
490 if (in_analysis_type==this->analysis_type)return true;
491 else return false;
492}
493/*}}}*/
494
495/*Update virtual functions definitions:*/
[12472]496/*FUNCTION Icefront::InputUpdateFromVector(IssmDouble* vector, int name, int type) {{{*/
497void Icefront::InputUpdateFromVector(IssmDouble* vector, int name, int type){
[4248]498 /*Nothing updated yet*/
499}
500/*}}}*/
[12365]501/*FUNCTION Icefront::InputUpdateFromVector(int* vector, int name, int type) {{{*/
[4248]502void Icefront::InputUpdateFromVector(int* vector, int name, int type){
503 /*Nothing updated yet*/
504}
505/*}}}*/
[12365]506/*FUNCTION Icefront::InputUpdateFromVector(bool* vector, int name, int type) {{{*/
[4248]507void Icefront::InputUpdateFromVector(bool* vector, int name, int type){
508 /*Nothing updated yet*/
509}
510/*}}}*/
[12472]511/*FUNCTION Icefront::InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrows, int ncols, int name, int type) {{{*/
512void Icefront::InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrows, int ncols, int name, int type){
[10576]513 /*Nothing updated yet*/
514}
515/*}}}*/
[12472]516/*FUNCTION Icefront::InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type) {{{*/
517void Icefront::InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){
[5311]518 /*Nothing updated yet*/
519}
520/*}}}*/
[12365]521/*FUNCTION Icefront::InputUpdateFromVectorDakota(int* vector, int name, int type) {{{*/
[5311]522void Icefront::InputUpdateFromVectorDakota(int* vector, int name, int type){
523 /*Nothing updated yet*/
524}
525/*}}}*/
[12365]526/*FUNCTION Icefront::InputUpdateFromVectorDakota(bool* vector, int name, int type) {{{*/
[5311]527void Icefront::InputUpdateFromVectorDakota(bool* vector, int name, int type){
528 /*Nothing updated yet*/
529}
530/*}}}*/
[12472]531/*FUNCTION Icefront::InputUpdateFromConstant(IssmDouble constant, int name) {{{*/
532void Icefront::InputUpdateFromConstant(IssmDouble constant, int name){
[4248]533 /*Nothing updated yet*/
534}
535/*}}}*/
[12365]536/*FUNCTION Icefront::InputUpdateFromConstant(int constant, int name) {{{*/
[4248]537void Icefront::InputUpdateFromConstant(int constant, int name){
538 /*Nothing updated yet*/
539}
540/*}}}*/
[12365]541/*FUNCTION Icefront::InputUpdateFromConstant(bool constant, int name) {{{*/
[4248]542void Icefront::InputUpdateFromConstant(bool constant, int name){
543 /*Nothing updated yet*/
544}
545/*}}}*/
[12365]546/*FUNCTION Icefront::InputUpdateFromSolution{{{*/
[12472]547void Icefront::InputUpdateFromSolution(IssmDouble* solution){
[4248]548 /*Nothing updated yet*/
549}
550/*}}}*/
551
552/*Icefront numerics: */
[9785]553#ifdef _HAVE_DIAGNOSTIC_
[12365]554/*FUNCTION Icefront::CreatePVectorDiagnosticHoriz {{{*/
[5935]555ElementVector* Icefront::CreatePVectorDiagnosticHoriz(void){
556
557 int type;
[14688]558 inputs->GetInputValue(&type,IceFrontTypeEnum);
[5935]559
560 switch(type){
561 case MacAyeal2dIceFrontEnum:
562 return CreatePVectorDiagnosticMacAyeal2d();
[11874]563 #ifdef _HAVE_3D_
[5935]564 case MacAyeal3dIceFrontEnum:
565 return CreatePVectorDiagnosticMacAyeal3d();
[15564]566 case HOIceFrontEnum:
567 return CreatePVectorDiagnosticHO();
568 case FSIceFrontEnum:
569 return CreatePVectorDiagnosticFS();
[9775]570 #endif
[5935]571 default:
[13036]572 _error_("Icefront type " << EnumToStringx(type) << " not supported yet");
[5935]573 }
574}
575/*}}}*/
[12365]576/*FUNCTION Icefront::CreatePVectorDiagnosticMacAyeal2d{{{*/
[5935]577ElementVector* Icefront::CreatePVectorDiagnosticMacAyeal2d(void){
[3683]578
[5719]579 /*Intermediary*/
[15298]580 int ig,index1,index2,fill;
581 IssmDouble Jdet;
582 IssmDouble thickness,bed,pressure,ice_pressure,rho_water,rho_ice,gravity;
583 IssmDouble water_pressure,air_pressure,surface_under_water,base_under_water;
584 IssmDouble xyz_list[NUMVERTICESSEG][3];
585 IssmDouble normal[2];
[5719]586 GaussTria *gauss;
[3683]587
[15298]588 /*return of element is on water*/
[5719]589 Tria* tria=((Tria*)element);
[15298]590 if(tria->IsOnWater()) return NULL;
[3683]591
[15298]592 /*Fetch number of nodes and dof for this finite element*/
[15452]593 int numnodes = tria->NumberofNodes();
[15298]594 int numdof = numnodes*NDOF2;
595
596 /*Initialize Element vector and vectors*/
[15452]597 ElementVector* pe=new ElementVector(tria->nodes,numnodes,this->parameters,MacAyealApproximationEnum);
[15298]598 IssmDouble* basis = xNew<IssmDouble>(numnodes);
[5935]599
600 /*Retrieve all inputs and parameters*/
[14763]601 GetVerticesCoordinates(&xyz_list[0][0],vertices,NUMVERTICESSEG);
[6412]602 Input* thickness_input=tria->inputs->GetInput(ThicknessEnum); _assert_(thickness_input);
603 Input* bed_input =tria->inputs->GetInput(BedEnum); _assert_(bed_input);
[10135]604 inputs->GetInputValue(&fill,FillEnum);
[5715]605 rho_water=matpar->GetRhoWater();
606 rho_ice =matpar->GetRhoIce();
607 gravity =matpar->GetG();
[5808]608 GetSegmentNormal(&normal[0],xyz_list);
[5715]609
[5935]610 /*Start looping on Gaussian points*/
[5719]611 index1=tria->GetNodeIndex(nodes[0]);
612 index2=tria->GetNodeIndex(nodes[1]);
613 gauss=new GaussTria(index1,index2,3);
[5715]614
[5719]615 for(ig=gauss->begin();ig<gauss->end();ig++){
[5715]616
[5719]617 gauss->GaussPoint(ig);
[5715]618
[10135]619 thickness_input->GetInputValue(&thickness,gauss);
620 bed_input->GetInputValue(&bed,gauss);
[5715]621
[5719]622 switch(fill){
623 case WaterEnum:
[8224]624 surface_under_water=min(0.,thickness+bed); // 0 if the top of the glacier is above water level
625 base_under_water=min(0.,bed); // 0 if the bottom of the glacier is above water level
[5719]626 water_pressure=1.0/2.0*gravity*rho_water*(pow(surface_under_water,2) - pow(base_under_water,2));
627 break;
628 case AirEnum:
629 water_pressure=0;
630 break;
[7306]631 case IceEnum:
632 water_pressure=-1.0/2.0*gravity*rho_ice*pow(thickness,2); // we are facing a wall of ice. use water_pressure to cancel the lithostatic pressure.
633 break;
[5719]634 default:
[13036]635 _error_("fill type " << EnumToStringx(fill) << " not supported yet");
[5715]636 }
[5719]637 ice_pressure=1.0/2.0*gravity*rho_ice*pow(thickness,2);
638 air_pressure=0;
[5715]639 pressure = ice_pressure + water_pressure + air_pressure;
640
[5719]641 tria->GetSegmentJacobianDeterminant(&Jdet,&xyz_list[0][0],gauss);
[15452]642 tria->GetNodalFunctions(basis,gauss);
[5715]643
[5719]644 for (int i=0;i<numnodes;i++){
[15298]645 pe->values[2*i+0]+= pressure*Jdet*gauss->weight*normal[0]*basis[i];
646 pe->values[2*i+1]+= pressure*Jdet*gauss->weight*normal[1]*basis[i];
[5715]647 }
[5719]648 }
[10381]649
[10367]650 /*Transform load vector*/
[15452]651 TransformLoadVectorCoord(pe,tria->nodes,numnodes,XYEnum);
[5715]652
[5935]653 /*Clean up and return*/
[15298]654 xDelete<IssmDouble>(basis);
[5719]655 delete gauss;
[5935]656 return pe;
[5715]657}
658/*}}}*/
[10407]659#endif
[10367]660
[9785]661#ifdef _HAVE_CONTROL_
[12365]662/*FUNCTION Icefront::CreatePVectorAdjointHoriz {{{*/
[9785]663ElementVector* Icefront::CreatePVectorAdjointHoriz(void){
664
665 /*No load vector applied to the adjoint*/
666 return NULL;
667}
668/*}}}*/
669#endif
[11874]670#ifdef _HAVE_3D_
[12365]671/*FUNCTION Icefront::CreatePVectorDiagnosticMacAyeal3d{{{*/
[5935]672ElementVector* Icefront::CreatePVectorDiagnosticMacAyeal3d(void){
[5715]673
[13813]674 Icefront *icefront = NULL;
675 Penta *penta = NULL;
676 Tria *tria = NULL;
[5715]677
[5720]678 /*Cast element onto Penta*/
679 penta =(Penta*)this->element;
[5715]680
[5720]681 /*Return if not on bed*/
[5935]682 if(!penta->IsOnBed() || penta->IsOnWater()) return NULL;
[5715]683
[5720]684 /*Spawn Tria and call MacAyeal2d*/
685 tria =(Tria*)penta->SpawnTria(0,1,2);
686 icefront=(Icefront*)this->copy();
687 icefront->element=tria;
[14688]688 icefront->inputs->AddInput(new IntInput(IceFrontTypeEnum,MacAyeal2dIceFrontEnum));
[5935]689 ElementVector* pe=icefront->CreatePVectorDiagnosticMacAyeal2d();
[3683]690
[5935]691 /*clean-up and return*/
[13129]692 delete tria->material;
[5720]693 delete tria;
694 delete icefront;
[5935]695 return pe;
[3683]696}
697/*}}}*/
[15564]698/*FUNCTION Icefront::CreatePVectorDiagnosticHO{{{*/
699ElementVector* Icefront::CreatePVectorDiagnosticHO(void){
[3683]700
[5808]701 /*Constants*/
702 const int numdofs = NUMVERTICESQUA *NDOF2;
[3683]703
[5808]704 /*Intermediaries*/
705 int i,j,ig,index1,index2,index3,index4;
706 int fill;
[12472]707 IssmDouble surface,pressure,ice_pressure,rho_water,rho_ice,gravity;
708 IssmDouble water_pressure,air_pressure;
709 IssmDouble Jdet,z_g;
710 IssmDouble xyz_list[NUMVERTICESQUA][3];
711 IssmDouble normal[3];
712 IssmDouble l1l4[4];
[5808]713 GaussPenta *gauss = NULL;
[3683]714
[5935]715 Penta* penta=(Penta*)element;
716
717 /*Initialize Element vector and return if necessary*/
718 if(penta->IsOnWater()) return NULL;
[15564]719 ElementVector* pe=new ElementVector(nodes,NUMVERTICESQUA,this->parameters,HOApproximationEnum);
[5935]720
721 /*Retrieve all inputs and parameters*/
[14763]722 GetVerticesCoordinates(&xyz_list[0][0],vertices,NUMVERTICESQUA);
[6412]723 Input* surface_input =penta->inputs->GetInput(SurfaceEnum); _assert_(surface_input);
[10135]724 inputs->GetInputValue(&fill,FillEnum);
[5808]725 rho_water=matpar->GetRhoWater();
726 rho_ice =matpar->GetRhoIce();
727 gravity =matpar->GetG();
728 GetQuadNormal(&normal[0],xyz_list);
[3683]729
[5808]730 /*Identify which nodes are in the quad: */
731 index1=element->GetNodeIndex(nodes[0]);
732 index2=element->GetNodeIndex(nodes[1]);
733 index3=element->GetNodeIndex(nodes[2]);
734 index4=element->GetNodeIndex(nodes[3]);
[3683]735
[5808]736 /* Start looping on the number of gaussian points: */
[12472]737 IssmDouble zmax=xyz_list[0][2]; for(i=1;i<NUMVERTICESQUA;i++) if(xyz_list[i][2]>zmax) zmax=xyz_list[i][2];
738 IssmDouble zmin=xyz_list[0][2]; for(i=1;i<NUMVERTICESQUA;i++) if(xyz_list[i][2]<zmin) zmin=xyz_list[i][2];
[5808]739 if(zmax>0 && zmin<0) gauss=new GaussPenta(index1,index2,index3,index4,3,10); //refined in vertical because of the sea level discontinuity
740 else gauss=new GaussPenta(index1,index2,index3,index4,3,3);
741 for(ig=gauss->begin();ig<gauss->end();ig++){
[3683]742
[5808]743 gauss->GaussPoint(ig);
[3683]744
[5808]745 penta->GetQuadNodalFunctions(l1l4,gauss,index1,index2,index3,index4);
746 penta->GetQuadJacobianDeterminant(&Jdet,xyz_list,gauss);
747 z_g=penta->GetZcoord(gauss);
[10135]748 surface_input->GetInputValue(&surface,gauss);
[3683]749
[5808]750 switch(fill){
751 case WaterEnum:
[8224]752 water_pressure=rho_water*gravity*min(0.,z_g);//0 if the gaussian point is above water level
[5808]753 break;
754 case AirEnum:
755 water_pressure=0;
756 break;
757 default:
[13036]758 _error_("fill type " << EnumToStringx(fill) << " not supported yet");
[5808]759 }
760 ice_pressure=rho_ice*gravity*(surface-z_g);
761 air_pressure=0;
762 pressure = ice_pressure + water_pressure + air_pressure;
[3683]763
[5935]764 for(i=0;i<NUMVERTICESQUA;i++) for(j=0;j<NDOF2;j++) pe->values[i*NDOF2+j]+=Jdet*gauss->weight*pressure*l1l4[i]*normal[j];
[3683]765 }
766
[10381]767 /*Transform load vector*/
[10523]768 TransformLoadVectorCoord(pe,nodes,NUMVERTICESQUA,XYEnum);
[10381]769
[5935]770 /*Clean up and return*/
[5808]771 delete gauss;
[5935]772 return pe;
[3683]773}
774/*}}}*/
[15564]775/*FUNCTION Icefront::CreatePVectorDiagnosticFS{{{*/
776ElementVector* Icefront::CreatePVectorDiagnosticFS(void){
[3683]777
[5808]778 /*Constants*/
779 const int numdofs = NUMVERTICESQUA *NDOF4;
[3683]780
[5808]781 /*Intermediaries*/
782 int i,j,ig,index1,index2,index3,index4;
783 int fill;
[12472]784 IssmDouble pressure,rho_water,gravity;
785 IssmDouble water_pressure,air_pressure;
786 IssmDouble Jdet,z_g;
787 IssmDouble xyz_list[NUMVERTICESQUA][3];
788 IssmDouble normal[3];
789 IssmDouble l1l4[4];
[5808]790 GaussPenta *gauss = NULL;
[3683]791
[5935]792 Penta* penta=(Penta*)element;
793
794 /*Initialize Element vector and return if necessary*/
795 if(penta->IsOnWater()) return NULL;
[15564]796 ElementVector* pe=new ElementVector(nodes,NUMVERTICESQUA,this->parameters,FSApproximationEnum);
[5935]797
798 /*Retrieve all inputs and parameters*/
[14763]799 GetVerticesCoordinates(&xyz_list[0][0],vertices,NUMVERTICESQUA);
[10135]800 inputs->GetInputValue(&fill,FillEnum);
[5808]801 rho_water=matpar->GetRhoWater();
802 gravity =matpar->GetG();
803 GetQuadNormal(&normal[0],xyz_list);
[3683]804
[5808]805 /*Identify which nodes are in the quad: */
806 index1=element->GetNodeIndex(nodes[0]);
807 index2=element->GetNodeIndex(nodes[1]);
808 index3=element->GetNodeIndex(nodes[2]);
809 index4=element->GetNodeIndex(nodes[3]);
[3683]810
[5808]811 /* Start looping on the number of gaussian points: */
[12472]812 IssmDouble zmax=xyz_list[0][2]; for(i=1;i<NUMVERTICESQUA;i++) if(xyz_list[i][2]>zmax) zmax=xyz_list[i][2];
813 IssmDouble zmin=xyz_list[0][2]; for(i=1;i<NUMVERTICESQUA;i++) if(xyz_list[i][2]<zmin) zmin=xyz_list[i][2];
[5808]814 if(zmax>0 && zmin<0) gauss=new GaussPenta(index1,index2,index3,index4,3,30); //refined in vertical because of the sea level discontinuity
815 else gauss=new GaussPenta(index1,index2,index3,index4,3,3);
816 for(ig=gauss->begin();ig<gauss->end();ig++){
[3683]817
[5808]818 gauss->GaussPoint(ig);
[3683]819
[5808]820 penta->GetQuadNodalFunctions(l1l4,gauss,index1,index2,index3,index4);
821 penta->GetQuadJacobianDeterminant(&Jdet,xyz_list,gauss);
822 z_g=penta->GetZcoord(gauss);
[3683]823
[5808]824 switch(fill){
825 case WaterEnum:
[8224]826 water_pressure=rho_water*gravity*min(0.,z_g);//0 if the gaussian point is above water level
[5808]827 break;
828 case AirEnum:
829 water_pressure=0;
830 break;
831 default:
[13036]832 _error_("fill type " << EnumToStringx(fill) << " not supported yet");
[5808]833 }
834 air_pressure=0;
[15564]835 pressure = water_pressure + air_pressure; //no ice pressure fore FS
[3683]836
[5808]837 for(i=0;i<NUMVERTICESQUA;i++){
838 for(j=0;j<NDOF4;j++){
[5935]839 if(j<3) pe->values[i*NDOF4+j]+=Jdet*gauss->weight*pressure*l1l4[i]*normal[j];
840 else pe->values[i*NDOF4+j]+=0; //pressure term
[5808]841 }
842 }
843 }
[3683]844
[10381]845 /*Transform load vector*/
[10523]846 TransformLoadVectorCoord(pe,nodes,NUMVERTICESQUA,XYZPEnum);
[10381]847
[5935]848 /*Clean up and return*/
[5808]849 delete gauss;
[5935]850 return pe;
[3683]851}
852/*}}}*/
[9775]853#endif
[12365]854/*FUNCTION Icefront::GetDofList {{{*/
[5772]855void Icefront::GetDofList(int** pdoflist,int approximation_enum,int setenum){
[3683]856
[5096]857 int numberofdofs=0;
858 int count=0;
[3683]859 int type;
[5096]860 int numberofnodes=2;
[3683]861
[5096]862 /*output: */
863 int* doflist=NULL;
864
865 /*recover type: */
[14688]866 inputs->GetInputValue(&type,IceFrontTypeEnum);
[5096]867
868 /*Some checks for debugging*/
[6412]869 _assert_(nodes);
[13622]870
[5096]871 /*How many nodes? :*/
[5715]872 if(type==MacAyeal2dIceFrontEnum || type==MacAyeal3dIceFrontEnum)
873 numberofnodes=2;
874 else
875 numberofnodes=4;
[13622]876
[5096]877 /*Figure out size of doflist: */
[13761]878 for(int i=0;i<numberofnodes;i++){
[5772]879 numberofdofs+=nodes[i]->GetNumberOfDofs(approximation_enum,setenum);
[3683]880 }
[5096]881
882 /*Allocate: */
[12455]883 doflist=xNew<int>(numberofdofs);
[5096]884
885 /*Populate: */
886 count=0;
[13761]887 for(int i=0;i<numberofnodes;i++){
[5772]888 nodes[i]->GetDofList(doflist+count,approximation_enum,setenum);
889 count+=nodes[i]->GetNumberOfDofs(approximation_enum,setenum);
[3683]890 }
891
892 /*Assign output pointers:*/
[5096]893 *pdoflist=doflist;
[3683]894}
895/*}}}*/
[12365]896/*FUNCTION Icefront::GetSegmentNormal {{{*/
[12472]897void Icefront:: GetSegmentNormal(IssmDouble* normal,IssmDouble xyz_list[4][3]){
[3683]898
[4946]899 /*Build unit outward pointing vector*/
[12472]900 IssmDouble vector[2];
901 IssmDouble norm;
[3683]902
[4946]903 vector[0]=xyz_list[1][0] - xyz_list[0][0];
904 vector[1]=xyz_list[1][1] - xyz_list[0][1];
[3683]905
[4946]906 norm=sqrt(pow(vector[0],2.0)+pow(vector[1],2.0));
[3683]907
[4946]908 normal[0]= + vector[1]/norm;
909 normal[1]= - vector[0]/norm;
[3683]910}
911/*}}}*/
[12365]912/*FUNCTION Icefront::GetQuadNormal {{{*/
[12472]913void Icefront:: GetQuadNormal(IssmDouble* normal,IssmDouble xyz_list[4][3]){
[5808]914
915 /*Build unit outward pointing vector*/
[12472]916 IssmDouble AB[3];
917 IssmDouble AC[3];
918 IssmDouble norm;
[5808]919
920 AB[0]=xyz_list[1][0] - xyz_list[0][0];
921 AB[1]=xyz_list[1][1] - xyz_list[0][1];
922 AB[2]=xyz_list[1][2] - xyz_list[0][2];
923 AC[0]=xyz_list[2][0] - xyz_list[0][0];
924 AC[1]=xyz_list[2][1] - xyz_list[0][1];
925 AC[2]=xyz_list[2][2] - xyz_list[0][2];
926
927 cross(normal,AB,AC);
928 norm=sqrt(pow(normal[0],2.0)+pow(normal[1],2.0)+pow(normal[2],2.0));
929
930 for(int i=0;i<3;i++) normal[i]=normal[i]/norm;
931}
932/*}}}*/
Note: See TracBrowser for help on using the repository browser.