Skip to main content

Simulator

Python: phynexis.parsim Headers: src/parsim/simulator/*.hpp, src/parsim/context/*.hpp

Simulation driver, context management, and operator system.

Simulator

Main simulation driver.

Constructors

SignatureDescription
Simulator()Default simulator.

Methods

MethodReturnsDescription
step()Advance one time step
run()Run until end condition
context()ContextSimulation context
operators()OperatorSystemOperator system
config()SimulationConfigCurrent configuration
save_to(path, file, opt)Save state
load_from(path, file, opt)Load state

Example:

import phynexis
pm = phynexis.parsim

sim = pm.Simulator()
ctx = sim.context()
print(type(ctx).__name__) # Context

SimulationConfig

Configuration struct.

AttributeTypeDescription
time_stepfloatSimulation time step
end_timefloatSimulation end time
max_stepsintMaximum number of steps
enable_gravityboolEnable gravity
gravityVec3dGravity vector
enable_loggingboolEnable logging

Context

Central simulation context managing all resources.

Methods

MethodReturnsDescription
initialize()Initialize context
finalize()Finalize context
graph()ComputationalGraphThe computational graph
domain()DomainSystemDomain decomposition system
state()RuntimeStateRuntime state
spatial_index()SpatialIndexSpatial index (may be None)
ensure_spatial_index()Ensure spatial index is created
find_resource(name)tupleFind resource handle (index, epoch)
resource(name)objectGet typed resource (4 hardcoded keys)
save_to(path, file, opt)Save context
load_from(path, file, opt)Load context

Resource keys:

  • "computational_graph"ComputationalGraph
  • "domain_system"DomainSystem
  • "runtime_state"RuntimeState
  • "uniform_grid_index"UniformGridIndex

Example:

ctx = pm.Context()
ctx.initialize()
g = ctx.graph()
print(g.is_empty()) # True

OperatorSystem

Container for simulation operators.

Methods

MethodDescription
insert(op)Insert an operator
insert_with_label(label, op)Insert with a label
get(label)Get operator by label
get(handle)Get operator by handle
erase(label)Remove operator by label
enable(handle)Enable operator
disable(handle)Disable operator
size()Number of operators
empty()True if no operators
clear()Remove all operators

Known issue: BaseOperator is not bound in Python, so insert() is only usable with C++-created operators. The operators submodule exposes concrete operators but their insertion API is incomplete.

Status: noted

OperatorSystemEntry

Metadata for an operator.

AttributeTypeDescription
ophandleOperator handle
labelstrOperator label

RuntimeState

Time and step tracking.

Methods

MethodReturnsDescription
step()intCurrent step
time()floatCurrent time
time_step()floatTime step size
set_step(v)Set step
set_time(v)Set time
set_time_step(v)Set time step
advance(dt)Advance time by dt
history()Get history recorder

DomainSystem

Spatial domain decomposition for MPI.

Methods

MethodReturnsDescription
initialize()Initialize domain decomposition
config()DomainSystemConfigConfiguration
subdomain_count()intNumber of subdomains
domain_bound()BoundingBoxGlobal domain bounds
self_subdomain_id()intLocal subdomain ID
self_subdomain_bound()BoundingBoxLocal subdomain bounds
get_overlapped_subdomain(position)intSubdomain overlapping position
is_judge_domain(bbox_a, bbox_b)boolWhether this rank judges bbox pair

DomainSystemConfig

AttributeTypeDescription
min_boundVec3dDomain minimum corner
max_boundVec3dDomain maximum corner
subdivisionsVec3iSubdivision counts per axis

SpatialIndex

Abstract base for spatial indexing.

Methods

MethodReturnsDescription
build(nodes)Build index from NodeSet
query(position, radius)list[int]Query nodes within radius
update()Update index

UniformGridIndex

Uniform grid spatial index.

Methods

MethodReturnsDescription
build(nodes)Build index from NodeSet
query(position, radius)list[int]Query nodes within radius
update()Update index
config()UniformGridIndexConfigCurrent config

UniformGridIndexConfig

AttributeTypeDescription
min_boundVec3dGrid minimum corner
max_boundVec3dGrid maximum corner
grid_sizeVec3dCell size
update_modestrUpdate strategy

ResourceRegistry / ContextResource

Resource factory pattern for extensible context resources.

ResourceRegistry

MethodDescription
register_factory(name, factory)Register a resource factory
create(name)Create a resource by name

ContextResource

Base class for context-managed resources.

Known Issues

OperatorSystem.insert() unusable from Python

BaseOperator is not exposed in Python bindings, so operators created in Python cannot be inserted into OperatorSystem.

Workaround: Use C++-side operator creation or the Simulator factory methods.

Status: noted

Context.resource() only supports 4 hardcoded keys

Extensible resources fall through to an exception.

Status: noted