source: issm/trunk/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp@ 24686

Last change on this file since 24686 was 24686, checked in by Mathieu Morlighem, 5 years ago

merged trunk-jpl and trunk for revision 24684

File size: 2.3 KB
Line 
1/*!\file ThicknessAbsMisfitx
2 * \brief: compute misfit between observations and model
3 */
4
5#include "./ThicknessAbsMisfitx.h"
6
7#include "../../shared/shared.h"
8#include "../../toolkits/toolkits.h"
9#include "../../classes/Inputs2/DatasetInput2.h"
10
11void ThicknessAbsMisfitx( 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(int i=0;i<elements->Size();i++){
19 Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
20 J+=ThicknessAbsMisfit(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 ThicknessAbsMisfit(Element* element){
33
34 IssmDouble thickness,thicknessobs,weight;
35 IssmDouble Jelem=0.;
36 IssmDouble misfit,Jdet;
37 IssmDouble* xyz_list = NULL;
38
39 /*If on water, return 0: */
40 if(!element->IsIceInElement()) return 0.;
41
42 /* Get node coordinates*/
43 element->GetVerticesCoordinates(&xyz_list);
44
45 /*Retrieve all inputs we will be needing: */
46 DatasetInput2* weights_input =element->GetDatasetInput2(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
47 Input2* thickness_input =element->GetInput2(ThicknessEnum); _assert_(thickness_input);
48 Input2* thicknessobs_input=element->GetInput2(InversionThicknessObsEnum); _assert_(thicknessobs_input);
49
50 /* Start looping on the number of gaussian points: */
51 Gauss* gauss=element->NewGauss(2);
52 for(int ig=gauss->begin();ig<gauss->end();ig++){
53
54 gauss->GaussPoint(ig);
55
56 /* Get Jacobian determinant: */
57 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
58
59 /*Get all parameters at gaussian point*/
60 weights_input->GetInputValue(&weight,gauss,ThicknessAbsMisfitEnum);
61 thickness_input->GetInputValue(&thickness,gauss);
62 thicknessobs_input->GetInputValue(&thicknessobs,gauss);
63
64 /*Compute ThicknessAbsMisfitEnum*/
65 Jelem+=0.5*(thickness-thicknessobs)*(thickness-thicknessobs)*weight*Jdet*gauss->weight;
66 }
67
68 /*clean up and Return: */
69 xDelete<IssmDouble>(xyz_list);
70 delete gauss;
71 return Jelem;
72}
Note: See TracBrowser for help on using the repository browser.