Ice Sheet System Model  4.18
Code documentation
Functions
M1qn3.cpp File Reference
#include "./M1qn3.h"

Go to the source code of this file.

Functions

 WRAPPER (M1qn3_python)
 

Function Documentation

◆ WRAPPER()

WRAPPER ( M1qn3_python  )

Definition at line 38 of file M1qn3.cpp.

38  {
39 
40  /*Boot module: */
41  MODULEBOOT();
42 
43 #ifdef _HAVE_M1QN3_
44  /*input: */
45  double* Xs=NULL;
46  double* Gs=NULL;
47  double* Js=NULL;
48  int intn;
49  int priorn;
50  Data data_struct;
51 
52  /* output: */
53  double* X_out = NULL;
54 
55  /*intermediary: */
56  double f;
57  double dxmin=0.01;
58  double gttol=0.0001;
59  long omode;
60 
61  /*checks on arguments on the matlab side: */
62  if(nlhs!=NLHS || nrhs!=3){
63  M1qn3Usage();
64  _error_("M1qn3 usage error");
65  }
66 
67  /*Input datasets: */
68  FetchData(&Xs,&intn,&priorn,XHANDLE);
69  FetchData(&Gs,&intn,&priorn,GHANDLE);
70  FetchData(&Js,&priorn,JHANDLE);
71 
72  /*Initialize M1QN3 parameters*/
73  SimulFunc costfuncion = &fakesimul; /*Cost function address*/
74  void** prosca = &euclid_; /*Dot product function (euclid is the default)*/
75  char normtype[] = "dfn"; /*Norm type: dfn = scalar product defined by prosca*/
76  long izs[5]; /*Arrays used by m1qn3 subroutines*/
77  long iz[5]; /*Integer m1qn3 working array of size 5*/
78  float rzs[1]; /*Arrays used by m1qn3 subroutines*/
79  long impres = 0; /*verbosity level*/
80  long imode[3] = {0}; /*scaling and starting mode, 0 by default*/
81  long indic = 4; /*compute f and g*/
82  long reverse = 0; /*reverse or direct mode*/
83  long io = 6; /*Channel number for the output*/
84 
85  /*Optimization criterions*/
86  long niter = long(intn); /*Maximum number of iterations*/
87  long nsim = long(intn); /*Maximum number of function calls*/
88 
89  /*Get problem dimension and initialize X, G and f: */
90  long n = long(intn);
91  IssmPDouble* G = xNew<IssmPDouble>(n); for (int i=0;i<n;i++)G[i]=Gs[i*priorn+0];
92  IssmPDouble* X = xNew<IssmPDouble>(n); for (int i=0;i<n;i++)X[i]=Xs[i*priorn+0];
93  f = Js[0];
94 
95  /*Allocate m1qn3 working arrays (see doc)*/
96  long m = 100;
97  long ndz = 4*n+m*(2*n+1);
98  double* dz = xNew<double>(ndz);
99  double f1=f;
100 
101  /*Initialize: */
102  data_struct.priorn=priorn;
103  data_struct.counter=0;
104  data_struct.Gs=Gs;
105  data_struct.Js=Js;
106  data_struct.Xs=Xs;
107 
108  m1qn3_(costfuncion,prosca,&ctonbe_,&ctcabe_,
109  &n,X,&f,G,&dxmin,&f1,
110  &gttol,normtype,&impres,&io,imode,&omode,&niter,&nsim,iz,dz,&ndz,
111  &reverse,&indic,izs,rzs,(void*)&data_struct);
112 
113  switch(int(omode)){
114  case 0: /* _printf0_(" Stop requested\n");*/ break;
115  case 1: _printf0_(" Convergence reached (gradient satisfies stopping criterion)\n"); break;
116  case 2: _printf0_(" Bad initialization\n"); break;
117  case 3: _printf0_(" Line search failure\n"); break;
118  case 4: _printf0_(" Maximum number of iterations exceeded\n");break;
119  case 5: _printf0_(" Maximum number of function calls exceeded\n"); break;
120  case 6: _printf0_(" stopped on dxmin during line search\n"); break;
121  case 7: _printf0_(" <g,d> > 0 or <y,s> <0\n"); break;
122  default: _printf0_(" Unknown end condition\n");
123  }
124 
125  /*build output: */
126  X_out=xNew<IssmPDouble>(n);
127  for(int i=0;i<n;i++)X_out[i]=X[i];
128 
129  /*Write data: */
130  WriteData(XOUT,X_out,n);
131 
132  /*end module: */
133  xDelete<double>(Xs);
134  xDelete<double>(Gs);
135  xDelete<double>(Js);
136  xDelete<double>(X_out);
137  xDelete<double>(G);
138  xDelete<double>(X);
139  #else
140  _error_("m1qn3 is not installed");
141  #endif
142  MODULEEND();
143 
144 }
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
WriteData
void WriteData(IssmPDouble **pmatrix, int *pnel, int *matrix, int M, int N)
Definition: WriteJavascriptData.cpp:16
FetchData
void FetchData(char **pstring, char *stringin)
Definition: FetchJavascriptData.cpp:16
NLHS
#define NLHS
Definition: BamgConvertMesh.h:50
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
IssmPDouble
IssmDouble IssmPDouble
Definition: types.h:38