-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCalcCostFunctionLevelSetEquation.m
67 lines (41 loc) · 1.32 KB
/
CalcCostFunctionLevelSetEquation.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
function [r,UserVar,RunInfo,rForce,rWork,D2]=CalcCostFunctionLevelSetEquation(UserVar,RunInfo,CtrlVar,MUA,gamma,F1,F0,L,Lrhs,l,dLSF,dl,BCs)
narginchk(13,13)
nargoutchk(1,6)
%
%
%
%
MLC=BCs2MLC(CtrlVar,MUA,BCs);
L=MLC.LSFL ; Lrhs=MLC.LSFRhs ;
if isempty(l) || (numel(l)~=numel(Lrhs))
l=Lrhs*0 ;
end
if isempty(dl) || (numel(dl)~=numel(Lrhs))
dl=Lrhs*0 ;
end
if isempty(dLSF) || (numel(dLSF)~=numel(F1.LSF))
dLSF=F1.LSF*0;
end
F1.LSF=F1.LSF+gamma*dLSF;
l=l+gamma*dl;
[UserVar,R]=LevelSetEquationAssemblyNR2(UserVar,CtrlVar,MUA,F0,F1) ;
%[UserVar,R]=LevelSetEquationAssemblyNR2(UserVar,CtrlVar,MUA,F0.LSF,F0.c,F0.ub,F0.vb,F1.LSF,F1.c,F1.ub,F1.vb,F0.LSFqx,F0.LSFqy,F1.LSFqx,F1.LSFqy);
if ~isempty(L)
frhs=-R-L'*l; % Units: Area [\varphi] / time
grhs=Lrhs-L*F1.LSF; % Units: [\varphi]=distance, but this should always be zero anyhow if initial point is feasable
else
frhs=-R;
grhs=[];
end
frhs=frhs/MUA.Area; % It's OK to do this only here, because I scale frhs and grhs equally.
grhs=grhs/MUA.Area;
D2=[frhs;grhs]'*[dLSF;dl];
rWork=full(D2^2);
rForce=full([frhs;grhs]'*[frhs;grhs]);
switch CtrlVar.LSFMinimisationQuantity
case "Force Residuals"
r=rForce;
case "Work Residuals"
r=rWork;
end
end