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