Skip to content

Commit fee6fbf

Browse files
committed
Trim simulation examples: remove boilerplate, keep domain content and code
1 parent f65a818 commit fee6fbf

3 files changed

Lines changed: 22 additions & 623 deletions

File tree

docs/examples/mpm.md

Lines changed: 4 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ This example demonstrates how to submit and monitor a Material Point Method (MPM
44

55
[![Try on DesignSafe](https://raw.githubusercontent.com/DesignSafe-CI/dapi/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/dapi/mpm/mpm-minimal.ipynb)
66

7-
## Overview
8-
9-
This example covers the essential workflow for running MPM simulations:
10-
11-
- Installing and importing dapi
12-
- Setting up MPM job parameters and input files
13-
- Configuring analysis types, materials, and boundary conditions
14-
- Submitting and monitoring MPM jobs
15-
- Post-processing results and output analysis
7+
For general job submission concepts, see [Jobs](../jobs.md). For resource sizing, see [DesignSafe Workflows](https://kks32.github.io/ds-workflows/guide/job-resources.html).
168

179
## Complete Example
1810

@@ -27,23 +19,13 @@ from dapi import DSClient
2719
import json
2820
```
2921

30-
**What this does:**
31-
- Installs the DesignSafe API package from PyPI
32-
- Imports the main client class and JSON for pretty-printing job requests
33-
3422
### Step 2: Initialize Client
3523

3624
```python
3725
# Initialize DesignSafe client
3826
ds = DSClient()
3927
```
4028

41-
**What this does:**
42-
43-
- Creates an authenticated connection to DesignSafe services
44-
- Handles OAuth2 authentication automatically
45-
- Sets up connections to Tapis API, file systems, and job services
46-
4729
**Authentication:** dapi supports multiple authentication methods including environment variables, .env files, and interactive prompts. For detailed authentication setup instructions, see the [authentication guide](../authentication.md).
4830

4931
### Step 3: Configure Job Parameters
@@ -57,32 +39,7 @@ tacc_allocation: str = "ASC25049" # TACC allocation to charge
5739
app_id_to_use = "mpm-s3" # MPM application ID
5840
```
5941

60-
**What each parameter does:**
61-
62-
- **`ds_path`**: DesignSafe path to your MPM case directory containing input files
63-
- **`input_filename`**: Main MPM configuration file (typically .json format)
64-
- **`max_job_minutes`**: Maximum wall-clock time for the job (prevents runaway simulations)
65-
- **`tacc_allocation`**: Your TACC allocation account (required for compute time billing)
66-
- **`app_id_to_use`**: Specific MPM application version on DesignSafe
67-
68-
**MPM input json file structure:**
69-
```python
70-
# Typical MPM configuration file contains:
71-
mpm_config = {
72-
"mesh": "mesh.txt", # Computational mesh definition
73-
"particles": "particles.txt", # Material point locations and properties
74-
"materials": { # Material constitutive models
75-
"LinearElastic2D": "For elastic analysis",
76-
"MohrCoulomb": "For soil mechanics",
77-
"NeoHookean": "For large deformation"
78-
},
79-
"analysis": {
80-
"type": "MPMExplicit2D", # Analysis type: 2D or 3D explicit
81-
"nsteps": 1000, # Number of time steps
82-
"dt": 0.001 # Time step size
83-
}
84-
}
85-
```
42+
The MPM input file is a JSON configuration that defines the mesh, particle locations, material constitutive models (e.g., LinearElastic2D, MohrCoulomb, NeoHookean), and analysis parameters (type, number of steps, time step size).
8643

8744
### Step 4: Convert Path to URI
8845

@@ -92,12 +49,6 @@ input_uri = ds.files.to_uri(ds_path)
9249
print(f"Input Directory Tapis URI: {input_uri}")
9350
```
9451

95-
**What this does:**
96-
97-
- Converts human-readable DesignSafe paths (like `/MyData/...`) to Tapis URI format
98-
- Tapis URIs are required for job submission and follow the pattern: `tapis://system/path`
99-
- Automatically detects your username and the correct storage system
100-
10152
### Step 5: Generate Job Request
10253

10354
```python
@@ -117,43 +68,6 @@ job_dict = ds.jobs.generate(
11768
print(json.dumps(job_dict, indent=2, default=str))
11869
```
11970

120-
**What each parameter does:**
121-
122-
- **`app_id`**: Specifies which MPM application to run
123-
- **`input_dir_uri`**: Location of your MPM input files
124-
- **`script_filename`**: Main MPM configuration file (mpm.json)
125-
- **`max_minutes`**: Job timeout (prevents infinite runs)
126-
- **`allocation`**: TACC account to charge for compute time
127-
- **`archive_system`**: Where to store results ("designsafe" = your MyData folder)
128-
129-
**Additional options you can add:**
130-
131-
```python
132-
# Extended job configuration options
133-
job_dict = ds.jobs.generate(
134-
app_id=app_id_to_use,
135-
input_dir_uri=input_uri,
136-
script_filename=input_filename,
137-
max_minutes=max_job_minutes,
138-
allocation=tacc_allocation,
139-
140-
# Resource configuration
141-
node_count=1, # Number of compute nodes
142-
cores_per_node=48, # Cores per node (max depends on system)
143-
memory_mb=192000, # Memory in MB per node
144-
queue="skx-dev", # Queue: "skx-dev", "skx", "normal", etc.
145-
146-
# Job metadata
147-
job_name="my_mpm_simulation", # Custom job name
148-
description="Large deformation analysis", # Job description
149-
tags=["research", "mpm", "geomechanics"], # Searchable tags
150-
151-
# Archive configuration
152-
archive_system="designsafe", # Where to store results
153-
archive_path="mpm-results", # Custom archive subdirectory
154-
)
155-
```
156-
15771
### Step 6: Customize Resources
15872

15973
```python
@@ -163,23 +77,6 @@ job_dict["coresPerNode"] = 1 # Use single core for small problems
16377
print(json.dumps(job_dict, indent=2, default=str))
16478
```
16579

166-
**What this does:**
167-
168-
- Overrides default resource allocation from the app
169-
- `nodeCount`: Number of compute nodes (1 for small jobs, multiple for large simulations)
170-
- `coresPerNode`: CPU cores per node (MPM can utilize parallel processing)
171-
- More cores = faster solution but higher cost
172-
173-
**Resource guidelines:**
174-
```python
175-
# Resource selection guidelines for MPM
176-
resources = {
177-
"small_case": {"nodes": 1, "cores": 1, "time": 30}, # < 10K particles
178-
"medium_case": {"nodes": 1, "cores": 16, "time": 120}, # 10K - 100K particles
179-
"large_case": {"nodes": 2, "cores": 48, "time": 480}, # > 100K particles
180-
}
181-
```
182-
18380
### Step 7: Submit Job
18481

18582
```python
@@ -188,12 +85,6 @@ submitted_job = ds.jobs.submit(job_dict)
18885
print(f"Job UUID: {submitted_job.uuid}")
18986
```
19087

191-
**What this does:**
192-
193-
- Sends the job request to TACC's job scheduler
194-
- Returns a `SubmittedJob` object for monitoring
195-
- Job UUID is a unique identifier for tracking
196-
19788
### Step 8: Monitor Job
19889

19990
```python
@@ -202,26 +93,6 @@ final_status = submitted_job.monitor(interval=15) # Check every 15 seconds
20293
print(f"Job {submitted_job.uuid} finished with status: {final_status}")
20394
```
20495

205-
**What this does:**
206-
207-
- Polls job status at specified intervals (15 seconds)
208-
- Shows progress bars for different job phases
209-
- Returns final status when job completes
210-
- `interval=15` means check every 15 seconds (can be adjusted)
211-
212-
**Job status meanings:**
213-
```python
214-
job_statuses = {
215-
"PENDING": "Job submitted but not yet processed",
216-
"PROCESSING_INPUTS": "Input files being staged",
217-
"QUEUED": "Job waiting in scheduler queue",
218-
"RUNNING": "Job actively executing",
219-
"ARCHIVING": "Output files being archived",
220-
"FINISHED": "Job completed successfully",
221-
"FAILED": "Job failed during execution"
222-
}
223-
```
224-
22596
### Step 9: Check Results
22697

22798
```python
@@ -239,13 +110,6 @@ print(f"Current status: {current_status}")
239110
print(f"Last message: {submitted_job.last_message}")
240111
```
241112

242-
**What each command does:**
243-
244-
- **`interpret_status`**: Provides human-readable explanation of job outcome
245-
- **`print_runtime_summary`**: Shows time spent in each job phase (queued, running, etc.)
246-
- **`status`**: Gets current job status (useful for checking later)
247-
- **`last_message`**: Shows last status message from the job scheduler
248-
249113
### Step 10: View Job Output
250114

251115
```python
@@ -256,23 +120,6 @@ if stdout_content:
256120
print(stdout_content)
257121
```
258122

259-
**What this does:**
260-
- `tapisjob.out` contains all console output from your MPM simulation
261-
- `max_lines=50` limits output to last 50 lines (prevents overwhelming output)
262-
- Shows MPM solver progress, timestep information, and timing data
263-
264-
**Typical MPM output includes:**
265-
```python
266-
# Example MPM console output:
267-
mpm_output_info = {
268-
"git_revision": "Version information",
269-
"step_progress": "Step: 1 of 1000",
270-
"warnings": "Material sets, boundary conditions",
271-
"solver_duration": "Explicit USF solver duration: 285 ms",
272-
"completion": "Job execution finished"
273-
}
274-
```
275-
276123
### Step 11: Access Results
277124

278125
```python
@@ -284,23 +131,6 @@ for item in outputs:
284131
print(f"- {item.name} ({item.type})")
285132
```
286133

287-
**What this does:**
288-
- **`archive_uri`**: Location where job results are stored
289-
- **`ds.files.list`**: Lists all files and directories in the archive
290-
- Shows output files like simulation results, visualization data, and logs
291-
292-
**Typical MPM output files:**
293-
```python
294-
typical_outputs = {
295-
"inputDirectory/": "Copy of your input directory with results",
296-
"tapisjob.out": "Console output from MPM simulation",
297-
"tapisjob.err": "Error messages (if any)",
298-
"tapisjob.sh": "Job script that was executed",
299-
"results/": "VTK files for visualization (particles, stresses, velocities)",
300-
"*.vtu": "Paraview-compatible visualization files"
301-
}
302-
```
303-
304134
## Post-processing Results
305135

306136
### Extract and Analyze Output
@@ -319,21 +149,14 @@ import os
319149
results_path = os.path.join(archive_path, "inputDirectory", "results")
320150
if os.path.exists(results_path):
321151
print(f"Results directory: {results_path}")
322-
152+
323153
# List VTK output files
324154
vtk_files = [f for f in os.listdir(results_path) if f.endswith('.vtu')]
325155
print(f"Found {len(vtk_files)} VTK files for visualization")
326-
156+
327157
# Example: Load and analyze particle data (requires appropriate library)
328158
# Note: Actual VTK analysis would require packages like vtk or pyvista
329159
print("Use ParaView or Python VTK libraries to visualize results")
330160
else:
331161
print("No results directory found - check job completion status")
332162
```
333-
334-
**What this does:**
335-
336-
- **`to_path`**: Converts Tapis URI to local file system path
337-
- **`os.listdir`**: Lists files in the results directory
338-
- **`.vtu files`**: VTK unstructured grid files for visualization
339-
- **ParaView**: Recommended tool for visualizing MPM particle data

0 commit comments

Comments
 (0)