function [Err] = ObjFxn_HM_PROXY(x,S_struct) global S_struct inj = S_struct.inj; qp = S_struct.qp; T = S_struct.T; cinj = S_struct.cinj; cwf = S_struct.cwf; % NDiv = S_struct.NDiv; Lwell = S_struct.Lwell; mwell_i = S_struct.mwell_i; mwell_p = S_struct.mwell_p; ni = length(mwell_i); np = length(mwell_p); TC = ni*np; Np = size(x,1); Err = zeros(Np,1); parfor i=1:Np xx = x(i,:); xx = xx'; count = 0; cwf_prod = zeros(length(T),np); % inj = 10^xx(end-1)*ones(size(qp,1),1); % cinj = xx(end); for ii = 1:ni len1 = np*(ii-1)+1; len2 = np*ii; fij = xx(len1:len2); %fij for corresponding injector with all producer for pp = 1:np sum1 = 0; f = xx(pp:np:TC); %fij for corresponding producer with all injector for i1 = 1:ni sum1 = sum1 + (f(i1)*inj(:,i1)); end qp1 = (qp(:,pp)*f(ii).*inj(:,ii))./sum1; inj1 = inj(:,ii)*fij(pp); len3 = TC + count+1; len4 = 2*TC + count+1; len5 = 3*TC + count+1; len6 = 4*TC + count+1; Vp = xx(len3); D = xx(len4); qf = xx(len5); NDiv = round(xx(len6)); cwf_prod(:,pp) = cwf_prod(:,pp) + ADE_model(qp1,inj1,T,cinj,NDiv,Lwell(count+1),Vp,D,qf); count = count + 1; end end Err1 = cwf_prod(:,1)-cwf(:,1); Err2 = cwf_prod(:,2)-cwf(:,2); Err3 = cwf_prod(:,3)-cwf(:,3); Err4 = cwf_prod(:,4)-cwf(:,4); % Err4 = cwf_prod(:,4)-cwf(:,4); % Err(i) = (sqrt(Err1'*Err1)/length(Err1)); Err(i) = (sqrt(Err1'*Err1)/length(Err1)) + (sqrt(Err2'*Err2)/length(Err2)) + (sqrt(Err3'*Err3)/length(Err3))+ (sqrt(Err4'*Err4)/length(Err4)); if isnan(Err(i)) Err(i) = 1e5; end end