added function updateruleunits

This commit is contained in:
Luke Butler
2023-03-30 16:22:58 -04:00
parent 56c569b56f
commit 9cde32080a
6 changed files with 415 additions and 80 deletions

View File

@@ -549,6 +549,126 @@ int checkrules(Project *pr, long dt)
return actionCount;
}
void updateruleunits(Project *pr, double dcf, double pcf, double hcf, double qcf)
//-----------------------------------------------------------
// Updates the units of a rule's premises and actions.
//-----------------------------------------------------------
{
Network *net = &pr->network;
Slink *Link = net->Link;
int i, k;
double x;
Spremise *p;
Saction *a;
for (i = 1; i <= net->Nrules; i++)
{
p = net->Rule[i].Premises;
while (p != NULL)
{
switch (p->variable)
{
case r_DEMAND:
p->value *= dcf;
break;
case r_HEAD:
case r_GRADE:
p->value *= hcf;
break;
case r_PRESSURE:
p->value *= pcf;
break;
case r_LEVEL:
p->value *= hcf;
break;
case r_FLOW:
p->value *= qcf;
break;
case r_SETTING:
switch (Link[p->index].Type)
{
case PRV:
case PSV:
case PBV:
p->value *= pcf;
break;
case FCV:
p->value *= qcf;
break;
default:
break;
}
break;
default:
break;
}
p = p->next;
}
a = net->Rule[i].ThenActions;
while (a != NULL)
{
k = a->link;
x = a->setting;
// Change link's setting
if (x != MISSING)
{
switch (net->Link[k].Type)
{
case PRV:
case PSV:
case PBV:
a->setting *= pcf;
break;
case FCV:
a->setting *= qcf;
break;
default:
break;
}
}
a = a->next;
}
a = net->Rule[i].ElseActions;
while (a != NULL)
{
k = a->link;
x = a->setting;
// Change link's setting
if (x != MISSING)
{
switch (net->Link[k].Type)
{
case PRV:
case PSV:
case PBV:
a->setting *= pcf;
break;
case FCV:
a->setting *= qcf;
break;
default:
break;
}
}
a = a->next;
}
}
}
void newrule(Project *pr)
//----------------------------------------------------------
// Adds a new rule to the project