source: issm/trunk/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp@ 25836

Last change on this file since 25836 was 25836, checked in by Mathieu Morlighem, 4 years ago

merged trunk-jpl and trunk for revision 25834

File size: 3.0 KB
Line 
1/*!\file DragCoefficientAbsGradientx
2 * \brief: compute misfit between observations and model
3 */
4
5#include "./DragCoefficientAbsGradientx.h"
6
7#include "../../shared/shared.h"
8#include "../../toolkits/toolkits.h"
9#include "../../classes/Inputs/DatasetInput.h"
10
11void DragCoefficientAbsGradientx( IssmDouble* pJ, Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials,Parameters* parameters){
12
13 /*output: */
14 IssmDouble J=0.;
15 IssmDouble J_sum;
16
17 /*Compute Misfit: */
18 for(Object* & object : elements->objects){
19 Element* element=xDynamicCast<Element*>(object);
20 J+=DragCoefficientAbsGradient(element);
21 }
22
23 /*Sum all J from all cpus of the cluster:*/
24 ISSM_MPI_Reduce (&J,&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,0,IssmComm::GetComm() );
25 ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
26 J=J_sum;
27
28 /*Assign output pointers: */
29 *pJ=J;
30}
31
32IssmDouble DragCoefficientAbsGradient(Element* element){
33
34 int domaintype,numcomponents;
35 int frictionlaw;
36 IssmDouble Jelem=0.;
37 IssmDouble misfit,Jdet;
38 IssmDouble dp[2],weight;
39 IssmDouble* xyz_list = NULL;
40
41 /*Get basal element*/
42 if(!element->IsOnBase()) return 0.;
43
44 /*If on water, return 0: */
45 if(!element->IsIceInElement()) return 0.;
46
47 /*Get problem dimension*/
48 element->FindParam(&domaintype,DomainTypeEnum);
49 switch(domaintype){
50 case Domain2DverticalEnum: numcomponents = 1; break;
51 case Domain3DEnum: numcomponents = 2; break;
52 case Domain2DhorizontalEnum: numcomponents = 2; break;
53 default: _error_("not supported yet");
54 }
55
56 /*Spawn basal element*/
57 Element* basalelement = element->SpawnBasalElement();
58
59 /* Get node coordinates*/
60 basalelement->GetVerticesCoordinates(&xyz_list);
61
62 /*Retrieve all inputs we will be needing: */
63 DatasetInput* weights_input=basalelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
64
65 /* get the friction law: if 11-Schoof, which has a different name of C */
66 element->FindParam(&frictionlaw, FrictionLawEnum);
67 Input* drag_input;
68 switch(frictionlaw) {
69 case 2:
70 case 11:
71 drag_input = basalelement->GetInput(FrictionCEnum); _assert_(drag_input);
72 break;
73 default:
74 drag_input = basalelement->GetInput(FrictionCoefficientEnum); _assert_(drag_input);
75 }
76
77 /* Start looping on the number of gaussian points: */
78 Gauss* gauss=basalelement->NewGauss(2);
79 while(gauss->next()){
80
81 /* Get Jacobian determinant: */
82 basalelement->JacobianDeterminant(&Jdet,xyz_list,gauss);
83
84 /*Get all parameters at gaussian point*/
85 weights_input->GetInputValue(&weight,gauss,DragCoefficientAbsGradientEnum);
86 drag_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
87
88 /*Compute Tikhonov regularization J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
89 Jelem+=weight*.5*dp[0]*dp[0]*Jdet*gauss->weight;
90 if(numcomponents==2) Jelem+=weight*.5*dp[1]*dp[1]*Jdet*gauss->weight;
91
92 }
93
94 /*clean up and Return: */
95 if(domaintype!=Domain2DhorizontalEnum){basalelement->DeleteMaterials(); delete basalelement;};
96 xDelete<IssmDouble>(xyz_list);
97 delete gauss;
98 return Jelem;
99}
Note: See TracBrowser for help on using the repository browser.