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

Last change on this file since 27035 was 27035, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 27033

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