mFES - molecular Finite Element Solver  0.4
nginterface.h
Go to the documentation of this file.
00001 #ifndef NGINTERFACE
00002 #define NGINTERFACE
00003 
00004 
00005 
00006 
00007 
00008 /**************************************************************************/
00009 /* File:   nginterface.h                                                  */
00010 /* Author: Joachim Schoeberl                                              */
00011 /* Date:   20. Nov. 99                                                    */
00012 /**************************************************************************/
00013 
00014 /*
00015   Application program interface to Netgen
00016 
00017 */
00018 
00019 #ifdef WIN32
00020    #if NGINTERFACE_EXPORTS || NGLIB_EXPORTS || nglib_EXPORTS
00021       #define DLL_HEADER   __declspec(dllexport)
00022    #else
00023       #define DLL_HEADER   __declspec(dllimport)
00024    #endif
00025 #else
00026    #define DLL_HEADER 
00027 #endif
00028 
00029 
00030 // max number of nodes per element
00031 #define NG_ELEMENT_MAXPOINTS 12
00032 
00033 // max number of nodes per surface element
00034 #define NG_SURFACE_ELEMENT_MAXPOINTS 8
00035 
00036 
00037 
00038 // implemented element types:
00039 enum NG_ELEMENT_TYPE { 
00040   NG_PNT = 0,
00041   NG_SEGM = 1, NG_SEGM3 = 2,
00042   NG_TRIG = 10, NG_QUAD=11, NG_TRIG6 = 12, NG_QUAD6 = 13,
00043   NG_TET = 20, NG_TET10 = 21, 
00044   NG_PYRAMID = 22, NG_PRISM = 23, NG_PRISM12 = 24,
00045   NG_HEX = 25
00046 };
00047 
00048 typedef double NG_POINT[3];  // coordinates
00049 typedef int NG_EDGE[2];      // initial point, end point
00050 typedef int NG_FACE[4];      // points, last one is 0 for trig
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055   
00056   // load geomtry from file 
00057   DLL_HEADER void Ng_LoadGeometry (const char * filename);
00058   
00059   // load netgen mesh
00060   DLL_HEADER void Ng_LoadMesh (const char * filename);
00061 
00062   // load netgen mesh
00063   DLL_HEADER void Ng_LoadMeshFromString (const char * mesh_as_string);
00064 
00065   // space dimension (2 or 3)
00066   DLL_HEADER int Ng_GetDimension ();
00067 
00068   // number of mesh points
00069   DLL_HEADER int Ng_GetNP ();
00070   
00071   // number of mesh vertices (differs from GetNP for 2nd order elements)
00072   DLL_HEADER int Ng_GetNV ();
00073   
00074   // number of mesh elements
00075   DLL_HEADER int Ng_GetNE ();
00076   
00077   // number of surface triangles
00078   DLL_HEADER int Ng_GetNSE ();
00079   
00080   // Get Point coordintes, index from 1 .. np
00081   DLL_HEADER void Ng_GetPoint (int pi, double * p);
00082   
00083   // Get Element Points
00084   DLL_HEADER NG_ELEMENT_TYPE Ng_GetElement (int ei, int * epi, int * np = 0);
00085 
00086   // Get Element Type
00087   DLL_HEADER NG_ELEMENT_TYPE Ng_GetElementType (int ei);
00088 
00089   // Get sub-domain of element ei
00090   DLL_HEADER int Ng_GetElementIndex (int ei);
00091 
00092   DLL_HEADER void Ng_SetElementIndex(const int ei, const int index);
00093 
00095   // Add element nr to element list
00096   DLL_HEADER void Ng_addElIndex(const int el);
00097   // Get size of element list
00098   DLL_HEADER int Ng_elIndexSize();
00099   // Get element nr by index
00100   DLL_HEADER int Ng_getElIndex(const int idx);
00101   // Add integration point for element nr at index
00102   DLL_HEADER void Ng_addIpPoint(NG_POINT p);
00103   // Get size of integration pointn list
00104   DLL_HEADER int Ng_ipPointSize();
00105   // Set p to coordinates of integration point at index idx
00106   DLL_HEADER void Ng_setIpPoint(const int idx, double* p);
00107 
00108 
00109   // Get Material of element ei
00110   DLL_HEADER char * Ng_GetElementMaterial (int ei);
00111 
00112   // Get Material of domain dom
00113   DLL_HEADER char * Ng_GetDomainMaterial (int dom);
00114   
00115   // Get User Data
00116   DLL_HEADER int Ng_GetUserDataSize (char * id);
00117   DLL_HEADER void Ng_GetUserData (char * id, double * data);
00118 
00119   // Get Surface Element Points
00120   DLL_HEADER NG_ELEMENT_TYPE Ng_GetSurfaceElement (int ei, int * epi, int * np = 0);
00121 
00122   // Get Surface Element Type
00123   DLL_HEADER NG_ELEMENT_TYPE Ng_GetSurfaceElementType (int ei);
00124 
00125   // Get Surface Element Index
00126   DLL_HEADER int Ng_GetSurfaceElementIndex (int ei);
00127 
00128   // Get Surface Element Surface Number
00129   DLL_HEADER int Ng_GetSurfaceElementSurfaceNumber (int ei);
00130   
00131   // Get Surface Element Number
00132   DLL_HEADER int Ng_GetSurfaceElementFDNumber (int ei);
00133 
00134   // Get BCName for Surface Element  
00135   DLL_HEADER char * Ng_GetSurfaceElementBCName (int ei);
00136   //void Ng_GetSurfaceElementBCName (int ei, char * name);
00137 
00138   // Get BCName for bc-number
00139   DLL_HEADER char * Ng_GetBCNumBCName (int bcnr);
00140   //void Ng_GetBCNumBCName (int bcnr, char * name);
00141 
00142   // Get normal vector of surface element node
00143   DLL_HEADER void Ng_GetNormalVector (int sei, int locpi, double * nv);     
00144   
00145 
00146   DLL_HEADER void Ng_SetPointSearchStartElement(int el);
00147   
00148   // Find element of point, returns local coordinates
00149   DLL_HEADER int Ng_FindElementOfPoint (double * p, double * lami,
00150                                         int build_searchtrees = 0, 
00151                                         const int * const indices = NULL, const int numind = 0);
00152   
00153   // Find surface element of point, returns local coordinates
00154   DLL_HEADER int Ng_FindSurfaceElementOfPoint (double * p, double * lami,
00155                                                int build_searchtrees = 0, 
00156                                                const int * const indices = NULL, const int numind = 0);
00157   
00158 
00159   // is elment ei curved ?
00160   DLL_HEADER int Ng_IsElementCurved (int ei);
00161   // is elment sei curved ?
00162   DLL_HEADER int Ng_IsSurfaceElementCurved (int sei);
00163 
00168   DLL_HEADER void Ng_GetElementTransformation (int ei, const double * xi, 
00169                                                double * x, double * dxdxi);
00170 
00171   
00173   DLL_HEADER void Ng_GetBufferedElementTransformation (int ei, const double * xi, 
00174                                                        double * x, double * dxdxi,
00175                                                        void * buffer, int buffervalid);
00176   
00177 
00178 
00184   DLL_HEADER void Ng_GetSurfaceElementTransformation (int sei, const double * xi, 
00185                                                       double * x, double * dxdxi);
00186   
00192   DLL_HEADER void Ng_GetMultiElementTransformation (int ei, int n,
00193                                                     const double * xi, size_t sxi,
00194                                                     double * x, size_t sx,
00195                                                     double * dxdxi, size_t sdxdxi);
00196 
00197   
00198   
00199   DLL_HEADER int Ng_GetSegmentIndex (int elnr);
00200   DLL_HEADER NG_ELEMENT_TYPE Ng_GetSegment (int elnr, int * epi, int * np = 0);
00201 
00202 
00203 
00204 
00205   // Mark element for refinement
00206   DLL_HEADER void Ng_SetRefinementFlag (int ei, int flag);
00207   DLL_HEADER void Ng_SetSurfaceRefinementFlag (int sei, int flag);
00208 
00209   // Do local refinement
00210   enum NG_REFINEMENT_TYPE { NG_REFINE_H = 0, NG_REFINE_P = 1, NG_REFINE_HP = 2 };
00211   DLL_HEADER void Ng_Refine (NG_REFINEMENT_TYPE reftype);
00212 
00213   // Use second order elements
00214   DLL_HEADER void Ng_SecondOrder ();
00215   DLL_HEADER void Ng_HighOrder (int order, bool rational = false);
00216   //void Ng_HPRefinement (int levels, double parameter = 0.125);
00217   DLL_HEADER void Ng_HPRefinement (int levels, double parameter = 0.125,
00218                                    bool setorders = true,bool ref_level = false);
00219   // void Ng_HPRefinement (int levels);
00220   // void Ng_HPRefinement (int levels, double parameter);
00221 
00222 
00223   // Topology and coordinate information of master element:
00224 
00225   DLL_HEADER int Ng_ME_GetNVertices (NG_ELEMENT_TYPE et);
00226   DLL_HEADER int Ng_ME_GetNEdges (NG_ELEMENT_TYPE et);
00227   DLL_HEADER int Ng_ME_GetNFaces (NG_ELEMENT_TYPE et);
00228 
00229   DLL_HEADER const NG_POINT * Ng_ME_GetVertices (NG_ELEMENT_TYPE et);
00230   DLL_HEADER const NG_EDGE * Ng_ME_GetEdges (NG_ELEMENT_TYPE et);
00231   DLL_HEADER const NG_FACE * Ng_ME_GetFaces (NG_ELEMENT_TYPE et);
00232 
00233   DLL_HEADER void Ng_UpdateTopology();
00234 
00235   DLL_HEADER int Ng_GetNEdges();
00236   DLL_HEADER int Ng_GetNFaces();
00237 
00238   
00239   DLL_HEADER int Ng_GetElement_Edges (int elnr, int * edges, int * orient = 0);
00240   DLL_HEADER int Ng_GetElement_Faces (int elnr, int * faces, int * orient = 0);
00241 
00242   DLL_HEADER int Ng_GetSurfaceElement_Edges (int selnr, int * edges, int * orient = 0);
00243   DLL_HEADER int Ng_GetSurfaceElement_Face (int selnr, int * orient = 0);
00244 
00245   DLL_HEADER void Ng_GetSurfaceElementNeighbouringDomains(const int selnr, int & in, int & out);
00246        
00247   DLL_HEADER int Ng_GetFace_Vertices (int fnr, int * vert);
00248   DLL_HEADER void Ng_GetEdge_Vertices (int ednr, int * vert);
00249   DLL_HEADER int Ng_GetFace_Edges (int fnr, int * edge);
00250 
00251   DLL_HEADER int Ng_GetNVertexElements (int vnr);
00252   DLL_HEADER void Ng_GetVertexElements (int vnr, int * els);
00253 
00254   DLL_HEADER int Ng_GetElementOrder (int enr);
00255   DLL_HEADER void Ng_GetElementOrders (int enr, int * ox, int * oy, int * oz);
00256 
00257   DLL_HEADER void Ng_SetElementOrder (int enr, int order);
00258   DLL_HEADER void Ng_SetElementOrders (int enr, int ox, int oy, int oz);
00259 
00260   DLL_HEADER int Ng_GetSurfaceElementOrder (int enr);
00261   DLL_HEADER void Ng_GetSurfaceElementOrders (int enr, int * ox, int * oy);
00262 
00263   DLL_HEADER void Ng_SetSurfaceElementOrder (int enr, int order);
00264   DLL_HEADER void Ng_SetSurfaceElementOrders (int enr, int ox, int oy);
00265 
00266   // Multilevel functions:
00267 
00268   // number of levels:
00269   DLL_HEADER int Ng_GetNLevels ();
00270   // get two parent nodes (indeed vertices !) of node ni
00271   DLL_HEADER void Ng_GetParentNodes (int ni, int * parents);
00272 
00273   // get parent element (first child has always same number)
00274   DLL_HEADER int Ng_GetParentElement (int ei);
00275 
00276   // get parent surface element (first child has always same number)
00277   DLL_HEADER int Ng_GetParentSElement (int ei);
00278 
00279   // representant of anisotropic cluster
00280   DLL_HEADER int Ng_GetClusterRepVertex (int vi);
00281   DLL_HEADER int Ng_GetClusterRepEdge (int edi);
00282   DLL_HEADER int Ng_GetClusterRepFace (int fai);
00283   DLL_HEADER int Ng_GetClusterRepElement (int eli);
00284 
00285 
00286   void Ng_SurfaceElementTransformation (int eli, double x, double y, 
00287                                         double * p3d, double * jacobian);
00288 
00289 #ifdef PARALLEL
00290 
00291   // the folling functions are 0-base  !!
00292 
00293   // number on distant processor 
00294   // returns pairs  (dist_proc, num_on_dist_proc)
00295   int NgPar_GetDistantNodeNums ( int nodetype, int locnum, int * pnums );
00296   int NgPar_GetNDistantNodeNums ( int nodetype, int locnum );
00297   
00298   int NgPar_GetGlobalNodeNum (int nodetype, int locnum);
00299 
00300 #endif
00301   
00302   namespace netgen {
00303   // #include "../visualization/soldata.hpp"
00304     class SolutionData;
00305     class MouseEventHandler;
00306   }
00307 
00308   enum Ng_SolutionType
00309   { NG_SOLUTION_NODAL = 1, 
00310     NG_SOLUTION_ELEMENT = 2, 
00311     NG_SOLUTION_SURFACE_ELEMENT = 3, 
00312     NG_SOLUTION_NONCONTINUOUS = 4,
00313     NG_SOLUTION_SURFACE_NONCONTINUOUS = 5,
00314     NG_SOLUTION_VIRTUAL_FUNCTION = 6,
00315     NG_SOLUTION_MARKED_ELEMENTS = 10,
00316     NG_SOLUTION_ELEMENT_ORDER = 11
00317   };
00318   
00319   struct Ng_SolutionData
00320   {
00321     const char * name; // name of gridfunction
00322     double * data;    // solution values
00323     int components;   // relevant (double) components in solution vector
00324     int dist;         // # doubles per entry alignment! 
00325     int iscomplex;    // complex vector ? 
00326     bool draw_surface;
00327     bool draw_volume;
00328     int order;        // order of elements, only partially supported 
00329     Ng_SolutionType soltype;  // type of solution function
00330     netgen::SolutionData * solclass;
00331   };
00332   
00333   // initialize solution data with default arguments
00334   DLL_HEADER void Ng_InitSolutionData (Ng_SolutionData * soldata);
00335   // set solution data
00336   DLL_HEADER void Ng_SetSolutionData (Ng_SolutionData * soldata);
00338   DLL_HEADER void Ng_ClearSolutionData();
00339   // redraw 
00340   DLL_HEADER void Ng_Redraw();
00342   DLL_HEADER void Ng_SetMouseEventHandler (netgen::MouseEventHandler * handler);
00343   //
00344   DLL_HEADER void Ng_SetVisualizationParameter (const char * name, 
00345                                                 const char * value);
00346   
00347 
00348   // number of periodic vertices  
00349   DLL_HEADER int Ng_GetNPeriodicVertices (int idnr);
00350   // pairs should be an integer array of 2*npairs
00351   DLL_HEADER void Ng_GetPeriodicVertices (int idnr, int * pairs); 
00352 
00353   // number of periodic edges  
00354   DLL_HEADER int Ng_GetNPeriodicEdges (int idnr);
00355   // pairs should be an integer array of 2*npairs
00356   DLL_HEADER void Ng_GetPeriodicEdges (int idnr, int * pairs); 
00357 
00358   DLL_HEADER void RunParallel ( void * (*fun)(void *), void * in);
00359 
00360   DLL_HEADER void Ng_PushStatus (const char * str);
00361   DLL_HEADER void Ng_PopStatus ();
00362   DLL_HEADER void Ng_SetThreadPercentage (double percent);
00363   DLL_HEADER void Ng_GetStatus (char ** str, double & percent);
00364 
00365   DLL_HEADER void Ng_SetTerminate(void);
00366   DLL_HEADER void Ng_UnSetTerminate(void);
00367   DLL_HEADER int Ng_ShouldTerminate(void);
00368   DLL_HEADER void Ng_SetRunning(int flag);
00369   DLL_HEADER int Ng_IsRunning();
00370   
00372   DLL_HEADER int Ng_GetVertex_Elements( int vnr, int* elems);
00373   DLL_HEADER int Ng_GetVertex_SurfaceElements( int vnr, int* elems );
00374   DLL_HEADER int Ng_GetVertex_NElements( int vnr );
00375   DLL_HEADER int Ng_GetVertex_NSurfaceElements( int vnr );
00376 
00377 
00378 #ifdef SOCKETS
00379   int Ng_SocketClientOpen( const int port, const char * host );
00380   void Ng_SocketClientWrite( const char * write, char ** reply);
00381   void Ng_SocketClientClose ( void );
00382   void Ng_SocketClientGetServerHost ( const int number, char ** host );
00383   void Ng_SocketClientGetServerPort ( const int number, int * port );
00384   void Ng_SocketClientGetServerClientID ( const int number, int * id );
00385 #endif
00386 
00387   DLL_HEADER void Ng_InitPointCurve(double red, double green, double blue);
00388   DLL_HEADER void Ng_AddPointCurvePoint(const double * point);
00389 
00390 
00391 #ifdef PARALLEL
00392   void Ng_SetElementPartition ( int elnr, int part );
00393   int  Ng_GetElementPartition ( int elnr );
00394 #endif
00395 
00396   DLL_HEADER void Ng_SaveMesh ( const char * meshfile );
00397   DLL_HEADER void Ng_Bisect ( const char * refinementfile );
00398 
00399   // if qualityloss is not equal to NULL at input, a (1-based) list of qualitylosses (due to projection)
00400   // is saved in *qualityloss, its size is the return value
00401   DLL_HEADER int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss);
00402 
00403   typedef void * Ng_Mesh;
00404   DLL_HEADER Ng_Mesh Ng_SelectMesh (Ng_Mesh mesh);
00405 
00406   DLL_HEADER void Ng_GetArgs (int & argc, char ** &argv);
00407 
00408 
00409 #ifdef __cplusplus
00410 }
00411 #endif
00412 
00413 #endif
00414 
00415 
00416 
00417 
00418 
00419 
00420 /*
00421   The new node interface ...
00422   it is 0-based !
00423  */
00424 
00425 extern "C" {
00426   
00427   /*
00428     number of nodes of type nt
00429     nt = 0 is Vertex
00430     nt = 1 is Edge
00431     nt = 2 is Face
00432     nt = 3 is Cell
00433    */
00434   DLL_HEADER int Ng_GetNNodes (int nt);
00435 
00436   /*
00437     closure nodes of node (nt, nodenr):
00438     nodeset is bit-coded, bit 0 includes Vertices, bit 1 edges, etc
00439     E.g., nodeset = 6 includes edge and face nodes
00440     nodes consists of pairs of integers (nodetype, nodenr) 
00441     return value is number of nodes
00442    */
00443   DLL_HEADER int Ng_GetClosureNodes (int nt, int nodenr, int nodeset, int * nodes);
00444 
00445   
00446   /*
00447     number of dim-dimensional elements 
00448     dim = 3 ... volume elements
00449     dim = 2 ... surface elements
00450     dim = 1 ... segments
00451     dim = 0 ... not available
00452   */
00453   DLL_HEADER int Ng_GetNElements (int dim);
00454 
00455   /*
00456     closure nodes of dim-dimensional element elmentnr:
00457     nodeset is bit-coded, bit 0 includes Vertices, bit 1 edges, etc
00458     E.g., nodeset = 6 includes edge and face nodes
00459     nodes consists of pairs of integers (nodetype, nodenr) 
00460     return value is number of nodes
00461    */
00462   DLL_HEADER int Ng_GetElementClosureNodes (int dim, int elementnr, int nodeset, int * nodes);
00463 
00464 
00465   struct Ng_Tcl_Interp;
00466   typedef int (Ng_Tcl_CmdProc) (Ng_Tcl_Interp *interp, int argc, const char *argv[]);
00467 
00468   DLL_HEADER void Ng_Tcl_CreateCommand (Ng_Tcl_Interp * interp, 
00469                                         const char * cmdName, Ng_Tcl_CmdProc * proc);
00470 
00471   void Ng_Tcl_SetResult (Ng_Tcl_Interp * interp, const char * result);
00472 }
00473 
00474 
00475 
00476 
00477 
00478 #ifdef __cplusplus
00479 #include <iostream>
00480 namespace netgen 
00481 {
00482   DLL_HEADER extern std::ostream * testout;
00483   DLL_HEADER extern int printmessage_importance;
00484 }
00485 
00486 #endif
00487