source: issm/trunk-jpl/src/c/objects/Loads/Penpair.cpp@ 11247

Last change on this file since 11247 was 11247, checked in by Mathieu Morlighem, 13 years ago

Added InputUpdateFromVector for Penpair

File size: 11.9 KB
Line 
1/*!\file Penpair.c
2 * \brief: implementation of the Penpair object
3 */
4
5/*Headers*/
6/*{{{1*/
7#ifdef HAVE_CONFIG_H
8#include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include <stdio.h>
14#include <string.h>
15#include "../objects.h"
16#include "../../EnumDefinitions/EnumDefinitions.h"
17#include "../../include/include.h"
18#include "../../shared/shared.h"
19/*}}}*/
20
21/*Element macros*/
22#define NUMVERTICES 2
23
24/*Penpair constructors and destructor*/
25/*FUNCTION Penpair::constructor {{{1*/
26Penpair::Penpair(){
27
28 this->hnodes=NULL;
29 this->nodes=NULL;
30 this->parameters=NULL;
31 return;
32}
33/*}}}1*/
34/*FUNCTION Penpair::creation {{{1*/
35Penpair::Penpair(int penpair_id, int* penpair_node_ids,int in_analysis_type){
36
37 this->id=penpair_id;
38 this->analysis_type=in_analysis_type;
39 this->hnodes=new Hook(penpair_node_ids,2);
40 this->parameters=NULL;
41 this->nodes=NULL;
42
43 return;
44}
45/*}}}1*/
46/*FUNCTION Penpair::destructor {{{1*/
47Penpair::~Penpair(){
48 delete hnodes;
49 return;
50}
51/*}}}1*/
52
53/*Object virtual functions definitions:*/
54/*FUNCTION Penpair::Echo {{{1*/
55void Penpair::Echo(void){
56
57 int i;
58
59 printf("Penpair:\n");
60 printf(" id: %i\n",id);
61 printf(" analysis_type: %s\n",EnumToStringx(analysis_type));
62 hnodes->Echo();
63
64 return;
65}
66/*}}}1*/
67/*FUNCTION Penpair::DeepEcho {{{1*/
68void Penpair::DeepEcho(void){
69
70 printf("Penpair:\n");
71 printf(" id: %i\n",id);
72 printf(" analysis_type: %s\n",EnumToStringx(analysis_type));
73 hnodes->DeepEcho();
74
75 return;
76}
77/*}}}1*/
78/*FUNCTION Penpair::Id {{{1*/
79int Penpair::Id(void){ return id; }
80/*}}}1*/
81/*FUNCTION Penpair::MyRank {{{1*/
82int Penpair::MyRank(void){
83 extern int my_rank;
84 return my_rank;
85}
86/*}}}1*/
87#ifdef _SERIAL_
88/*FUNCTION Penpair::Marshall {{{1*/
89void Penpair::Marshall(char** pmarshalled_dataset){
90
91 char* marshalled_dataset=NULL;
92 int enum_type=0;
93
94 /*recover marshalled_dataset: */
95 marshalled_dataset=*pmarshalled_dataset;
96
97 /*get enum type of Penpair: */
98 enum_type=PenpairEnum;
99
100 /*marshall enum: */
101 memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
102
103 /*marshall Penpair data: */
104 memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
105 memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
106
107 /*Marshall hooks*/
108 hnodes->Marshall(&marshalled_dataset);
109
110 *pmarshalled_dataset=marshalled_dataset;
111 return;
112}
113/*}}}1*/
114/*FUNCTION Penpair::MarshallSize {{{1*/
115int Penpair::MarshallSize(){
116
117 return sizeof(id)+
118 +sizeof(analysis_type)
119 +hnodes->MarshallSize()
120 +sizeof(int); //sizeof(int) for enum type
121}
122/*}}}1*/
123/*FUNCTION Penpair::Demarshall {{{1*/
124void Penpair::Demarshall(char** pmarshalled_dataset){
125
126 int i;
127 char* marshalled_dataset=NULL;
128
129 /*recover marshalled_dataset: */
130 marshalled_dataset=*pmarshalled_dataset;
131
132 /*this time, no need to get enum type, the pointer directly points to the beginning of the
133 *object data (thanks to DataSet::Demarshall):*/
134 memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
135 memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
136
137 /*demarshall hooks: */
138 hnodes=new Hook(); hnodes->Demarshall(&marshalled_dataset);
139
140 /*pointers are garbabe, until configuration is carried out: */
141 nodes=NULL;
142 parameters=NULL;
143
144 /*return: */
145 *pmarshalled_dataset=marshalled_dataset;
146 return;
147}
148/*}}}1*/
149#endif
150/*FUNCTION Penpair::ObjectEnum{{{1*/
151int Penpair::ObjectEnum(void){
152
153 return PenpairEnum;
154}
155/*}}}1*/
156/*FUNCTION Penpair::copy {{{1*/
157Object* Penpair::copy() {
158
159 Penpair* penpair=NULL;
160
161 penpair=new Penpair();
162
163 /*copy fields: */
164 penpair->id=this->id;
165 penpair->analysis_type=this->analysis_type;
166
167 /*now deal with hooks and objects: */
168 penpair->hnodes=(Hook*)this->hnodes->copy();
169 penpair->nodes =(Node**)penpair->hnodes->deliverp();
170
171 /*point parameters: */
172 penpair->parameters=this->parameters;
173
174 return penpair;
175
176}
177/*}}}*/
178
179/*Load virtual functions definitions:*/
180/*FUNCTION Penpair::Configure {{{1*/
181void Penpair::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){
182
183 /*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective
184 * datasets, using internal ids and offsets hidden in hooks: */
185 hnodes->configure(nodesin);
186
187 /*Initialize hooked fields*/
188 this->nodes =(Node**)hnodes->deliverp();
189
190 /*point parameters to real dataset: */
191 this->parameters=parametersin;
192
193}
194/*}}}1*/
195/*FUNCTION Penpair::SetCurrentConfiguration {{{1*/
196void Penpair::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){
197
198}
199/*}}}1*/
200/*FUNCTION Penpair::CreateKMatrix {{{1*/
201void Penpair::CreateKMatrix(Mat Kff, Mat Kfs){
202 /*If you code this piece, don't forget that a penalty will be inactive if it is dealing with clone nodes*/
203 /*No loads applied, do nothing: */
204 return;
205
206}
207/*}}}1*/
208/*FUNCTION Penpair::CreatePVector {{{1*/
209void Penpair::CreatePVector(Vec pf){
210
211 /*No loads applied, do nothing: */
212 return;
213
214}
215/*}}}1*/
216/*FUNCTION Penpair::PenaltyCreateKMatrix {{{1*/
217void Penpair::PenaltyCreateKMatrix(Mat Kff, Mat Kfs,double kmax){
218
219 /*Retrieve parameters: */
220 ElementMatrix* Ke=NULL;
221 int analysis_type;
222 this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
223
224 switch(analysis_type){
225 case DiagnosticHorizAnalysisEnum:
226 Ke=PenaltyCreateKMatrixDiagnosticHoriz(kmax);
227 break;
228 case PrognosticAnalysisEnum:
229 Ke=PenaltyCreateKMatrixPrognostic(kmax);
230 break;
231 default:
232 _error_("analysis %i (%s) not supported yet",analysis_type,EnumToStringx(analysis_type));
233 }
234
235 /*Add to global Vector*/
236 if(Ke){
237 Ke->AddToGlobal(Kff,Kfs);
238 delete Ke;
239 }
240}
241/*}}}1*/
242/*FUNCTION Penpair::PenaltyCreatePVector {{{1*/
243void Penpair::PenaltyCreatePVector(Vec pf,double kmax){
244 /*No loads applied, do nothing: */
245 return;
246}
247/*}}}1*/
248/*FUNCTION Penpair::InAnalysis{{{1*/
249bool Penpair::InAnalysis(int in_analysis_type){
250 if (in_analysis_type==this->analysis_type)return true;
251 else return false;
252}
253/*}}}*/
254
255/*Update virtual functions definitions:*/
256/*FUNCTION Penpair::InputUpdateFromConstant(double constant, int name) {{{1*/
257void Penpair::InputUpdateFromConstant(double constant, int name){
258 /*Nothing updated yet*/
259}
260/*}}}*/
261/*FUNCTION Penpair::InputUpdateFromConstant(int constant, int name) {{{1*/
262void Penpair::InputUpdateFromConstant(int constant, int name){
263 /*Nothing updated yet*/
264}
265/*}}}*/
266/*FUNCTION Penpair::InputUpdateFromConstant(bool constant, int name) {{{1*/
267void Penpair::InputUpdateFromConstant(bool constant, int name){
268 /*Nothing updated yet*/
269}
270/*}}}*/
271/*FUNCTION Penpair::InputUpdateFromVector(double* vector, int name, int type) {{{1*/
272void Penpair::InputUpdateFromVector(double* vector, int name, int type){
273 /*Nothing updated yet*/
274}
275/*}}}*/
276/*FUNCTION Penpair::InputUpdateFromVector(int* vector, int name, int type) {{{1*/
277void Penpair::InputUpdateFromVector(int* vector, int name, int type){
278 /*Nothing updated yet*/
279}
280/*}}}*/
281/*FUNCTION Penpair::InputUpdateFromVector(bool* vector, int name, int type) {{{1*/
282void Penpair::InputUpdateFromVector(bool* vector, int name, int type){
283 /*Nothing updated yet*/
284}
285/*}}}*/
286
287/*Penpair management:*/
288/*FUNCTION Penpair::PenaltyCreateKMatrixDiagnosticHoriz{{{1*/
289ElementMatrix* Penpair::PenaltyCreateKMatrixDiagnosticHoriz(double kmax){
290
291 int approximation0=nodes[0]->GetApproximation();
292 int approximation1=nodes[1]->GetApproximation();
293
294 switch(approximation0){
295 case MacAyealApproximationEnum:
296 switch(approximation1){
297 case MacAyealApproximationEnum: return PenaltyCreateKMatrixDiagnosticMacAyealPattyn(kmax);
298 case PattynApproximationEnum: return PenaltyCreateKMatrixDiagnosticMacAyealPattyn(kmax);
299 default: _error_("not supported yet");
300 }
301 case PattynApproximationEnum:
302 switch(approximation1){
303 case MacAyealApproximationEnum: return PenaltyCreateKMatrixDiagnosticMacAyealPattyn(kmax);
304 case PattynApproximationEnum: return PenaltyCreateKMatrixDiagnosticMacAyealPattyn(kmax);
305 default: _error_("not supported yet");
306 }
307 case StokesApproximationEnum:
308 switch(approximation1){
309 case StokesApproximationEnum: return PenaltyCreateKMatrixDiagnosticStokes(kmax);
310 case NoneApproximationEnum: return PenaltyCreateKMatrixDiagnosticStokes(kmax);
311 default: _error_("not supported yet");
312 }
313 case NoneApproximationEnum:
314 switch(approximation1){
315 case StokesApproximationEnum: return PenaltyCreateKMatrixDiagnosticStokes(kmax);
316 case NoneApproximationEnum: return PenaltyCreateKMatrixDiagnosticStokes(kmax);
317 default: _error_("not supported yet");
318 }
319 default: _error_("not supported yet");
320 }
321}
322/*}}}1*/
323/*FUNCTION Penpair::PenaltyCreateKMatrixDiagnosticMacAyealPattyn {{{1*/
324ElementMatrix* Penpair::PenaltyCreateKMatrixDiagnosticMacAyealPattyn(double kmax){
325
326 const int numdof=NUMVERTICES*NDOF2;
327 double penalty_offset;
328
329 /*Initialize Element vector and return if necessary*/
330 ElementMatrix* Ke=new ElementMatrix(nodes,NUMVERTICES,this->parameters);
331
332 /*recover parameters: */
333 parameters->FindParam(&penalty_offset,DiagnosticPenaltyFactorEnum);
334
335 //Create elementary matrix: add penalty to
336 Ke->values[0*numdof+0]=+kmax*pow((double)10.0,penalty_offset);
337 Ke->values[0*numdof+2]=-kmax*pow((double)10.0,penalty_offset);
338 Ke->values[2*numdof+0]=-kmax*pow((double)10.0,penalty_offset);
339 Ke->values[2*numdof+2]=+kmax*pow((double)10.0,penalty_offset);
340
341 Ke->values[1*numdof+1]=+kmax*pow((double)10.0,penalty_offset);
342 Ke->values[1*numdof+3]=-kmax*pow((double)10.0,penalty_offset);
343 Ke->values[3*numdof+1]=-kmax*pow((double)10.0,penalty_offset);
344 Ke->values[3*numdof+3]=+kmax*pow((double)10.0,penalty_offset);
345
346 /*Clean up and return*/
347 return Ke;
348}
349/*}}}1*/
350/*FUNCTION Penpair::PenaltyCreateKMatrixDiagnosticStokes {{{1*/
351ElementMatrix* Penpair::PenaltyCreateKMatrixDiagnosticStokes(double kmax){
352
353 const int numdof=NUMVERTICES*NDOF4;
354 double penalty_offset;
355
356 /*Initialize Element vector and return if necessary*/
357 ElementMatrix* Ke=new ElementMatrix(nodes,NUMVERTICES,this->parameters);
358
359 /*recover parameters: */
360 parameters->FindParam(&penalty_offset,DiagnosticPenaltyFactorEnum);
361
362 //Create elementary matrix: add penalty to
363 Ke->values[0*numdof+0]=+kmax*pow((double)10.0,penalty_offset);
364 Ke->values[0*numdof+4]=-kmax*pow((double)10.0,penalty_offset);
365 Ke->values[4*numdof+0]=-kmax*pow((double)10.0,penalty_offset);
366 Ke->values[4*numdof+4]=+kmax*pow((double)10.0,penalty_offset);
367
368 Ke->values[1*numdof+1]=+kmax*pow((double)10.0,penalty_offset);
369 Ke->values[1*numdof+5]=-kmax*pow((double)10.0,penalty_offset);
370 Ke->values[5*numdof+1]=-kmax*pow((double)10.0,penalty_offset);
371 Ke->values[5*numdof+5]=+kmax*pow((double)10.0,penalty_offset);
372
373 Ke->values[2*numdof+2]=+kmax*pow((double)10.0,penalty_offset);
374 Ke->values[2*numdof+6]=-kmax*pow((double)10.0,penalty_offset);
375 Ke->values[6*numdof+2]=-kmax*pow((double)10.0,penalty_offset);
376 Ke->values[6*numdof+6]=+kmax*pow((double)10.0,penalty_offset);
377
378 Ke->values[3*numdof+3]=+kmax*pow((double)10.0,penalty_offset);
379 Ke->values[3*numdof+7]=-kmax*pow((double)10.0,penalty_offset);
380 Ke->values[7*numdof+3]=-kmax*pow((double)10.0,penalty_offset);
381 Ke->values[7*numdof+7]=+kmax*pow((double)10.0,penalty_offset);
382
383 /*Clean up and return*/
384 return Ke;
385}
386/*}}}1*/
387/*FUNCTION Penpair::PenaltyCreateKMatrixPrognostic {{{1*/
388ElementMatrix* Penpair::PenaltyCreateKMatrixPrognostic(double kmax){
389
390 const int numdof=NUMVERTICES*NDOF1;
391 double penalty_factor;
392
393 /*Initialize Element vector and return if necessary*/
394 ElementMatrix* Ke=new ElementMatrix(nodes,NUMVERTICES,this->parameters);
395
396 /*recover parameters: */
397 parameters->FindParam(&penalty_factor,PrognosticPenaltyFactorEnum);
398
399 //Create elementary matrix: add penalty to
400 Ke->values[0*numdof+0]=+kmax*pow((double)10.0,penalty_factor);
401 Ke->values[0*numdof+1]=-kmax*pow((double)10.0,penalty_factor);
402 Ke->values[1*numdof+0]=-kmax*pow((double)10.0,penalty_factor);
403 Ke->values[1*numdof+1]=+kmax*pow((double)10.0,penalty_factor);
404
405 /*Clean up and return*/
406 return Ke;
407}
408/*}}}1*/
Note: See TracBrowser for help on using the repository browser.