Skip to content

Commit 2d3cc79

Browse files
committed
Color the figures by their physics, not by condition type
A color in the figures now means its physics, as everywhere in FEAScript: a prescribed temperature is crimson on the hot side and blue on the cold side, so the 5 °C wall and the 0 °C sides of TPLP01 and TPLP302 no longer look hot. Moving walls and inlets are blue and no-slip walls ink; the initial front is gold; beam supports are ink, loads green and springs gold. Zero flux or no condition (symmetry, insulated, zero gradient, stress-free) is a dashed ink line, and the zero-gradient end of a 1D domain an open circle. The Taylor-Hood pressure nodes are ink squares. The CSS variables are renamed after the physics (--fig-heat, --fig-flow, --fig-structure, --fig-gold). Signed-off-by: Nikos Chamakos <nikoscham@gmail.com>
1 parent d0f6dcc commit 2d3cc79

61 files changed

Lines changed: 857 additions & 656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scripts/figure_style.py‎

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@
22
33
The same file is in FEAScript-documentation/scripts and FEAScript-website/scripts; keep the two copies identical.
44
5-
Style: line art in the FEAScript colors, Roboto Mono labels, a sunken fill for domains, and boundaries colored by the
6-
type of their condition. Every SVG carries a small stylesheet that maps a few fixed colors to CSS variables:
7-
8-
#000 ink, #666 muted text, #fff background, #f6efd9 domain fill,
9-
#c8003f given value (Dirichlet), #d4aa00 convection or spring (Robin), #0086d4 given flux, force or load,
10-
#00a86b zero flux (symmetry, insulated, zero gradient, stress-free), #8f7200 gold text.
11-
12-
The variables (--fig-ink, --fig-muted, --fig-bg, --fig-area, --fig-value, --fig-robin, --fig-flux, --fig-zero,
5+
Style: line art in the FEAScript colors, Roboto Mono labels and a sunken fill for domains. A color always means its
6+
physics, as in the rest of FEAScript (heat crimson, flow blue, structure green, front gold), so the boundaries are
7+
colored by what they do:
8+
9+
heat a prescribed temperature in crimson on the hot side and blue on the cold side (compared with the
10+
other temperatures of the problem, fixed or ambient); convection in gold
11+
flow moving walls and inlets in blue; no-slip walls in ink
12+
front the initial front in gold
13+
beam supports in ink, loads (force, moment, distributed load) in green, springs in gold
14+
any model zero flux or no condition (symmetry, insulated, zero gradient, stress-free) as a dashed ink line;
15+
a given value of an abstract unknown (the u of the general form PDE) in ink
16+
17+
Every SVG carries a small stylesheet that maps the fixed colors to CSS variables: #000 ink, #666 muted text, #fff
18+
background, #f6efd9 domain fill, #c8003f heat, #0086d4 flow, #00a86b structure, #d4aa00 gold, #8f7200 gold text. The
19+
variables (--fig-ink, --fig-muted, --fig-bg, --fig-area, --fig-heat, --fig-flow, --fig-structure, --fig-gold,
1320
--fig-gold-ink) are set by the page for its light and dark themes, and the pages inline the SVG so that it follows the
14-
theme. Opened on its own, an SVG falls back to the light colors. The fixed colors double as names: draw with them,
15-
never with other colors, so that every figure stays in the scheme.
21+
theme. Opened on its own, an SVG falls back to the light colors. Draw only with these fixed colors, so that every
22+
figure stays in the scheme.
1623
17-
Series in plots: FEAScript results in flow blue (#0086d4), references and exact solutions in ink, dashed.
24+
Series in plots: FEAScript results in flow blue, references and exact solutions in ink, dashed.
1825
"""
1926

2027
import math
2128

2229
INK, MUTED, BG, AREA = "#000", "#666", "#fff", "#f6efd9"
23-
VALUE, ROBIN, FLUX, ZERO, GOLD_TEXT = "#c8003f", "#d4aa00", "#0086d4", "#00a86b", "#8f7200"
24-
SERIES = [FLUX, VALUE, ROBIN] # Colors of the first, second and third series of a plot
30+
HEAT, FLOW, STRUCTURE, GOLD, GOLD_TEXT = "#c8003f", "#0086d4", "#00a86b", "#d4aa00", "#8f7200"
31+
HOT, COLD = HEAT, FLOW # A prescribed temperature on the hot or the cold side
32+
ZERO = "zero" # Zero flux or no condition: drawn as a dashed ink line, not a color
33+
SERIES = [FLOW, HEAT, GOLD] # Colors of the first, second and third series of a plot
2534

2635
STYLE = """ <style>
2736
.fig { font-family: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
@@ -32,14 +41,14 @@
3241
.fig [stroke="#fff"] { stroke: var(--fig-bg, #fdfaf2); }
3342
.fig [fill="#f6efd9"] { fill: var(--fig-area, #f6efd9); }
3443
.fig [stroke="#f6efd9"] { stroke: var(--fig-area, #f6efd9); }
35-
.fig [stroke="#c8003f"] { stroke: var(--fig-value, #c8003f); }
36-
.fig [fill="#c8003f"] { fill: var(--fig-value, #c8003f); }
37-
.fig [stroke="#d4aa00"] { stroke: var(--fig-robin, #d4aa00); }
38-
.fig [fill="#d4aa00"] { fill: var(--fig-robin, #d4aa00); }
39-
.fig [stroke="#0086d4"] { stroke: var(--fig-flux, #0086d4); }
40-
.fig [fill="#0086d4"] { fill: var(--fig-flux, #0086d4); }
41-
.fig [stroke="#00a86b"] { stroke: var(--fig-zero, #00a86b); }
42-
.fig [fill="#00a86b"] { fill: var(--fig-zero, #00a86b); }
44+
.fig [stroke="#c8003f"] { stroke: var(--fig-heat, #c8003f); }
45+
.fig [fill="#c8003f"] { fill: var(--fig-heat, #c8003f); }
46+
.fig [stroke="#d4aa00"] { stroke: var(--fig-gold, #d4aa00); }
47+
.fig [fill="#d4aa00"] { fill: var(--fig-gold, #d4aa00); }
48+
.fig [stroke="#0086d4"] { stroke: var(--fig-flow, #0086d4); }
49+
.fig [fill="#0086d4"] { fill: var(--fig-flow, #0086d4); }
50+
.fig [stroke="#00a86b"] { stroke: var(--fig-structure, #00a86b); }
51+
.fig [fill="#00a86b"] { fill: var(--fig-structure, #00a86b); }
4352
.fig [fill="#8f7200"] { fill: var(--fig-gold-ink, #8f7200); }
4453
.fig [font-size="11"] { font-size: 10px; }
4554
.fig [font-size="12"] { font-size: 11px; }
@@ -52,9 +61,12 @@
5261
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
5362
<path d="M0,0 L10,5 L0,10 z" fill="#000"/>
5463
</marker>
55-
<marker id="arrow-flux" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
64+
<marker id="arrow-flow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
5665
<path d="M0,0 L10,5 L0,10 z" fill="#0086d4"/>
5766
</marker>
67+
<marker id="arrow-structure" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
68+
<path d="M0,0 L10,5 L0,10 z" fill="#00a86b"/>
69+
</marker>
5870
</defs>"""
5971

6072
HALO = 'stroke="#fff" stroke-width="4" stroke-linejoin="round" paint-order="stroke"' # Background outline behind labels
@@ -107,25 +119,41 @@ def bname(boundary):
107119

108120

109121
def kind(condition):
110-
"""The color of a boundary from the wording of its condition (see the module docstring)."""
122+
"""The color of a boundary from the wording of its condition (see the module docstring).
123+
124+
A prescribed temperature is taken as the hot side; pass COLD explicitly where it is the cold side."""
111125
plain = condition.lower()
112126
for tag in ("<tspan", "</tspan>"):
113127
plain = plain.replace(tag, " ")
114-
if "convection" in plain or "spring" in plain:
115-
return ROBIN
116-
if any(word in plain for word in ("symmetry", "insulated", "zero gradient", "stress-free", "∂", "d<")):
128+
if "convection" in plain or "spring" in plain or "initial front" in plain:
129+
return GOLD
130+
if any(word in plain for word in ("symmetry", "insulated", "zero gradient", "stress-free", "∂")) or ("/d" in plain and "= 0" in plain):
117131
return ZERO
118-
if "force" in plain or "load" in plain:
119-
return FLUX
120-
return VALUE
132+
if any(word in plain for word in ("moving", "lid", "inlet")):
133+
return FLOW
134+
if any(word in plain for word in ("force", "load", "moment")):
135+
return STRUCTURE
136+
if "temperature" in plain or "°c" in plain:
137+
return HOT
138+
return INK # No-slip walls, supports and the given values of an abstract unknown
121139

122140

123141
def edge(points, color, width=4):
124-
"""A boundary drawn over the outline in the color of its condition."""
142+
"""A boundary drawn over the outline in the color of its condition; ZERO is a dashed ink line."""
125143
path = " ".join(f"{fmt(x)},{fmt(y)}" for x, y in points)
144+
if color == ZERO:
145+
return (
146+
f'<polyline points="{path}" fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>'
147+
f'<polyline points="{path}" fill="none" stroke="#000" stroke-width="2" stroke-dasharray="7 5" stroke-linejoin="round"/>'
148+
)
126149
return f'<polyline points="{path}" fill="none" stroke="{color}" stroke-width="{width}" stroke-linecap="round" stroke-linejoin="round"/>'
127150

128151

152+
def end_dot(x, y, color):
153+
"""The end node of a 1D domain in the color of its condition: open for zero flux or no condition."""
154+
return dot(x, y, 5, filled=False) if color == ZERO else dot(x, y, 5, color=color)
155+
156+
129157
def label(x, y, condition, key, side):
130158
"""Boundary condition and its key, placed outside a domain edge (side: bottom, top, left or right)."""
131159
if side == "bottom":

‎scripts/generate-example-figures.py‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def format_level(value):
221221
return f"{value:g}"
222222

223223

224-
def contour_figure(record, values, levels, title, comment, markers=(), extra=None, color=VALUE):
224+
def contour_figure(record, values, levels, title, comment, markers=(), extra=None, color=HEAT):
225225
"""Contour lines of a nodal field, labeled with their values, on the outline of the domain."""
226226
fit = Fit(record, top=60)
227227
body = [text(fit.left + fit.width / 2, 30, title)]
@@ -280,7 +280,7 @@ def draw(fit):
280280
continue
281281
ex, ey = px + length_per_speed * fit.scale * u[k], py - length_per_speed * fit.scale * v[k]
282282
lines.append(
283-
f'<line x1="{fmt(px)}" y1="{fmt(py)}" x2="{fmt(ex)}" y2="{fmt(ey)}" stroke="{FLUX}" '
283+
f'<line x1="{fmt(px)}" y1="{fmt(py)}" x2="{fmt(ex)}" y2="{fmt(ey)}" stroke="{FLOW}" '
284284
'stroke-width="1.2" marker-end="url(#arrow-small)"/>'
285285
)
286286
marker = (
@@ -321,22 +321,22 @@ def py(y):
321321
body += [text(24, (top + bottom) / 2, y_label, rotate=-90)]
322322
for points, dashed, markers, name, name_at in series:
323323
dash = ' stroke-dasharray="5 4"' if dashed else ""
324-
color = INK if dashed else FLUX # References dashed in ink, FEAScript in flow blue
324+
color = INK if dashed else FLOW # References dashed in ink, FEAScript in flow blue
325325
if points:
326326
path = " ".join(f"{fmt(px(x))},{fmt(py(y))}" for x, y in points)
327327
body.append(f'<polyline points="{path}" fill="none" stroke="{color}" stroke-width="2"{dash}/>')
328328
if markers:
329-
body += [dot(px(x), py(y), 3.5, filled=False, color=FLUX) for x, y in markers]
329+
body += [dot(px(x), py(y), 3.5, filled=False, color=FLOW) for x, y in markers]
330330
if name:
331331
x, y = points[name_at]
332332
body.append(f'<text x="{fmt(px(x) + 8)}" y="{fmt(py(y) - 8)}" font-size="13" {HALO}>{name}</text>')
333333
for k, (dashed, marker, name) in enumerate(legend):
334334
ly = top + 18 + 22 * k
335335
if marker:
336-
body.append(dot(left + 34, ly, 3.5, filled=False, color=FLUX))
336+
body.append(dot(left + 34, ly, 3.5, filled=False, color=FLOW))
337337
else:
338338
dash = ' stroke-dasharray="5 4"' if dashed else ""
339-
body.append(f'<line x1="{left + 18}" y1="{ly}" x2="{left + 50}" y2="{ly}" stroke="{INK if dashed else FLUX}" stroke-width="2"{dash}/>')
339+
body.append(f'<line x1="{left + 18}" y1="{ly}" x2="{left + 50}" y2="{ly}" stroke="{INK if dashed else FLOW}" stroke-width="2"{dash}/>')
340340
body.append(f'<text x="{left + 60}" y="{ly + 4}" font-size="13" {HALO}>{name}</text>')
341341
return svg(width, height, body, comment)
342342

@@ -363,7 +363,7 @@ def hermite_deflection(record, samples=20):
363363
# ── 1D domains ──────────────────────────────────────────────────────────────
364364

365365

366-
def domain_1d(record, left, right, length_label, comment, regions=None, title=None):
366+
def domain_1d(record, left, right, length_label, comment, regions=None, title=None, colors=None):
367367
"""1D mesh: element end nodes as open circles, midside nodes of quadratic elements as dots."""
368368
x0, x1, y = 80, 500, 130
369369
xs = record["x"]
@@ -385,7 +385,8 @@ def px(x):
385385
body.append(f'<circle cx="{fmt(px(x))}" cy="{y}" r="2"/>')
386386
else:
387387
body.append(dot(px(x), y, 4, filled=False))
388-
body += [dot(x0, y, 5, color=kind(left)), dot(x1, y, 5, color=kind(right))]
388+
left_color, right_color = colors or (kind(left), kind(right))
389+
body += [end_dot(x0, y, left_color), end_dot(x1, y, right_color)]
389390
body += [text(x0, y - 26, left), text(x0, y - 44, bname("left"), 12, "#666")]
390391
body += [text(x1, y - 26, right), text(x1, y - 44, bname("right"), 12, "#666")]
391392
body += dimension(x0, y + 55, x1, y + 55, length_label, offset_y=20)
@@ -451,8 +452,8 @@ def rhomboid_geometry():
451452
frame = Frame(140, 260, 80)
452453
corners = [(0, 0), (4, 0), (5, 2), (1, 2)]
453454
body = [outline([frame(x, y) for x, y in corners], filled=True)]
454-
body += [edge([frame(0, 0), frame(4, 0)], VALUE), edge([frame(4, 0), frame(5, 2)], VALUE)]
455-
body += [edge([frame(5, 2), frame(1, 2)], ROBIN), edge([frame(1, 2), frame(0, 0)], ZERO)]
455+
body += [edge([frame(0, 0), frame(4, 0)], HEAT), edge([frame(4, 0), frame(5, 2)], HEAT)]
456+
body += [edge([frame(5, 2), frame(1, 2)], GOLD), edge([frame(1, 2), frame(0, 0)], ZERO)]
456457
body += label(*frame(2, 0), f"{T} = 200 °C", bname("bottom"), "bottom")
457458
body += label(*frame(3, 2), H_CONV, bname("top"), "top")
458459
body += slanted_label(*frame(0.5, 1), "Symmetry", bname("left"), *RHOMBOID_LEFT)
@@ -491,7 +492,7 @@ def solidification_geometry():
491492
return rect_geometry(4, 2, sides, [(f"|∇{italic('u')}| = 1", (2, 1))], "Solidification front: 4 m x 2 m")
492493

493494

494-
def wall_geometry(name, left, right, regions, comment):
495+
def wall_geometry(name, left, right, regions, comment, right_color=None):
495496
"""A wall of width 0.15 m, hatched, with its left and right conditions."""
496497
x0, x1, y0, y1 = 210, 350, 50, 230
497498
body = [f'<rect x="{x0}" y="{y0}" width="{x1 - x0}" height="{y1 - y0}" fill="{AREA}"/>']
@@ -507,7 +508,7 @@ def wall_geometry(name, left, right, regions, comment):
507508
if start > 0:
508509
body.append(f'<line x1="{fmt(a)}" y1="{y0}" x2="{fmt(a)}" y2="{y1}" stroke="#000" stroke-width="1" stroke-dasharray="5 4"/>')
509510
body.append(f'<rect x="{x0}" y="{y0}" width="{x1 - x0}" height="{y1 - y0}" fill="none" stroke="#000" stroke-width="2"/>')
510-
body += [edge([(x0, y0), (x0, y1)], kind(" ".join(left))), edge([(x1, y0), (x1, y1)], kind(" ".join(right)))]
511+
body += [edge([(x0, y0), (x0, y1)], kind(" ".join(left))), edge([(x1, y0), (x1, y1)], right_color or kind(" ".join(right)))]
511512
for k, content in enumerate(left):
512513
body.append(text(x0 - 16, 115 + 21 * k, content, anchor="end"))
513514
body.append(text(x0 - 16, 115 + 21 * len(left), '"left"', 12, "#666", "end"))
@@ -531,7 +532,7 @@ def line_domain_geometry(length_label, left, right, equation, comment, source=No
531532
body += [f'<line x1="{x0}" y1="{y}" x2="{x1}" y2="{y}" stroke="#000" stroke-width="2"/>', dot(x0, y, 4, filled=False), dot(x1, y, 4, filled=False)]
532533
if source:
533534
body += source(x0, x1, y)
534-
body += [dot(x0, y, 5, color=kind(left)), dot(x1, y, 5, color=kind(right))]
535+
body += [end_dot(x0, y, kind(left)), end_dot(x1, y, kind(right))]
535536
body += [text(x0, y + 28, left), text(x0, y + 44, bname("left"), 12, "#666")]
536537
body += [text(x1, y + 28, right), text(x1, y + 44, bname("right"), 12, "#666")]
537538
body += dimension(x0, y + 75, x1, y + 75, length_label, offset_y=20)
@@ -554,10 +555,10 @@ def second_derivative(variable="u"):
554555

555556
def cantilever_geometry():
556557
body = [f'<rect x="100" y="115" width="400" height="10" fill="{AREA}" stroke="#000" stroke-width="2"/>']
557-
body += [f'<line x1="100" y1="65" x2="100" y2="175" stroke="{VALUE}" stroke-width="4"/>', '<g stroke="#000" stroke-width="1">']
558+
body += ['<line x1="100" y1="65" x2="100" y2="175" stroke="#000" stroke-width="4"/>', '<g stroke="#000" stroke-width="1">']
558559
body += [f' <line x1="100" y1="{71 + 14 * k}" x2="88" y2="{83 + 14 * k}"/>' for k in range(8)]
559560
body += ["</g>"] + [dot(100 + 100 * k, 120) for k in range(5)]
560-
body += [f'<line x1="500" y1="40" x2="500" y2="110" stroke="{FLUX}" stroke-width="2.5" marker-end="url(#arrow-flux)"/>']
561+
body += [f'<line x1="500" y1="40" x2="500" y2="110" stroke="{STRUCTURE}" stroke-width="2.5" marker-end="url(#arrow-structure)"/>']
561562
body += [text(512, 58, f"{italic('P')} = −1000 N", anchor="start"), text(512, 76, 'node "5"', 12, "#666", "start")]
562563
body += [text(100, 196, "Clamped"), text(100, 212, 'node "1"', 12, "#666")]
563564
body += [text(300, 90, f"{italic('EI')} = 10<tspan dy=\"-6\" font-size=\"11\">5</tspan><tspan dy=\"6\">&#160;N·m²</tspan>")]
@@ -573,8 +574,8 @@ def cantilever_geometry():
573574
def figures():
574575
out = {}
575576
wall = load("heatConduction1DWall")
576-
out["wall-geometry"] = wall_geometry("wall", ["Convection", f"{italic('h')} = 1 W/(m²·K)", f"{T}{sub('∞')} = 25 °C"], ["Constant temperature", f"{T} = 5 °C"], [(0, 0.15, "sparse")], "1D wall, 0.15 m")
577-
out["wall-mesh"] = domain_1d(wall, "Convection", f"{T} = 5 °C", "0.15 m", "1D wall: 10 linear elements")
577+
out["wall-geometry"] = wall_geometry("wall", ["Convection", f"{italic('h')} = 1 W/(m²·K)", f"{T}{sub('∞')} = 25 °C"], ["Constant temperature", f"{T} = 5 °C"], [(0, 0.15, "sparse")], "1D wall, 0.15 m", right_color=COLD)
578+
out["wall-mesh"] = domain_1d(wall, "Convection", f"{T} = 5 °C", "0.15 m", "1D wall: 10 linear elements", colors=(GOLD, COLD))
578579
out["wall-results"] = line_plot([(nodal_series(wall), False, nodal_series(wall), None, 0)], f"{italic('x')} (m)", f"{T} (°C)", [0, 0.05, 0.1, 0.15], [5, 6, 7, 8], "1D wall: temperature")
579580

580581
varying_k = load("heatConduction1DVaryingK")
@@ -615,7 +616,7 @@ def figures():
615616
front = load("solidificationFront2D")
616617
out["solidification-geometry"] = solidification_geometry()
617618
out["solidification-mesh"] = mesh_figure(front, RECT_SIDES, "12 × 8 quadratic quadrilaterals, 425 nodes", "Solidification front: structured mesh")
618-
out["solidification-results"] = contour_figure(front, front["solution"], [0.25 * k for k in range(1, 8)], f"Front arrival {italic('u')} (distance from the initial front)", "Solidification front: contours of u", color=ROBIN)
619+
out["solidification-results"] = contour_figure(front, front["solution"], [0.25 * k for k in range(1, 8)], f"Front arrival {italic('u')} (distance from the initial front)", "Solidification front: contours of u", color=GOLD)
619620

620621
cavity = load("lidDrivenCavity2DCreepingFlow")
621622
out["cavity-geometry"] = cavity_geometry()

0 commit comments

Comments
 (0)