/[ascend]/trunk/base/generic/compiler/dimen.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/dimen.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1066 - (show annotations) (download) (as text)
Sun Jan 7 10:02:41 2007 UTC (17 years, 9 months ago) by johnpye
File MIME type: text/x-chdr
File size: 10039 byte(s)
Adding doxygen 'addtogroup' for Solver, Compiler, Integrator.
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 @file
21 Ascend Dimensions Data Structure.
22 *//*
23 by Tom Epperly
24 8/18/89
25 Version: $Revision: 1.7 $
26 Version control file: $RCSfile: dimen.h,v $
27 Date last modified: $Date: 1997/07/18 12:28:58 $
28 Last modified by: $Author: mthomas $
29 */
30
31 #ifndef ASC_DIMEN_H
32 #define ASC_DIMEN_H
33
34 /** addtogroup compiler Compiler
35 @{
36 */
37
38 #include <utilities/ascConfig.h>
39 #include "fractions.h"
40 #include "compiler.h"
41
42
43 /* Keep these defines current with DimNames in dimen.h. */
44 #define NUM_DIMENS 10 /**< Number of dimension types. */
45 #define D_MASS 0 /**< Index for mass dimension. */
46 #define D_QUANTITY 1 /**< Index for quantity dimension. */
47 #define D_LENGTH 2 /**< Index for length dimension. */
48 #define D_TIME 3 /**< Index for time dimension. */
49 #define D_TEMPERATURE 4 /**< Index for temperature dimension. */
50 #define D_CURRENCY 5 /**< Index for currency dimension. */
51 #define D_ELECTRIC_CURRENT 6 /**< Index for electric current dimension. */
52 #define D_LUMINOUS_INTENSITY 7 /**< Index for luminous intensity dimension. */
53 #define D_PLANE_ANGLE 8 /**< Index for plane angle dimension. */
54 #define D_SOLID_ANGLE 9 /**< Index for solid angle dimension. */
55
56 /** Dimension data structure. */
57 struct DimStruct {
58 struct fraction f[NUM_DIMENS]; /**< Array of fractions, one for each dimension type. */
59 unsigned int wild; /**< Wild flag. Only valid values are 0 and DIM_WILD */
60 };
61 #define DIM_WILD 0x1
62 /**< Code for a wild dimension. */
63
64 /** Dimension typedef for general use */
65 typedef struct DimStruct dim_type;
66
67 ASC_DLLSPEC struct gl_list_t *g_dimen_list;
68 /**<
69 * Global list of dimension data structures. All persistent dim pointers
70 * should resolve to something pointed at in this list to minimize dim
71 * overhead.
72 */
73
74 extern void InitDimenList(void);
75 /**<
76 * Initialize the dimension list.
77 * Must be called once and only once before any other dimension calls.
78 */
79
80 extern void DestroyDimenList(void);
81 /**<
82 * This can be called to deallocate all of the allocated dimensions.
83 */
84
85 #define GetDimFraction(d,i) ((d).f[i])
86 /**<
87 * Returns a fraction struct from a dim_type.
88 * i should be one of
89 * - D_MASS
90 * - D_QUANTITY
91 * - D_LENGTH
92 * - D_TIME
93 * - D_TEMPERATURE
94 * - D_CURRENCY
95 * - D_ELECTRIC_CURRENT
96 * - D_LUMINOUS_INTENSITY
97 * - D_PLANE_ANGLE
98 * - D_SOLID_ANGLE
99 */
100
101 #define GetDimPower(d,i) \
102 (int)(Denominator((d).f[i])==1 ? Numerator((d).f[i]) : 0)
103 /**<
104 * Returns an int value of the numerator, or 0 if the
105 * denominator != 1.
106 */
107
108 #define SetDimFraction(d,i,frac) ( (d).f[(i)] = (frac) )
109 /**<
110 * Set fraction i in dim_type d to frac.
111 */
112
113 ASC_DLLSPEC void ClearDimensions(dim_type *d);
114 /**<
115 * Initialize all the dimension fractions to zero.
116 */
117
118 ASC_DLLSPEC CONST dim_type*Dimensionless(void);
119 /**<
120 * Return a pointer to the dimensionless structure.
121 */
122
123 ASC_DLLSPEC CONST dim_type *TrigDimension(void);
124 /**<
125 * Return a pointer to the dimension structure for plane angle.
126 */
127
128 ASC_DLLSPEC CONST dim_type *WildDimension(void);
129 /**<
130 * Return a pointer to a wild dimension structure. You don't need to
131 * call FindOrAddDimen with this dimension.
132 */
133
134 extern CONST dim_type *HalfDimension(CONST dim_type *d, int b);
135 /**<
136 * Return a pointer to a dimension structure with sqrt dimensionality.
137 * Returns null if sqrt dimensionality is fractional when tested (b true).
138 * If not b, result may point to noninteger dim. Dim will be in global list.
139 */
140
141 extern CONST dim_type *ThirdDimension(CONST dim_type *d, int b);
142 /**<
143 * Return a pointer to a dimension structure with cbrt dimensionality.
144 * Returns null if cbrt dimensionality is fractional when tested (b true).
145 * If !b, result may point to noninteger dim. Dim will be in global list.
146 */
147
148 extern CONST dim_type *SquareDimension(CONST dim_type *d, int b);
149 /**<
150 * Return a pointer to a dimension structure with square dimensionality.
151 * Returns null if square dimensionality is fractional when tested (b true).
152 * If not b, result may point to noninteger dim. Dim will be in global list.
153 */
154
155 extern CONST dim_type *CubeDimension(CONST dim_type *d, int b);
156 /**<
157 * Return a pointer to a dimension structure with cube dimensionality.
158 * Returns null if cube dimensionality is fractional when tested (b true).
159 * If !b, result may point to noninteger dim. Dim will be in global list.
160 */
161
162 extern CONST dim_type *PowDimension(long mult, CONST dim_type *d, int b);
163 /**<
164 * Return a pointer to a dimension structure with d*mult dimensionality.
165 * Returns null if cube dimensionality is fractional when tested (b true)
166 * or if mult*d yields integer overflow of the dimensionality.
167 * If !b, result may point to noninteger dim. Dim will be in global list.
168 */
169
170 extern void SetWild(dim_type *dim);
171 /**<
172 * Set the wild flag of dimensions dim.
173 */
174
175 ASC_DLLSPEC int IsWild(CONST dim_type *d);
176 /**<
177 * Return a true value if d is wild, and otherwise return a false value.
178 */
179
180 extern int OddDimension(CONST dim_type *d);
181 /**<
182 * Return a true value if d has an odd, wild, or non-integer dimension.
183 */
184
185 extern int NonCubicDimension(CONST dim_type *d);
186 /**<
187 * Return a true value if d has an noncubic, wild, or non-integer dimension.
188 */
189
190 extern int SameDimen(CONST dim_type *d1, CONST dim_type *d2);
191 /**<
192 * Return 1 if d1 and d2 have the same dimensional value, or 0
193 * otherwise. Two wild dimensions are the same, regardless of any
194 * other data they may contain.
195 * Wild and any non-wild are NOT the same.
196 */
197
198 ASC_DLLSPEC int CmpDimen(CONST dim_type *d1, CONST dim_type *d2);
199 /**<
200 * Return 1,0,-1 if d1 is >,=, or < d2 respectively.
201 */
202
203 ASC_DLLSPEC CONST dim_type *FindOrAddDimen(CONST dim_type *d);
204 /**<
205 * This function is run to make sure only one copy of each dimensions
206 * is stored. It is designed to be called as follows:
207 * <pre>
208 * Example:
209 * dim_type d,*p;
210 * ClearDimensions(&d);
211 * SetDimFraction(d,D_MASS,CreateFraction(1,2));
212 * ...etc...
213 * p = FindOrAddDimen(&d);
214 * p will never point to d. p != &d.
215 * </pre>
216 */
217
218 ASC_DLLSPEC void CopyDimensions(CONST dim_type *src, dim_type *dest);
219 /**<
220 * Copy from src to dest.
221 */
222
223 ASC_DLLSPEC dim_type AddDimensions(CONST dim_type *d1, CONST dim_type *d2);
224 /**<
225 * Add 2 dimensions.
226 * Wild+anything equals wild.
227 * return d1+d2;
228 * NOTE: This returns a dim by value, not by pointer. There are places
229 * where this is desirable. Where you want a pointer from the dim
230 * table instead, use SumDimensions.
231 */
232
233 extern CONST dim_type *SumDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
234 /**<
235 * Add 2 dimensions with checking.
236 * Wild+anything equals wild.
237 * return d1+d2;
238 * If check != 0, verifies that d1 and d2 are not fractional, returning
239 * NULL if fractional found.
240 * Result will be in global list.
241 */
242
243 ASC_DLLSPEC dim_type SubDimensions(CONST dim_type *d1, CONST dim_type *d2);
244 /**<
245 * Subtract 2 dimensions.
246 * Wild-anything equals wild.
247 * return d1-d2;
248 * NOTE: This returns a dim by value, not by pointer. There are places
249 * where this is desirable. Where you want a pointer from the dim
250 * table instead, use DiffDimensions.
251 */
252
253 extern CONST dim_type *DiffDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
254 /**<
255 * Subtract 2 dimensions with checking.
256 * Wild-anything equals wild.
257 * return d1-d2;
258 * If check != 0, verifies that d1 and d2 are not fractional, returning
259 * NULL if fractional found.
260 * Result will be in global list.
261 */
262
263 ASC_DLLSPEC dim_type ScaleDimensions(CONST dim_type *dim, struct fraction frac);
264 /**<
265 * Scale the dimensions by frac. A wild scaled always remains wild.
266 */
267
268 ASC_DLLSPEC void ParseDim(dim_type *dim, CONST char *c);
269 /**<
270 * Initialize dim appropriately according to the string c. If c doesn't
271 * match any of the dimension strings, dim will be dimensionless and
272 * an error message will be printed.
273 * <pre>
274 * String Dimension Index
275 * "M" D_MASS
276 * "Q" D_QUANTITY
277 * "T" D_TIME
278 * "L" D_LENGTH
279 * "TMP" D_TEMPERATURE
280 * "C" D_CURRENCY
281 * "E" D_ELECTRIC_CURRENT
282 * "LUM" D_LUMINOUS_INTENSITY
283 * "P" D_PLANE_ANGLE
284 * "S" D_SOLID_ANGLE
285 * </pre>
286 */
287
288 ASC_DLLSPEC char *DimName(CONST int nIndex);
289 /**<
290 * Return the internal copy of the name of the dimension corresponding
291 * to index if index is within [0..NUM_DIMENS-1], otherwise return NULL.
292 */
293
294 extern CONST dim_type *CheckDimensionsMatch(CONST dim_type *d1, CONST dim_type *d2);
295 /**<
296 * Compare 2 dimensions.
297 * - Return d1 if d2 is wild
298 * - Return d2 if d1 is wild or d1 == d2
299 * - Return d1 if *d1 == *d2
300 * - Otherwise return NULL
301 */
302
303 ASC_DLLSPEC void PrintDimen(FILE *f ,CONST dim_type *d);
304 /**< Print a dimension to a file. Used in interface */
305
306
307 ASC_DLLSPEC void PrintDimenMessage(CONST char *message
308 , CONST char *label1, CONST dim_type *d1
309 , CONST char *label2, CONST dim_type *d2
310 );
311
312 /**< Print a message like "LABEL1='dim1', LABEL2='dim2'" */
313
314 ASC_DLLSPEC void DumpDimens(FILE *f);
315 /**< Dump all dimensions to a file. Used in interface */
316
317 /* @} */
318
319 #endif /* ASC_DIMEN_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22