Skip to main content

LDPE polymerization reactor simulation (moments + chain-length distribution) and reinforcement-learning operating-condition optimisation.

Project description

pypolymer

Simulation and reinforcement-learning optimisation of free-radical polymerization reactors (LDPE-type chemistry), in pure NumPy + SciPy.

pypolymer provides one reactor class, PolyRxn, that simulates Batch, CSTR, and tubular PFR reactors by the method of moments, plus a chain-length-distribution (CLD) batch solver that integrates every chain length explicitly to recover the full molecular-weight distribution. A set of REINFORCE-based helpers optimise reactor operating conditions.

Installation

pip install pypolymer
# with plotting extras (matplotlib):
pip install "pypolymer[plot]"

From a local checkout:

pip install -e ".[dev]"

Reaction model

Free-radical polymerization with initiator decay, propagation, chain transfer to monomer / polymer / agent (CTA), and termination by combination and disproportionation:

Step Reaction
Initiation I → 2 R·, R· + M → P₁
Propagation Pₙ + M → Pₙ₊₁
Transfer to monomer Pₙ + M → Dₙ + P₁
Transfer to polymer Pₙ + Dₘ → Dₙ + Pₘ
Transfer to agent (CTA) Pₙ + S → Dₙ + P₁
Termination (combination) Pₙ + Pₘ → Dₙ₊ₘ
Termination (disproportionation) Pₙ + Pₘ → Dₙ + Dₘ

Quick start

Method-of-moments batch

from pypolymer import PolyRxn

rx = PolyRxn(kd=0.8, kp=15.0, ktc=0.02, ktd=0.02, ktrm=15e-3,
             ktrp=10e-3, kca=5e-3, f=0.8, dH_p=-1.0e5, Mw_mono=28.05)
rx.set_batch_params(Tc_const=473.15, rho=1.0e4, Cp_ass=1.5, U_heat=400.0, D=0.05)

out = rx.run_batch(mono_0=8000.0, ini_0=50.0, CTA_0=20.0,
                   T_0=473.15, t_end=5.0, dt=0.01)
print(out["Mn_final"], out["Mw_final"], out["PDI_final"])

Chain-length-distribution (CLD) batch

run_batch_cld resolves every active (Pₙ) and dead (Dₙ) chain length up to N_max, so the molecular-weight distribution and its exact moments come out directly — no Hulburt–Katz closure. It is isothermal and needs no set_batch_params.

from pypolymer import PolyRxn

rx = PolyRxn(kd=10.0, kp=2.0, ktc=1e-3, ktd=1e-3, ktrm=8e-3,
             ktrp=1e-3, kca=0.0, f=1.0, dH_p=-1.0e5, Mw_mono=28.05)

out = rx.run_batch_cld(mono_0=180.0, ini_0=5e-2,
                       t_end=20.0, dt=0.1, N_max=1400)

print(out["Mn_final"], out["Mw_final"], out["PDI_final"])  # ≈ 6100, 12500, 2.05
mwd  = out["MWD_final"]          # full chain-length distribution P + D
nvec = out["chain_length"]       # 1 .. N_max

Choosing N_max. Faster propagation produces longer chains; pick N_max large enough that the distribution has decayed to ~0 at the boundary (check out["MWD_final"][-1] is small relative to the peak). Cost grows with N_max (an N_max × N_max outer product per RHS evaluation).

Operating-condition optimisation (RL)

from pypolymer import run_batch_rl, run_cstr_rl, run_pfr_rl

run_batch_rl(n_eps=120)          # Batch
run_cstr_rl(n_eps=120)           # CSTR
run_pfr_rl(n_eps=150, plot=True) # LDPE PFR (heavier)

Or from the command line:

python -m pypolymer            # Batch + CSTR optimisation
python -m pypolymer pfr        # LDPE PFR optimisation
python -m pypolymer all        # all three

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypolymer-0.2.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypolymer-0.2.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file pypolymer-0.2.0.tar.gz.

File metadata

  • Download URL: pypolymer-0.2.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for pypolymer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 64770f33340e9708c5fc6c8610144735ee918d82f0e0576fddcec90e59f4f4e8
MD5 e796b4486eb625d4ab2bb0c36af50982
BLAKE2b-256 3215eb8027ef8b022d2b6c626c86ae5910f8ee989580f489f525b89e85c68274

See more details on using hashes here.

File details

Details for the file pypolymer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pypolymer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for pypolymer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb1fc5d74825b0f04a83b74eb151d4cd8de6a80fc59dceaecfd74447152a3f77
MD5 22cc223a5a6f140eee89557e802a01ee
BLAKE2b-256 e3bed515f7a93cec4d675c625342e8d8675a1b4fb443cdeafb03135c29555146

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page