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

Last change on this file since 21341 was 21341, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 21337

File size: 6.1 KB
RevLine 
[16787]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"
[16793]15#include "../modules/SurfaceAreax/SurfaceAreax.h"
16#include "../classes/Params/Parameters.h"
[19105]17#include "../classes/Inputs/Input.h"
18#include "../classes/gauss/Gauss.h"
[16787]19/*}}}*/
[19105]20IssmDouble OutputDefinitionsResponsex(FemModel* femmodel,int output_enum);
[16787]21
22class Misfit: public Object, public Definition{
23
24 public:
25
[19105]26 int definitionenum;
[21341]27 bool local;
28 int model_enum;
[16787]29 char* name;
30 int observation_enum;
[21341]31 char* timeinterpolation;
[16787]32 int weights_enum;
33
[21341]34 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
[16793]35 IssmDouble misfit; //value carried over in time.
36
[16787]37 /*Misfit constructors, destructors :*/
[18301]38 Misfit(){/*{{{*/
[16787]39
[19105]40 this->definitionenum = -1;
[16787]41 this->name = NULL;
42 this->model_enum = UNDEF;
43 this->observation_enum = UNDEF;
44 this->weights_enum = UNDEF;
45 this->timeinterpolation=NULL;
[19105]46 this->local=true;
[16793]47 this->misfit=0;
48 this->lock=0;
[16787]49
50 }
51 /*}}}*/
[19105]52 Misfit(char* in_name, int in_definitionenum, int in_model_enum, int in_observation_enum, char* in_timeinterpolation, bool in_local, int in_weights_enum){/*{{{*/
[16787]53
[19105]54 this->definitionenum=in_definitionenum;
[21341]55
56 this->name = xNew<char>(strlen(in_name)+1);
[16787]57 xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
58
[21341]59 this->timeinterpolation = xNew<char>(strlen(in_timeinterpolation)+1);
[16787]60 xMemCpy<char>(this->timeinterpolation,in_timeinterpolation,strlen(in_timeinterpolation)+1);
[21341]61
[16787]62 this->model_enum=in_model_enum;
63 this->observation_enum=in_observation_enum;
64 this->weights_enum=in_weights_enum;
[19105]65 this->local=in_local;
[16793]66
67 this->misfit=0;
68 this->lock=0;
[16787]69 }
70 /*}}}*/
[18301]71 ~Misfit(){/*{{{*/
[16787]72 if(this->name)xDelete(this->name);
73 if(this->timeinterpolation)xDelete(this->timeinterpolation);
[16793]74 this->misfit=0;
75 this->lock=0;
[16787]76 }
77 /*}}}*/
78 /*Object virtual function resolutoin: */
[21341]79 Object* copy() {/*{{{*/
80 Misfit* mf = new Misfit(this->name,this->definitionenum, this->model_enum,this->observation_enum,this->timeinterpolation,this->local,this->weights_enum);
81 mf->misfit=this->misfit;
82 mf->lock=this->lock;
83 return (Object*) mf;
84 }
85 /*}}}*/
86 void DeepEcho(void){/*{{{*/
87 this->Echo();
88 }
89 /*}}}*/
[18301]90 void Echo(void){/*{{{*/
[19105]91 _printf_(" Misfit: " << name << " " << this->definitionenum << "\n");
[16787]92 _printf_(" model_enum: " << model_enum << " " << EnumToStringx(model_enum) << "\n");
93 _printf_(" observation_enum: " << observation_enum << " " << EnumToStringx(observation_enum) << "\n");
94 _printf_(" weights_enum: " << weights_enum << " " << EnumToStringx(weights_enum) << "\n");
95 _printf_(" timeinterpolation: " << timeinterpolation << "\n");
[19105]96 _printf_(" local: " << local << "\n");
[16787]97 }
98 /*}}}*/
[18301]99 int Id(void){/*{{{*/
[16787]100 return -1;
101 }
102 /*}}}*/
[21341]103 void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
104 _error_("not implemented yet!");
105 }
106 /*}}}*/
[18301]107 int ObjectEnum(void){/*{{{*/
[16787]108 return MisfitEnum;
109 }
110 /*}}}*/
[21341]111 /*Definition virtual function resolutoin: */
112 int DefinitionEnum(){/*{{{*/
113 return this->definitionenum;
[16787]114 }
115 /*}}}*/
[18301]116 char* Name(){/*{{{*/
[16787]117 char* name2=xNew<char>(strlen(this->name)+1);
118 xMemCpy(name2,this->name,strlen(this->name)+1);
119
120 return name2;
121 }
122 /*}}}*/
[18301]123 IssmDouble Response(FemModel* femmodel){/*{{{*/
[19105]124
125 /*diverse: */
126 IssmDouble time,starttime,finaltime;
[16793]127 IssmDouble dt;
[19105]128
129 /*recover time parameters: */
[16793]130 femmodel->parameters->FindParam(&starttime,TimesteppingStartTimeEnum);
131 femmodel->parameters->FindParam(&finaltime,TimesteppingFinalTimeEnum);
132 femmodel->parameters->FindParam(&time,TimeEnum);
[19105]133 femmodel->parameters->FindParam(&dt,TimesteppingTimeStepEnum);
[16793]134
[19105]135 if (this->local){ /*local computation: {{{*/
[16793]136
[19105]137 int i;
138 IssmDouble misfit_t=0.;
139 IssmDouble all_misfit_t=0.;
140 IssmDouble area_t=0.;
141 IssmDouble all_area_t;
[17048]142
[19105]143
144 /*If we are locked, return time average: */
145 if(this->lock)return misfit/(time-starttime);
[16793]146
[19105]147 for(i=0;i<femmodel->elements->Size();i++){
148 Element* element=(Element*)femmodel->elements->GetObjectByOffset(i);
149 misfit_t+=element->Misfit(model_enum,observation_enum,weights_enum);
150 area_t+=element->MisfitArea(weights_enum);
151 }
[16793]152
[19105]153 ISSM_MPI_Allreduce ( (void*)&misfit_t,(void*)&all_misfit_t,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
154 ISSM_MPI_Allreduce ( (void*)&area_t,(void*)&all_area_t,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
155 area_t=all_area_t;
156 misfit_t=all_misfit_t;
157
158 /*Divide by surface area if not nill!: */
159 if (area_t!=0) misfit_t=misfit_t/area_t;
[16793]160
[19105]161 /*Add this time's contribution to curent misfit: */
162 misfit+=dt*misfit_t;
[16793]163
[19105]164 /*Do we lock? i.e. are we at final_time? :*/
165 if(time==finaltime)this->lock=1;
[16793]166
[19105]167 /*What we return is the value of misfit / time: */
168 return misfit/(time-starttime);
169 } /*}}}*/
170 else{ /*global computation: {{{ */
171
172 IssmDouble model, observation;
173
174 /*If we are locked, return time average: */
175 if(this->lock)return misfit/(time-starttime);
176
177 /*First, the global model response: */
178 model=OutputDefinitionsResponsex(femmodel,this->model_enum);
179 /*Now, the observation is buried inside the elements, go fish it in the first element (cludgy, needs fixing): */
180 Element* element=(Element*)femmodel->elements->GetObjectByOffset(0); _assert_(element);
181 Input* input = element->GetInput(observation_enum); _assert_(input);
182 input->GetInputAverage(&observation);
183
184 /*Add this time's contribution to curent misfit: */
185 misfit+=dt*(model-observation);
186
187 /*Do we lock? i.e. are we at final_time? :*/
188 if(time==finaltime)this->lock=1;
189
190 /*What we return is the value of misfit / time: */
191 return misfit/(time-starttime);
192 } /*}}}*/
193
[16787]194 }
195 /*}}}*/
196};
197
198#endif /* _MISFIT_H_ */
Note: See TracBrowser for help on using the repository browser.