source: issm/trunk/src/c/classes/Misfit.h@ 17806

Last change on this file since 17806 was 17806, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 17804

File size: 4.6 KB
Line 
1/*!\file Misfit.h
2 * \brief: header file for Misfit object
3 */
4
5#ifndef _MISFIT_H_
6#define _MISFIT_H_
7
8/*Headers:*/
9/*{{{*/
10#include "./Definition.h"
11#include "../datastructures/datastructures.h"
12#include "./Elements/Element.h"
13#include "./Elements/Elements.h"
14#include "./FemModel.h"
15#include "../modules/SurfaceAreax/SurfaceAreax.h"
16#include "../classes/Params/Parameters.h"
17/*}}}*/
18
19class Misfit: public Object, public Definition{
20
21 public:
22
23 char* name;
24 int model_enum;
25 int observation_enum;
26 int weights_enum;
27 char* timeinterpolation;
28
29 IssmDouble misfit; //value carried over in time.
30 int lock; // if lock is on, we just return the value stored in "misfit". this is used so we don't compute misfit past the final_time
31
32 /*Misfit constructors, destructors :*/
33 /*FUNCTION Misfit() {{{*/
34 Misfit(){
35
36 this->name = NULL;
37 this->model_enum = UNDEF;
38 this->observation_enum = UNDEF;
39 this->weights_enum = UNDEF;
40 this->timeinterpolation=NULL;
41 this->misfit=0;
42 this->lock=0;
43
44 }
45 /*}}}*/
46 /*FUNCTION Misfit(char* in_name, int in_model_enum, int in_observation_enum char* in_timeinterpolation, int in_weights_enum) {{{*/
47 Misfit(char* in_name, int in_model_enum, int in_observation_enum, char* in_timeinterpolation, int in_weights_enum){
48
49 this->name = xNew<char>(strlen(in_name)+1);
50 xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
51
52 this->timeinterpolation = xNew<char>(strlen(in_timeinterpolation)+1);
53 xMemCpy<char>(this->timeinterpolation,in_timeinterpolation,strlen(in_timeinterpolation)+1);
54
55 this->model_enum=in_model_enum;
56 this->observation_enum=in_observation_enum;
57 this->weights_enum=in_weights_enum;
58
59 this->misfit=0;
60 this->lock=0;
61 }
62 /*}}}*/
63 /*FUNCTION ~Misfit() {{{*/
64 ~Misfit(){
65 if(this->name)xDelete(this->name);
66 if(this->timeinterpolation)xDelete(this->timeinterpolation);
67 this->misfit=0;
68 this->lock=0;
69 }
70 /*}}}*/
71 /*Object virtual function resolutoin: */
72 /*FUNCTION Echo(){{{*/
73 void Echo(void){
74 _printf_(" Misfit: " << name << "\n");
75 _printf_(" model_enum: " << model_enum << " " << EnumToStringx(model_enum) << "\n");
76 _printf_(" observation_enum: " << observation_enum << " " << EnumToStringx(observation_enum) << "\n");
77 _printf_(" weights_enum: " << weights_enum << " " << EnumToStringx(weights_enum) << "\n");
78 _printf_(" timeinterpolation: " << timeinterpolation << "\n");
79 }
80 /*}}}*/
81 /*FUNCTION DeepEcho(){{{*/
82 void DeepEcho(void){
83 this->Echo();
84 }
85 /*}}}*/
86 /*FUNCTION Id(){{{*/
87 int Id(void){
88 return -1;
89 }
90 /*}}}*/
91 /*FUNCTION ObjectEnum{{{*/
92 int ObjectEnum(void){
93 return MisfitEnum;
94 }
95 /*}}}*/
96 /*FUNCTION copy {{{*/
97 Object* copy() {
98 return new Misfit(this->name,this->model_enum,this->observation_enum,this->timeinterpolation,this->weights_enum);
99 }
100 /*}}}*/
101 /*Definition virtual function resolutoin: */
102 /*FUNCTION char* Name() {{{*/
103 char* Name(){
104
105 char* name2=xNew<char>(strlen(this->name)+1);
106 xMemCpy(name2,this->name,strlen(this->name)+1);
107
108 return name2;
109 }
110 /*}}}*/
111 /*FUNCTION IssmDouble Response(FemModel* femmodel) {{{*/
112 IssmDouble Response(FemModel* femmodel){
113
114 int i;
115 IssmDouble misfit_t=0.;
116 IssmDouble all_misfit_t=0.;
117 IssmDouble dt;
118 IssmDouble area_t=0.;
119 IssmDouble all_area_t;
120 IssmDouble time,starttime,finaltime;
121
122 femmodel->parameters->FindParam(&starttime,TimesteppingStartTimeEnum);
123 femmodel->parameters->FindParam(&finaltime,TimesteppingFinalTimeEnum);
124 femmodel->parameters->FindParam(&time,TimeEnum);
125
126 /*If we are locked, return time average: */
127 if(this->lock)return misfit/(time-starttime);
128
129
130 for(i=0;i<femmodel->elements->Size();i++){
131 Element* element=(Element*)femmodel->elements->GetObjectByOffset(i);
132 misfit_t+=element->Misfit(model_enum,observation_enum,weights_enum);
133 area_t+=element->MisfitArea(weights_enum);
134 }
135
136 ISSM_MPI_Allreduce ( (void*)&misfit_t,(void*)&all_misfit_t,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
137 ISSM_MPI_Allreduce ( (void*)&area_t,(void*)&all_area_t,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
138 area_t=all_area_t;
139 misfit_t=all_misfit_t;
140
141 /*Divide by surface area if not nill!: */
142 if (area_t!=0) misfit_t=misfit_t/area_t;
143
144 /*Recover delta_t: */
145 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
146
147 /*Add this time's contribution to curent misfit: */
148 misfit+=dt*misfit_t;
149
150 /*Do we lock? i.e. are we at final_time? :*/
151 if(time==finaltime)this->lock=1;
152
153 /*What we return is the value of misfit / time: */
154 return misfit/(time-starttime);
155 }
156 /*}}}*/
157};
158
159#endif /* _MISFIT_H_ */
Note: See TracBrowser for help on using the repository browser.