From 9475eea89317c828eb69b8a3637821a8af2a1cd4 Mon Sep 17 00:00:00 2001
From: Thomas Lambert <t.lambert@uliege.be>
Date: Thu, 18 May 2023 15:11:54 +0200
Subject: [PATCH] fix(ElPerf): proper pitch in plotveltriangles

---
 src/classes/@ElemPerf/plotveltriangles.m |  4 ++--
 src/classes/@Rotor/Rotor.m               |  2 +-
 src/classes/@Rotor/plotblade.m           | 21 ++++++++++++++-------
 src/configs/knight1937.m                 |  2 +-
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/classes/@ElemPerf/plotveltriangles.m b/src/classes/@ElemPerf/plotveltriangles.m
index 0d4be5e..243b4f8 100644
--- a/src/classes/@ElemPerf/plotveltriangles.m
+++ b/src/classes/@ElemPerf/plotveltriangles.m
@@ -47,7 +47,7 @@ function plotveltriangles(self, nTriangles, varargin)
     % Defaults and constants
     TRI_POS_Z = 1; % Number of chords of space to display the triangle position
     VECT_SCALE_FACTOR = 2; % Number of chords of space to display the triangle position
-    DEF.FIG_TYPE = 'all'; % Only 3D plot by default
+    DEF.FIG_TYPE = '3D'; % Only 3D plot by default
     DEF.NEW_FIG = false; % New figure is false by default
     DEF.ALLOWED_FIG_TYPES = {'all', '3D', 'sections'};
 
@@ -94,7 +94,7 @@ function plotveltriangles(self, nTriangles, varargin)
             figure('Name', 'Velocity triangles along the blade');
         end
 
-        self.Rot.plotblade(nTriangles);
+        self.Rot.plotblade(self.Op.coll, nTriangles);
         hold on;
 
         for i = iSec
diff --git a/src/classes/@Rotor/Rotor.m b/src/classes/@Rotor/Rotor.m
index f31888c..8ce4761 100644
--- a/src/classes/@Rotor/Rotor.m
+++ b/src/classes/@Rotor/Rotor.m
@@ -134,7 +134,7 @@ classdef Rotor < handle
         % ---------------------------------------------
         % Other methods
         plot(self, varargin) % 3D plot of the rotor
-        plotblade(self, nSec, varargin) % Plot the blade
+        plotblade(self, pitch, nSec, varargin) % Plot the blade
 
     end
 end
diff --git a/src/classes/@Rotor/plotblade.m b/src/classes/@Rotor/plotblade.m
index 75589cb..a300af3 100644
--- a/src/classes/@Rotor/plotblade.m
+++ b/src/classes/@Rotor/plotblade.m
@@ -1,4 +1,4 @@
-function plotblade(self, nSec, varargin)
+function plotblade(self, pitch, nSec, varargin)
     % PLOTBLADE 3D plot of a single blade.
     %   This method generates a 3D plot of the blade.
     %   If provided, it can also colorize the blade elements using some input data (e.g. cT, cP,
@@ -8,8 +8,11 @@ function plotblade(self, nSec, varargin)
     % Syntax:
     %   Rot.plotblade() draws a 3D plot of a single blade with default colors.
     %
-    %   Rot.plotblade(nSec) specifies the number of sections to explicitely draw. If not specified,
-    %   all sections will be drawned on top of the blade outline.
+    %   Rot.plotblade(pitch) pitches the blade according to the `pitch` angle in radians. If not
+    %   specified, no pitch will be applied.
+    %
+    %   Rot.plotblade(pitch, nSec) specifies the number of sections to explicitely draw. If not
+    %   specified, all sections will be drawned on top of the blade outline.
     %
     %   Rot.plotblade(..., 'data', vector) draws the 3D of a single blade and colorize the sections
     %   using the values found in 'data'.
@@ -34,7 +37,8 @@ function plotblade(self, nSec, varargin)
     %
     % Examples:
     %   Rot.plotblade()
-    %   Rot.plotblade(5)
+    %   Rot.plotblade(deg2rad(10))
+    %   Rot.plotblade(deg2rad(10), 5)
     %   Rot.plotblade('data', cT)
     %   Rot.plotblade('newFig', true)
     %   Rot.plotblade('surfProp', {'FaceAlpha', 1, 'FaceColor','blue'})
@@ -63,6 +67,9 @@ function plotblade(self, nSec, varargin)
     DEF.CHORD_SPACING_RULE = 'halfcosine';
 
     if nargin < 2
+        pitch = 0;
+    end
+    if nargin < 3
         nSec = 0;
     end
 
@@ -100,7 +107,7 @@ function plotblade(self, nSec, varargin)
     dataMat = repmat(data, length(coords(:, 1)), 1);
 
     % Scale elements and twist them properly to create the correct blade
-    Blade = gettrueposition(self.Bl, coords, chordMat, DEF);
+    Blade = gettrueposition(self.Bl, coords, chordMat, pitch, DEF);
 
     % Plot blade and rotor
     if newFig
@@ -143,7 +150,7 @@ function coords = normalizeafcoord(self, DEF)
 
 end
 
-function Blade = gettrueposition(Elem, coords, chordMat, DEF)
+function Blade = gettrueposition(Elem, coords, chordMat, pitch, DEF)
     % GETTRUEPOSITION  Returns the true position of the blade elements after scaling and twisting
 
     % Scale the blade to actual chord and span
@@ -156,7 +163,7 @@ function Blade = gettrueposition(Elem, coords, chordMat, DEF)
 
     % Pitch the airfoil according to the correct local twist angle
     for i = 1:length(Elem.chord)
-        rotY = roty(rad2deg(Elem.twist(i)));
+        rotY = roty(rad2deg(Elem.twist(i) + pitch));
         dummy = rotY * [geomX(:, i), geomY(:, i), geomZ(:, i)]';
         Blade.x(:, i) = dummy(1, :);
         Blade.y(:, i) = dummy(2, :);
diff --git a/src/configs/knight1937.m b/src/configs/knight1937.m
index 078fe14..5cfac8e 100644
--- a/src/configs/knight1937.m
+++ b/src/configs/knight1937.m
@@ -46,7 +46,7 @@ Sim.Misc.appli  = 'heli'; % Type of application ('helicopter', 'propeller', 'win
 % ==================================================================================================
 
 % Solvers
-Mod.solvers = {'all'};   % BEMT Solver ('leishman', 'indfact', 'indvel', 'stahlhut', 'all')
+Mod.solvers = {'indvel'};   % BEMT Solver ('leishman', 'indfact', 'indvel', 'stahlhut', 'all')
 
 % Extensions/corrections
 Mod.Ext.losses = 'all';  % Include losses using Prandtl formula ('none', 'hub', 'tip', 'both')
-- 
GitLab