[8608] | 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"
|
---|
[25836] | 9 | #include "../../classes/Inputs/DatasetInput.h"
|
---|
[8608] | 10 |
|
---|
[16560] | 11 | void DragCoefficientAbsGradientx( IssmDouble* pJ, Elements* elements,Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials,Parameters* parameters){
|
---|
[8608] | 12 |
|
---|
| 13 | /*output: */
|
---|
[17989] | 14 | IssmDouble J=0.;
|
---|
[13395] | 15 | IssmDouble J_sum;
|
---|
[8608] | 16 |
|
---|
| 17 | /*Compute Misfit: */
|
---|
[25836] | 18 | for(Object* & object : elements->objects){
|
---|
| 19 | Element* element=xDynamicCast<Element*>(object);
|
---|
[17989] | 20 | J+=DragCoefficientAbsGradient(element);
|
---|
[8608] | 21 | }
|
---|
| 22 |
|
---|
| 23 | /*Sum all J from all cpus of the cluster:*/
|
---|
[16137] | 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());
|
---|
[8608] | 26 | J=J_sum;
|
---|
| 27 |
|
---|
| 28 | /*Assign output pointers: */
|
---|
| 29 | *pJ=J;
|
---|
| 30 | }
|
---|
[17989] | 31 |
|
---|
| 32 | IssmDouble DragCoefficientAbsGradient(Element* element){
|
---|
| 33 |
|
---|
| 34 | int domaintype,numcomponents;
|
---|
[25836] | 35 | int frictionlaw;
|
---|
[17989] | 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: */
|
---|
[25836] | 63 | DatasetInput* weights_input=basalelement->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
|
---|
[17989] | 64 |
|
---|
[25836] | 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 |
|
---|
[17989] | 77 | /* Start looping on the number of gaussian points: */
|
---|
| 78 | Gauss* gauss=basalelement->NewGauss(2);
|
---|
[25836] | 79 | while(gauss->next()){
|
---|
[17989] | 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 | }
|
---|