g2mblprivated.h

Go to the documentation of this file.
00001 
00002 /* ///////////////////////////////////////////////////////////////////////// */  
00003 /* This file is a part of the BSTools package                                */
00004 /* written by Przemyslaw Kiciak                                              */   
00005 /* ///////////////////////////////////////////////////////////////////////// */
00006 /* (C) Copyright by Przemyslaw Kiciak, 2010, 2012                            */
00007 /* this package is distributed under the terms of the                        */
00008 /* Lesser GNU Public License, see the file COPYING.LIB                       */
00009 /* ///////////////////////////////////////////////////////////////////////// */
00010 
00011 #define COUNT
00012 #define _DEBUG
00013 
00014 #define MYINFINITY    1.0e+308
00015 
00016 /*#define GRDIV(a,b) ((1.0-TAU)*(a)+TAU*(b)) */
00017 #define GRDIV(a,b) (exp((1.0-TAU)*log(a)+TAU*log(b)))
00018 
00019 #define CG_THRESHOLD  10000
00020 /*#define CG_THRESHOLD  1000*/
00021 
00022 
00023 typedef struct {
00024     char   type;
00025     short  ncp;       /* number of control points relevant for this element */
00026     int    firstcpi;  /* index of the first relevant control point number */
00027                       /* and (x3) to the gradient integrals table */
00028     int    hti;       /* index to the Hessian integrals table */
00029     double C;         /* regularization constant */
00030     int    cfn;       /* central facet number */
00031     int    blmask;    /* bit mask for blocks, unused by nonblock procedures */
00032   } meshdom_elem;
00033 
00034 typedef struct {
00035     int   vnum;      /* number of the mesh vertex */
00036     int   firstsel;  /* number of the first selected neighbour */
00037     short nneigh;    /* number of nonzero elements in its Hessian row (neighbours) */
00038     short nncn;      /* number of neighbours not chosen yet */
00039     int   fneigh;    /* index of the first neighbour element */
00040   } vertex_desc;
00041 
00042 typedef struct {
00043     int     n0, n1, m0, m1;     /* block limits and influence interval */
00044     int     ncp, nvars;
00045     int     ndomelems, *domelind;
00046     int     *nncpi;
00047     int     *vpermut, *vncpi;   /* variable permutation and indices */
00048     int     hsize;              /* band coefficient array size */
00049     int     *hprof;             /* Hessian block profile */
00050     double  **hrows, **lhrows;  /* block rows */
00051     double  func, gn0, nu;
00052     boolean accurate;
00053     char    hblstat;            /* 0 - undefined, */
00054                                 /* 1 - computed,  */
00055                                 /* 2 - decomposed (positive), */
00056                                 /* 3 - to be reused */
00057   } block_desc;
00058 
00059 typedef struct {
00060     int firsthbl, nhbl;
00061   } nzHbl_rowdesc;
00062 
00063 typedef struct {
00064         /* mesh data */
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         /* coarse mesh - total number of vertices */
00074     int           cnv;
00075         /* the refinement matrix */
00076     int           rmnnz;
00077     index2        *rmnzi;
00078     double        *rmnzc;
00079         /* relevant vertices of the coarse mesh */
00080     int           nwcp, *wncpi;
00081         /* the submatrix used by the preconditioner */
00082     int           pmnnz;
00083     index3        *pmnzi;
00084         /* domain element description */
00085     int           ndomelems, ndomelcpind;
00086     meshdom_elem  *domelem;
00087     int           *domelcpind;
00088     boolean       eltypes[GH_MAX_K-2];  /* which special elements are present? */
00089 
00090     int           hti;
00091     double        *ftab, *gtab, *htab;
00092         /* number of control points to be optimized, their indices */
00093     int           nvcp, nvars;
00094     int           *nncpi, *vncpi;
00095         /* Hessian */
00096     int           hsize, *hprof;
00097     double        *Hessian, **hrows, *LHessian, **lhrows;
00098         /* Hessian coarse mesh preconditioner term */
00099     int           phsize, *phprof;
00100     double        **phrows;
00101     int           nnz1, nnz2;
00102         /* iterations data */
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         /* the data below are used only by the block algorithm */
00112     boolean       use_cg, last_ntn;
00113           /* 3x3 nonzero block Hessian representation */
00114     int           Hblsize;  /* number of nonzero Hessian blocks */
00115     nzHbl_rowdesc *iHbl;    /* indices for subsequent rows */
00116     int           *cHbl;    /* indices of columns with nonzero blocks in a row */
00117     double        *Hbl;     /* actual blocks */
00118           /* block description */
00119     int           nbl;                       /* number of blocks */
00120     block_desc    block[G2MBL_MAX_BLOCKS];   /* block description */
00121     int           *belind;                   /* indices of domain elements */
00122                                              /* for each block */
00123     int           ibl;                       /* number of blocks, which did not */
00124                                              /* satisfy the criterion for */
00125                                              /* quadrature switching */
00126     int           nextblock;
00127     double        *BHessian;
00128 
00129     int           *bltag;              /* for alternative block setup */
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 /* nonblock algorithm functions */
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 /* block algorithm functions */
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 /* auxiliary procedures */
00338 void _g2mbl_OutputNZDistr ( mesh_lmt_optdata *d );
00339