| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id$";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Add User View Factors to EnergyPlus Input Data File
|
| 6 |
*
|
| 7 |
* G.Ward for LBNL
|
| 8 |
*/
|
| 9 |
|
| 10 |
#include <stdio.h>
|
| 11 |
#include <stdlib.h>
|
| 12 |
#include <string.h>
|
| 13 |
#include "eplus_idf.h"
|
| 14 |
#include "triangulate.h"
|
| 15 |
|
| 16 |
#ifndef NSAMPLES
|
| 17 |
#define NSAMPLES 100000 /* number of samples to use */
|
| 18 |
#endif
|
| 19 |
|
| 20 |
#define UVF_PNAME "ZoneProperty:UserViewFactor:bySurfaceName"
|
| 21 |
|
| 22 |
const char ADD_HEADER[] =
|
| 23 |
"!+++ User View Factors computed by Radiance +++!\n";
|
| 24 |
|
| 25 |
#define NAME_FLD 1 /* name field always first? */
|
| 26 |
|
| 27 |
typedef struct {
|
| 28 |
const char *pname; /* parameter type name */
|
| 29 |
short zone_fld; /* zone field index */
|
| 30 |
short vert_fld; /* vertex field index */
|
| 31 |
} SURF_PTYPE; /* surface type we're interested in */
|
| 32 |
|
| 33 |
const SURF_PTYPE surf_type[] = {
|
| 34 |
{"BuildingSurface:Detailed", 4, 10},
|
| 35 |
{NULL}
|
| 36 |
};
|
| 37 |
|
| 38 |
struct s_zone {
|
| 39 |
const char *zname; /* zone name */
|
| 40 |
struct s_zone *next; /* next zone in list */
|
| 41 |
IDF_PARAMETER *pfirst; /* first matching parameter */
|
| 42 |
IDF_PARAMETER *plast; /* last matching parameter */
|
| 43 |
} *zone_list = NULL;
|
| 44 |
|
| 45 |
IDF_LOADED *our_idf = NULL; /* loaded/modified IDF */
|
| 46 |
|
| 47 |
/* Create a new zone and push to top of our list */
|
| 48 |
static struct s_zone *
|
| 49 |
new_zone(const char *zname, IDF_PARAMETER *param)
|
| 50 |
{
|
| 51 |
struct s_zone *znew = (struct s_zone *)malloc(sizeof(struct s_zone));
|
| 52 |
|
| 53 |
if (znew == NULL)
|
| 54 |
return(NULL);
|
| 55 |
znew->zname = zname; /* assumes static */
|
| 56 |
znew->next = zone_list;
|
| 57 |
znew->pfirst = znew->plast = param;
|
| 58 |
return(zone_list = znew);
|
| 59 |
}
|
| 60 |
|
| 61 |
/* Add the detailed surface (polygon) to the named zone */
|
| 62 |
static struct s_zone *
|
| 63 |
add2zone(IDF_PARAMETER *param, const char *zname)
|
| 64 |
{
|
| 65 |
struct s_zone *zptr;
|
| 66 |
|
| 67 |
for (zptr = zone_list; zptr != NULL; zptr = zptr->next)
|
| 68 |
if (!strcmp(zptr->zname, zname))
|
| 69 |
break;
|
| 70 |
if (zptr == NULL)
|
| 71 |
return(new_zone(zname, param));
|
| 72 |
/* keep surfaces together */
|
| 73 |
if (!idf_movparam(our_idf, param, zptr->plast))
|
| 74 |
return(NULL);
|
| 75 |
zptr->plast = param;
|
| 76 |
return(zptr);
|
| 77 |
}
|
| 78 |
|
| 79 |
/* Compute zone User View Factors */
|
| 80 |
static int
|
| 81 |
compute_zones(void)
|
| 82 |
{
|
| 83 |
fputs("compute_zones() unimplemented\n", stderr);
|
| 84 |
return(0);
|
| 85 |
}
|
| 86 |
|
| 87 |
/* Load IDF and compute User View Factors */
|
| 88 |
int
|
| 89 |
main(int argc, char *argv[])
|
| 90 |
{
|
| 91 |
char *origIDF, *revIDF;
|
| 92 |
IDF_PARAMETER *pptr;
|
| 93 |
int i;
|
| 94 |
|
| 95 |
if ((argc < 2) | (argc > 3)) {
|
| 96 |
fputs("Usage: ", stderr);
|
| 97 |
fputs(argv[0], stderr);
|
| 98 |
fputs(" Model.idf [Revised.idf]\n", stderr);
|
| 99 |
return(1);
|
| 100 |
}
|
| 101 |
origIDF = argv[1];
|
| 102 |
revIDF = (argc == 2) ? argv[1] : argv[2];
|
| 103 |
/* load Input Data File */
|
| 104 |
our_idf = idf_load(origIDF);
|
| 105 |
if (our_idf == NULL) {
|
| 106 |
fputs(argv[0], stderr);
|
| 107 |
fputs(": cannot load IDF '", stderr);
|
| 108 |
fputs(origIDF, stderr);
|
| 109 |
fputs("'\n", stderr);
|
| 110 |
return(1);
|
| 111 |
}
|
| 112 |
/* remove existing UVFs */
|
| 113 |
if ((pptr = idf_getparam(our_idf, UVF_PNAME)) != NULL) {
|
| 114 |
IDF_PARAMETER *pnext;
|
| 115 |
fputs(argv[0], stderr);
|
| 116 |
fputs(": removing previous User View Factors\n", stderr);
|
| 117 |
do {
|
| 118 |
pnext = pptr->pnext;
|
| 119 |
idf_delparam(our_idf, pptr);
|
| 120 |
} while (pnext != NULL);
|
| 121 |
}
|
| 122 |
/* add to header */
|
| 123 |
if (our_idf->hrem == NULL ||
|
| 124 |
(i = strlen(our_idf->hrem)-strlen(ADD_HEADER)) < 0 ||
|
| 125 |
strcmp(our_idf->hrem+i, ADD_HEADER))
|
| 126 |
idf_add2hdr(our_idf, ADD_HEADER);
|
| 127 |
/* gather zone surfaces */
|
| 128 |
for (i = 0; surf_type[i].pname != NULL; i++)
|
| 129 |
for (pptr = idf_getparam(our_idf, surf_type[i].pname);
|
| 130 |
pptr != NULL; pptr = pptr->pnext) {
|
| 131 |
IDF_FIELD *fptr = idf_getfield(pptr,
|
| 132 |
surf_type[i].zone_fld);
|
| 133 |
if (fptr == NULL) {
|
| 134 |
fputs("Warning: missing zone field!\n", stderr);
|
| 135 |
continue;
|
| 136 |
}
|
| 137 |
if (add2zone(pptr, fptr->arg) == NULL)
|
| 138 |
return(1);
|
| 139 |
}
|
| 140 |
/* run rcontrib on each zone */
|
| 141 |
if (!compute_zones())
|
| 142 |
return(1);
|
| 143 |
/* write out modified IDF */
|
| 144 |
if (!idf_write(our_idf, revIDF, 1)) {
|
| 145 |
fputs(argv[0], stderr);
|
| 146 |
fputs(": error writing IDF '", stderr);
|
| 147 |
fputs(revIDF, stderr);
|
| 148 |
fputs("'\n", stderr);
|
| 149 |
return(1);
|
| 150 |
}
|
| 151 |
return(0); /* finito! */
|
| 152 |
}
|