Projects and replay
Every grid SHORE builds through a Project is the result of a list of commands, and that list is a Python script: the journal. In this tutorial you build a project with two components, undo and redo, save it, load it with and without replay, write the Xall run and a CGNS file, and then replay the journal on an edited input to get a new grid with no other change. The last step does the same from the command line.
You need
- SHORE installed, plus the
cgnsextra for the CGNS step (pip install 'shore-mesh[cgns]'). - About 2 s for the script
examples/tutorials/projects.py.
1. Build two components
A project holds named geometries and named components (ADR 0016). Each mesh command acts on the current component, "main" by default; use_component switches to another one, creating it empty if it is new. A geometry is loaded once and any component can build on it.
shapes.sphere(radius=0.5, subdivisions=3).export("sphere.stl")
p = Project()
p.load_geometry("sphere.stl", name="sphere") # a named geometry, shared by all components
# component "main" (the default): an O-grid on the sphere, marched
p.build_topology("ogrid", nk=17, ds=2e-3, growth=1.2, geometry="sphere", ni=17, nj=32)
p.march()
# component "background": a Cartesian box round it
p.use_component("background")
p.build_primitive("box", vmin=(-3.0, -3.0, -3.0), vmax=(3.0, 3.0, 3.0), ni=13, nj=13, nk=13)
print("components:", {name: len(m.blocks) for name, m in p.components.items() if m})components: {'main': 1, 'background': 1}main holds an O-grid marched from the sphere; background a box of 13 × 13 × 13 nodes round it. In a Chimera run they are two independent component grids.
2. Undo and redo
Every state-changing command records how to revert itself (ADR 0004). undo reverts the last one (output commands such as write_xall are skipped: they are never undone), redo applies it again.
p.undo() # drops the box
print("after undo:", p.mesh)
p.redo() # builds it again
print("after redo:", [b.label for b in p.mesh.blocks])after undo: None
after redo: ['box']3. Read the journal
journal() renders the history as a script of the same method calls. save_journal writes it; shore run journal.py (or run_journal) replays it and gives the same grids bit for bit.
print(p.journal())
p.save_journal("journal.py") # `shore run journal.py` replays it# SHORE journal: replay with `shore run <this file>`.
from shore.project import Project
p = Project()
p.load_geometry('sphere.stl', name='sphere')
p.build_topology('ogrid', nk=17, ds=0.002, growth=1.2, geometry='sphere', ni=17, nj=32)
p.march()
p.use_component('background')
p.build_primitive('box', vmin=(-3.0, -3.0, -3.0), vmax=(3.0, 3.0, 3.0), ni=13, nj=13, nk=13)The undone and redone box appears once: the journal is the history as it stands, not a log of what you typed. A journal is Python, so run only journals you trust.
4. Save and load
save(dir) writes a portable project directory: project.toml (format, components and their block labels, input hashes), journal.py, inputs/ (a copy of every file the journal reads) and grids/<component>/ (the node arrays and each component's face graph).
p.save("proj") # project.toml, journal.py, inputs/, grids/<component>/
q = Project.load("proj") # replays the journal and checks every grid (to 1e-10)
r = Project.load("proj", replay=False) # reads the saved grids: no march
same = np.array_equal(q.components["main"].blocks[0].nodes, r.components["main"].blocks[0].nodes)
print("replay == saved grids:", same)replay == saved grids: TrueThe two loads differ:
Project.load(dir) | Project.load(dir, replay=False) | |
|---|---|---|
| Inputs | checked against their SHA-256 | checked against their SHA-256 |
| Grids | rebuilt by replaying the journal, then required to match the saved ones to 1e-10 of their size | read from grids/, rewired from the saved face graphs |
| Cost | the whole build again (marches, premesh) | reading the files |
| Afterwards | undo and redo work as in the original session | the loaded history cannot be undone, and a loaded mesh cannot be marched |
A replaying load is also a determinism check: it fails if anything gives a different grid. Load without replay (ADR 0033) when you only want to inspect, export or add components.
5. Write the solver files
write_xall writes each component's .geo, adjacency sidecar, .grd and cc.par under run/<component>/, then the merged .grd and cc.par and one proc.input balanced over all blocks of the run. write_cgns writes one CGNS base per component.
p.write_xall("run", np=4) # per component under run/<component>/, then merged files
p.write_cgns("proj.cgns") # a CGNS base per component
print(sorted(f.name for f in Path("run").iterdir()))['background', 'cc.par', 'main', 'mesh.grd', 'proc.input']Per-component options (marker boxes, free_face_bc, body numbers, per-block metadata) are in Multi-component Xall run.
6. Replay on an edited input
The journal names its inputs by path. run_journal(path, input_dir=d) resolves relative paths against d, so the same commands run on a different file of the same name. Here the sphere grows from radius 0.5 to 0.6:
# edit the input: a larger sphere, same file name, in another directory
Path("edited").mkdir(exist_ok=True)
shapes.sphere(radius=0.6, subdivisions=3).export("edited/sphere.stl")
e = run_journal("journal.py", input_dir="edited") # 'sphere.stl' resolves in edited/
wall = e.components["main"].blocks[0].nodes[:, :, 0]
print(f"edited wall radius: {np.linalg.norm(wall, axis=-1).mean():.3f}")edited wall radius: 0.598The wall now lies on the larger sphere (0.598: the mean over the STL facets), with the same node counts, spacing and topology. This is how a grid follows a design change. For a CAD model, an edit that keeps the model's faces and edges recognisable replays the same way: the associations re-find their entities by fingerprint (ADR 0003). Blocking a wing–body does it on a STEP file whose span and fuselage radius change.
7. The same from the command line
--project DIR [--component C] on shore mesh, shore collar and shore primitive * loads the project in DIR (or creates it), builds component C and saves the project back (ADR 0018). shore xall and shore cgns write from a saved project. The commands below use sphere.stl and journal.py from the steps above and box.stl / post.stl from the collar tutorial.
shore mesh sphere.stl --topology ogrid --ni 17 --nj 32 --nk 17 \
--ds 2e-3 --growth 1.2 -o out/sphere --project proj --journal sphere_journal.py
shore collar box.stl post.stl --seed 0.55 0 0.02 --n-loop 48 \
--ds-surface 0.01 --growth-surface 1.12 --m-a 12 --m-b 12 \
--ds-wall 1e-4 --growth-wall 1.2 --nk 25 --project proj
shore xall proj --out run --options xall.toml
shore cgns proj -o proj.cgns
shore cgns proj -o collar.cgns -c collar --no-replay
shore run journal.py --save-project replayedwith xall.toml:
[run]
grd = "run.grd"
np = 4
[components.collar]
body = 1shore meshbuilds componentmain(its default),shore collarcomponentcollar. A geometry already loaded from a file with the same content is reused, so the earlier components survive; a file whose stem matches a geometry loaded from a different file is an error (name it with--name-a,--name-bor--geometry-name).shore xallwritesrun/main/,run/collar/, thenrun/run.grd,run/cc.parandrun/proc.input.--no-replayon any of them opens the project from its saved grids.
What you learned
- A project is geometries, components and the command history that built them;
use_componentselects where mesh commands act. undo/redowalk the history; the journal is that history as a script.savemakes a portable directory;loadreplays and verifies it,load(replay=False)reads the saved grids.- Replaying the journal on edited inputs rebuilds the grid with the same commands.
--projectand--componentgive the CLI the same model;shore xallandshore cgnswrite from it.
Next
- Blocking a wing–body: a 46-command journal replayed after a CAD edit.
- Projects and journals: the command layer.
- Save, load, replay and Export CGNS and Plot3D.
- Project scripts,
shore xall,shore cgns.