Defining pattern time for valves setting in EPANET


#1

Hi all,
Is it possible to define a pattern time for valves in EPANET 2.00.12 and the EPANET-MATLAB Toolkit?
There are pattern option for junctions, reservoirs and pumps to define several pattern time but it isn’t this options for valves.
I want to create a pattern time for PRV setting in my network.
Thanks


#2

Hi Alireza,

I can suggest you two options to create a pattern time for PRV setting.

You can edit the setting in valve step-by-step or you can add many controls for valve!

Check the example below:

%Add paths and load inp file
addpath(genpath(pwd));
d=epanet(‘BWSN_Network_1.inp’);

% Get times
hydstep = d.getTimeHydraulicStep;
duration = d.getTimeSimulationDuration;

% Create random settings
a = 60; b = 90;
settings = (b-a).*rand((duration/hydstep)+1,1) + a;

% Settings for valve ‘VALVE-173’
valveID = ‘VALVE-173’;
valveIndex = d.getLinkIndex(valveID);

% Check pressures at node after valve
nodeIndex = d.getNodeIndex(‘JUNCTION-112’);

%% Change setting step by step
% Runs hydraulics Step-by-step
d.openHydraulicAnalysis;
d.initializeHydraulicAnalysis;
tstep=1; T=[]; P=[];
i=1;
while (tstep>0)
t=d.runHydraulicAnalysis;
if mod(t,hydstep)==0
d.setLinkSettings(valveIndex,settings(i));i=i+1;
end
P=[P; d.getNodePressure];
T=[T; t];
tstep=d.nextHydraulicAnalysisStep;
end
d.closeHydraulicAnalysis;
d.unload;

%% Change setting via controls
%Load again the same input file
d=epanet(‘BWSN_Network_1.inp’);

settings = [d.getLinkInitialSetting(valveIndex) settings’]’;
settings = num2str(settings,’%04.4f’);

hrs = duration/3600;
hours = 0:hrs;
step = 0:hydstep/60:55; %step 30min
i=1; Time = cell(hrs,1);
for u=1:hrs
for j=1:length(step)
Time{i} = sprintf(’%03d:%02d:00’,hours(u),step(j));
Controls(i,: ) = [‘LINK ‘,valveID,’ ‘,settings(i,:),’ AT TIME ‘,Time{i}];
i=i+1;
end
end
Time{i} = sprintf(’%03d:%02d:00’,duration/3600,0);
Controls(i,: ) = ['LINK ‘,valveID,’ ‘,settings(i,:),’ AT TIME ',Time{i}];

d.addBinControl(Controls);
Sim = d.getComputedHydraulicTimeSeries;
d.unload;

%%Plots
figure;
ignoreEvents = find(mod(T,double(hydstep))==0);
plot(T(ignoreEvents)/3600,P(ignoreEvents,nodeIndex));
hold on;
plot(Sim.Time(ignoreEvents)/3600,Sim.Pressure(ignoreEvents,nodeIndex),‘r’);
legend(‘Change setting step-by-step’, ‘Change setting via Controls’);

P.S. Check for updates EPANET-Matlab-Toolkit(dev-2.1b)..

Thanks,
Marios


#3

Thank you very much Dear Mariosmask,
The code was very useful. In the first section that was written without controls, is it possible to save the pattern for PRV setting in .inp file?


#4

Also, is it possible to write the first section of this code with “BinWithoutDLL” functions, completely?


#5

Hi,

No, you can’t save the pattern for PRV setting except if you want to save the setting like you save the pattern and after you can use the steps (e.g., Change setting step by step) of the above example. You can’t run the step by step code with “BinWithoutDLL”. So, you can use the example below without using the dll functions .

%%BinWithoutDLL

%Add paths and load inp file
addpath(genpath(pwd));
d=epanet(‘BWSN_Network_1.inp’,‘Bin’);

% Get times
t = d.getBinTimesInfo;
hydstep = t.BinTimeHydraulicStep;
duration = t.BinTimeSimulationDuration;

% Create random settings
a = 60; b = 90;
settings = (b-a).*rand((duration/hydstep)+1,1) + a;

% Settings for valve ‘VALVE-173’
valveID = ‘VALVE-173’;
valveIndex = d.getBinLinkIndex(valveID);

% Check pressures at node after valve
nodeIndex = d.getBinNodeIndex(‘JUNCTION-112’);
settings = num2str(settings,’%04.4f’);

hrs = duration/3600;
hours = 0:hrs;
step = 0:hydstep/60:55; %step 30min
i=1; Time = cell(hrs,1);
for u=1:hrs
for j=1:length(step)
Time{i} = sprintf(’%03d:%02d:00’,hours(u),step(j));
Controls(i,: ) = ['LINK ‘,valveID,’ ‘,settings(i,:),’ AT TIME ',Time{i}];
i=i+1;
end
end

d.addBinControl(Controls);

% Run simulation with executable
Sim = d.getBinComputedAllParameters;

d.saveBinInpFile(‘NetwithControls.inp’);
d.BinClose;

figure;
plot(Sim.BinnodePressure(:,nodeIndex));


#6

Hello,
Thank you very much for this code.
I receive the error at below line:

Controls(i,: ) = ['LINK ‘,valveID,’ ‘,settings(i,:),’ AT TIME ',Time{i}];

the error is:
Subscripted assignment dimension mismatch.

Thanks,
Alireza


#7

Dear All,
i’m new in that. i have to do the same in vba code, do you know how to write that in vba?
thanks so much