Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/vtkpost/mc.h
5213 views
1
#ifndef MC_H
2
#define MC_H
3
4
extern "C" {
5
6
/*******************************************************************
7
LIST HANDLING DEFINITIONS
8
*******************************************************************/
9
10
typedef struct list {
11
struct list *next; /* pointer to next item in list */
12
char *name; /* name of list item */
13
} LIST;
14
15
#ifdef MATC_OPENMP
16
/* Move initialization to matc.c::mtc_init() for thread safety */
17
extern LIST *listheaders;
18
#pragma omp threadprivate(listheaders)
19
20
/* Data with thread-local storage cannot be reliably accessed across DLL
21
borders. Use an accessor function instead. */
22
LIST * mtc_get_listheaders(void);
23
#else
24
extern LIST listheaders[];
25
#endif /* MATC_OPENMP */
26
27
#define ALLOCATIONS 0
28
#define CONSTANTS 1
29
#define VARIABLES 2
30
#define COMMANDS 3
31
#define FUNCTIONS 4
32
33
#define MAX_HEADERS 5
34
35
#ifdef MATC_OPENMP
36
#define LISTHEADERS (mtc_get_listheaders())
37
#else
38
#define LISTHEADERS listheaders
39
#endif /* MATC_OPENMP */
40
#define ALLOC_HEAD LISTHEADERS[ALLOCATIONS].next
41
#define CONST_HEAD LISTHEADERS[CONSTANTS].next
42
#define VAR_HEAD LISTHEADERS[VARIABLES].next
43
#define COM_HEAD LISTHEADERS[COMMANDS].next
44
#define FUNC_HEAD LISTHEADERS[FUNCTIONS].next
45
46
#define NEXT(lst) (lst)->next
47
#define NAME(lst) (lst)->name
48
49
/*******************************************************************
50
MEMORY HANDLING
51
********************************************************************/
52
53
/*
54
memory allocation and deallocation routines
55
*/
56
#define ALLOCMEM(size) mem_alloc(size)
57
#define FREEMEM(ptr) mem_free(ptr)
58
59
/*
60
we use a lot of string copying.
61
*/
62
#define STRCOPY(str) strcpy((char *)ALLOCMEM(strlen(str)+1),(str))
63
64
typedef struct alloc_list {
65
struct alloc_list *next;
66
char *mem;
67
} ALLOC_LIST;
68
69
#define ALLOC_LST(mem) (ALLOC_LIST *)((char *)mem-sizeof(ALLOC_LIST))
70
#define ALLOC_SIZE(size) (size+sizeof(ALLOC_LIST))
71
#define ALLOC_PTR(lst) (char *)((char *)lst+sizeof(ALLOC_LIST))
72
73
/*******************************************************************
74
VARIABLES
75
*******************************************************************/
76
77
/*
78
* MATC matrix is internally represented by this structure.
79
*/
80
typedef struct MATRIX
81
{
82
int type, /* TYPE_DOUBLE or TYPE_STRING */
83
refcount, /* reference count */
84
nrow, ncol; /* number of rows and columns */
85
double *data; /* pointer to double array */
86
} MATRIX;
87
88
89
/*
90
* list of VARIABLES
91
*/
92
93
typedef struct variable
94
{
95
struct variable *next; /* pointer to next item in list */
96
char *name; /* name of the item */
97
int changed;
98
MATRIX *me;
99
} VARIABLE;
100
101
/*
102
shortcuts for accessing structure MATRIX
103
*/
104
#define MATR(ptr) (ptr)->me->data
105
#define TYPE(ptr) (ptr)->me->type
106
#define NROW(ptr) (ptr)->me->nrow
107
#define NCOL(ptr) (ptr)->me->ncol
108
#define REFCNT(ptr) (ptr)->me->refcount
109
#define M(ptr,i,j) (ptr)->me->data[(i) * NCOL(ptr) + (j)]
110
111
#define VARIABLESIZE sizeof(VARIABLE)
112
#define MATRIXSIZE sizeof(MATRIX)
113
#define MATSIZE(ptr) NROW(ptr)*NCOL(ptr)*sizeof(double)
114
115
#define TYPE_DOUBLE 0
116
#define TYPE_COMPLEX 1 /* this is not */
117
#define TYPE_STRING 2
118
119
/*******************************************************************
120
INTERNAL COMMANDS AND USER FUNCTIONS
121
*******************************************************************/
122
123
typedef struct command
124
{
125
struct command *next; /* pointer to next item in list */
126
char *name; /* name of the item */
127
int flags, /* CMDFLAG_PW & CMDFLAG_CE */
128
minp, maxp; /* min. and max. no. of parameters */
129
VARIABLE *(*sub)(); /* function to execute */
130
char *help; /* help string... */
131
} COMMAND;
132
133
#define COMSIZE sizeof(COMMAND)
134
135
#define CMDFLAG_PW 1 /* element by element operation */
136
#define CMDFLAG_CE 2 /* command can be executed when
137
preprocessing if constant
138
arguments. */
139
140
/*******************************************************************
141
USER DEFINED FUNCTIONS
142
*******************************************************************/
143
144
typedef struct function
145
{
146
struct function *next; /* pointer to next function in list */
147
char *name, /* name of the function */
148
**parnames, /* function parameter names (if any) */
149
**exports, /* functions exported variables */
150
**imports, /* functions imported variables */
151
*help; /* functions help text */
152
int parcount; /* defined number of parameters */
153
struct clause *body; /* function body */
154
} FUNCTION;
155
156
#define FUNCSIZE sizeof(FUNCTION)
157
158
}
159
160
#endif // MC_H
161
162