source: issm/trunk-jpl/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp

Last change on this file was 25539, checked in by bdef, 5 years ago

CHG:Modifying loop on elements towards for on iterator

File size: 2.2 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/Inputs/DatasetInput.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(Object* & object : elements->objects){
19 Element* element=xDynamicCast<Element*>(object);
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 DatasetInput* weights_input =element->GetDatasetInput(InversionCostFunctionsCoefficientsEnum); _assert_(weights_input);
47 Input* thickness_input =element->GetInput(ThicknessEnum); _assert_(thickness_input);
48 Input* thicknessobs_input=element->GetInput(InversionThicknessObsEnum); _assert_(thicknessobs_input);
49
50 /* Start looping on the number of gaussian points: */
51 Gauss* gauss=element->NewGauss(2);
52 while(gauss->next()){
53
54 /* Get Jacobian determinant: */
55 element->JacobianDeterminant(&Jdet,xyz_list,gauss);
56
57 /*Get all parameters at gaussian point*/
58 weights_input->GetInputValue(&weight,gauss,ThicknessAbsMisfitEnum);
59 thickness_input->GetInputValue(&thickness,gauss);
60 thicknessobs_input->GetInputValue(&thicknessobs,gauss);
61
62 /*Compute ThicknessAbsMisfitEnum*/
63 Jelem+=0.5*(thickness-thicknessobs)*(thickness-thicknessobs)*weight*Jdet*gauss->weight;
64 }
65
66 /*clean up and Return: */
67 xDelete<IssmDouble>(xyz_list);
68 delete gauss;
69 return Jelem;
70}
Note: See TracBrowser for help on using the repository browser.