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