Merge branch 'hotfix-3.07.3'
[felt.git] / lib / Generate / trimesh_geompk.c
blob44b2be7b07ceac60b8785e5adf8caac9ed179f36
1 /*
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 /****************************************************************************
22 * File: triangle.c
24 ***************************************************************************/
26 # include <math.h>
27 # include <stdio.h>
28 # include "allocate.h"
29 # include "error.h"
30 # include "fe.h"
31 # include "objects.h"
32 # include "mesh.h"
34 typedef double dbl_pair [2];
35 typedef int triple_int [3];
37 void geompk_ ( );
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)
49 TriMesh trimesh;
50 Element **element;
51 Node **node;
52 unsigned *numelts;
53 unsigned *numnodes;
54 unsigned bnode;
55 unsigned belement;
57 unsigned i,j;
58 unsigned count;
59 int ne, nn;
60 int nvertices,
61 *nvbc;
62 double (*vcl) [2];
63 int (*eln) [3];
64 int status;
66 nvertices = 0;
68 if (trimesh -> numcurves <= 0) {
69 error ("must have at least a boundary curve to generate a TriMesh");
70 return 1;
73 if (trimesh -> definition -> numnodes != 3) {
74 error ("TriMesh generation requires three node elements");
75 return 1;
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);
86 if (nvbc == NULL)
87 Fatal ("allocation error creating TriMesh");
89 count = 0;
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];
98 count++;
102 if (nvertices <= 0) {
103 error ("nothing to generate");
104 Deallocate (vcl);
105 Deallocate (eln);
107 return 1;
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);
117 if (status) {
118 error ("Geompack error code #%d in TriMesh generation",status);
119 return 1;
122 if (ne <= 0) {
123 error ("nothing to generate");
124 return 1;
128 * allocate some memory to hold everything that we will generate
131 nn = nvertices;
133 if (nn <= 0) {
134 error ("nothing to generate");
135 return 1;
138 if (!(*node = Allocate(Node, nn)))
139 Fatal ("allocation error in TriMesh generation");
141 UnitOffset (*node);
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]];
184 *numnodes = nn;
185 *numelts = ne;
187 Deallocate (vcl);
188 Deallocate (eln);
190 return 0;