From 880bdfffba8cdc1c892ceb0a713f98f98d4617ce Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Fri, 12 Apr 2019 18:00:36 -0400 Subject: [PATCH] Work in progress compiles with warnings, definitely not working --- CMakeLists.txt | 4 +- src/demand.c | 72 +++++++++++++++++++++++++++++++++ src/demand.h | 42 ++++++++++++++++++++ src/types.h | 106 +++++++++++++++++++++++++------------------------ 4 files changed, 171 insertions(+), 53 deletions(-) create mode 100644 src/demand.c create mode 100644 src/demand.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 93fbda1..6892dcc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,8 +83,8 @@ ENDIF (MSVC) # configure file groups -file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c) -file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/*) +file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c src/util/list.c) +file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/* src/util/list.*) # exclude epanet python API from the default build list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c") source_group("Library" FILES ${EPANET_LIB_ALL}) diff --git a/src/demand.c b/src/demand.c new file mode 100644 index 0000000..dc91221 --- /dev/null +++ b/src/demand.c @@ -0,0 +1,72 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: demand.c + Description: demand pattern list + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 04/12/2019 + ****************************************************************************** +*/ + +#include +#include + +#include "demand.h" + + +typedef struct demand_data_s +{ + double base_demand; + int pattern_index; + char *category_name; +} demand_data_t; + + +demand_data_t *create_demand_data(double base_demand, int pat_index, char *cat_name) +{ + demand_data_t *demand_data = (demand_data_t *)malloc(sizeof(demand_data_t)); + + demand_data->base_demand = base_demand; + demand_data->pattern_index = pat_index; + + if (cat_name) + demand_data->category_name = strdup(cat_name); + else + demand_data->category_name = NULL; + + return demand_data; +} + +void delete_demand_data(void *data) +{ + demand_data_t *demand_data = *(demand_data_t **)data; + + if (demand_data->category_name) + free(demand_data->category_name); + + free(demand_data); +} + +demand_data_t *get_demand_data(list_node_t *lnode) +{ + return *(demand_data_t **)get_data(lnode); +} + + +double get_base_demand(demand_data_t *data) +{ + return data->base_demand; +} + +int get_pattern_index(demand_data_t *data) +{ + return data->pattern_index; +} + +char *get_category_name(demand_data_t *data) +{ + return data->category_name; +} diff --git a/src/demand.h b/src/demand.h new file mode 100644 index 0000000..e593ed2 --- /dev/null +++ b/src/demand.h @@ -0,0 +1,42 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: demand.h + Description: demand pattern list + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 04/12/2019 + ****************************************************************************** +*/ + +#ifndef DEMAND_H +#define DEMAND_H + + +#include "util/list.h" + + +// Forward declarations +typedef struct demand_data_s demand_data_t; + +// demand list gets declared in types.h typedef struct Snode +extern list_t *p_demand_list; + + +demand_data_t *create_demand_data(double base_demand, int pat_index, char *cat_name); + +void delete_demand_data(void *data); + +demand_data_t *get_demand_data(list_node_t *lnode); + + +double get_base_demand(demand_data_t *data); + +int get_pattern_index(demand_data_t *data); + +char *get_category_name(demand_data_t *data); + + +#endif /* DEMAND_H */ diff --git a/src/types.h b/src/types.h index 476afac..01b25af 100755 --- a/src/types.h +++ b/src/types.h @@ -14,15 +14,18 @@ #ifndef TYPES_H #define TYPES_H -#include "hash.h" #include + +#include "hash.h" +#include "util/list.h" + /* ------------------------------------------- Definition of 4-byte integers & reals ------------------------------------------- */ -typedef float REAL4; +typedef float REAL4; typedef int INT4; /* @@ -64,7 +67,7 @@ typedef int INT4; Flow units conversion factors ---------------------------------------------- */ -#define GPMperCFS 448.831 +#define GPMperCFS 448.831 #define AFDperCFS 1.9837 #define MGDperCFS 0.64632 #define IMGDperCFS 0.5382 @@ -91,9 +94,9 @@ typedef int INT4; /* --------------------------------------------------------------------- - Conversion macros to be used in place of functions + Conversion macros to be used in place of functions --------------------------------------------------------------------- -*/ +*/ #define INT(x) ((int)(x)) // integer portion of x #define FRAC(x) ((x)-(int)(x)) // fractional part of x #define ABS(x) (((x)<0) ? -(x) : (x)) // absolute value of x @@ -109,10 +112,10 @@ typedef int INT4; /* ------------------------------------------------------ Macro to evaluate function x with error checking - (Fatal errors are numbered higher than 100) + (Fatal errors are numbered higher than 100) ------------------------------------------------------ */ -#define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x))) +#define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x))) /* ---------------------------------------------- @@ -187,7 +190,7 @@ typedef enum { HILEVEL, // act when grade above set level TIMER, // act when set time reached TIMEOFDAY // act when time of day occurs -} ControlType; +} ControlType; typedef enum { XHEAD, // pump cannot deliver head (closed) @@ -206,12 +209,12 @@ typedef enum { HW, // Hazen-Williams DW, // Darcy-Weisbach CM // Chezy-Manning -} HeadLossType; +} HeadLossType; typedef enum { US, // US SI // SI (metric) -} UnitsType; +} UnitsType; typedef enum { CFS, // cubic feet per second @@ -224,7 +227,7 @@ typedef enum { MLD, // megaliters per day CMH, // cubic meters per hour CMD // cubic meters per day -} FlowUnitsType; +} FlowUnitsType; typedef enum { PSI, // pounds per square inch @@ -236,14 +239,14 @@ typedef enum { LOW, // lower limit HI, // upper limit PREC // precision -} RangeType; +} RangeType; typedef enum { MIX1, // complete mix model MIX2, // 2-compartment model FIFO, // first in, first out model LIFO // last in, first out model -} MixType; +} MixType; typedef enum { SERIES, // point time series @@ -259,7 +262,7 @@ typedef enum { HEAD, // nodal hydraulic head PRESSURE, // nodal pressure QUALITY, // nodal water quality - + LENGTH, // link length DIAM, // link diameter FLOW, // link flow rate @@ -270,7 +273,7 @@ typedef enum { SETTING, // pump/valve setting REACTRATE, // avg. reaction rate in link FRICTION, // link friction factor - + POWER, // pump power output TIME, // simulation time VOLUME, // tank volume @@ -293,7 +296,7 @@ typedef enum { ENERHDR, // energy usage header NODEHDR, // node results header LINKHDR // link results header -} HdrType; +} HdrType; typedef enum { NEGATIVE = -1, // flow in reverse of pre-assigned direction @@ -302,13 +305,13 @@ typedef enum { } FlowDirection; typedef enum { - DDA, // demand driven analysis + DDA, // demand driven analysis PDA // pressure driven analysis } DemandModelType; /* ------------------------------------------------------ - Fundamental Data Structures + Fundamental Data Structures ------------------------------------------------------ */ @@ -370,7 +373,8 @@ typedef struct // Node Object double X; // x-coordinate double Y; // y-coordinate double El; // elevation - Pdemand D; // demand pointer +// Pdemand D; // demand pointer + list_t *D; // pointer to demand list Psource S; // source pointer double C0; // initial quality double Ke; // emitter coeff. @@ -383,7 +387,7 @@ typedef struct // Link Object { char ID[MAXID+1]; // link ID int N1; // start node index - int N2; // end node index + int N2; // end node index double Diam; // diameter double Len; // length double Kc; // roughness @@ -510,7 +514,7 @@ typedef struct s_ActionItem // Action List Item { int ruleIndex; // index of rule action belongs to Saction *action; // an action clause - struct s_ActionItem *next; // next action on the list + struct s_ActionItem *next; // next action on the list } SactionList; typedef struct // Mass Balance Components @@ -532,15 +536,15 @@ typedef struct // Mass Balance Components // Input File Parser Wrapper typedef struct { FILE *InFile; // Input file handle - + char DefPatID[MAXID + 1], // Default demand pattern ID InpFname[MAXFNAME + 1], // Input file name *Tok[MAXTOKS], // Array of token strings Comment[MAXMSG + 1], // Comment text LineComment[MAXMSG + 1]; // Full line comment - - int + + int MaxNodes, // Node count from input file */ MaxLinks, // Link count " " " MaxJuncs, // Junction count " " " @@ -559,7 +563,7 @@ typedef struct { Flowflag, // Flow units flag Pressflag, // Pressure units flag DefPat; // Default demand pattern - + Spattern *PrevPat; // Previous pattern processed Scurve *PrevCurve; // Previous curve processed double *X; // Temporary array for curve data @@ -590,7 +594,7 @@ typedef struct { typedef struct { FILE *RptFile; // Report file handle - + int Nperiods, // Number of reporting periods PageSize, // Lines/page in output report/ @@ -607,13 +611,13 @@ typedef struct { long LineNum, // Current line number PageNum; // Current page number - + char Atime[13], // Clock time (hrs:min:sec) Rpt1Fname[MAXFNAME+1], // Primary report file name Rpt2Fname[MAXFNAME+1], // Secondary report file name DateStamp[26]; // Current date & time - + SField Field[MAXVAR]; // Output reporting fields } Report; @@ -624,19 +628,19 @@ typedef struct { char HydFname[MAXFNAME+1], // Hydraulics file name OutFname[MAXFNAME+1]; // Binary output file name - + int Outflag, // Output file flag Hydflag, // Hydraulics flag SaveHflag, // Hydraulic results saved flag SaveQflag, // Quality results saved flag Saveflag; // General purpose save flag - - long + + long HydOffset, // Hydraulics file byte offset OutOffset1, // 1st output file byte offset OutOffset2; // 2nd output file byte offset - + FILE *OutFile, // Output file handle *HydFile, // Hydraulics file handle @@ -665,7 +669,7 @@ typedef struct { *Aij, // Non-zero, off-diagonal matrix coeffs. *F, // Right hand side vector *temp; // Array used by linear eqn. solver - + int Ncoeffs, // Number of non-zero matrix coeffs *Order, // Node-to-row of re-ordered matrix @@ -683,7 +687,7 @@ typedef struct { // Hydraulics Solver Wrapper typedef struct { - double + double *NodeHead, // Node hydraulic heads *NodeDemand, // Node demand + emitter flows *DemandFlow, // Demand outflows @@ -711,13 +715,13 @@ typedef struct { Dcost, // Energy demand charge/kw/day Emax, // Peak energy usage RelativeError, // Total flow change / total flow - MaxHeadError, // Max. error for link head loss + MaxHeadError, // Max. error for link head loss MaxFlowChange, // Max. change in link flow RelaxFactor, // Relaxation factor for flow updating *P, // Inverse of head loss derivatives *Y, // Flow correction factors *Xflow; // Inflow - outflow at each node - + int Epat, // Energy cost time pattern DemandModel, // Fixed or pressure dependent @@ -730,10 +734,10 @@ typedef struct { OpenHflag, // Hydraulic system opened flag Haltflag; // Flag to halt simulation - StatusType + StatusType *LinkStatus, // Link status *OldStatus; // Previous link/tank status - + Smatrix smatrix; // Sparse matrix storage } Hydraul; @@ -747,7 +751,7 @@ typedef struct { int Qualflag, // Water quality analysis flag OpenQflag, // Quality system opened flag - Reactflag, // Reaction indicator + Reactflag, // Reaction indicator OutOfMemory, // Out of memory indicator TraceNode, // Source node for flow tracing *SortedNodes; // Topologically sorted node indexes @@ -768,17 +772,17 @@ typedef struct { Bucf, // Bulk reaction units conversion factor Tucf, // Tank reaction units conversion factor BulkOrder, // Bulk flow reaction order - WallOrder, // Pipe wall reaction order - TankOrder, // Tank reaction order - Kbulk, // Global bulk reaction coeff. - Kwall, // Global wall reaction coeff. + WallOrder, // Pipe wall reaction order + TankOrder, // Tank reaction order + Kbulk, // Global bulk reaction coeff. + Kwall, // Global wall reaction coeff. Climit, // Limiting potential quality SourceQual, // External source quality *NodeQual, // Reported node quality state *PipeRateCoeff; // Pipe reaction rate coeffs. struct Mempool - *SegPool; // Memory pool for water quality segments + *SegPool; // Memory pool for water quality segments Pseg FreeSeg, // Pointer to unused segment @@ -808,7 +812,7 @@ typedef struct { Nrules, // Number of control rules Npats, // Number of time patterns Ncurves; // Number of data curves - + Snode *Node; // Node array Slink *Link; // Link array Stank *Tank; // Tank array @@ -836,13 +840,13 @@ typedef struct Project { Rules rules; // Rule-based controls wrapper Hydraul hydraul; // Hydraulics solver wrapper Quality quality; // Water quality solver wrapper - + double Ucf[MAXVAR]; // Unit conversion factors - + int Openflag, // Project open flag Warnflag; // Warning flag - + char Msg[MAXMSG+1], // General-purpose string: errors, messages Title[MAXTITLE][TITLELEN+1], // Project title @@ -850,9 +854,9 @@ typedef struct Project { TmpHydFname[MAXFNAME+1], // Temporary hydraulics file name TmpOutFname[MAXFNAME+1], // Temporary output file name TmpStatFname[MAXFNAME+1]; // Temporary statistic file name - - void (* viewprog) (char *); // Pointer to progress viewing function - + + void (* viewprog) (char *); // Pointer to progress viewing function + } Project, *EN_Project; #endif