source: issm/trunk/src/c/classes/Cfdragcoeffabsgrad.cpp@ 22758

Last change on this file since 22758 was 22758, checked in by Mathieu Morlighem, 7 years ago

merged trunk-jpl and trunk for revision 22757

File size: 5.6 KB
RevLine 
[22612]1/*!\file Cfdragcoeffabsgrad.cpp
2 * \brief: Cfdragcoeffabsgrad Object
3 */
4
5/*Headers:*/
6/*{{{*/
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 "./classes.h"
14#include "./ExternalResults/ExternalResult.h"
15#include "./ExternalResults/Results.h"
16#include "../datastructures/datastructures.h"
17#include "./Elements/Element.h"
18#include "./Elements/Elements.h"
19#include "./FemModel.h"
20#include "../modules/SurfaceAreax/SurfaceAreax.h"
21#include "../classes/Params/Parameters.h"
22#include "../classes/Inputs/Input.h"
23#include "../classes/gauss/Gauss.h"
24/*}}}*/
25
26/*Cfdragcoeffabsgrad constructors, destructors :*/
27Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(){/*{{{*/
28
29 this->definitionenum = -1;
30 this->name = NULL;
31 this->weights_enum = UNDEF;
32 this->misfit=0;
33 this->lock=0;
34 this->datatime=0.;
35 this->timepassedflag = false;
36 this->last_time = 0.;
37
38}
39/*}}}*/
40Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
41
42 this->definitionenum=in_definitionenum;
43
44 this->name = xNew<char>(strlen(in_name)+1);
45 xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
46
47 this->weights_enum=in_weights_enum;
48 this->datatime=in_datatime;
49 this->timepassedflag=in_timepassedflag;
50
51 this->misfit=0;
52 this->lock=0;
53}
54/*}}}*/
55Cfdragcoeffabsgrad::~Cfdragcoeffabsgrad(){/*{{{*/
56 if(this->name)xDelete(this->name);
57 this->misfit=0;
58 this->lock=0;
59}
60/*}}}*/
61/*Object virtual function resolutoin: */
62Object* Cfdragcoeffabsgrad::copy() {/*{{{*/
63 Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum, this->weights_enum,this->datatime,this->timepassedflag);
64 mf->misfit=this->misfit;
65 mf->lock=this->lock;
66 return (Object*) mf;
67}
68/*}}}*/
69void Cfdragcoeffabsgrad::DeepEcho(void){/*{{{*/
70 this->Echo();
71}
72/*}}}*/
73void Cfdragcoeffabsgrad::Echo(void){/*{{{*/
74 _printf_(" Cfdragcoeffabsgrad: " << name << " " << this->definitionenum << "\n");
75 _printf_(" weights_enum: " << weights_enum << " " << EnumToStringx(weights_enum) << "\n");
76 _printf_(" datatime: " << datatime << "\n");
77 _printf_(" timepassedflag: "<<timepassedflag<<"\n");
78}
79/*}}}*/
80int Cfdragcoeffabsgrad::Id(void){/*{{{*/
81 return -1;
82}
83/*}}}*/
84void Cfdragcoeffabsgrad::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
85 _error_("not implemented yet!");
86}
87/*}}}*/
88int Cfdragcoeffabsgrad::ObjectEnum(void){/*{{{*/
89 return CfdragcoeffabsgradEnum;
90}
91/*}}}*/
92/*Definition virtual function resolutoin: */
93int Cfdragcoeffabsgrad::DefinitionEnum(){/*{{{*/
94 return this->definitionenum;
95}
96/*}}}*/
97char* Cfdragcoeffabsgrad::Name(){/*{{{*/
98 char* name2=xNew<char>(strlen(this->name)+1);
99 xMemCpy(name2,this->name,strlen(this->name)+1);
100
101 return name2;
102}
103/*}}}*/
104IssmDouble Cfdragcoeffabsgrad::Response(FemModel* femmodel){/*{{{*/
105 /*diverse: */
106 IssmDouble time;
107
108 /*recover time parameters: */
109 femmodel->parameters->FindParam(&time,TimeEnum);
110 if(time < last_time) timepassedflag = false;
111 last_time = time;
112
113 int i;
114 IssmDouble J=0.;
115 IssmDouble J_sum=0.;
116
117 if(datatime<=time && !timepassedflag){
118 for(i=0;i<femmodel->elements->Size();i++){
119 Element* element=(Element*)femmodel->elements->GetObjectByOffset(i);
120 J+=this->Cfdragcoeffabsgrad_Calculation(element,weights_enum);
121 }
122
123 ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
124 ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
125 J=J_sum;
126
127 timepassedflag = true;
128 return J;
129 }
130 else return J;
131 }
132 /*}}}*/
133IssmDouble Cfdragcoeffabsgrad::Cfdragcoeffabsgrad_Calculation(Element* element, int weights_enum){/*{{{*/
134
135 int domaintype,numcomponents;
136 IssmDouble Jelem=0.;
137 IssmDouble misfit,Jdet;
138 IssmDouble dp[2],weight;
139 IssmDouble* xyz_list = NULL;
140
141 /*Get basal element*/
142 if(!element->IsOnBase()) return 0.;
143
144 /*If on water, return 0: */
145 if(!element->IsIceInElement()) return 0.;
146
147 /*Get problem dimension*/
148 element->FindParam(&domaintype,DomainTypeEnum);
149 switch(domaintype){
150 case Domain2DverticalEnum: numcomponents = 1; break;
151 case Domain3DEnum: numcomponents = 2; break;
152 case Domain2DhorizontalEnum: numcomponents = 2; break;
153 default: _error_("not supported yet");
154 }
155
156 /*Spawn surface element*/
157 Element* basalelement = element->SpawnBasalElement();
158
159 /* Get node coordinates*/
160 basalelement->GetVerticesCoordinates(&xyz_list);
161
162 /*Get input if it already exists*/
163 Input* tempinput = basalelement->GetInput(definitionenum);
164 /*Cast it to a Datasetinput*/
165 if(tempinput->ObjectEnum()!=DatasetInputEnum) _error_("don't know what to do! confused!");
166 DatasetInput* datasetinput = (DatasetInput*)tempinput;
167
168 /*Get the drag from the model*/
169 Input* drag_input=basalelement->GetInput(FrictionCoefficientEnum); _assert_(drag_input);
170
171 /* Start looping on the number of gaussian points: */
172 Gauss* gauss=basalelement->NewGauss(2);
173 for(int ig=gauss->begin();ig<gauss->end();ig++){
174
175 gauss->GaussPoint(ig);
176
177 /* Get Jacobian determinant: */
178 basalelement->JacobianDeterminant(&Jdet,xyz_list,gauss);
179
180 /*Get all parameters at gaussian point*/
181 datasetinput->GetInputValue(&weight,gauss,WeightsSurfaceObservationEnum);
182 drag_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
183
184 /*Add to cost function*/
185 Jelem+=weight*.5*dp[0]*dp[0]*Jdet*gauss->weight;
186 if(numcomponents==2) Jelem+=weight*.5*dp[1]*dp[1]*Jdet*gauss->weight;
187 }
188
189 /*clean up and Return: */
190 if(domaintype!=Domain2DhorizontalEnum){basalelement->DeleteMaterials(); delete basalelement;};
191 xDelete<IssmDouble>(xyz_list);
192 delete gauss;
193 return Jelem;
194}/*}}}*/
195
Note: See TracBrowser for help on using the repository browser.