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

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

merged trunk-jpl and trunk for revision 23187

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