source: issm/oecreview/Archive/21724-22754/ISSM-22409-22410.diff@ 22755

Last change on this file since 22755 was 22755, checked in by Mathieu Morlighem, 7 years ago

CHG: added 21724-22754

File size: 5.3 KB
RevLine 
[22755]1Index: ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
2===================================================================
3--- ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp (revision 22409)
4+++ ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp (revision 22410)
5@@ -181,7 +181,6 @@
6 /*Free ressources:*/
7 for(j=0;j<numnodalvalues;j++){
8 char* string=NULL;
9- IssmDouble* matrix = NULL;
10 string = nodalvalue_name_s[j]; xDelete<char>(string);
11 }
12 xDelete<char*>(nodalvalue_name_s);
13@@ -321,11 +320,9 @@
14 int numout;
15 char **ncf_name_s = NULL;
16 char **ncf_definitionstring_s = NULL;
17+ char **cost_functions = NULL;
18 int cost_function ,domaintype;
19 int num_cost_functions;
20- char **cost_functions = NULL;
21- int num_costfunc;
22- char **cm_responses = NULL;
23
24 /*Process cost functions and convert from string to enums*/
25 iomodel->FindConstant(&num_cost_functions,"md.numberedcostfunction.num_cost_functions");
26@@ -336,7 +333,7 @@
27 cost_function_enums[i]=StringToEnumx(cost_functions[i]);
28 }
29
30- iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
31+ //iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
32
33 iomodel->FetchMultipleData(&ncf_name_s,&numout,"md.numberedcostfunction.name");
34 iomodel->FetchMultipleData(&ncf_definitionstring_s,&numout,"md.numberedcostfunction.definitionstring");
35@@ -361,29 +358,25 @@
36
37 for(j=0;j<numout;j++){
38
39- output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_costfunc,cost_function_enums));
40+ output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums));
41
42 }
43
44- parameters->AddObject(iomodel->CopyConstantObject("md.inversion.num_cost_functions",InversionNumCostFunctionsEnum));
45
46- iomodel->FindConstant(&cm_responses,&num_costfunc,"md.inversion.cost_functions");
47- //if(num_costfunc<1) error ("no cost functions found");
48- int* costfunc_enums=xNew<int>(num_costfunc);
49- for(int i=0;i<num_costfunc;i++){
50- costfunc_enums[i]=StringToEnumx(cm_responses[i]);
51- xDelete<char>(cm_responses[i]);
52- }
53- xDelete<char*>(cm_responses);
54-
55- parameters->AddObject(new IntVecParam(InversionCostFunctionsEnum,costfunc_enums,num_costfunc));
56- xDelete<int>(costfunc_enums);
57-
58 /*Free data: */
59- iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
60+ //iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
61+ iomodel->DeleteData(2,"md.numberedcostfunction.name","md.numberedcostfunction.definitionstring");
62 xDelete<int>(cost_function_enums);
63 for(int i=0;i<num_cost_functions;i++) xDelete<char>(cost_functions[i]);
64 xDelete<char*>(cost_functions);
65+
66+ /*Free ressources:*/
67+ for(j=0;j<numout;j++){
68+ xDelete<char>(ncf_name_s[j]);
69+ xDelete<char>(ncf_definitionstring_s[j]);
70+ }
71+ xDelete<char*>(ncf_name_s);
72+ xDelete<char*>(ncf_definitionstring_s);
73 }
74 /*}}}*/
75 else _error_("output definition enum " << EnumToStringx(output_definition_enums[i]) << " not supported yet!");
76Index: ../trunk-jpl/src/c/classes/Numberedcostfunction.h
77===================================================================
78--- ../trunk-jpl/src/c/classes/Numberedcostfunction.h (revision 22409)
79+++ ../trunk-jpl/src/c/classes/Numberedcostfunction.h (revision 22410)
80@@ -37,7 +37,6 @@
81 }
82 /*}}}*/
83 Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/
84-
85 _assert_(number_cost_functions_in>0);
86 _assert_(cost_functions_list_in);
87
88@@ -107,40 +106,34 @@
89 /*}}}*/
90 IssmDouble Response(FemModel* femmodel){/*{{{*/
91
92+ _assert_(number_cost_functions>0 && number_cost_functions<1e3);
93 /*output:*/
94 IssmDouble value;
95
96 /*Intermediary*/
97- int num_responses;
98- int *responses = NULL;
99 Results *cost_functions = NULL;
100
101-
102- /*Recover parameters*/
103- femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
104- femmodel->parameters->FindParam(&responses,NULL,InversionCostFunctionsEnum);
105-
106 /*Get the value of all cost functions*/
107- femmodel->RequestedOutputsx(&cost_functions,responses,num_responses);
108+ femmodel->RequestedOutputsx(&cost_functions,cost_functions_list,number_cost_functions);
109
110 /*Get and add all contributions one by one*/
111- IssmDouble J=0;
112- IssmDouble* Jlist = xNew<IssmDouble>(num_responses);
113- for(int i=0;i<num_responses;i++){
114+ IssmDouble J=0.;
115+ IssmDouble* Jlist = xNew<IssmDouble>(number_cost_functions);
116+ for(int i=0;i<number_cost_functions;i++){
117 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i);
118 Jlist[i] = reCast<IssmDouble>(result->GetValue());
119 J += Jlist[i];
120 }
121- _assert_(cost_functions->Size()==num_responses);
122+ _assert_(cost_functions->Size()==number_cost_functions);
123
124
125 value = J;
126 _printf_("J: "<<J<<"\n");
127-
128- // _error_("STOP!");
129
130 /*done:*/
131- return value;
132+ delete cost_functions;
133+ xDelete<IssmDouble>(Jlist);
134+ return value;
135 }
136 /*}}}*/
137 };
Note: See TracBrowser for help on using the repository browser.