File: bound.h

package info (click to toggle)
yorick 2.2.03+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,620 kB
  • ctags: 9,317
  • sloc: ansic: 85,521; sh: 1,665; cpp: 1,282; lisp: 1,234; makefile: 1,034; fortran: 19
file content (137 lines) | stat: -rw-r--r-- 5,972 bytes parent folder | download | duplicates (6)
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
/*
 * $Id: bound.h,v 1.1 2005-09-18 22:04:53 dhmunro Exp $
 * Routines for finding the boundary of a cylindrical mesh.
 */
/* Copyright (c) 2005, The Regents of the University of California.
 * All rights reserved.
 * This file is part of yorick (http://yorick.sourceforge.net).
 * Read the accompanying LICENSE file for details.
 */

#ifndef BOUND_H
#define BOUND_H

/* These function pointers are initialized to malloc, realloc, and free,
   but can be reset at runtime to an alternate memory manager.  */
extern void *(*Dmalloc)(long);
extern void *(*Drealloc)(void *, long);
extern void (*Dfree)(void *);

/* ---------------------------------------------------------------------- */

/* The Mesh structure includes pointers to the coordinate arrays
 * z[lmax][kmax] and r[lmax][kmax], the region number array
 * ireg[lmax+1][kmax] (which includes an extra row of region 0!),
 * and various flags which determine mesh symmetry conditions.
 */
typedef struct Mesh Mesh;
struct Mesh {
   long kmax, lmax;     /* mesh dimensions */
   long klmax;          /* kmax*lmax, overall number of points */
   double *z, *r;       /* kmax-by-lmax coordinate arrays */
   int *ireg;           /* kmax-by-(lmax+1) region number array --
                         * ireg[0][]= ireg[][0]= ireg[lmax][]= 0 */
   int zsym;            /* 1 if z=0 is symmetry plane, else 0
                           2 if RayTrackS (spherical tracker) */
};

/* ---------------------------------------------------------------------- */

/* Lists of boundary points and edges, normally running counterclockwise
 * around the bounded region (but see FindBoundaryPoints for flag to
 * alter boundary orientation)
 */
typedef struct Boundary Boundary;
struct Boundary {
   int zsym;            /* 1 if problem has z-symmetry, else 0 */
   long nk,nl;          /* number of k-edges and l-edges in boundary */
   long npoints;        /* number of boundary points */
   long *zone;          /* [npoints] arrays of entry zones and sides... */
   int *side;           /* the end of a contiguous section of boundary
                         * is marked by zone=0 */
   double *z, *r;       /* [npoints] arrays of boundary points */
};

/* Linked list of edges used to build Boundary lists */
typedef struct Edge Edge;
struct Edge {
   Edge *next;
   long zone, side;
};

/* ---------------------------------------------------------------------- */

/* Given a mesh and a region number, compute the boundary of that region
 * and present it in counterclockwise order in (z,r)-plane.
 * The working array is int work[2][klmax+kmax].
 * Split into kedges, ledges working arrays.
 * Note that for region=0, this returns the problem boundary clockwise.
 * If cw is non-zero, the boundary is returned in clockwise order (or
 * counterclockwise for region 0).
 * A quick check is performed first to determine whether the input
 * boundary is actually the mesh boundary.
 * Return 1 if boundary list had to be changed, 0 if list was correct.
 */
extern int FindBoundaryPoints(Mesh *mesh, int region, int cw,
                              Boundary *boundary, int *work);

/* Trim specific edges out of a boundary list made by FindBoundaryPoints. */
extern void
TrimBoundary(Boundary *trimmed,   /* Resulting trimmed boundary */
             Mesh *mesh,          /* Problem mesh */
             Boundary *boundary,  /* Initial boundary within mesh */
             long *rmlist,        /* rmlist[nsegs][2][2]= [[k1,l1],[k2,l2]]
                                   * are nsegs logical line segments, where
                                   * (k,l) are point coordinates and either
                                   * k1=k2 or l1=l2 */ 
             long nsegs,
             int *work);          /* work[2][klmax] */

/* Make a single boundary edge linked list element.  The edge list is
 * a temporary construct used by FindBoundaryPoints.
 */
extern Edge *
MakeEdge(long stride,           /* ==1 for k-edge, ==kmax for l-edge */
         long edgeIndex,        /* index into kedges or ledges array */
         int sign);             /* 1 (-1) if region left or below
                                 * (right or above) edgeIndex edge */

/* Free the storage used for an Edge, returning edge->next */
extern Edge *ReleaseEdge(Edge *edge);

/* Take one step along the boundary in the given direction starting at
 * the given edge.  Returns NULL at end of boundary.
 */
extern Edge *
WalkBoundary(int direction,     /* 0 clockwise, 1 counterclockwise */
             Edge *edge,        /* current edge */
             long kmax, long klmax,     /* mesh dimensions */
             int *kedges, int *ledges,  /* lists of edges not yet visited
                                         * 1 if region to left or below,
                                         * -1 if to right or above, 0 if
                                         * not a boundary edge --
                                         * UPDATED */
             long *nk, long *nl);       /* number of k or l edges --
                                         * UPDATED */

/* Extend boundary->zone and boundary->side arrays, initializing to
 * the values in the given linked list of edge(s)
 */
extern void
NewBoundaryEdges(Boundary *boundary,    /* boundary lists to be expanded */
              long nedges, Edge *edge); /* # and linked list of edges */

/* Create boundary->z and boundary->r arrays from mesh and
 * boundary->zone, boundary->side arrays.  (cw must be as FindBoundaryPoints)
 */
extern void MakeBoundaryZR(Boundary *boundary, int cw, Mesh *mesh);

/* Free the memory used for the zone, side, z, and r arrays in boundary */
extern void EraseBoundary(Boundary *boundary);

/* Create a Boundary with a given number of points, allocating zone,
 * side arrays, but NOT z, r (use MakeBoundaryZR). */
extern Boundary *MakeBoundary(int zsym, long nk, long nl, long npoints);

/* ---------------------------------------------------------------------- */
#endif