GithubHelp home page GithubHelp logo

io-saito / polyfields.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sfriedowitz/polyfields.jl

0.0 0.0 0.0 684 KB

A Julia implementation of polymer self-consistent field theory.

License: MIT License

Julia 100.00%

polyfields.jl's Introduction

PolyFields.jl

PolyFields is a minimal Julia implementation of polymer self-consistent field theory, as described in the extensive monograph "Fredrickson, G. (2005). The Equilibrium Theory of Inhomogeneous Polymers." Core implementation details are heavily inspired by the Fortran package PSCF.

Currently, the package only has the capability of solving the self-consistent field theory (SCFT) equations, corresponding to a mean-field solution of the underlying field-theoretic partition function. Implementation of full field-theoretic simultions (FTS) via complex Langevin sampling is a later goal.

Usage

The PolyFields package is amenable for use in an interactive workspace environment. The basic objects required for a field-theoretic simulation can be created as follows.

using PolyFields

# Number of grid-points in x/y/z dimensions
dims = (64, 1, 1);

# Unit cell for 1D system
cell = UnitCell(1, :lamellar, 10.0); 

# Create monomers, which represent a distinct chemical type
amon = Monomer(; id = 1, vol = 1.0, charge = 0.0);
bmon = Monomer(; id = 2, vol = 1.0, charge = 0.0);

# Create a diblock copolymer species with: N = 100, fA = 0.5, bA = bB = 1.0, Ns = 100
chain = Diblock(amon, bmon, 100, 0.5, 1.0, 1.0, 100);

# Create a Flory-Huggins interaction
itx = FloryInteraction();
set_interaction!(itx, amon, bmon, 0.2);

# Create a system to hold all the pieces
sys = FieldSystem(dims, cell; monomers = [amon, bmon], ensemble = Canonical);
add_species!(sys, chain);
add_interaction!(sys, itx);

# Initialize the fields randomly with a scaling factor of 0.1
fieldinit!(sys; scale = 0.1)

Then, after creating a system and adding the appropriate components, we can run an SCFT calculation. This is done by specifying an AbstractFieldUpdater to relax the field configurations, and optionally the cell configurations as well.

# Runtime options for SCFT
opts = SCFTOptions(nsteps = 1500, nsout = 100, ftol = 1e-4, stol = 1e-4);

# Anderson mixing field updater, with a history size of 10 previous configurations
updater = AndersonUpdater(; nhist = 10);

# Variable cell implementation. Update cell every 5 SCFT steps, and perform 20 iterations
domain = DomainUpdater(; nskip = 5, nper = 20);

# Run the SCFT simulation
scft!(sys, updater; domain = domain, opts = opts)
--------------------------------------------------------------
Step (0     /  1500): ferr = 1.530661e+00, fhelm = 6.70556e-02
Updating cell dimensions: serr = 9.72180e-04
Step (10    /  1500): ferr = 8.668635e-01, fhelm = 7.12575e-02
Updating cell dimensions: serr = 4.82911e-05
Step (20    /  1500): ferr = 3.592973e-01, fhelm = 8.17260e-02
Updating cell dimensions: serr = 2.49362e-05
Step (30    /  1500): ferr = 1.366519e-03, fhelm = 8.12312e-02
Converged @ step = 36: ferr = 6.278932e-06, fhelm = 8.12381e-02
Converged cell parameters: [16.528709413909947]

SCFTResults
  time: Float64 0.0257432
  nsteps: Int64 36
  converged: Bool true
  ferr: Float64 5.0874415525661515e-6
  serr: Float64 1.6582423877606872e-6
  fhelm: Float64 0.0812381288285528

TODO

  • Add plotting tools for system and field output
  • Ordered initialization: Cell --> System --> Updaters, no setup calls internally
  • Add species to system without adding monomers beforehand?
  • Divergence issues for AndersonUpdater w/ sub-optimal seeding
  • GCE performance and stability, chemical potential constraints
  • Add FDDD2 crystal systems, more generic format for basis construction
  • Custom field containers -- analogous to NN tensors, stores residuals

polyfields.jl's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.