Changeset 22422
- Timestamp:
- 02/16/18 07:57:38 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/Numberedcostfunction.h
r22410 r22422 14 14 #include "./ExternalResults/ExternalResult.h" 15 15 #include "./ExternalResults/Results.h" 16 #include "../modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.h" 17 #include "../modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.h" 18 #include "../modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.h" 19 #include "../modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.h" 20 #include "../modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.h" 21 #include "../modules/ThicknessAlongGradientx/ThicknessAlongGradientx.h" 22 #include "../modules/ThicknessAcrossGradientx/ThicknessAcrossGradientx.h" 23 #include "../modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.h" 24 #include "../modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.h" 16 25 17 26 … … 28 37 29 38 /*Numberedcostfunction constructors, destructors :*/ 30 Numberedcostfunction(){/*{{{*/ 31 32 this->definitionenum = -1; 33 this->name = NULL; 34 this->number_cost_functions = -1; 35 this->cost_functions_list = NULL; 36 37 } 38 /*}}}*/ 39 Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/ 40 _assert_(number_cost_functions_in>0); 41 _assert_(cost_functions_list_in); 42 43 this->definitionenum=in_definitionenum; 44 this->name = xNew<char>(strlen(in_name)+1); 45 xMemCpy<char>(this->name,in_name,strlen(in_name)+1); 46 47 this->number_cost_functions = number_cost_functions_in; 48 this->cost_functions_list = xNew<int>(number_cost_functions_in); 49 50 for(int i=0;i<number_cost_functions_in;i++){ 51 this->cost_functions_list[i] = cost_functions_list_in[i]; 52 } 53 } 54 /*}}}*/ 55 ~Numberedcostfunction(){/*{{{*/ 56 xDelete<int>(this->cost_functions_list); 57 if(this->name)xDelete(this->name); 58 } 59 /*}}}*/ 39 Numberedcostfunction(); 40 Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in); 41 ~Numberedcostfunction(); 60 42 61 43 /*Object virtual function resolutoin: */ 62 Object* copy() {/*{{{*/ 63 Numberedcostfunction* out = new Numberedcostfunction(this->name,this->definitionenum,this->number_cost_functions,this->cost_functions_list); 64 return (Object*)out; 65 } 66 /*}}}*/ 67 void DeepEcho(void){/*{{{*/ 68 this->Echo(); 69 } 70 /*}}}*/ 71 void Echo(void){/*{{{*/ 72 _printf_(" Numberedcostfunction: " << this->name << " " << this->definitionenum << "\n"); 73 _printf_(" number_cost_functions: "<<this->number_cost_functions<<"\n"); 74 _printf_(" "); 75 for(int i=0;i<this->number_cost_functions;i++){ 76 _printf_(this->cost_functions_list[i]<< " "); 77 } 78 _printf_("\n"); 79 } 80 /*}}}*/ 81 int Id(void){/*{{{*/ 82 return -1; 83 } 84 /*}}}*/ 85 void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/ 86 _error_("not implemented yet!"); 87 } 88 /*}}}*/ 89 int ObjectEnum(void){/*{{{*/ 90 return NumberedcostfunctionEnum; 91 } 92 /*}}}*/ 44 Object* copy(); 45 void DeepEcho(void); 46 void Echo(void); 47 int Id(void); 48 void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction); 49 int ObjectEnum(void); 93 50 94 51 /*Definition virtual function resolutoin: */ 95 int DefinitionEnum(){/*{{{*/ 96 return this->definitionenum; 97 } 98 /*}}}*/ 99 char* Name(){/*{{{*/ 100 101 char* name2=xNew<char>(strlen(this->name)+1); 102 xMemCpy(name2,this->name,strlen(this->name)+1); 103 104 return name2; 105 } 106 /*}}}*/ 107 IssmDouble Response(FemModel* femmodel){/*{{{*/ 108 109 _assert_(number_cost_functions>0 && number_cost_functions<1e3); 110 /*output:*/ 111 IssmDouble value; 112 113 /*Intermediary*/ 114 Results *cost_functions = NULL; 115 116 /*Get the value of all cost functions*/ 117 femmodel->RequestedOutputsx(&cost_functions,cost_functions_list,number_cost_functions); 118 119 /*Get and add all contributions one by one*/ 120 IssmDouble J=0.; 121 IssmDouble* Jlist = xNew<IssmDouble>(number_cost_functions); 122 for(int i=0;i<number_cost_functions;i++){ 123 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i); 124 Jlist[i] = reCast<IssmDouble>(result->GetValue()); 125 J += Jlist[i]; 126 } 127 _assert_(cost_functions->Size()==number_cost_functions); 128 129 130 value = J; 131 _printf_("J: "<<J<<"\n"); 132 133 /*done:*/ 134 delete cost_functions; 135 xDelete<IssmDouble>(Jlist); 136 return value; 137 } 138 /*}}}*/ 52 int DefinitionEnum(); 53 char* Name(); 54 IssmDouble Response(FemModel* femmodel); 139 55 }; 140 56 141 #endif /* _N ODALVALUE_H_ */57 #endif /* _NUMBEREDCOSTFUNCTION_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.