Is it possible to simulate scenarios without using EPANET-MSX?


#1

Hi,
A question has come to my mind, is there any answer?
If the simple simulation be the same simulation that is done only by EPANET not by EPANET-MSX.
Is it possible to do a simple simulation with MATLAB?
I mean , Can we simulate a scenario in EMT without using Epanet-MSX ?
If we can, how?

Thanks


#2

@Atosa, EPANET-MSX just use for multi-species analysis quality in network and you can apply EPANET for hydraulic and simple quality analysis. I mean, if you want to consider only one concentration such as computing chlorine residual at nodes, you can use EPANET. In the other words, MSX use for advanced quality analysis at water distribution network. EMT is a package which includes EPANET and EPANET-MSX functions.


#3

Hi Mr @alireza2032 , سال نو مبارک
Thanks a lot!
I just want to simulate the injection of Arsenic, but I don’t know exactly what command and function should l use.
I wanted to generate 200 scenarios, first I tried to do this without using the MATLAB code and alone with EPANET. But it takes a long time!
In fact, I want to generate 200 scenarios in the form below
Each contamination scenario consists of a single EPANET mass injection event of rate 57000 and duration 6h. And the duration of entire simulation be 48h.
My network:
bangalore_epanet.inp (46.8 KB)

Thanks again


#4

I created 3 new time pattern with ID 2 to 4,
And I tried to use the available functions defined for EPANET,
But I didn’t see a function like “getComputedNodeQuality” and I’ve got error too!



close all; clear; rng(1)

%% Load EPANET Network 
G = epanet('bangalore_epanet.inp'); % Load EPANET Input file


% Sensor locations

sensor_id = G.getNodeNameID 
sensor_index = G.getNodeIndex(sensor_id);

%% Simulation Setup

t_d = 2; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 2 days

%% Get Network data
demand_pattern = G.getPattern;
roughness_coeff = G.getLinkRoughnessCoeff;
node_id = G.getNodeNameID;

%% Scenarios
Ns = 1; % Number of scenarios to simulate
u_p = 0.20; % pattern uncertainty
u_r = 0.20; % roughness coefficient uncertainty
max_inj_conc = 2.0;
inj_start_time =0; %(Dt = 1h)
inj_duration = 24; % maximum duration of 8 hours
inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(8,Ns,1)+inj_start_time, randi(inj_duration,Ns,1)]; % Injection location, magnitude, start time, duration 

PatternIndex=[2,3,4];

%% Run epochs
    % Randomize hydraulics
    r_p = -u_p + 2*u_p.*rand(size(demand_pattern,1),size(demand_pattern,2));
    new_demand_pattern = demand_pattern + demand_pattern.*r_p;
    G.setPatternMatrix(new_demand_pattern); % Set new patterns
    r_r = -u_r + 2*u_r.*rand(size(roughness_coeff,1),size(roughness_coeff,2));
    new_roughness_coeff = roughness_coeff + roughness_coeff.*r_r;
    G.setLinkRoughnessCoeff(new_roughness_coeff); % Set new roughness coefficients
tic
for i = 1:Ns
    for timepatt=1:3
    disp(['Iteration ', int2str(i)])

    % Randomize injection
    	
    G.NodeSourceQuality=57000; % Specify Arsenite injection source
    G.setNodeSourceType='Setpoint';
    G.setNodeSourcePatternIndex=PatternIndex(timepatt);
    
    Q{i} = G.getBinComputedNodeQuality(sensor_index); % Solve hydraulics and quality dynamics
    end
   
end
toc

Can anyone guide me?
How to use these functions: G.setNodeSourceType, G.NodeSourceQuality?

Thanks in advance!


#5

I have added an example without MSX here Example16 - Create scenarios

Also, you can check out the S-PLACE Toolkit v2.1 pre-released.

S-PLACE Toolkit paper


#6

Hi @Mariosmsk Great! you’re awesome. This is exactly what I was looking for. Really thanks. :slight_smile:


#7

I have made some changes:

close all; clear; 

%% Load EPANET Network 
G = epanet('bangalore_epanet.inp'); % Load EPANET Input file

G.setQualityType('chem','mg/L');

% Sensor locations

sensor_id = G.getNodeNameID 
sensor_index = G.getNodeIndex(sensor_id);

%% Simulation Setup

t_d = 2; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 2 days

%% Get Network data
demand_pattern = G.getPattern;
roughness_coeff = G.getLinkRoughnessCoeff;
node_id = G.getNodeNameID;

%% Scenarios
Ns = 10; % Number of scenarios to simulate
u_p = 0.20; % pattern uncertainty
u_r = 0.20; % roughness coefficient uncertainty
max_inj_conc = 2.0;
inj_start_time =0; %(Dt = 1h)
inj_duration = 24; % maximum duration of 8 hours
inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(8,Ns,1)+inj_start_time, randi(inj_duration,Ns,1)]; % Injection location, magnitude, start time, duration 

PatternIndex=[2,3,4];

%% Run epochs
% Randomize hydraulics
zeroNodes=zeros(1,G.getNodeCount);
for i = 1:Ns
    tic
    r_p = -u_p + 2*u_p.*rand(size(demand_pattern,1),size(demand_pattern,2));
    new_demand_pattern = demand_pattern + demand_pattern.*r_p;
    PAT_INDEX = G.addPattern('new_PAT', new_demand_pattern); % Set new patterns
    r_r = -u_r + 2*u_r.*rand(size(roughness_coeff,1),size(roughness_coeff,2));
    new_roughness_coeff = roughness_coeff + roughness_coeff.*r_r;
    G.setLinkRoughnessCoeff(new_roughness_coeff); % Set new roughness coefficients
    disp(['Iteration ', int2str(i)])

    tmp_values = zeroNodes;
    % Randomize injection
    G.setNodeSourceType(inj_sc(i,1),'SETPOINT')
    tmp_values(inj_sc(i,1)) = 57000;
    G.setNodeSourceQuality(tmp_values)
    tmp_values_pat_ind = zeroNodes;
    tmp_values_pat_ind(inj_sc(i,1)) = PAT_INDEX;
    G.setNodeSourcePatternIndex(tmp_values_pat_ind)

    Q{i} = G.getComputedQualityTimeSeries('quality', sensor_index).NodeQuality; % Solve hydraulics and quality dynamics
   figure;
    plot(Q{i})
end
toc
Q

#8

I don’t know how to thank you enough! Thanks so much!


#9

Hi,

I wanted to make an injection at each node (For 6 h and at time 0), So I changed the code, but Why are the results (by MATLAB and EPANET) not the same?

My change:
first I set the time period reporting time step = 5 minutes

close all; clear; 

%% Load EPANET Network 
G = epanet('bangalore_epanet.inp'); % Load EPANET Input file

G.setQualityType('chem','mg/L');

% Sensor locations

sensor_id = G.getNodeNameID 
sensor_index = G.getNodeIndex(sensor_id);

%% Simulation Setup

t_d = 2; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 2 days
G.setTimeReportingStep(300);	
%% Get Network data
demand_pattern = G.getPattern;
roughness_coeff = G.getLinkRoughnessCoeff;
node_id = G.getNodeNameID;

%% Scenarios
Ns = 1; % Number of scenarios to simulate
u_p = 0.20; % pattern uncertainty
u_r = 0.20; % roughness coefficient uncertainty
max_inj_conc = 2.0;
inj_start_time =0; %(Dt = 1h)
inj_duration = 6; % maximum duration of 6 hours
row=1;

for node=1:double(G.NodeCount)
        inj_sc(row,:)=[node , 1, 0 , 6]; 
        %Injection location, magnitude, start time, duration 
        row=row+1;
end

%inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(8,Ns,1)+inj_start_time, randi(inj_duration,Ns,1)]; % Injection location, magnitude, start time, duration 

PatternIndex=[2,3,4];

%% Run epochs
% Randomize hydraulics
zeroNodes=zeros(1,G.getNodeCount);
for i = 1:Ns
    tic
    r_p = -u_p + 2*u_p.*rand(size(demand_pattern,1),size(demand_pattern,2));
    new_demand_pattern = demand_pattern + demand_pattern.*r_p;
    PAT_INDEX = G.addPattern('new_PAT', new_demand_pattern); % Set new patterns
    r_r = -u_r + 2*u_r.*rand(size(roughness_coeff,1),size(roughness_coeff,2));
    new_roughness_coeff = roughness_coeff + roughness_coeff.*r_r;
    G.setLinkRoughnessCoeff(new_roughness_coeff); % Set new roughness coefficients
    disp(['Iteration ', int2str(i)])

    tmp_values = zeroNodes;
    % Randomize injection
    G.setNodeSourceType(inj_sc(i,1),'SETPOINT')
    tmp_values(inj_sc(i,1)) = 57000;
    G.setNodeSourceQuality(tmp_values)
    tmp_values_pat_ind = zeroNodes;
    tmp_values_pat_ind(inj_sc(i,1)) = PAT_INDEX;
    G.setNodeSourcePatternIndex(tmp_values_pat_ind)

    Q{i} = G.getComputedQualityTimeSeries('quality', sensor_index).NodeQuality; % Solve hydraulics and quality dynamics
   figure;
    plot(Q{i})
end
toc
Q

But the results are not the same in MATLAB and EPANET!

For example, if we only have one scenario

image

The results for node 2 are as follows

image

But the node2 will not be affected at any time by injection into node 1.

Do I make a mistake?What’s wrong?

Thanks in advance!


#10

Hi,
Results in the Q cell array are based on the indexes?
it’s true?
The element in row 6 and column 21 means = At the sixth time, in the Node with index 21 ,concentration= 68000

Thanks in avance!


#11

@Atosa, Yes, The columns in the Q matrix refer to nodes index and the rows refer to time. Pay attestation, each row is for a time step report (5 minutes in your program).


#12

Yes @Atosa. row is the time step , column is the node index


#13

Hi @alireza2032 and @Mariosmsk , Thanks. So I confused the ID and Index.
Thanks again!