"Reference to non-existent field 'msxFile' "What does this error mean?


#1

Hi,

I had already read this question.I also liked to try it.I downloaded and replaced the files.
But I got this error!

EPANET-MATLAB Toolkit Paths Loaded.

 EPANET loaded sucessfuly.
 Input File "bangalore_epanet.inp" loaded sucessfuly.
Reference to non-existent field 'msxFile'.

Error in epanet/writeMSXFile (line 3747)
            f = writenewTemp(msx.msxFile);

Error in EX15_write_msx_file (line 74)
d.writeMSXFile(msx);

What should I do to fix the error?
bangalore_epanet.inp (46.8 KB)

Thanks


#2

@Atosa, Please make sure to replace your epanet.m


#3

Hi @Mariosmsk , Thanks a lot! You are right . I copied it again and this time it worked .
But now I have another problem, I used this code

%%  Case Study for CCWI2016

close all; clear; rng(1)

%% Load EPANET Network and MSX
G = epanet('bangalore_epanet.inp'); % Load EPANET Input file
G.loadMSXFile('bangalore.msx'); % Load MSX file

% Sensor locations
sensor_id = {'4', '19'};
%sensor_id = G.getNodeNameID 
sensor_index = G.getNodeIndex(sensor_id);

%% Simulation Setup

t_d = 3; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 5 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; % after day 2 (Dt = 30min)
inj_duration = 24; % maximum duration of 12 hours
inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(12,Ns,1)+inj_start_time, randi(inj_duration,Ns,1)]; % Injection location, magnitude, start time, duration 

%% Run epochs
tic
for i = 1:Ns
    disp(['Iteration ', int2str(i)])
    % 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
    % Randomize injection
    G.setMSXSources(node_id(inj_sc(i,1)), 'AsIII', 'Setpoint', inj_sc(i,2), 'AS3PAT'); % Specify Arsenite injection source
    as3_pat = zeros(1, t_d*48);
    as3_pat(inj_sc(i,3):(inj_sc(i,3)+inj_sc(i,4))) = 1; % 
    G.setMSXPattern('AS3PAT',as3_pat); % Set pattern for injection
    Q{i} = G.getMSXComputedQualityNode(sensor_index); % Solve hydraulics and MSX quality dynamics
    G.setMSXSources(node_id(inj_sc(i,1)), 'AsIII', 'Setpoint', 0, 'AS3PAT'); % Reset injection source
end
toc
G.unloadMSX


%
%% Plot results
for i = 1:Ns
    for j = 1:length(sensor_index)
       subplot(5,1,j)
       plot(Q{i}.Time/24/60/60, Q{i}.Quality{j}(:,1),'-','Color',[0,0.7,0.9]); hold on; grid on
    end
end
for i = 1:length(sensor_index)
   subplot(5,1,i)
   title(sensor_id{i})
   ylabel('Cl_2 (mg/L)')
   xlabel('Time (days)')
end
%

I got this error

EPANET loaded sucessfuly.
Input File "bangalore_epanet.inp" loaded sucessfuly.
Iteration 1

Error 517 - reference made to an undefined object ID.
Error 517 - reference made to an undefined object ID.
Error 516 - reference made to an illegal object index.
Error 517 - reference made to an undefined object ID.
Error 516 - reference made to an illegal object index.
Error 517 - reference made to an undefined object ID.
Error 517 - reference made to an undefined object ID.
Error 516 - reference made to an illegal object index.
Elapsed time is 0.327533 seconds.
MSX unloaded

but got the answer!
Are these results correct?

bangalore_epanet.inp (46.8 KB)

and This is MSX file

[TITLE]


[OPTIONS]
AREA_UNITS     FT2
RATE_UNITS     DAY
SOLVER     EUL
COUPLING     NONE
COMPILER     NONE
TIMESTEP     300
ATOL     0.001
RTOL     0.001

[SPECIES]
BULK CL2 MG 0.01 0.001

[COEFFICIENTS]
PARAMETER Kb 0.3
PARAMETER Kw 1

[TERMS]
Kf 1.5826e-4 * RE^0.88 / D

[PIPES]
RATE CL2 -Kb*CL2-(4/D)*Kw*Kf/(Kw+Kf)*CL2

[TANKS]
RATE CL2 -Kb*CL2

[SOURCES]
CONC 1 CL2 0.8 

[QUALITY]
NODE 26 CL2 0.1
Global CL2 0.5

[PARAMETERS]


[PATTERNS]
[REPORT]
NODES ALL
LINKS ALL

Thanks


#4

@Atosa, I check you code and MSX file. There are some errors in you MSX file:
1- You use ‘AsIII’ specie in your code but there isn’t ‘AsIII’ in your MSX file.
2- Also you introduce ‘AS3PAT’ pattern in code but in MSX file it’s undefined in [PATTERN] section.
Error 517 & 516 are related two points mentioned above. I suggest use from a sample MSX file such as Arsenite.msx and make your changes in it.


#5

@alireza2032 , Ok, I’ll try it, thanks very much for your help.