/[escript]/trunk/esysUtils/src/maths.h
ViewVC logotype

Annotation of /trunk/esysUtils/src/maths.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1407 - (hide annotations)
Mon Feb 4 06:45:48 2008 UTC (11 years, 8 months ago) by gross
Original Path: trunk/paso/src/Common.h
File MIME type: text/plain
File size: 5155 byte(s)
new upwinding algorithm (still fails)
1 ksteube 1312
2 jgs 150 /* $Id$ */
3    
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15 dhawcroft 631
16 jgs 150 #ifndef INC_PASO_COMMON
17     #define INC_PASO_COMMON
18    
19     /**************************************************************/
20    
21     /* Finley finite element solver: common include file */
22    
23     /**************************************************************/
24    
25     /* Copyrights by ACcESS Australia, 2003 */
26     /* Version: $Id$ */
27    
28     /**************************************************************/
29    
30     /* some system values */
31 woo409 779 #if ( defined __INTEL_COMPILER )
32 woo409 757 #include <mathimf.h>
33     #else
34     #include <math.h>
35     #endif
36 jgs 150
37     #include <float.h>
38     #include <stdio.h>
39     #include <limits.h>
40     #include <stdlib.h>
41     #include <string.h>
42    
43     #define LenString_MAX FILENAME_MAX*2
44     #define LenErrorMsg_MAX LenString_MAX
45    
46     /* on some arcitectures it could be a good idea to use long rather than int */
47     /* this has not really been tested */
48    
49     typedef int dim_t;
50     typedef int index_t;
51     typedef int bool_t;
52     typedef int type_t;
53     typedef int err_t;
54    
55     #define INDEX_T_MAX INT_MAX
56     #define EPSILON DBL_EPSILON
57 gross 1370 #define LARGE_POSITIVE_FLOAT DBL_MAX
58 jgs 150
59     /**************************************************************/
60    
61     /* some useful functions: */
62    
63     #define FALSE 0
64     #define TRUE 1
65     #define UNKNOWN -1
66     #define DBLE(_x_) (double)(_x_)
67     #define INDEX1(_X1_) (_X1_)
68     #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
69     #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
70     #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
71     #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
72     #define INDEX6(_X1_,_X2_,_X3_,_X4_,_X5_,_X6_,_N1_,_N2_,_N3_,_N4_,_N5_) ((_X1_)+(_N1_)*INDEX5(_X2_,_X3_,_X4_,_X5_,_X6_,_N2_,_N3_,_N4_,_N5_))
73    
74     #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
75 ksteube 1312 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
76 jgs 150 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
77 ksteube 1312 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
78 jgs 150 #define ABS(_arg_) MAX((_arg_),-(_arg_))
79 gross 1361 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
80 jgs 150 /**************************************************************/
81    
82     /* memory allocation: */
83    
84 ksteube 1312 /*
85     This is useful for seeing what memory is being allocated if you get an "Out of memory" error
86     #define TMPMEMALLOC(_LENGTH_,_TYPE_) (printf("TMPMEMALLOC at %s %d #bytes=%d*%d=%d\n", __FILE__, __LINE__, _LENGTH_, sizeof(_TYPE_), ((size_t)(_LENGTH_) * sizeof(_TYPE_))) , (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)))
87    
88     This is useful for seeing where memory is being freed if you get an "glibc detected...free" error
89     #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { printf("TMPMEMFREE AAA %s %d\n", __FILE__, __LINE__); free(_PTR_); (_PTR_) = NULL; printf("TMPMEMFREE BBB %s %d\n", __FILE__, __LINE__); }
90     */
91    
92 jgs 150 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
93     #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
94     #ifdef __ECC
95 ksteube 1322 /*#define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)); if( !(_LENGTH_) ) printf( "Trying malloc(0) at %s %d\n", __FILE__, __LINE__ ); //else printf( "malloc(%d) at %s %d\n", _LENGTH_, __FILE__, __LINE__ );*/
96 jgs 150 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
97     #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
98     #ifdef _OPENMP
99     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) kmp_malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
100     #define THREAD_MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { kmp_free(_PTR_); (_PTR_) = NULL; }
101     #else
102     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
103     #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
104     #endif
105 bcumming 730 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) if( (_POINTER_)!=NULL ){ _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_),((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }else{ _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }
106    
107 jgs 150 #else
108     #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
109     #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
110     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
111     #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
112 bcumming 730 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) if( (_POINTER_)!=NULL ){ _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_),((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }else{ _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }
113 jgs 150 #endif
114    
115 gross 1407 #define TMPMEMALLOC_AND_PASOCHECK(_LENGTH_,_TYPE_) ( MEMALLOC(_LENGTH_,_TYPE_);
116    
117 jgs 150 #endif /* #ifndef INC_PASO_COMMON */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26