Skip to content

Commit ab705db

Browse files
authored
Make pdflatex optional (#114)
* add param use_tex to plotting functions * define USE_TEX in rectangular_wing.jl and use it * All examples with USE_TEX=false now * improve doc strings
1 parent 001bd3e commit ab705db

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

examples/ram_air_kite.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using CSV
1111
using DataFrames
1212

1313
PLOT = true
14+
USE_TEX = false
1415
DEFORM = false
1516

1617
# Create wing geometry
@@ -52,7 +53,8 @@ PLOT && plot_geometry(
5253
is_save=false,
5354
is_show=true,
5455
view_elevation=15,
55-
view_azimuth=-120
56+
view_azimuth=-120,
57+
use_tex=USE_TEX
5658
)
5759

5860
# Solving and plotting distributions
@@ -68,7 +70,8 @@ PLOT && plot_distribution(
6870
title="CAD_spanwise_distributions_alpha_$(round(aoa, digits=1))_beta_$(round(side_slip, digits=1))_yaw_$(round(yaw_rate, digits=1))_v_a_$(round(v_a, digits=1))",
6971
data_type=".pdf",
7072
is_save=false,
71-
is_show=true
73+
is_show=true,
74+
use_tex=USE_TEX
7275
)
7376

7477
PLOT && plot_polars(
@@ -85,6 +88,7 @@ PLOT && plot_polars(
8588
title="ram_kite_panels_$(wing.n_panels)_distribution_$(wing.spanwise_panel_distribution)",
8689
data_type=".pdf",
8790
is_save=false,
88-
is_show=true
91+
is_show=true,
92+
use_tex=USE_TEX
8993
)
9094
nothing

examples/rectangular_wing.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using ControlPlots
33
using VortexStepMethod
44

55
PLOT = true
6+
USE_TEX = false
67

78
# Step 1: Define wing parameters
89
n_panels = 20 # Number of panels
@@ -60,6 +61,7 @@ PLOT && plot_geometry(
6061
save_path=".",
6162
is_save=false,
6263
is_show=true,
64+
use_tex=USE_TEX
6365
)
6466

6567
# Step 7: Plot spanwise distributions
@@ -69,7 +71,8 @@ PLOT && plot_distribution(
6971
[y_coordinates, y_coordinates],
7072
[results_vsm, results_llt],
7173
["VSM", "LLT"],
72-
title="Spanwise Distributions"
74+
title="Spanwise Distributions",
75+
use_tex=USE_TEX
7376
)
7477

7578
# Step 8: Plot polar curves
@@ -81,6 +84,7 @@ PLOT && plot_polars(
8184
angle_range,
8285
angle_type="angle_of_attack",
8386
v_a,
84-
title="Rectangular Wing Polars"
87+
title="Rectangular Wing Polars",
88+
use_tex=USE_TEX
8589
)
8690
nothing

examples/stall_model.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using CSV
1010
using DataFrames
1111

1212
PLOT = true
13+
USE_TEX = false
1314

1415
# Find root directory
1516
root_dir = dirname(@__DIR__)
@@ -75,7 +76,8 @@ PLOT && plot_geometry(
7576
is_save=false,
7677
is_show=true,
7778
view_elevation=15,
78-
view_azimuth=-120
79+
view_azimuth=-120,
80+
use_tex=USE_TEX
7981
)
8082

8183
# Solving and plotting distributions
@@ -93,7 +95,8 @@ PLOT && plot_distribution(
9395
data_type=".pdf",
9496
save_path=joinpath(save_folder, "spanwise_distributions"),
9597
is_save=false,
96-
is_show=true
98+
is_show=true,
99+
use_tex=USE_TEX
97100
)
98101

99102
# Plotting polar
@@ -124,6 +127,7 @@ PLOT && plot_polars(
124127
data_type=".pdf",
125128
save_path=joinpath(save_folder, "polars"),
126129
is_save=true,
127-
is_show=true
130+
is_show=true,
131+
use_tex=USE_TEX
128132
)
129133
nothing

src/plotting.jl

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Set the default style for plots using LaTeX.
66
``
77
# Arguments:
88
- `titel_size`: size of the plot title in points (default: 16)
9-
- `use_tex`: if a separately installed LaTeX version shall be used
9+
- `ùse_tex`: if the external `pdflatex` command shall be used
1010
"""
1111
function set_plot_style(titel_size=16; use_tex=false)
1212
rcParams = plt.PyDict(plt.matplotlib."rcParams")
@@ -148,7 +148,8 @@ function set_axes_equal!(ax; zoom=1.8)
148148
end
149149

150150
"""
151-
create_geometry_plot(body_aero::BodyAerodynamics, title, view_elevation, view_azimuth; zoom=1.8)
151+
create_geometry_plot(body_aero::BodyAerodynamics, title, view_elevation, view_azimuth;
152+
zoom=1.8, use_tex=false)
152153
153154
Create a 3D plot of wing geometry including panels and filaments.
154155
@@ -162,8 +163,8 @@ Create a 3D plot of wing geometry including panels and filaments.
162163
- zoom: zoom factor (default: 1.8)
163164
"""
164165
function create_geometry_plot(body_aero::BodyAerodynamics, title, view_elevation, view_azimuth;
165-
zoom=1.8)
166-
set_plot_style(28)
166+
zoom=1.8, use_tex=false)
167+
set_plot_style(28; use_tex)
167168

168169
panels = body_aero.panels
169170
va = isa(body_aero.va, Tuple) ? body_aero.va[1] : body_aero.va
@@ -249,7 +250,7 @@ end
249250
plot_geometry(body_aero::BodyAerodynamics, title;
250251
data_type=".pdf", save_path=nothing,
251252
is_save=false, is_show=false,
252-
view_elevation=15, view_azimuth=-120)
253+
view_elevation=15, view_azimuth=-120, use_tex=false)
253254
254255
Plot wing geometry from different viewpoints and optionally save/show plots.
255256
@@ -264,6 +265,7 @@ Plot wing geometry from different viewpoints and optionally save/show plots.
264265
- `is_show`: boolean value, indicates if the graphic shall be displayed (default: `false`)
265266
- `view_elevation`: initial view elevation angle (default: 15) [°]
266267
- `view_azimuth`: initial view azimuth angle (default: -120) [°]
268+
- `use_tex`: if the external `pdflatex` command shall be used (default: false)
267269
268270
"""
269271
function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title;
@@ -272,41 +274,42 @@ function VortexStepMethod.plot_geometry(body_aero::BodyAerodynamics, title;
272274
is_save=false,
273275
is_show=false,
274276
view_elevation=15,
275-
view_azimuth=-120)
277+
view_azimuth=-120,
278+
use_tex=false)
276279

277280
if is_save
278281
plt.ioff()
279282
# Angled view
280-
fig = create_geometry_plot(body_aero, "$(title)_angled_view", 15, -120)
283+
fig = create_geometry_plot(body_aero, "$(title)_angled_view", 15, -120; use_tex)
281284
save_plot(fig, save_path, "$(title)_angled_view", data_type=data_type)
282285

283286
# Top view
284-
fig = create_geometry_plot(body_aero, "$(title)_top_view", 90, 0)
287+
fig = create_geometry_plot(body_aero, "$(title)_top_view", 90, 0; use_tex)
285288
save_plot(fig, save_path, "$(title)_top_view", data_type=data_type)
286289

287290
# Front view
288-
fig = create_geometry_plot(body_aero, "$(title)_front_view", 0, 0)
291+
fig = create_geometry_plot(body_aero, "$(title)_front_view", 0, 0; use_tex)
289292
save_plot(fig, save_path, "$(title)_front_view", data_type=data_type)
290293

291294
# Side view
292-
fig = create_geometry_plot(body_aero, "$(title)_side_view", 0, -90)
295+
fig = create_geometry_plot(body_aero, "$(title)_side_view", 0, -90; use_tex)
293296
save_plot(fig, save_path, "$(title)_side_view", data_type=data_type)
294297
end
295298

296299
if is_show
297300
plt.ion()
298-
fig = create_geometry_plot(body_aero, title, view_elevation, view_azimuth)
301+
fig = create_geometry_plot(body_aero, title, view_elevation, view_azimuth; use_tex)
299302
plt.display(fig)
300303
else
301-
fig = create_geometry_plot(body_aero, title, view_elevation, view_azimuth)
304+
fig = create_geometry_plot(body_aero, title, view_elevation, view_azimuth; use_tex)
302305
end
303306
fig
304307
end
305308

306309
"""
307310
plot_distribution(y_coordinates_list, results_list, label_list;
308311
title="spanwise_distribution", data_type=".pdf",
309-
save_path=nothing, is_save=false, is_show=true)
312+
save_path=nothing, is_save=false, is_show=true, use_tex=false)
310313
311314
Plot spanwise distributions of aerodynamic properties.
312315
@@ -321,20 +324,22 @@ Plot spanwise distributions of aerodynamic properties.
321324
- `save_path`: Path to save plots (default: nothing)
322325
- `is_save`: Whether to save plots (default: false)
323326
- `is_show`: Whether to display plots (default: true)
327+
- `use_tex`: if the external `pdflatex` command shall be used
324328
"""
325329
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list;
326330
title="spanwise_distribution",
327331
data_type=".pdf",
328332
save_path=nothing,
329333
is_save=false,
330-
is_show=true)
334+
is_show=true,
335+
use_tex=false)
331336

332337
length(results_list) == length(label_list) || throw(ArgumentError(
333338
"Number of results ($(length(results_list))) must match number of labels ($(length(label_list)))"
334339
))
335340

336341
# Set the plot style
337-
set_plot_style()
342+
set_plot_style(; use_tex)
338343

339344
# Initializing plot
340345
fig, axs = plt.subplots(3, 3, figsize=(16, 10))
@@ -474,7 +479,7 @@ end
474479
"""
475480
generate_polar_data(solver, body_aero::BodyAerodynamics, angle_range;
476481
angle_type="angle_of_attack", angle_of_attack=0.0,
477-
side_slip=0.0, v_a=10.0)
482+
side_slip=0.0, v_a=10.0, use_latex=false)
478483
479484
Generate polar data for aerodynamic analysis over a range of angles.
480485
@@ -499,7 +504,8 @@ function generate_polar_data(
499504
angle_type="angle_of_attack",
500505
angle_of_attack=0.0,
501506
side_slip=0.0,
502-
v_a=10.0
507+
v_a=10.0,
508+
use_latex=false
503509
)
504510
n_panels = length(body_aero.panels)
505511
n_angles = length(angle_range)
@@ -517,8 +523,6 @@ function generate_polar_data(
517523
# Previous gamma for initialization
518524
gamma = nothing
519525

520-
set_plot_style()
521-
522526
for (i, angle_i) in enumerate(angle_range)
523527
# Set angle based on type
524528
if angle_type == "angle_of_attack"
@@ -578,7 +582,7 @@ end
578582
angle_range=range(0, 20, 2), angle_type="angle_of_attack",
579583
angle_of_attack=0.0, side_slip=0.0, v_a=10.0,
580584
title="polar", data_type=".pdf", save_path=nothing,
581-
is_save=true, is_show=true)
585+
is_save=true, is_show=true, use_tex=false)
582586
583587
Plot polar data comparing different solvers and configurations.
584588
@@ -599,6 +603,7 @@ Plot polar data comparing different solvers and configurations.
599603
- `save_path`: Path to save plots (default: nothing)
600604
- `is_save`: Whether to save plots (default: true)
601605
- `is_show`: Whether to display plots (default: true)
606+
- `use_tex`: if the external `pdflatex` command shall be used (default: false)
602607
"""
603608
function VortexStepMethod.plot_polars(
604609
solver_list,
@@ -614,7 +619,8 @@ function VortexStepMethod.plot_polars(
614619
data_type=".pdf",
615620
save_path=nothing,
616621
is_save=true,
617-
is_show=true
622+
is_show=true,
623+
use_tex=false
618624
)
619625
# Validate inputs
620626
total_cases = length(body_aero_list) + length(literature_path_list)
@@ -623,6 +629,7 @@ function VortexStepMethod.plot_polars(
623629
"cases ($total_cases), and labels ($(length(label_list)))"))
624630
end
625631
main_title = replace(title, " " => "_")
632+
set_plot_style(; use_tex)
626633

627634
# Generate polar data
628635
polar_data_list = []

0 commit comments

Comments
 (0)