Skip to content

Release v. 1.006 - with full example3

Latest

Choose a tag to compare

@ovitrac ovitrac released this 20 Feb 12:18
· 11 commits to main since this release

Pizza³ stable release🍕✨

Empower your LAMMPS workflows with:

  • Improved DSCRIPT Templates 🧩 for faster, cleaner setup of complex simulations.
  • Enhanced MachDYN/USER-SMD Support 🚀 to tackle advanced SPH and continuum mechanics.
  • User-Friendly Group & Forcefield Management 🤝 making your multiphase or multibody modeling a breeze.
  • test your code 📜 with LAMMPS-GUI.

📦 Available Versions

  • Full version: Includes sample dump files for a complete demonstration — Pizza3_v1.00.zip.
  • Minimal version: Lightweight, containing only essential files — Pizza3_v1.00min.zip.

📥 Download Links and Example Locations

The download links are available at the end of this page. The mentioned examples, example2.py, example2bis.py example2ter.py and example3.py, can be found in the root folder of the project.

🛠️ Test and Explore

🔗 Test the generated LAMMPS code with LAMMPS-GUI for your platform.
📚 Read the online documentation of Pizza3 on GitHub Pages.


Click to expand example3.py

🆕 What's new? - A comprehensive example

A new full example (example3.py) has been uploaded. It is a follow-up of example1.py, example2.py, example2bis.py and example2ter.py with all steps included and using the last features of Pizza³ v 1.006. Note that the parameters are not optimized or fit any purpose.

Below is a short multi-part snippet illustrating how you can mix Pizza³ features—regions, groups, DSCRIPT templates, and pipescripts—to script a more complex LAMMPS project. Each “snapshot” shows a different piece of the puzzle, so you can see how they might combine in practice.


1️⃣ Geometry Setup (Region Definition)

# SNAPSHOT 1: Define a basic 3D region with cylinder subregions
from pizza.region import region

l0 = 5e-5  # Lattice unit length
R = region(
    name="MyBox",
    dimension=3,
    boundary=["p","p","f"],    # periodic in x and y, fixed in z
    width=0.01, height=0.01, depth=0.005,
    units="si", regionunits="si",
    lattice_scale=l0, lattice_style="sc", lattice_spacing=l0
)

# Create a cylinder inside this region
R.cylinder(
    name="MyCylinder",
    dim="z",
    c1=0, c2=0, 
    radius=0.003,
    lo=0.0, hi=0.004,
    beadtype=1
)

# Generate LAMMPS init, lattice, box scripts
init_scripts = R.pscriptHeaders(what=["init","lattice","box"])

What’s happening?

  • region sets up a 3D box with lattice details.
  • R.cylinder(...) directly places geometry into that box.
  • pscriptHeaders(...) automatically generates block commands for LAMMPS.

2️⃣ Groups & Group Objects

# SNAPSHOT 2: Create group objects for different bead types
from pizza.group import group, groupobject

g1 = groupobject(beadtype=1, group="Solid", mass=2.0)
g2 = groupobject(beadtype=2, group="Fluid")
gcollection = g1 + g2  # combine them

# Optionally define a higher-level group
G = group(name="AllGroups", collection=gcollection)
G.evaluate("all", G.Solid + G.Fluid)

# Mass assignment script
assign_mass_script = gcollection.mass(default_mass=1.0)

What’s happening?

  • Each groupobject points to a bead type (e.g., type=1 for solid, type=2 for fluid).
  • Combining them into gcollection helps manage them at once (e.g., mass assignment).
  • group can define advanced group logic—like combining or subtracting sets.

3️⃣ DSCRIPT for SPH Discretization

# SNAPSHOT 3: A short DSCRIPT snippet to set SPH parameters
from pizza.dscript import dscript

SPH_template = r"""
{
    description = "SPH Setup",
    userid = "sph"
}
discretization: [!
variable  h equal 3.0e-4
variable  vol_one equal (3.0e-4)^3
set       group all diameter ${h}
set       group all volume ${vol_one}
neighbor  ${h} bin
]
"""
SPH_dscript = dscript.parsesyntax(SPH_template, name="SPH_Discretization")
print(SPH_dscript.do(verbose=False))  # Just to see the final LAMMPS commands

What’s happening?

  • DSCRIPT is a mini-language for LAMMPS commands (e.g., setting diameters, volumes).
  • parsesyntax interprets the docstring into a script.
  • SPH_dscript.do(...) merges variables and returns actual LAMMPS lines.

4️⃣ DSCRIPT for Motion / Oscillation

# SNAPSHOT 4: Another DSCRIPT snippet to impose sinusoidal velocity
MOVE_template = r"""
{
    description = "move",
    userid = "movefix"
}
oscillation: [!
variable vel_amp equal 0.001
variable freq equal 2*PI/0.5
variable vx atom ${vel_amp}*sin(${freq}*time)
fix fix_oscill MyCylinder smd/setvel v_vx 0.0 0.0
]
"""
move_dscript = dscript.parsesyntax(MOVE_template, name="Oscillation")
print(move_dscript.do(verbose=False))

What’s happening?

  • Another DSCRIPT block handles dynamic motion: a sinusoidal velocity in x.
  • fix ... smd/setvel is from the MachDYN package, controlling velocities of selected atoms/regions.

5️⃣ Forcefield & Final Assembly

# SNAPSHOT 5: Forcefield plus final pipescript
from pizza.forcefield import parameterforcefield, tlsphalone
from pizza.dforcefield import dforcefield

# Create a base TLSPH forcefield
FF_params = parameterforcefield(base_class=tlsphalone, rho=1000, c0=10.0)
FF = dforcefield(userid="baseFF", **FF_params)

# Attach to group: e.g., solid objects
ff_script = FF.scriptobject(name="solidFF", group="Solid")

# Combine geometry, groups, SPH, motion, and forcefield via pipe
S = init_scripts | R | G | assign_mass_script | SPH_dscript | move_dscript | ff_script

# Optionally write out the final LAMMPS input
final_in = S.write("tmp/in.example_project", verbosity=0, overwrite=True)
print(f"Final LAMMPS input: {final_in}")

What’s happening?

  • We build a TLSPH-based forcefield (tlsphalone for solids/fluid).
  • scriptobject(...) attaches that forcefield to a chosen group.
  • Everything merges via the pipe (|) operator, forming a single pipescript.

Putting It All Together

These small snapshots illustrate the different ways Pizza3 handles:

  1. Geometry & Regions (Snapshot 1)
  2. Groups & Collections (Snapshot 2)
  3. DSCRIPT Templates for setting SPH or Motion (Snapshots 3 & 4)
  4. Forcefield definitions & Final Assembly (Snapshot 5)

In a real project, you’d connect them sequentially and run the final compiled script in LAMMPS for a multi-physics simulation. This approach lets you reuse your DSCRIPT code blocks or group definitions across different simulations—making it easier to maintain and scale up your projects.