00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #define COUNT
00012 #define _DEBUG
00013
00014 #define MYINFINITY 1.0e+308
00015
00016
00017 #define GRDIV(a,b) (exp((1.0-TAU)*log(a)+TAU*log(b)))
00018
00019 #define CG_THRESHOLD 10000
00020
00021
00022
00023 typedef struct {
00024 char type;
00025 short ncp;
00026 int firstcpi;
00027
00028 int hti;
00029 double C;
00030 int cfn;
00031 int blmask;
00032 } meshdom_elem;
00033
00034 typedef struct {
00035 int vnum;
00036 int firstsel;
00037 short nneigh;
00038 short nncn;
00039 int fneigh;
00040 } vertex_desc;
00041
00042 typedef struct {
00043 int n0, n1, m0, m1;
00044 int ncp, nvars;
00045 int ndomelems, *domelind;
00046 int *nncpi;
00047 int *vpermut, *vncpi;
00048 int hsize;
00049 int *hprof;
00050 double **hrows, **lhrows;
00051 double func, gn0, nu;
00052 boolean accurate;
00053 char hblstat;
00054
00055
00056
00057 } block_desc;
00058
00059 typedef struct {
00060 int firsthbl, nhbl;
00061 } nzHbl_rowdesc;
00062
00063 typedef struct {
00064
00065 int nv, nhe, nfac;
00066 BSMvertex *mv;
00067 int *mvhei;
00068 point3d *mvcp;
00069 BSMhalfedge *mhe;
00070 BSMfacet *mfac;
00071 int *mfhei;
00072 char *mvtag;
00073
00074 int cnv;
00075
00076 int rmnnz;
00077 index2 *rmnzi;
00078 double *rmnzc;
00079
00080 int nwcp, *wncpi;
00081
00082 int pmnnz;
00083 index3 *pmnzi;
00084
00085 int ndomelems, ndomelcpind;
00086 meshdom_elem *domelem;
00087 int *domelcpind;
00088 boolean eltypes[GH_MAX_K-2];
00089
00090 int hti;
00091 double *ftab, *gtab, *htab;
00092
00093 int nvcp, nvars;
00094 int *nncpi, *vncpi;
00095
00096 int hsize, *hprof;
00097 double *Hessian, **hrows, *LHessian, **lhrows;
00098
00099 int phsize, *phprof;
00100 double **phrows;
00101 int nnz1, nnz2;
00102
00103 int itn, next_entire;
00104 double func, gn0, nu[2];
00105 boolean newpoint, accurate;
00106 int nkn1, nkn2;
00107 double *aqcoeff, *bqcoeff;
00108 double *aNitabs[GH_MAX_K-2], *aNijtabs[GH_MAX_K-2],
00109 *aMijtabs[GH_MAX_K-2], *aJac[GH_MAX_K-2],
00110 *bNitabs[GH_MAX_K-2], *bJac[GH_MAX_K-2];
00111
00112 boolean use_cg, last_ntn;
00113
00114 int Hblsize;
00115 nzHbl_rowdesc *iHbl;
00116 int *cHbl;
00117 double *Hbl;
00118
00119 int nbl;
00120 block_desc block[G2MBL_MAX_BLOCKS];
00121 int *belind;
00122
00123 int ibl;
00124
00125
00126 int nextblock;
00127 double *BHessian;
00128
00129 int *bltag;
00130 #ifdef COUNT
00131 int nLM, nN, nF, nG, nH;
00132 #endif
00133 } mesh_lmt_optdata;
00134
00135
00136 void _g2mbl_TagBoundaryCondVert ( int nv, BSMvertex *mv, int *mvhei,
00137 int nhe, BSMhalfedge *mhe, int cvn,
00138 char *vtag );
00139 void _g2mbl_CountRegularFacets ( int d, int *vertnum, int *mtab, void *usrptr );
00140 void _g2mbl_CountSpecialVertices ( int d, int k, int *vertnum, int *mtab,
00141 void *usrptr );
00142 void _g2mbl_GetRegularFacetVertNum ( int d, int *vertnum, int *mtab, void *usrptr );
00143 void _g2mbl_GetSpecialElemVertNum ( int d, int k, int *vertnum, int *mtab,
00144 void *usrptr );
00145 boolean _g2mbl_AssignMeshd ( mesh_lmt_optdata *d,
00146 int nv, BSMvertex *mv, int *mvhei, point3d *mvcp,
00147 int nhe, BSMhalfedge *mhe,
00148 int nfac, BSMfacet *mfac, int *mfhei,
00149 byte *mkcp );
00150 boolean _g2mbl_OrderCPoints ( int nv, int nvcp, int fcp,
00151 int nzcdsize, byte *nzcdistr,
00152 int *nncpi, int *vncpi, vertex_desc *nvcpi,
00153 int ndomelems, meshdom_elem *domelem, int *domelcpind,
00154 int *domelind,
00155 int blsize, int *hsize, int *hprof, int *vpermut );
00156 boolean _g2mbl_SetupHessianProfiled ( mesh_lmt_optdata *d, boolean use_blocks );
00157 boolean _g2mbl_AllocBFArraysd ( mesh_lmt_optdata *d, int nkn1, int nkn2 );
00158 boolean _g2mbl_SetupElemConstd ( mesh_lmt_optdata *d,
00159 double dM, double dO, double C );
00160
00161 boolean _g2mbl_SetupHbl3x3d ( mesh_lmt_optdata *d );
00162 boolean _g2mbl_SetupBlockHessianProfiled ( mesh_lmt_optdata *d, int bnum );
00163 boolean _g2mbl_SetupBlocksd ( mesh_lmt_optdata *d, int nbl );
00164 boolean _g2mbl_SetupBlockRowsd ( mesh_lmt_optdata *d );
00165
00166 int g2mbl_NiSize ( int nkn, int k );
00167 int g2mbl_NijSize ( int nkn, int k );
00168 int g2mbl_MijSize ( int nkn, int k );
00169
00170 boolean g2mbl_TabNid ( int hole_k, int nkn, double *qknots,
00171 double *Nitab, double *Jac, boolean reparam );
00172 void g2mbl_TabNijd ( int nf, int nkn, double *Nitab, double *Nijtab );
00173 void g2mbl_TabMijd ( int nf, int nkn, double *Nitab, double *Mijtab );
00174
00175 boolean g2mbl_FindDistances ( int nv, BSMvertex *mv, int *mvhei,
00176 int nhe, BSMhalfedge *mhe,
00177 int nfac, BSMfacet *mfac, int *mfhei,
00178 int *fdist );
00179
00180 void _g2mbl_UCompRDerd ( int nkn2, double *Nitab, int knot,
00181 int *cpind, point3d *mvcp, vector3d pder[11] );
00182 void g2mbl_UFuncRSQd ( int nkn, double *qcoeff, double *Nitab,
00183 int *cpind, point3d *mvcp,
00184 double C, double *ftab );
00185 void _g2mbl_UCompSDerd ( int nkn2, double *Nitab, int knot, int k, int l,
00186 int *cpind, point3d *mvcp, vector3d pder[11] );
00187 void g2mbl_UFuncSSQd ( int nkn, double *qcoeff, int k, double *Nitab, double *Jac,
00188 int *cpind, point3d *mvcp, double C,
00189 double *ftab );
00190 void _g2mbl_UCompDGStard ( int nkn2, int nf, double *Nitab, int knot, int k, int l,
00191 const vector3d *pder, int *cpind, int *nncpi,
00192 double *DGstar );
00193 void _g2mbl_UCompDBStard ( int nkn2, int nf, double *Nitab, int knot, int k, int l,
00194 const vector3d *pder, int *cpind, int *nncpi,
00195 double *DBstar );
00196 void _g2mbl_UFuncGradSQIntegrandd ( int nkn2, int nf, double *Nitab,
00197 int knot, int k, int l, vector3d pder[11],
00198 int *cpind, int *nncpi,
00199 double Gstar[9], double *DGstar,
00200 double Bstar[11], double *DBstar,
00201 double C,
00202 double *F, double *DF );
00203 void g2mbl_UFuncGradRSQd ( int nkn, double *qcoeff, double *Nitab,
00204 int *cpind, int *nncpi, point3d *mvcp,
00205 double C,
00206 double *ftab, double *gtab );
00207 boolean g2mbl_UFuncGradSSQd ( int nkn, double *qcoeff, int k,
00208 double *Nitab, double *Jac,
00209 int *cpind, int *nncpi, point3d *mvcp,
00210 double C,
00211 double *ftab, double *gtab );
00212 void _g2mbl_UCompDDGstard ( int nkn2, int nf, double *Nijtab,
00213 int knot, int k, int l,
00214 int *cpind, int *nncpi, double *DDGstar );
00215 void _g2mbl_UCompDDBstard ( int nkn2, int nf, double *Mijtab, int knot, int k, int l,
00216 vector3d *pder, int *cpind, int *nncpi,
00217 double *DDBstar );
00218 boolean _g2mbl_UFuncGradHessSQIntegrandd ( int nkn2, int nf, double *Nitab,
00219 int knot, int k, int l, vector3d *pder,
00220 int *cpind, int *nncpi,
00221 double *Gstar, double *DGstar, double *DDGstar,
00222 double *Bstar, double *DBstar, double *DDBstar,
00223 double C,
00224 double *F, double *DF, double *DDF );
00225 boolean g2mbl_UFuncGradHessRSQd ( int nkn, double *qcoeff,
00226 double *Nitab, double *Nijtab, double *Mijtab,
00227 int *cpind, int *nncpi, point3d *mvcp,
00228 double C,
00229 double *ftab, double *gtab, double *htab );
00230 boolean g2mbl_UFuncGradHessSSQd ( int nkn, double *qcoeff, int k,
00231 double *Nitab, double *Nijtab, double *Mijtab,
00232 double *Jac,
00233 int *cpind, int *nncpi, point3d *mvcp,
00234 double C,
00235 double *ftab, double *gtab, double *htab );
00236
00237 void g2mbl_SFuncGradRSQd ( int nkn, double *qcoeff, double *Nitab,
00238 int *cpind, int *nncpi, point3d *mvcp, vector3d *mvcpn,
00239 double *ftab, double *gtab );
00240 boolean g2mbl_SFuncGradSSQd ( int nkn, double *qcoeff, int k,
00241 double *Nitab, double *Jac,
00242 int *cpind, int *nncpi, point3d *mvcp, vector3d *mvcpn,
00243 double *ftab, double *gtab );
00244 boolean g2mbl_SFuncGradHessRSQd ( int nkn, double *qcoeff,
00245 double *Nitab, double *Nijtab, double *Mijtab,
00246 int *cpind, int *nncpi, point3d *mvcp, vector3d *mvcpn,
00247 double *ftab, double *gtab, double *htab );
00248 boolean g2mbl_SFuncGradHessSSQd ( int nkn, double *qcoeff, int k,
00249 double *Nitab, double *Nijtab, double *Mijtab,
00250 double *Jac,
00251 int *cpind, int *nncpi, point3d *mvcp, vector3d *mvcpn,
00252 double *ftab, double *gtab, double *htab );
00253
00254
00255 double g2mbl_UFuncd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00256 int nv, point3d *mvcp,
00257 int ndomelems, meshdom_elem *domelem, int *domelcpind,
00258 boolean force, double *ftab );
00259 boolean g2mbl_UFuncGradd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00260 int nv, point3d *mvcp,
00261 int ndomelems, meshdom_elem *domelem,
00262 int *domelcpind, int *nncpi,
00263 boolean force, double *ftab, double *gtab,
00264 double *func, int nvars, double *grad );
00265 boolean g2mbl_UFuncGradHessiand ( int nkn, double *qcoeff,
00266 double **Nitabs, double **Nijtabs, double **Mijtabs,
00267 double **Jac,
00268 int nv, point3d *mvcp,
00269 int ndomelems, meshdom_elem *domelem,
00270 int *domelcpind, int *nncpi,
00271 boolean force,
00272 double *ftab, double *gtab, double *htab,
00273 double *func, int nvars, double *grad,
00274 int hsize, int *hprof, double **hrows );
00275
00276 void _g2mbl_AddCPIncrement ( int nvcp, int *vncpi, point3d *mvcp,
00277 vector3d *incr, point3d *omvcp );
00278 double _g2mbl_AuxNuFuncd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00279 int nv, point3d *mvcp, int nvcp, int *vncpi,
00280 int ndomelems, meshdom_elem *domelem, int *domelcpind,
00281 double *ftab, int nvars, int hsize, int *hprof,
00282 double *Hessian, double *LHessian, double **lhrows,
00283 double *grad, double *dcoeff, point3d *auxmvcp,
00284 double nu );
00285
00286
00287 boolean g2mbl_B3x3FuncGradHessiand ( int nkn, double *qcoeff,
00288 double **Nitabs, double **Nijtabs, double **Mijtabs,
00289 double **Jac,
00290 int nv, point3d *mvcp,
00291 int ndomelems, meshdom_elem *domelem,
00292 int *domelcpind, int *nncpi,
00293 boolean force,
00294 double *ftab, double *gtab, double *htab,
00295 double *func, int nvars, double *grad,
00296 int Hblsize, nzHbl_rowdesc *iHbl, int *cHbl, double *Hbl );
00297 double g2mbl_AFuncd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00298 int nv, point3d *mvcp, int bdomelems, int *domelind,
00299 meshdom_elem *domelem, int *domelcpind,
00300 boolean force, double *ftab );
00301 boolean g2mbl_AFuncGradd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00302 int nv, point3d *mvcp, int bdomelems, int *domelind,
00303 meshdom_elem *domelem, int *domelcpind, int *bncpi,
00304 boolean force, double *ftab, double *gtab,
00305 double *func, int nvars, double *grad );
00306 boolean g2mbl_AFuncGradHessiand ( int nkn, double *qcoeff,
00307 double **Nitabs, double **Nijtabs, double **Mijtabs,
00308 double **Jac, int nv, point3d *mvcp,
00309 int bdomelems, int *domelind, meshdom_elem *domelem,
00310 int *domelcpind, int *nncpi, int *bncpi,
00311 boolean force,
00312 double *ftab, double *gtab, double *htab,
00313 double *func, int nvars, double *grad,
00314 int hsize, int *hprof, double **hrows );
00315
00316 double _g2mbl_AuxAltBNuFuncd ( int nkn, double *qcoeff, double **Nitabs, double **Jac,
00317 int nv, point3d *mvcp, int nvcp, int *vncpi,
00318 int ndomelems, int *domelind, meshdom_elem *domelem,
00319 int *domelcpind, double *ftab,
00320 int nvars, int hsize, int *hprof,
00321 double *Hessian, double *LHessian, double **lhrows,
00322 double *grad, double *dcoeff, point3d *auxmvcp,
00323 double nu );
00324
00325 boolean _g2mbl_SetupAltBlocks ( int nv, BSMvertex *mv, int *mvhei,
00326 int nhe, BSMhalfedge *mhe,
00327 int nfac, BSMfacet *mfac, int *mfhei,
00328 int *nncpi, char nbl, int *bltag, int *blseed );
00329 boolean _g2mbl_SetupAltBlockHessianProfiled ( mesh_lmt_optdata *d, int bnum );
00330 boolean _g2mbl_SetupAltBlockDescription ( mesh_lmt_optdata *d, int nbl );
00331
00332 boolean _g2mbl_MultAxd ( int n, void *usrdata, const double *x, double *Ax );
00333 boolean _g2mbl_MultQixAltd ( int n, void *usrdata, const double *x, double *Qix );
00334
00335 boolean _g2mbl_CMPSetupCGPrecondd ( mesh_lmt_optdata *d );
00336
00337
00338 void _g2mbl_OutputNZDistr ( mesh_lmt_optdata *d );
00339