-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_cost_single.m
102 lines (72 loc) · 2.67 KB
/
get_cost_single.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
%....................Cost function............%
function cost = get_cost_single(x)
global max_col;
global max_row;
global filename;
global index_wells;
global glo_stress_period;
global all_cost;
global well_position_mat;
global cp;
global gen_wise_data;
f_name = [filename '.mfs'];
cost = ones([size(x,1) 2]);
d = ones([size(x,1) 1]);
..............read well data to update file...%
% well_data = read_well();
% well_data.discharge(:) = x;
% write_well(well_data);
total_discharge = 0;
temp = h5read([filename '.h5'],'///Well/07. Property');
arcs = size(temp,2) - size(index_wells,2);
for p = 1:size(x,1)
xn = x(p,:);
temp = h5read([filename '.h5'],'///Well/07. Property');
total_discharge = 0;
for i = 1:numel(xn)
temp(:,[false([1 arcs]) index_wells(i,:)],1) = ones(glo_stress_period,sum(index_wells(i,:))).*xn(i);
% total discharge calculated
total_discharge = total_discharge + xn(i)*sum(index_wells(i,:));
end
h5write([filename '.h5'],'///Well/07. Property',temp);
% Runmodflow
[s t] = system(sprintf('mf2k_h5.exe "%s" ', f_name));
if(contains(t,'Error'))
cost(p,1) = 1000000;
cost(p,2) = 1000000;
else
temp3 = readDat([filename '.hed']);
if size(temp3,1)<glo_stress_period
% penalty multiplied by the number of unconverged stress periods
cost(p,1) = 100000*(glo_stress_period-size(temp3,1));
cost(p,2) = 100000*(glo_stress_period-size(temp3,1));
else
temp2 = reading_ccf();
temp2 = temp2{7,glo_stress_period*8};
total_leakage_out = sum(temp2(temp2(:)<0));
% leakage out is negative and is needed to be maximised
cost(p,1) = total_leakage_out;
% discharge -> negative, (maximization)
cost(p,2) = total_discharge; % total_discharge
% add constraints to drawdown
temp = readDat([filename '.drw']);
drawdown = temp(end).values;
dd = drawdown(well_position_mat);
dd_threshold = 2;
index = dd>dd_threshold;
dd_distance = sqrt(sum((dd(index)-dd_threshold).^2));
% drawndown should not be greater than 2.
% decreasing the magnitude as penalty
cost = cost(p,1) + cost(p,2) + cp*dd_distance ;
% cost(p,2) = cost(p,2) + cp*dd_distance ;
d(p) = dd_distance;
% only valid solutions without penalty are recorded in the
% variable all_cost
end
end
end
gen_wise_data{end+1,1} = {x};
gen_wise_data{end,2} = {cost};
gen_wise_data{end,3} = {d};
all_cost = vertcat(all_cost,[cost d x]);
end