-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI_Panels_method.m
1572 lines (1371 loc) · 63.4 KB
/
GUI_Panels_method.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = GUI_Panels_method(varargin)
%% GUI FOR THE PANEL METHOD IMPLEMENTATION
% Authors:
% Martínez Ibáñez, Josep Balbino
% Matoses Gimenez, Andreu
% Ortiz Moya, Álvaro
% Ruiz López, Álvaro
% Soriano Pascual, Fernando
%
% UPV Aerodynamics
% 31/05/2019
%% LICENCE
% MIT License Copyright (c) 2019 uerdnaGitHub
%
% Permission is hereby granted, free of charge, to any person obtaining a
% copy of this software and associated documentation files (the
% "Software"), to deal in the Software without restriction, including
% without limitation the rights to use, copy, modify, merge, publish,
% distribute, sublicense, and/or sell copies of the Software, and to permit
% persons to whom the Software is furnished to do so, subject to the
% following conditions:
%
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
% NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
% OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
% USE OR OTHER DEALINGS IN THE SOFTWARE.
%% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_Panels_method_OpeningFcn, ...
'gui_OutputFcn', @GUI_Panels_method_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI_Panels_method is made visible.
function GUI_Panels_method_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_Panels_method (see VARARGIN)
% Choose default command line output for GUI_Panels_method
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_Panels_method wait for user response (see UIRESUME)
% uiwait(handles.figure1);
clear; clc;
% Define colors
global colors colorines
colors.facemodel=[0.8 0.8 1.0]; colors.edgemodel='none'; colors.sectionplane='red';
colors.sectionpoints=[0.7,0,0.7]; colors.xysection='k'; colors.arrows='r';
colors.panelvertex=[0.7,0.2,0]; colors.panelmidpoints=[0.7,0.7,0];
colors.uppercp=[0.7,0.2,0]; colors.lowercp=[0.7,0.7,0];
colorines={[0 0 1]; [0 1 0]; [1 0 0]; [0 1 1]; [1 0 1]; [1 1 0]; [0 0 0]; [0.8 0.8 1.0]; [0.7,0,0.7]; [0.7,0.7,0]; [0.7,0.2,0]; [0 0 1]; [0 1 0]; [1 0 0]; [0 1 1]; [1 0 1]; [1 1 0]; [0 0 0]; [0.8 0.8 1.0]; [0.7,0,0.7]; [0.7,0.7,0]; [0.7,0.2,0]};
numberimage=1;
numberdata=1;
% Add path of used functions
addpath('functions\');
% --- Outputs from this function are returned to the command line.
function varargout = GUI_Panels_method_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in tglopen.
function tglopen_Callback(hObject, eventdata, handles)
% hObject handle to tglopen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global geometry section panels solutionplot colors solutionplot_fill solution_colorbar streamplot streamplot_fill contourplot contourplot_fill contourplot_colorbar
% Reset all panels to zero
set(handles.txtsection,'String','Information about current section');
set(handles.tglsection,'Enable','off');
set(handles.lblsectionpoint,'Enable','off');
set(handles.lblsectionvector,'Enable','off');
set(handles.tgldiscretize,'Enable','off');
set(handles.lblnpanels,'Enable','off');
set(handles.lblslpsens,'Enable','off');
set(handles.poptypesolver,'Enable','off');
set(handles.lblangleincidencestart,'Enable','off');
set(handles.lblangleincidencestep,'Enable','off');
set(handles.lblangleincidenceend,'Enable','off');
set(handles.tglsolve,'Enable','off');
set(handles.lblvelocity,'Enable','off');
set(handles.tglinvert,'Enable','off');
set(handles.lblrotate,'Enable','off');
set(handles.lblxtrans,'Enable','off');
set(handles.lblytrans,'Enable','off');
% File explorer to select geometry
[geometry.name, geometry.path]=uigetfile('.stl','Select a geometry');
% Check that an geometry in .stl format has been selected
if strfind(geometry.name,'.stl')
% Indicate the name of the geometry file in the static text: txtopen
set(handles.txtopen,'String',geometry.name);
% Add the path of the geometry and read it
addpath(geometry.path);
geometry.model=stlread(geometry.name);
% Delete previous plot and plot the new geometry, lights, material...
try
delete(geometry.plot.model)
delete(geometry.plot.light)
catch
end
try
delete(section.plot.surf)
delete(section.plot.intersec)
catch
end
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
delete(panels.plot)
delete(panels.plot_text)
delete(panels.plot_midpoints)
catch
end
try
delete(solutionplot)
delete(solutionplot_fit)
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
geometry.plot.model=patch(handles.axplot,geometry.model,'FaceColor',colors.facemodel,...
'EdgeColor',colors.edgemodel,'FaceLighting','gouraud',...
'AmbientStrength',0.15,'FaceAlpha',0.5); % Represent the model
hold(handles.axplot,'on'); % Hold the graph to add other geometries
geometry.plot.light=light(handles.axplot); % Add a light
xlabel(handles.axplot,'x [m]'); % Label of each axes
ylabel(handles.axplot,'y [m]');
zlabel(handles.axplot,'z [m]');
title('')
material('metal'); % Change the material of the model
axis('image'); % Select the scale of the axes
view([45 35]); % Indicate the perspective angle
legend('Geometry','Location','northeast'); % Add the legend
% Activate the selection of the section plane
set(handles.lblsectionpoint,'Enable','on');
set(handles.lblsectionvector,'Enable','on');
% Read the position of the section plane and plot it
section_evaluation(hObject, eventdata, handles);
% If the selected file is not a valid .stl file indicate it
else
% Delete, if any, geometry and section
try
delete(geometry.plot.model)
delete(geometry.plot.light)
catch
end
try
delete(section.plot.surf)
delete(section.plot.intersec)
catch
end
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
delete(panels.plot)
delete(panels.plot_text)
delete(panels.plot_midpoints)
catch
end
try
delete(solutionplot)
delete(solutionplot_fit)
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
% Change texts and status of buttons
set(handles.txtopen,'String','Invalid file');
set(handles.txtsection,'String','Information about current section');
set(handles.tglsection,'Enable','off');
set(handles.lblsectionpoint,'Enable','off');
set(handles.lblsectionvector,'Enable','off');
set(handles.tgldiscretize,'Enable','off');
set(handles.lblnpanels,'Enable','off');
set(handles.lblslpsens,'Enable','off');
set(handles.poptypesolver,'Enable','off');
set(handles.lblangleincidencestart,'Enable','off');
set(handles.lblangleincidencestep,'Enable','off');
set(handles.lblangleincidenceend,'Enable','off');
set(handles.tglsolve,'Enable','off');
set(handles.lblvelocity,'Enable','off');
set(handles.tglinvert,'Enable','off');
set(handles.lblrotate,'Enable','off');
set(handles.lblxtrans,'Enable','off');
set(handles.lblytrans,'Enable','off');
end
function lblsectionpoint_Callback(hObject, eventdata, handles)
% hObject handle to lblsectionpoint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblsectionpoint as text
% str2double(get(hObject,'String')) returns contents of lblsectionpoint as a double
section_evaluation(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function lblsectionpoint_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblsectionpoint (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblsectionvector_Callback(hObject, eventdata, handles)
% hObject handle to lblsectionvector (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblsectionvector as text
% str2double(get(hObject,'String')) returns contents of lblsectionvector as a double
section_evaluation(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function lblsectionvector_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblsectionvector (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Function to calculate the section and represent it in the plot
function section_evaluation(hObject, eventdata, handles)
% This function is evaluated either when a geometry is selected to check if
% default section is valid or when the user manually changes the position
% or orientation of the section.
global geometry section colors
% Delete, if any, previous sections
try
delete(section.plot.surf)
delete(section.plot.intersec)
catch
end
% Read the origin where the section will be placed
section.origin=str2num(get(handles.lblsectionpoint,'String'));
% Check that this points has 3 coordinates, if not, set an empty vector
if length(section.origin)~=3
section.origin=[];
end
% Read the orientation of the section plane
section.normal=get(handles.lblsectionvector,'String');
% Check that it is a valid orientation, if not, set an empty vector
if strlength(section.normal)==1
if strfind(section.normal,'x')
section.normal=[1,0,0];
elseif strfind(section.normal,'y')
section.normal=[0,1,0];
elseif strfind(section.normal,'z')
section.normal=[0,0,1];
else
section.normal=[];
end
else
section.normal=[];
end
% If the origin and the orientation of the section plane, represent it
if (not(isempty(section.origin))&¬(isempty(section.normal)))
% Find geometry points enclosed by the section
section.valid_indexes=geometry.model.vertices(:,section.normal==1)==section.origin(section.normal==1);
section.points=geometry.model.vertices(section.valid_indexes,:);
% Delete repeated points of this intersection
section.points=unique(section.points,'rows');
% Sort these points in a closed pattern
section=angular_sorting(section);
% If the intersection is not empty
if not(isempty(section.points))
% Find two orthonormal vectors which are orthogonal to v
section.ortovectors = null(section.normal);
section.max_points=max(section.points);
section.min_points=min(section.points);
section.max_points=section.max_points(section.normal==0);
section.min_points=section.min_points(section.normal==0);
% Provide a gridwork (you choose the size)
[section.P,section.Q] = meshgrid(-[section.max_points(1),section.min_points(1)],[section.max_points(2),section.min_points(2)]);
% Compute the corresponding cartesian coordinates
% using the two vectors in section.ortovectors
section.X = section.origin(1)+section.ortovectors(1,1)*section.P+section.ortovectors(1,2)*section.Q;
section.Y = section.origin(2)+section.ortovectors(2,1)*section.P+section.ortovectors(2,2)*section.Q;
section.Z = section.origin(3)+section.ortovectors(3,1)*section.P+section.ortovectors(3,2)*section.Q;
section.plot.surf=surf(section.X,section.Y,section.Z,'FaceAlpha',0.5,'FaceColor',colors.sectionplane);
% Plot intersection points
section.plot.intersec=plot3(handles.axplot,section.points(:,1),section.points(:,2),section.points(:,3),'*','MarkerEdgeColor',colors.sectionpoints);
legend('Geometry','Section','Intersection points','Location','northeast'); % Add the legend
% Indicate that the section is valid and activate tglsection
set(handles.txtsection,'String','Valid section');
set(handles.tglsection,'Enable','on');
% If the intersection is not valid, indicate it and desactivate tglsection
else
set(handles.txtsection,'String','Invalid section');
set(handles.tglsection,'Enable','off');
end
% If the intersection is not valid, indicate it and desactivate tglsection
else
set(handles.txtsection,'String','Invalid section');
set(handles.tglsection,'Enable','off');
end
% --- Executes on button press in tglsection.
function tglsection_Callback(hObject, eventdata, handles)
% hObject handle to tglsection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of tglsection
global section geometry colors
% Prepare the points in two dimensions
section.xy_points=section.points(:,not(section.normal));
% Delete the plot to represent only the section
try
delete(geometry.plot.model)
delete(geometry.plot.light)
catch
end
try
delete(section.plot.surf)
delete(section.plot.intersec)
catch
end
% Represent in the graph the two dimensional intersection
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
view([0,90]); % Set perspective of the intersection, top view
% Enable the discretization panel and section options
set(handles.tgldiscretize,'Enable','on');
set(handles.lblnpanels,'Enable','on');
set(handles.lblslpsens,'Enable','on');
set(handles.tglinvert,'Enable','on');
set(handles.lblrotate,'Enable','on');
set(handles.lblxtrans,'Enable','on');
set(handles.lblytrans,'Enable','on');
% Desactivate the section panel and indicate it
set(handles.tglsection,'Value',0);
set(handles.tglsection,'Enable','off');
set(handles.lblsectionpoint,'Enable','off');
set(handles.lblsectionvector,'Enable','off');
set(handles.txtsection,'String','Section correctly selected')
% Plot the free stream
section.arrowY=linspace(min(section.xy_points(:,2)),max(section.xy_points(:,2)),5);
section.arrowX=ones(size(section.arrowY))*(min(section.xy_points(:,1))-(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/5);
section.arrowDX=ones(size(section.arrowY))*(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/7;
section.arrowDY=ones(size(section.arrowY))*0;
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
legend('Section','Freestream','Location','southwest','Location','southwest'); % Add the legend
function lblnpanels_Callback(hObject, eventdata, handles)
% hObject handle to lblnpanels (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblnpanels as text
% str2double(get(hObject,'String')) returns contents of lblnpanels as a double
% --- Executes during object creation, after setting all properties.
function lblnpanels_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblnpanels (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblslpsens_Callback(hObject, eventdata, handles)
% hObject handle to lblslpsens (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblslpsens as text
% str2double(get(hObject,'String')) returns contents of lblslpsens as a double
% --- Executes during object creation, after setting all properties.
function lblslpsens_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblslpsens (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in tgldiscretize.
function tgldiscretize_Callback(hObject, eventdata, handles)
% hObject handle to tgldiscretize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global section panels solutionplot colors solutionplot_fit streamplot streamplot_fill contourplot contourplot_fill contourplot_colorbar
% Desactivate section options
set(handles.tglinvert,'Enable','off');
set(handles.lblrotate,'Enable','off');
set(handles.lblxtrans,'Enable','off');
set(handles.lblytrans,'Enable','off');
% Delete previous sections, arrows and discretizations, if any
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
delete(panels.plot)
delete(panels.plot_text)
delete(panels.plot_midpoints)
catch
end
%Delete previous solutions if any
try
delete(solutionplot)
delete(solutionplot_fit)
catch
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
% Label of the axes
xlabel(handles.axplot,'x [m]')
ylabel(handles.axplot,'y [m]')
title('')
% Replot the section and the free stream
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
panels.npanels=str2double(get(handles.lblnpanels,'String')); % Get number of panels desired by the user
panels.slpsens=str2double(get(handles.lblslpsens,'String')); % Get slope sensitivity desired by the user
% According to selected values calculate the panels
panels=panel_generator(section.xy_points,panels.npanels,panels.slpsens);
% Plot the panels
panels.plot=plot(handles.axplot,[panels.vertex(:,1); panels.vertex(1,1)],[panels.vertex(:,2); panels.vertex(1,2)],'-o','Color',colors.panelvertex,'MarkerEdgeColor',colors.panelvertex);
panels.plot_midpoints=plot(handles.axplot,panels.mid_points(:,1),panels.mid_points(:,2),'*','MarkerEdgeColor',colors.panelmidpoints);
panels.plot_text=text(panels.mid_points(:,1),panels.mid_points(:,2),num2str([1:length(panels.mid_points(:,2))]'));
legend('Section','Freestream','Panels','Midpoints','Location','southwest'); % Add the legend
axis('image')
% Enable the solution button
set(handles.poptypesolver,'Enable','on');
set(handles.tglsolve,'Enable','on');
set(handles.lblvelocity,'Enable','on');
if (get(handles.poptypesolver,'Value')==1)
set(handles.lblangleincidencestart,'Enable','off');
set(handles.lblangleincidencestep,'Enable','off');
set(handles.lblangleincidenceend,'Enable','off');
elseif (get(handles.poptypesolver,'Value')==2)
set(handles.lblangleincidencestart,'Enable','on');
set(handles.lblangleincidencestep,'Enable','on');
set(handles.lblangleincidenceend,'Enable','on');
end
function lblvelocity_Callback(hObject, eventdata, handles)
% hObject handle to lblvelocity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblvelocity as text
% str2double(get(hObject,'String')) returns contents of lblvelocity as a double
set(handles.tglsolve,'Enable','on')
% --- Executes during object creation, after setting all properties.
function lblvelocity_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblvelocity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in tglsolve.
function tglsolve_Callback(hObject, eventdata, handles)
% hObject handle to tglsolve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of tglsolve
global panels solution section solutionplot flow solutionplot_fit streamplot streamplot_fill contourplot contourplot_fill contourplot_colorbar
% Get desired velocity of the free stream by the user
flow.velocity_infinite=str2double(get(handles.lblvelocity,'String'));
% Solve the proble considering the type of the solver
if (get(handles.poptypesolver,'Value')==1)
flow.type=1;
flow.alpha=0; %alpha in deg
solucion(1)=panel_solveNL(panels,flow.velocity_infinite,flow.alpha);
solution=solucion;
elseif (get(handles.poptypesolver,'Value')==2)
flow.type=2;
flow.alpha=linspace(str2double(get(handles.lblangleincidencestart,'String')),...
str2double(get(handles.lblangleincidenceend,'String')),str2double(get(handles.lblangleincidencestep,'String')));
for i=1:length(flow.alpha)
solucion(i)=panel_solverL_iter(panels,flow.velocity_infinite,flow.alpha(i));
end
solution=solucion;
end
% Delete previous solutions or discretizations
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
delete(panels.plot)
delete(panels.plot_text)
delete(panels.plot_midpoints)
catch
end
try
delete(solutionplot)
delete(solutionplot_fit)
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
axis('normal')
% Indicate which angles of incidence are calculated
flow.txtalpha=[];
for i=1:length(flow.alpha)
flow.txtalpha{i,1}=num2str(flow.alpha(i));
end
% Enable post processing panel
set(handles.popsolutions,'String',flow.txtalpha);
set(handles.chkcpplot,'Enable','on');
set(handles.chkclplot,'Enable','on');
set(handles.chkstreamlines,'Enable','on');
set(handles.chkpressure,'Enable','on');
set(handles.lblresolution,'Enable','on');
set(handles.lblsizex,'Enable','on');
set(handles.lblsizey,'Enable','on');
set(handles.lblnstreamlines,'Enable','on');
set(handles.popxyabs,'Enable','on');
set(handles.chkvelocitycontour,'Enable','on');
% Indicate that the cp plot is the one selected, and indicate the first angle of incidence
set(handles.chkcpplot,'Value',1);
set(handles.chkclplot,'Value',0);
flow.alphaplot=zeros(size(flow.alpha));
flow.alphaplot(1)=1;
set(handles.txtcpplot,'String', ['alphas: ' num2str(flow.alpha(1))])
% Plot the solution
solutionplot=plot(panels.upperx,solution(1).Cpupper,'-^',panels.lowerx,solution(1).Cplower,'-o','Color',[0,0,1]);
legend(['Upper Alpha= ' num2str(flow.alpha(1))],['Lower Alpha= ' num2str(flow.alpha(1))],'Location','southwest'); % Add the legend
ylabel('Pressure coefficient, -Cp');
xlabel('x/c');
title('')
% Disable the solution button
set(handles.tglsolve,'Enable','off');
function lblrotate_Callback(hObject, eventdata, handles)
% hObject handle to lblrotate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblrotate as text
% str2double(get(hObject,'String')) returns contents of lblrotate as a double
global section colors
% Delete previous section and free stream plots
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
catch
end
% Calculate the new positions of the points and plot them
section.rot_alfa=str2double(get(hObject,'String'));
section.xy_points=section.xy_points*[cosd(section.rot_alfa),-sind(section.rot_alfa);sind(section.rot_alfa),cosd(section.rot_alfa)];
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
% Plot again the free stream
section.arrowY=linspace(min(section.xy_points(:,2)),max(section.xy_points(:,2)),5);
section.arrowX=ones(size(section.arrowY))*(min(section.xy_points(:,1))-(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/5);
section.arrowDX=ones(size(section.arrowY))*(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/7;
section.arrowDY=ones(size(section.arrowY))*0;
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
legend('Section','Freestream','Location','southwest'); % Add the legend
% --- Executes during object creation, after setting all properties.
function lblrotate_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblrotate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblxtrans_Callback(hObject, eventdata, handles)
% hObject handle to lblxtrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblxtrans as text
% str2double(get(hObject,'String')) returns contents of lblxtrans as a double
global section colors
% Delete previous section and free stream plots
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
catch
end
% Calculate the new positions of the points and plot them
section.x_trans=str2double(get(hObject,'String'));
section.xy_points=[section.xy_points(:,1)+section.x_trans,section.xy_points(:,2)];
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
% Plot again the free stream
section.arrowY=linspace(min(section.xy_points(:,2)),max(section.xy_points(:,2)),5);
section.arrowX=ones(size(section.arrowY))*(min(section.xy_points(:,1))-(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/5);
section.arrowDX=ones(size(section.arrowY))*(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/7;
section.arrowDY=ones(size(section.arrowY))*0;
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
legend('Section','Freestream','Location','southwest'); % Add the legend
% --- Executes during object creation, after setting all properties.
function lblxtrans_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblxtrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblytrans_Callback(hObject, eventdata, handles)
% hObject handle to lblytrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblytrans as text
% str2double(get(hObject,'String')) returns contents of lblytrans as a double
global section colors
% Delete previous section and free stream plots
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
catch
end
% Calculate the new positions of the points and plot them
section.y_trans=str2double(get(hObject,'String'));
section.xy_points=[section.xy_points(:,1),section.xy_points(:,2)+section.y_trans];
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
% Plot again the free stream
section.arrowY=linspace(min(section.xy_points(:,2)),max(section.xy_points(:,2)),5);
section.arrowX=ones(size(section.arrowY))*(min(section.xy_points(:,1))-(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/5);
section.arrowDX=ones(size(section.arrowY))*(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/7;
section.arrowDY=ones(size(section.arrowY))*0;
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
legend('Section','Freestream','Location','southwest'); % Add the legend
% --- Executes during object creation, after setting all properties.
function lblytrans_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblytrans (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in tglinvert.
function tglinvert_Callback(hObject, eventdata, handles)
% hObject handle to tglinvert (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global section colors
% Delete previous section and free stream plots
try
delete(section.plot.xyintersec)
delete(section.plot.arrows)
catch
end
% Calculate the new positions of the points and plot them
section.xy_points=[-section.xy_points(:,1),section.xy_points(:,2)];
section.plot.xyintersec=plot(handles.axplot,[section.xy_points(:,1);section.xy_points(1,1)],[section.xy_points(:,2);section.xy_points(1,2)],colors.xysection);
% Plot again the free stream
section.arrowY=linspace(min(section.xy_points(:,2)),max(section.xy_points(:,2)),5);
section.arrowX=ones(size(section.arrowY))*(min(section.xy_points(:,1))-(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/5);
section.arrowDX=ones(size(section.arrowY))*(max(section.xy_points(:,1))-min(section.xy_points(:,1)))/7;
section.arrowDY=ones(size(section.arrowY))*0;
section.plot.arrows=quiver(section.arrowX,section.arrowY,section.arrowDX,section.arrowDY,0,colors.arrows);
legend('Section','Freestream','Location','southwest'); % Add the legend
% --- Executes on button press in tglpan.
function tglpan_Callback(hObject, eventdata, handles)
% hObject handle to tglpan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rotate3d(handles.axplot,'off'); % Disable manual rotation of the graph
zoom(handles.axplot,'off'); % Disable zoom in the plot
pan(handles.axplot,'on'); % Enable manual pan of the graph
% --- Executes on button press in tglrotate.
function tglrotate_Callback(hObject, eventdata, handles)
% hObject handle to tglrotate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rotate3d(handles.axplot,'on'); % Enable manual rotation of the graph
zoom(handles.axplot,'off'); % Disable zoom in the plot
pan(handles.axplot,'off'); % Disable manual pan of the graph
% --- Executes on button press in tglzoom.
function tglzoom_Callback(hObject, eventdata, handles)
% hObject handle to tglzoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rotate3d(handles.axplot,'off'); % Disable manual rotation of the graph
zoom(handles.axplot,'on'); % Enable zoom in the plot
pan(handles.axplot,'off'); % Disable manual pan of the graph
% --- Executes on button press in tglmouse.
function tglmouse_Callback(hObject, eventdata, handles)
% hObject handle to tglmouse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rotate3d(handles.axplot,'off'); % Disable manual rotation of the graph
zoom(handles.axplot,'off'); % Disable zoom in the plot
pan(handles.axplot,'off'); % Disable manual pan of the graph
% --- Executes on selection change in poptypesolver.
function poptypesolver_Callback(hObject, eventdata, handles)
% hObject handle to poptypesolver (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns poptypesolver contents as cell array
% contents{get(hObject,'Value')} returns selected item from
% poptypesolver
global solutionplot solutionplot_fit streamplot streamplot_fill contourplot contourplot_fill contourplot_colorbar
if (get(handles.poptypesolver,'Value')==1)
set(handles.lblangleincidencestart,'Enable','off');
set(handles.lblangleincidencestep,'Enable','off');
set(handles.lblangleincidenceend,'Enable','off');
set(handles.tglsolve,'Enable','on')
elseif (get(handles.poptypesolver,'Value')==2)
set(handles.lblangleincidencestart,'Enable','on');
set(handles.lblangleincidencestep,'Enable','on');
set(handles.lblangleincidenceend,'Enable','on');
set(handles.tglsolve,'Enable','on')
end
try
delete(solutionplot)
delete(solutionplot_fit)
catch
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
% --- Executes during object creation, after setting all properties.
function poptypesolver_CreateFcn(hObject, eventdata, handles)
% hObject handle to poptypesolver (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblangleincidencestart_Callback(hObject, eventdata, handles)
% hObject handle to lblangleincidencestart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblangleincidencestart as text
% str2double(get(hObject,'String')) returns contents of lblangleincidencestart as a double
set(handles.tglsolve,'Enable','on')
% --- Executes during object creation, after setting all properties.
function lblangleincidencestart_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblangleincidencestart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblangleincidencestep_Callback(hObject, eventdata, handles)
% hObject handle to lblangleincidencestep (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblangleincidencestep as text
% str2double(get(hObject,'String')) returns contents of lblangleincidencestep as a double
set(handles.tglsolve,'Enable','on')
% --- Executes during object creation, after setting all properties.
function lblangleincidencestep_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblangleincidencestep (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lblangleincidenceend_Callback(hObject, eventdata, handles)
% hObject handle to lblangleincidenceend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblangleincidenceend as text
% str2double(get(hObject,'String')) returns contents of lblangleincidenceend as a double
set(handles.tglsolve,'Enable','on')
% --- Executes during object creation, after setting all properties.
function lblangleincidenceend_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblangleincidenceend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popsolutions.
function popsolutions_Callback(hObject, eventdata, handles)
% hObject handle to popsolutions (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popsolutions contents as cell array
% contents{get(hObject,'Value')} returns selected item from popsolutions
% --- Executes during object creation, after setting all properties.
function popsolutions_CreateFcn(hObject, eventdata, handles)
% hObject handle to popsolutions (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in chkcpplot.
function chkcpplot_Callback(hObject, eventdata, handles)
% hObject handle to chkcpplot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of chkcpplot
global solutionplot flow colorines panels solution solutionplot_fit streamplot streamplot_fill contourplot contourplot_fill contourplot_colorbar
flow.alphaplotval=flow.alpha(flow.alphaplot==1);
flow.numberalphas=length(flow.alphaplotval);
if (get(hObject,'Value'))
try
delete(solutionplot)
delete(solutionplot_fit)
end
try
delete(streamplot)
delete(streamplot_fill)
end
try
delete(contourplot)
delete(contourplot_fill)
delete(contourplot_colorbar)
end
set(handles.chkclplot,'Value',0);
% Colors of the plot
indexes=[1:flow.numberalphas,12:(12+flow.numberalphas-1)];
for i=1:length(indexes)
colores{i,1}=colorines{indexes(i),1};
end
% Plot the solutions
solutionplot=plot(panels.upperx,[solution(flow.alphaplot==1).Cpupper],'-^',panels.lowerx,[solution(flow.alphaplot==1).Cplower],'-o');
set(solutionplot, {'color'}, colores);
ylabel('Pressure coefficient, -Cp');
xlabel('x/c');
axis('square');
title('')
leg={};
for i=1:flow.numberalphas
leg{i}=['Upper Alpha= ' num2str(flow.alphaplotval(i))];
leg{i+flow.numberalphas}=['Lower Alpha= ' num2str(flow.alphaplotval(i))];
end
legend(handles.axplot,leg);
else
% Delete previous solution plot
try
delete(solutionplot)
delete(solutionplot_fit)
end
try
delete(streamplot)
delete(streamplot_fill)