1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 /*! \file
4  * \ingroup ug
5  */
6 
7 /** \addtogroup ug
8  *
9  * @{
10  */
11 
12 
13 /****************************************************************************/
14 /*                                                                          */
15 /* File:      initug.c                                                      */
16 /*                                                                          */
17 /* Purpose:   call the init routines of the ug modules                      */
18 /*                                                                          */
19 /* Author:    Henrik Rentz-Reichert                                         */
20 /*            Institut fuer Computeranwendungen III                         */
21 /*            Universitaet Stuttgart                                        */
22 /*            Pfaffenwaldring 27                                            */
23 /*            70569 Stuttgart                                               */
24 /*            email: ug@ica3.uni-stuttgart.de                               */
25 /*                                                                          */
26 /* History:   27.02.95 begin, ug version 3.0                                */
27 /*                                                                          */
28 /* Remarks:                                                                 */
29 /*                                                                          */
30 /****************************************************************************/
31 
32 
33 /****************************************************************************/
34 /*                                                                          */
35 /* include files                                                            */
36 /*    system include files                                                  */
37 /*    application include files                                             */
38 /*                                                                          */
39 /****************************************************************************/
40 
41 /* ANSI-C includes */
42 #include <config.h>
43 #include <cstdio>
44 #include <cstring>
45 
46 /* low module */
47 #include <dune/uggrid/low/initlow.h>
48 #include <dune/uggrid/low/misc.h>
49 #include <dune/uggrid/low/ugstruct.h>
50 
51 /* parallelization module */
52 #ifdef ModelP
53 #include <dune/uggrid/parallel/dddif/parallel.h>
54 #include <dune/uggrid/parallel/ppif/ppif.h>
55 using namespace PPIF;
56 #endif
57 
58 /* devices module */
59 #include <dune/uggrid/ugdevices.h>
60 
61 /* domain module */
62 #include <dune/uggrid/domain/domain.h>
63 
64 /* grid manager module */
65 #include <dune/uggrid/gm/initgm.h>
66 
67 /* own header */
68 #include "initug.h"
69 
70 /** \todo delete this */
71 #include <dune/uggrid/low/debug.h>
72 
73 
74 USING_UG_NAMESPACES
75 
76 /****************************************************************************/
77 /*                                                                          */
78 /* defines in the following order                                           */
79 /*                                                                          */
80 /*        compile time constants defining static data size (i.e. arrays)    */
81 /*        other constants                                                   */
82 /*        macros                                                            */
83 /*                                                                          */
84 /****************************************************************************/
85 
86 #define UGDEBUGRFILE            "debugfile"
87 
88 /****************************************************************************/
89 /*                                                                          */
90 /* definition of variables global to this source file only (static!)        */
91 /*                                                                          */
92 /****************************************************************************/
93 
94 
95 /****************************************************************************/
96 /** \brief Call the init functions for all the ug modules
97  *
98  * @param argcp - pointer to argument counter
99  * @param argvp - pointer to argument vector
100  *
101  *   This function initializes.
102  *
103  * @return <ul>
104  *   <li> 0 if ok </li>
105  *   <li> 1 if error occured. </li>
106  * </ul>
107  */
108 /****************************************************************************/
109 
InitUg(int * argcp,char *** argvp)110 INT NS_DIM_PREFIX InitUg (int *argcp, char ***argvp)
111 {
112   INT err;
113 
114 #ifdef ModelP
115   /* init ppif module */
116   if ((err = InitPPIF (argcp, argvp)) != PPIF_SUCCESS)
117   {
118     printf ("ERROR in InitParallel while InitPPIF.\n");
119     printf ("aborting ug\n");
120 
121     return (1);
122   }
123 #endif
124 
125   /* init the low module */
126   if ((err = InitLow ()) != 0)
127   {
128     printf
129       ("ERROR in InitUg while InitLow (line %d): called routine line %d\n",
130       (int) HiWrd (err), (int) LoWrd (err));
131     printf ("aborting ug\n");
132 
133     return (1);
134   }
135 
136   /* create struct for configuration parameters */
137   if (MakeStruct (":conf"))
138     return (__LINE__);
139 
140   /* init the devices module */
141   if ((err = InitDevices()) != 0)
142   {
143     printf
144       ("ERROR in InitUg while InitDevices (line %d): called routine line %d\n",
145       (int) HiWrd (err), (int) LoWrd (err));
146     printf ("aborting ug\n");
147 
148     return (1);
149   }
150 
151 #ifdef Debug
152   {
153     int i;
154     for (i = 1; i < *argcp; i++)
155       if (strncmp ((*argvp)[i], "-dbgfile", 8) == 0)
156         break;
157     if (i < *argcp)
158     {
159       const char* debugfilename = "dune-uggrid.dbg";
160       if (SetPrintDebugToFile (debugfilename) != 0)
161       {
162         printf ("ERROR while opening debug file '%s'\n", debugfilename);
163         printf ("aborting ug\n");
164         return (1);
165       }
166       UserWriteF ("debug info is captured to file '%s'\n", debugfilename);
167     }
168     else
169     {
170       SetPrintDebugProc (printf);
171       UserWriteF ("debug info is printed to stdout\n");
172     }
173   }
174 #endif
175 
176   /* init the domain module */
177   if ((err = InitDom ()) != 0)
178   {
179     printf
180       ("ERROR in InitDom while InitDom (line %d): called routine line %d\n",
181       (int) HiWrd (err), (int) LoWrd (err));
182     printf ("aborting ug\n");
183 
184     return (1);
185   }
186 
187   /* init the gm module */
188   if ((err = InitGm ()) != 0)
189   {
190     printf
191       ("ERROR in InitUg while InitGm (line %d): called routine line %d\n",
192       (int) HiWrd (err), (int) LoWrd (err));
193     printf ("aborting ug\n");
194 
195     return (1);
196   }
197 
198   return (0);
199 }
200 
201 
202 /****************************************************************************/
203 /** \brief Call of the exitfunctions for all the ug modules
204  *
205  * This function exits ug. It is called at the end of the CommandLoop.
206  * It calls all available exit functions in reverse order of the corresponding
207  * calls in InitUg().
208  *
209  * @return <ul>
210  *   <li> 0 if ok </li>
211  *   <li> 1 if error occured. </li>
212  * </ul>
213  */
214 /****************************************************************************/
215 
216 INT NS_DIM_PREFIX
ExitUg(void)217 ExitUg (void)
218 {
219   INT err;
220 
221   /* exit gm module */
222   PRINTDEBUG (init, 1, ("     ExitGm()...\n"))
223   if ((err = ExitGm ()) != 0)
224   {
225     printf
226       ("ERROR in ExitUg while ExitGm (line %d): called routine line %d\n",
227       (int) HiWrd (err), (int) LoWrd (err));
228     printf ("aborting ug\n");
229 
230     return (1);
231   }
232 
233   /* exit devices module */
234   PRINTDEBUG (init, 1, ("     ExitDevices()...\n"))
235   if ((err = ExitDevices ()) != 0)
236   {
237     printf
238       ("ERROR in ExitUg while ExitDevices (line %d): called routine line %d\n",
239       (int) HiWrd (err), (int) LoWrd (err));
240     printf ("aborting ug\n");
241 
242     return (1);
243   }
244 
245   /* exit low module */
246   PRINTDEBUG (init, 1, ("     ExitLow()...\n"))
247   if ((err = ExitLow ()) != 0)
248   {
249     printf
250       ("ERROR in ExitUg while ExitLow (line %d): called routine line %d\n",
251       (int) HiWrd (err), (int) LoWrd (err));
252     printf ("aborting ug\n");
253 
254     return (1);
255   }
256 
257   return (0);
258 }
259 
260 /** @} */
261