Work in progress

compiles with warnings, definitely not working
This commit is contained in:
Michael Tryby
2019-04-12 18:00:36 -04:00
parent 8989be193a
commit 880bdfffba
4 changed files with 171 additions and 53 deletions

View File

@@ -83,8 +83,8 @@ ENDIF (MSVC)
# configure file groups # configure file groups
file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c) file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c src/util/list.c)
file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/*) file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/* src/util/list.*)
# exclude epanet python API from the default build # exclude epanet python API from the default build
list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c") list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c")
source_group("Library" FILES ${EPANET_LIB_ALL}) source_group("Library" FILES ${EPANET_LIB_ALL})

72
src/demand.c Normal file
View File

@@ -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 <stdlib.h>
#include <string.h>
#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;
}

42
src/demand.h Normal file
View File

@@ -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 */

View File

@@ -14,15 +14,18 @@
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H
#include "hash.h"
#include <stdio.h> #include <stdio.h>
#include "hash.h"
#include "util/list.h"
/* /*
------------------------------------------- -------------------------------------------
Definition of 4-byte integers & reals Definition of 4-byte integers & reals
------------------------------------------- -------------------------------------------
*/ */
typedef float REAL4; typedef float REAL4;
typedef int INT4; typedef int INT4;
/* /*
@@ -64,7 +67,7 @@ typedef int INT4;
Flow units conversion factors Flow units conversion factors
---------------------------------------------- ----------------------------------------------
*/ */
#define GPMperCFS 448.831 #define GPMperCFS 448.831
#define AFDperCFS 1.9837 #define AFDperCFS 1.9837
#define MGDperCFS 0.64632 #define MGDperCFS 0.64632
#define IMGDperCFS 0.5382 #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 INT(x) ((int)(x)) // integer portion of x
#define FRAC(x) ((x)-(int)(x)) // fractional part of x #define FRAC(x) ((x)-(int)(x)) // fractional part of x
#define ABS(x) (((x)<0) ? -(x) : (x)) // absolute value 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 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 HILEVEL, // act when grade above set level
TIMER, // act when set time reached TIMER, // act when set time reached
TIMEOFDAY // act when time of day occurs TIMEOFDAY // act when time of day occurs
} ControlType; } ControlType;
typedef enum { typedef enum {
XHEAD, // pump cannot deliver head (closed) XHEAD, // pump cannot deliver head (closed)
@@ -206,12 +209,12 @@ typedef enum {
HW, // Hazen-Williams HW, // Hazen-Williams
DW, // Darcy-Weisbach DW, // Darcy-Weisbach
CM // Chezy-Manning CM // Chezy-Manning
} HeadLossType; } HeadLossType;
typedef enum { typedef enum {
US, // US US, // US
SI // SI (metric) SI // SI (metric)
} UnitsType; } UnitsType;
typedef enum { typedef enum {
CFS, // cubic feet per second CFS, // cubic feet per second
@@ -224,7 +227,7 @@ typedef enum {
MLD, // megaliters per day MLD, // megaliters per day
CMH, // cubic meters per hour CMH, // cubic meters per hour
CMD // cubic meters per day CMD // cubic meters per day
} FlowUnitsType; } FlowUnitsType;
typedef enum { typedef enum {
PSI, // pounds per square inch PSI, // pounds per square inch
@@ -236,14 +239,14 @@ typedef enum {
LOW, // lower limit LOW, // lower limit
HI, // upper limit HI, // upper limit
PREC // precision PREC // precision
} RangeType; } RangeType;
typedef enum { typedef enum {
MIX1, // complete mix model MIX1, // complete mix model
MIX2, // 2-compartment model MIX2, // 2-compartment model
FIFO, // first in, first out model FIFO, // first in, first out model
LIFO // last in, first out model LIFO // last in, first out model
} MixType; } MixType;
typedef enum { typedef enum {
SERIES, // point time series SERIES, // point time series
@@ -259,7 +262,7 @@ typedef enum {
HEAD, // nodal hydraulic head HEAD, // nodal hydraulic head
PRESSURE, // nodal pressure PRESSURE, // nodal pressure
QUALITY, // nodal water quality QUALITY, // nodal water quality
LENGTH, // link length LENGTH, // link length
DIAM, // link diameter DIAM, // link diameter
FLOW, // link flow rate FLOW, // link flow rate
@@ -270,7 +273,7 @@ typedef enum {
SETTING, // pump/valve setting SETTING, // pump/valve setting
REACTRATE, // avg. reaction rate in link REACTRATE, // avg. reaction rate in link
FRICTION, // link friction factor FRICTION, // link friction factor
POWER, // pump power output POWER, // pump power output
TIME, // simulation time TIME, // simulation time
VOLUME, // tank volume VOLUME, // tank volume
@@ -293,7 +296,7 @@ typedef enum {
ENERHDR, // energy usage header ENERHDR, // energy usage header
NODEHDR, // node results header NODEHDR, // node results header
LINKHDR // link results header LINKHDR // link results header
} HdrType; } HdrType;
typedef enum { typedef enum {
NEGATIVE = -1, // flow in reverse of pre-assigned direction NEGATIVE = -1, // flow in reverse of pre-assigned direction
@@ -302,13 +305,13 @@ typedef enum {
} FlowDirection; } FlowDirection;
typedef enum { typedef enum {
DDA, // demand driven analysis DDA, // demand driven analysis
PDA // pressure driven analysis PDA // pressure driven analysis
} DemandModelType; } DemandModelType;
/* /*
------------------------------------------------------ ------------------------------------------------------
Fundamental Data Structures Fundamental Data Structures
------------------------------------------------------ ------------------------------------------------------
*/ */
@@ -370,7 +373,8 @@ typedef struct // Node Object
double X; // x-coordinate double X; // x-coordinate
double Y; // y-coordinate double Y; // y-coordinate
double El; // elevation double El; // elevation
Pdemand D; // demand pointer // Pdemand D; // demand pointer
list_t *D; // pointer to demand list
Psource S; // source pointer Psource S; // source pointer
double C0; // initial quality double C0; // initial quality
double Ke; // emitter coeff. double Ke; // emitter coeff.
@@ -383,7 +387,7 @@ typedef struct // Link Object
{ {
char ID[MAXID+1]; // link ID char ID[MAXID+1]; // link ID
int N1; // start node index int N1; // start node index
int N2; // end node index int N2; // end node index
double Diam; // diameter double Diam; // diameter
double Len; // length double Len; // length
double Kc; // roughness double Kc; // roughness
@@ -510,7 +514,7 @@ typedef struct s_ActionItem // Action List Item
{ {
int ruleIndex; // index of rule action belongs to int ruleIndex; // index of rule action belongs to
Saction *action; // an action clause Saction *action; // an action clause
struct s_ActionItem *next; // next action on the list struct s_ActionItem *next; // next action on the list
} SactionList; } SactionList;
typedef struct // Mass Balance Components typedef struct // Mass Balance Components
@@ -532,15 +536,15 @@ typedef struct // Mass Balance Components
// Input File Parser Wrapper // Input File Parser Wrapper
typedef struct { typedef struct {
FILE *InFile; // Input file handle FILE *InFile; // Input file handle
char char
DefPatID[MAXID + 1], // Default demand pattern ID DefPatID[MAXID + 1], // Default demand pattern ID
InpFname[MAXFNAME + 1], // Input file name InpFname[MAXFNAME + 1], // Input file name
*Tok[MAXTOKS], // Array of token strings *Tok[MAXTOKS], // Array of token strings
Comment[MAXMSG + 1], // Comment text Comment[MAXMSG + 1], // Comment text
LineComment[MAXMSG + 1]; // Full line comment LineComment[MAXMSG + 1]; // Full line comment
int int
MaxNodes, // Node count from input file */ MaxNodes, // Node count from input file */
MaxLinks, // Link count " " " MaxLinks, // Link count " " "
MaxJuncs, // Junction count " " " MaxJuncs, // Junction count " " "
@@ -559,7 +563,7 @@ typedef struct {
Flowflag, // Flow units flag Flowflag, // Flow units flag
Pressflag, // Pressure units flag Pressflag, // Pressure units flag
DefPat; // Default demand pattern DefPat; // Default demand pattern
Spattern *PrevPat; // Previous pattern processed Spattern *PrevPat; // Previous pattern processed
Scurve *PrevCurve; // Previous curve processed Scurve *PrevCurve; // Previous curve processed
double *X; // Temporary array for curve data double *X; // Temporary array for curve data
@@ -590,7 +594,7 @@ typedef struct {
typedef struct { typedef struct {
FILE *RptFile; // Report file handle FILE *RptFile; // Report file handle
int int
Nperiods, // Number of reporting periods Nperiods, // Number of reporting periods
PageSize, // Lines/page in output report/ PageSize, // Lines/page in output report/
@@ -607,13 +611,13 @@ typedef struct {
long long
LineNum, // Current line number LineNum, // Current line number
PageNum; // Current page number PageNum; // Current page number
char char
Atime[13], // Clock time (hrs:min:sec) Atime[13], // Clock time (hrs:min:sec)
Rpt1Fname[MAXFNAME+1], // Primary report file name Rpt1Fname[MAXFNAME+1], // Primary report file name
Rpt2Fname[MAXFNAME+1], // Secondary report file name Rpt2Fname[MAXFNAME+1], // Secondary report file name
DateStamp[26]; // Current date & time DateStamp[26]; // Current date & time
SField Field[MAXVAR]; // Output reporting fields SField Field[MAXVAR]; // Output reporting fields
} Report; } Report;
@@ -624,19 +628,19 @@ typedef struct {
char char
HydFname[MAXFNAME+1], // Hydraulics file name HydFname[MAXFNAME+1], // Hydraulics file name
OutFname[MAXFNAME+1]; // Binary output file name OutFname[MAXFNAME+1]; // Binary output file name
int int
Outflag, // Output file flag Outflag, // Output file flag
Hydflag, // Hydraulics flag Hydflag, // Hydraulics flag
SaveHflag, // Hydraulic results saved flag SaveHflag, // Hydraulic results saved flag
SaveQflag, // Quality results saved flag SaveQflag, // Quality results saved flag
Saveflag; // General purpose save flag Saveflag; // General purpose save flag
long long
HydOffset, // Hydraulics file byte offset HydOffset, // Hydraulics file byte offset
OutOffset1, // 1st output file byte offset OutOffset1, // 1st output file byte offset
OutOffset2; // 2nd output file byte offset OutOffset2; // 2nd output file byte offset
FILE FILE
*OutFile, // Output file handle *OutFile, // Output file handle
*HydFile, // Hydraulics file handle *HydFile, // Hydraulics file handle
@@ -665,7 +669,7 @@ typedef struct {
*Aij, // Non-zero, off-diagonal matrix coeffs. *Aij, // Non-zero, off-diagonal matrix coeffs.
*F, // Right hand side vector *F, // Right hand side vector
*temp; // Array used by linear eqn. solver *temp; // Array used by linear eqn. solver
int int
Ncoeffs, // Number of non-zero matrix coeffs Ncoeffs, // Number of non-zero matrix coeffs
*Order, // Node-to-row of re-ordered matrix *Order, // Node-to-row of re-ordered matrix
@@ -683,7 +687,7 @@ typedef struct {
// Hydraulics Solver Wrapper // Hydraulics Solver Wrapper
typedef struct { typedef struct {
double double
*NodeHead, // Node hydraulic heads *NodeHead, // Node hydraulic heads
*NodeDemand, // Node demand + emitter flows *NodeDemand, // Node demand + emitter flows
*DemandFlow, // Demand outflows *DemandFlow, // Demand outflows
@@ -711,13 +715,13 @@ typedef struct {
Dcost, // Energy demand charge/kw/day Dcost, // Energy demand charge/kw/day
Emax, // Peak energy usage Emax, // Peak energy usage
RelativeError, // Total flow change / total flow 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 MaxFlowChange, // Max. change in link flow
RelaxFactor, // Relaxation factor for flow updating RelaxFactor, // Relaxation factor for flow updating
*P, // Inverse of head loss derivatives *P, // Inverse of head loss derivatives
*Y, // Flow correction factors *Y, // Flow correction factors
*Xflow; // Inflow - outflow at each node *Xflow; // Inflow - outflow at each node
int int
Epat, // Energy cost time pattern Epat, // Energy cost time pattern
DemandModel, // Fixed or pressure dependent DemandModel, // Fixed or pressure dependent
@@ -730,10 +734,10 @@ typedef struct {
OpenHflag, // Hydraulic system opened flag OpenHflag, // Hydraulic system opened flag
Haltflag; // Flag to halt simulation Haltflag; // Flag to halt simulation
StatusType StatusType
*LinkStatus, // Link status *LinkStatus, // Link status
*OldStatus; // Previous link/tank status *OldStatus; // Previous link/tank status
Smatrix smatrix; // Sparse matrix storage Smatrix smatrix; // Sparse matrix storage
} Hydraul; } Hydraul;
@@ -747,7 +751,7 @@ typedef struct {
int int
Qualflag, // Water quality analysis flag Qualflag, // Water quality analysis flag
OpenQflag, // Quality system opened flag OpenQflag, // Quality system opened flag
Reactflag, // Reaction indicator Reactflag, // Reaction indicator
OutOfMemory, // Out of memory indicator OutOfMemory, // Out of memory indicator
TraceNode, // Source node for flow tracing TraceNode, // Source node for flow tracing
*SortedNodes; // Topologically sorted node indexes *SortedNodes; // Topologically sorted node indexes
@@ -768,17 +772,17 @@ typedef struct {
Bucf, // Bulk reaction units conversion factor Bucf, // Bulk reaction units conversion factor
Tucf, // Tank reaction units conversion factor Tucf, // Tank reaction units conversion factor
BulkOrder, // Bulk flow reaction order BulkOrder, // Bulk flow reaction order
WallOrder, // Pipe wall reaction order WallOrder, // Pipe wall reaction order
TankOrder, // Tank reaction order TankOrder, // Tank reaction order
Kbulk, // Global bulk reaction coeff. Kbulk, // Global bulk reaction coeff.
Kwall, // Global wall reaction coeff. Kwall, // Global wall reaction coeff.
Climit, // Limiting potential quality Climit, // Limiting potential quality
SourceQual, // External source quality SourceQual, // External source quality
*NodeQual, // Reported node quality state *NodeQual, // Reported node quality state
*PipeRateCoeff; // Pipe reaction rate coeffs. *PipeRateCoeff; // Pipe reaction rate coeffs.
struct Mempool struct Mempool
*SegPool; // Memory pool for water quality segments *SegPool; // Memory pool for water quality segments
Pseg Pseg
FreeSeg, // Pointer to unused segment FreeSeg, // Pointer to unused segment
@@ -808,7 +812,7 @@ typedef struct {
Nrules, // Number of control rules Nrules, // Number of control rules
Npats, // Number of time patterns Npats, // Number of time patterns
Ncurves; // Number of data curves Ncurves; // Number of data curves
Snode *Node; // Node array Snode *Node; // Node array
Slink *Link; // Link array Slink *Link; // Link array
Stank *Tank; // Tank array Stank *Tank; // Tank array
@@ -836,13 +840,13 @@ typedef struct Project {
Rules rules; // Rule-based controls wrapper Rules rules; // Rule-based controls wrapper
Hydraul hydraul; // Hydraulics solver wrapper Hydraul hydraul; // Hydraulics solver wrapper
Quality quality; // Water quality solver wrapper Quality quality; // Water quality solver wrapper
double Ucf[MAXVAR]; // Unit conversion factors double Ucf[MAXVAR]; // Unit conversion factors
int int
Openflag, // Project open flag Openflag, // Project open flag
Warnflag; // Warning flag Warnflag; // Warning flag
char char
Msg[MAXMSG+1], // General-purpose string: errors, messages Msg[MAXMSG+1], // General-purpose string: errors, messages
Title[MAXTITLE][TITLELEN+1], // Project title Title[MAXTITLE][TITLELEN+1], // Project title
@@ -850,9 +854,9 @@ typedef struct Project {
TmpHydFname[MAXFNAME+1], // Temporary hydraulics file name TmpHydFname[MAXFNAME+1], // Temporary hydraulics file name
TmpOutFname[MAXFNAME+1], // Temporary output file name TmpOutFname[MAXFNAME+1], // Temporary output file name
TmpStatFname[MAXFNAME+1]; // Temporary statistic 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; } Project, *EN_Project;
#endif #endif