2 This file is part of the FElt finite element analysis package.
3 Copyright (C) 1993 Jason I. Gobat and Darren C. Atkinson
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 of the License, or
8 (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /****************************************************************************
24 ***************************************************************************/
28 # include "allocate.h"
34 typedef double dbl_pair
[2];
35 typedef int triple_int
[3];
39 /****************************************************************************
41 * Function: GenerateTriMesh
43 * Description: a procedure to interface to Geompack and generate a mesh
44 * of triangular elements.
46 ****************************************************************************/
48 unsigned GenerateTriMesh (trimesh
,element
,node
,numelts
,numnodes
,bnode
,belement
)
68 if (trimesh
-> numcurves
<= 0) {
69 error ("must have at least a boundary curve to generate a TriMesh");
73 if (trimesh
-> definition
-> numnodes
!= 3) {
74 error ("TriMesh generation requires three node elements");
78 vcl
= Allocate (dbl_pair
, 4*trimesh
-> max
);
79 eln
= Allocate (triple_int
, 2*trimesh
-> max
);
81 if (vcl
== NULL
|| eln
== NULL
)
82 Fatal ("allocation error creating TriMesh");
84 nvbc
= Allocate (int, trimesh
-> numcurves
);
87 Fatal ("allocation error creating TriMesh");
91 for (i
= 0 ; i
< trimesh
-> numcurves
; i
++) {
92 nvertices
+= trimesh
-> curves
[i
] -> numvc
;
93 nvbc
[i
] = trimesh
-> curves
[i
] -> numvc
;
95 for (j
= 0 ; j
< trimesh
-> curves
[i
] -> numvc
; j
++) {
96 vcl
[count
][0] = trimesh
-> curves
[i
] -> vcl
[j
][0];
97 vcl
[count
][1] = trimesh
-> curves
[i
] -> vcl
[j
][1];
102 if (nvertices
<= 0) {
103 error ("nothing to generate");
111 geompk_ (&(trimesh
-> tolin
), &(trimesh
-> angspc
),
112 &(trimesh
-> angtol
), &(trimesh
-> kappa
),
113 &(trimesh
-> dmin
), &(trimesh
-> min
),
114 &(trimesh
-> max
), &nvertices
, &(trimesh
-> numcurves
),
115 nvbc
, vcl
, eln
, &ne
, &status
);
118 error ("Geompack error code #%d in TriMesh generation",status
);
123 error ("nothing to generate");
128 * allocate some memory to hold everything that we will generate
134 error ("nothing to generate");
138 if (!(*node
= Allocate(Node
, nn
)))
139 Fatal ("allocation error in TriMesh generation");
143 for (i
= 1 ; i
<= nn
; i
++) {
144 if (!((*node
) [i
] = CreateNode (0)))
145 Fatal ("allocation error in TriMesh generation");
148 if (!(*element
= Allocate(Element
, ne
)))
149 Fatal ("allocation error in TriMesh generation");
151 UnitOffset (*element
);
153 for (i
= 1 ; i
<= ne
; i
++) {
154 if (!((*element
) [i
] = CreateElement (0, trimesh
-> definition
)))
155 Fatal ("allocation error in TriMesh generation");
159 * generate all the nodes
162 for (i
= 1 ; i
<= nn
; i
++) {
164 (*node
) [i
] -> number
= i
+ bnode
;
165 (*node
) [i
] -> x
= vcl
[i
-1][0];
166 (*node
) [i
] -> y
= vcl
[i
-1][1];
167 (*node
) [i
] -> z
= 0;
172 * attach all the elements to the nodes
175 for (i
= 1 ; i
<= ne
; i
++) {
177 (*element
) [i
] -> number
= i
+ belement
;
178 (*element
) [i
] -> node
[1] = (*node
) [eln
[i
-1][0]];
179 (*element
) [i
] -> node
[2] = (*node
) [eln
[i
-1][1]];
180 (*element
) [i
] -> node
[3] = (*node
) [eln
[i
-1][2]];