File: objects.c

package info (click to toggle)
felt 3.06-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 17,512 kB
  • ctags: 7,946
  • sloc: ansic: 85,476; fortran: 3,614; yacc: 2,803; lex: 1,178; makefile: 305; sh: 302
file content (539 lines) | stat: -rw-r--r-- 15,582 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
/*
    This file is part of the FElt finite element analysis package.
    Copyright (C) 1993-2000 Jason I. Gobat and Darren C. Atkinson

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/************************************************************************
 * File:	objects.c						*
 *									*
 * Description:	This file contains the function definitions for		*
 *		operations on the various objects.			*
 ************************************************************************/

# include <stdio.h>
# include <string.h>
# include "fe.h"
# include "error.h"
# include "objects.h"
# include "allocate.h"

# ifdef NEED_STRDUP
extern char *strdup ( );
# endif

/************************************************************************
 * Function:	 CreateNode						*
 *									*
 * Description:	 CreateNode creates and initializes a node structure.	*
 *		 The node number is assigned and all pointer fields are	*
 *		 set to NULL.						*
 ************************************************************************/

Node CreateNode (number)
    unsigned number;
{
    Node     node;
    unsigned i;


    if (!(node = AllocNew (struct node)))
	Fatal ("unable to allocate memory for new node");

    node -> number     = number;
    node -> m          = 0.0;
    node -> force      = NULL;
    node -> eq_force   = NULL;
    node -> constraint = NULL;
    node -> aux        = NULL;
    node -> stress     = NULL;
    node -> numelts    = 0;

    for (i = 1; i <= 6; i ++)
	node -> dx [i] = 0;

    return node;
}


/************************************************************************
 * Function:	 DestroyNode						*
 *									*
 * Description:	 DestroyNode deallocates a node structure.  The		*
 *		 auxillary pointer and equivalent force vector are	*
 *		 deallocated.						*
 ************************************************************************/

void DestroyNode (node)
    Node node;
{
    if (node) {
	Deallocate (node -> aux);
	Deallocate (node -> eq_force);
	Deallocate (node);
    }
}


/************************************************************************
 * Function:	 CreateElement						*
 *									*
 * Description:	 CreateElement creates and initializes a new element	*
 *		 structure.  The element number and definition are	*
 *		 assigned, the array of node pointers is allocated and	*
 *		 if definition is not NULL, and all other pointer	*
 *		 fields are initialized to NULL.			*
 ************************************************************************/

Element CreateElement (number, defn)
    unsigned   number;
    Definition defn;
{
    unsigned i;
    Element  element;


    if (!(element = AllocNew (struct element)))
	Fatal ("unable to allocate memory for new element");

    element -> node = NULL;

    if (defn && !(element -> node = Allocate (Node, defn -> numnodes)))
	Fatal ("unable to allocate memory for nodes of new element");

    element -> K  	  = NullMatrix;
    element -> M	  = NullMatrix;
    element -> f	  = NullMatrix;
    element -> aux 	  = NULL;
    element -> number 	  = number;
    element -> definition = defn;

    if (element -> node) {
	UnitOffset (element -> node);
	for (i = 1; i <= defn -> numnodes; i ++)
	    element -> node [i] = NULL;
    }

    element -> material = NULL;
    element -> numdistributed = 0;

    for (i = 0; i <= 3; i ++)
	element -> distributed [i] = NULL;

    element -> stress = NULL;
    element -> ninteg = 0;

    return element;
}


/************************************************************************
 * Function:	 DestroyElement						*
 *									*
 * Description:	 DestroyElement deallocates an element structure.  The	*
 *		 array of pointers to nodes, the array of stresses, and	*
 *		 the structure pointed to by the auxillary pointer are	*
 *		 deallocated.						*
 ************************************************************************/

void DestroyElement (element)
    Element element;
{
    unsigned i;


    if (element) {
        for (i = 1; i <= element -> ninteg; i ++) {
	    ZeroOffset (element -> stress [i] -> values);	
	    Deallocate (element -> stress [i] -> values);		
	    Deallocate (element -> stress [i]);
	}
	ZeroOffset (element -> stress);
	Deallocate (element -> stress);
	ZeroOffset (element -> node);
	Deallocate (element -> node);
	Deallocate (element -> aux);
	Deallocate (element);
    }
}


/************************************************************************
 * Function:	 CreateForce						*
 *									*
 * Description:	 CreateForce creates and initializes a force structure.	*
 *		 The name of the force is assigned (not copied) and the	*
 *		 force components are initialized to zero.		*
 ************************************************************************/

Force CreateForce (name)
    char *name;
{
    int   i;
    Force force;


    if (!(force = AllocNew (struct force)))
	Fatal ("unable to allocate memory for new force");

    force -> aux = NULL;
    force -> color = NULL;
    force -> name = name;
    for (i = 0; i < 7; i ++) {
	force -> force [i].value = 0;
	force -> force [i].expr  = NULL;
	force -> force [i].text  = NULL;
	force -> spectrum [i].value = 0;
	force -> spectrum [i].expr  = NULL;
	force -> spectrum [i].text  = NULL;
    }

    return force;
}


/************************************************************************
 * Function:	 DestroyForce						*
 *									*
 * Description:	 DestroyForce deallocates a force structure.  The name	*
 *		 and auxillary pointer are also deallocated.		*
 ************************************************************************/

void DestroyForce (force)
    Force force;
{
    int i;


    if (force) {
	for (i = 1; i <= 6; i ++) {
	    FreeCode (force -> force [i].expr);
	    Deallocate (force -> force [i].text);
	}
	Deallocate (force -> name);
	Deallocate (force -> color);
	Deallocate (force -> aux);
	Deallocate (force);
    }
}


/************************************************************************
 * Function:	 CreateMaterial						*
 *									*
 * Description:	 CreateMaterial creates and initializes a new material	*
 *		 structure.  The name is assigned (not copied) and the	*
 *		 fields are initialized to zero.			*
 ************************************************************************/

Material CreateMaterial (name)
    char *name;
{
    Material material;


    if (!(material = AllocNew (struct material)))
	Fatal ("unable to allocate memory for new material");

    material -> aux   = NULL;
    material -> color = NULL;
    material -> name  = name;
    material -> E     = 0;
    material -> Ix    = 0;
    material -> Iy    = 0;
    material -> Iz    = 0;
    material -> A     = 0;
    material -> J     = 0;
    material -> G     = 0;
    material -> t     = 0;
    material -> rho   = 0;
    material -> nu    = 0;
    material -> kappa = 0;
    material -> Rk    = 0;
    material -> Rm    = 0;
    material -> Kx    = 0;
    material -> Ky    = 0;
    material -> Kz    = 0;
    material -> c     = 0;

    return material;
}


/************************************************************************
 * Function:	 DestroyMaterial					*
 *									*
 * Description:	 DestroyMaterial deallocates a material structure.  The	*
 *		 name and auxillary structure are also deallocated.	*
 ************************************************************************/

void DestroyMaterial (material)
    Material material;
{
    if (material) {
	Deallocate (material -> name);
	Deallocate (material -> color);
	Deallocate (material -> aux);
	Deallocate (material);
    }
}


/************************************************************************
 * Function:	 CreateConstraint					*
 *									*
 * Description:	 CreateConstraint creates and initializes a new		*
 *		 constraint structure.  The name is assigned (not	*
 *		 copied) and the fields are initialized to zero.	*
 ************************************************************************/

Constraint CreateConstraint (name)
    char *name;
{
    int        i;
    Constraint constraint;


    if (!(constraint = AllocNew (struct constraint)))
	Fatal ("unable to allocate memory for new constraint");

    constraint -> aux = NULL;
    constraint -> color = NULL;
    constraint -> name = name;
    for (i = 0; i < 7; i ++) {
	constraint -> constraint [i] = 0;
	constraint -> dx [i].expr  = NULL;
	constraint -> dx [i].text  = NULL;
	constraint -> dx [i].value = 0;
	constraint -> ix [i] = 0;
    }

    for (i = 0; i < 4; i ++) {
	constraint -> vx [i] = 0;
	constraint -> ax [i] = UnspecifiedValue;
    }

    return constraint;
}


/************************************************************************
 * Function:	 DestroyConstraint					*
 *									*
 * Description:	 DestroyConstraint deallocates a constraint structure.	*
 *		 The name and auxillary structure are also deallocated.	*
 ************************************************************************/

void DestroyConstraint (constraint)
    Constraint constraint;
{
    int i;


    if (constraint) {
	for (i = 1; i <= 6; i ++) {
	    FreeCode (constraint -> dx [i].expr);
	    Deallocate (constraint -> dx [i].text);
	}
	Deallocate (constraint -> name);
	Deallocate (constraint -> color);
	Deallocate (constraint -> aux);
	Deallocate (constraint);
    }
}


/************************************************************************
 * Function:	 CreateDistributed					*
 *									*
 * Description:	 CreateDistributed creates and initializes a new	*
 *		 distributed structure.  The name is assigned (not	*
 *		 copied) and the array of values allocated.		*
 ************************************************************************/

Distributed CreateDistributed (name, nvalues)
    char    *name;
    unsigned nvalues;
{
    Distributed distributed;


    if (!(distributed = AllocNew (struct distributed)))
	Fatal ("unable to allocate memory for new distributed");

    distributed -> aux = NULL;
    distributed -> color = NULL;
    distributed -> value = NULL;

    if (nvalues && !(distributed -> value = Allocate (Pair, nvalues)))
	Fatal ("unable to allocate memory values for new distributed");

    distributed -> name = name;
    distributed -> nvalues = nvalues;
    UnitOffset (distributed -> value);

    return distributed;
}


/************************************************************************
 * Function:	 DestroyDistributed					*
 *									*
 * Description:	 DestroyDistributed deallocates a distributed		*
 *		 structure.  The array of values, name, and auxillary	*
 *		 structure are deallocated.				*
 ************************************************************************/

void DestroyDistributed (distributed)
    Distributed distributed;
{
    if (distributed) {
	ZeroOffset (distributed -> value);
	Deallocate (distributed -> value);
	Deallocate (distributed -> name);
	Deallocate (distributed -> color);
	Deallocate (distributed -> aux);
	Deallocate (distributed);
    }
}


/************************************************************************
 * Function:	 CreateLoadCase						*
 *									*
 * Description:	 CreateLoadCase creates and initializes a new		*
 *		 load case structure.  The name is assigned (not	*
 *		 copied) and the array of values allocated.		*
 ************************************************************************/

LoadCase CreateLoadCase (name)
    char    *name;
{
    LoadCase	loadcase;


    if (!(loadcase = AllocNew (struct loadcase)))
	Fatal ("unable to allocate memory for new load case");

    loadcase -> numforces = 0;
    loadcase -> numloads  = 0;
    loadcase -> nodes     = NULL;
    loadcase -> elements  = NULL;
    loadcase -> forces    = NULL;
    loadcase -> loads     = NULL;

    loadcase -> name = name;

    return loadcase;
}


/************************************************************************
 * Function:	 DestroyLoadCase					*
 *									*
 * Description:	 DestroyLoadCase deallocates a load case 		*
 *		 structure.                                           	* 
 ************************************************************************/

void DestroyLoadCase (loadcase)
    LoadCase	loadcase;
{
    if (loadcase) {
        if (loadcase -> forces) {
	   ZeroOffset (loadcase -> forces);
           Deallocate (loadcase -> forces);
        }
        if (loadcase -> loads) {
	   ZeroOffset (loadcase -> loads); 
           Deallocate (loadcase -> loads);
        }
        if (loadcase -> nodes) {
	   ZeroOffset (loadcase -> nodes); 
           Deallocate (loadcase -> nodes);
        }
        if (loadcase -> elements) {
	   ZeroOffset (loadcase -> elements);
           Deallocate (loadcase -> elements);
        }

	Deallocate (loadcase);
    }
}
/************************************************************************
 * Function:	AssignForce						*
 *									*
 * Description:	Assigns a force given as a piece of code to a force	*
 *		structure.						*
 ************************************************************************/

void AssignForce (force, dof, expr, text)
    Force force;
    DOF   dof;
    Code  expr;
    char *text;
{
    Deallocate (force -> force [dof].text);
    FreeCode (force -> force [dof].expr);

    force -> force [dof].value = EvalCode (expr, 0.0);
    force -> force [dof].expr  = IsConstant (expr) ? NULL : CopyCode (expr);
    force -> force [dof].text  = text ? strdup (text) : NULL;
}

/************************************************************************
 * Function:	AssignSpectrum						*
 *									*
 * Description:	Assigns a spectrum given as a piece of code to a force	*
 *		structure.						*
 ************************************************************************/

void AssignSpectrum (force, dof, expr, text)
    Force force;
    DOF   dof;
    Code  expr;
    char *text;
{
    Deallocate (force -> spectrum [dof].text);
    FreeCode (force -> spectrum [dof].expr);

    force -> spectrum [dof].value = EvalCode (expr, 0.0);
    force -> spectrum [dof].expr  = IsConstant (expr) ? NULL : CopyCode (expr);
    force -> spectrum [dof].text  = text ? strdup (text) : NULL;
}

/************************************************************************
 * Function:	AssignConstraint					*
 *									*
 * Description:	Assigns a boundary condition given as a piece of code   *
 *		to the boundary value part of a constraint structure	*
 *              (Tx=, Ty=, Tz=, Rx=, Ry=, Rz=)				*
 ************************************************************************/

void AssignConstraint (constraint, dof, expr, text, symbol)
    Constraint	constraint;
    DOF   	dof;
    Code  	expr;
    char       *text;
    int  	symbol;
{
    Deallocate (constraint -> dx [dof].text);
    FreeCode (constraint -> dx [dof].expr);

    constraint -> constraint [dof] = symbol;
    constraint -> dx [dof].value   = EvalCode (expr, 0.0);
    constraint -> dx [dof].expr    = IsConstant (expr) ? NULL : CopyCode (expr);
    constraint -> dx [dof].text    = text ? strdup (text) : NULL;
}