PSCF v1.4.0
r1d/system/System.h
1#ifndef R1D_SYSTEM_H
2#define R1D_SYSTEM_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11// Header file includes
12#include <util/param/ParamComposite.h> // base class
13#include <r1d/field/FieldIo.h> // member
14#include <r1d/solvers/Mixture.h> // member
15#include <r1d/field/Domain.h> // member
16#include <util/misc/FileMaster.h> // member
17#include <util/containers/DArray.h> // member template
18#include <util/containers/Array.h> // function parameter
19
20// Forward declarations
21namespace Pscf {
22 class Interaction;
23 namespace R1d {
24 class Iterator;
25 class IteratorFactory;
26 class Sweep;
27 class SweepFactory;
28 using namespace Util;
29 }
30}
31
32namespace Pscf {
33namespace R1d {
34
66 class System : public ParamComposite
67 {
68
69 public:
70
73
76
79
82
86 System();
87
91 ~System();
92
96
100 void setOptions(int argc, char **argv);
101
107 virtual void readParam(std::istream& in);
108
112 void readParam();
113
119 virtual void readParameters(std::istream& in);
120
126 void readCommands(std::istream& in);
127
131 void readCommands();
132
135
136
152 void compute();
153
165 int iterate(bool isContinuation = false);
166
178 void sweep();
179
181
183
191 void computeFreeEnergy();
192
199 double fHelmholtz() const;
200
207 double pressure() const;
208
210
212
218 void writeParamNoSweep(std::ostream& out) const;
219
229 void writeThermo(std::ostream& out) const;
230
233
234
240 void writeW(std::string const & filename) const;
241
247 void writeC(std::string const & filename) const;
248
259 void writeBlockC(std::string const & filename) const;
260
270 void writeQSlice(std::string const & filename,
271 int polymerId, int blockId,
272 int directionId, int segmentId) const;
273
282 void writeQTail(std::string const & filename, int polymerId,
283 int blockId, int directionId) const;
284
293 void writeQ(std::string const & filename, int polymerId,
294 int blockId, int directionId) const;
295
314 void writeQAll(std::string const & basename) const;
315
317
319
326
332 DArray<WField> const & wFields() const;
333
339 WField& wField(int monomerId);
340
346 WField const & wField(int monomerId) const;
347
354
360 DArray<Field> const & cFields() const;
361
367 Field& cField(int monomerId);
368
374 Field const & cField(int monomerId) const;
375
379
383 Mixture& mixture();
384
388 Mixture const & mixture() const;
389
394
398 Interaction const & interaction() const;
399
403 Domain& domain();
404
409
414
416
417 private:
418
422 Mixture mixture_;
423
427 Domain domain_;
428
432 FileMaster fileMaster_;
433
437 FieldIo fieldIo_;
438
442 Interaction* interactionPtr_;
443
447 Iterator* iteratorPtr_;
448
452 IteratorFactory* iteratorFactoryPtr_;
453
457 Sweep* sweepPtr_;
458
462 SweepFactory* sweepFactoryPtr_;
463
469 DArray<WField> wFields_;
470
476 DArray<Field> cFields_;
477
481 mutable DArray<double> f_;
482
486 mutable DArray<double> c_;
487
491 double fHelmholtz_;
492
500 double fIdeal_;
501
505 double fInter_;
506
510 double pressure_;
511
515 bool hasMixture_;
516
520 bool hasDomain_;
521
525 bool hasFields_;
526
530 bool hasSweep_;
531
532 // Private member functions
533
537 void allocateFields();
538
545 void readEcho(std::istream& in, std::string& string) const;
546
547 };
548
549 // Inline member functions
550
551 /*
552 * Get the associated Mixture object by reference.
553 */
555 { return mixture_; }
556
557 /*
558 * Get the associated Mixture object by const reference.
559 */
560 inline Mixture const & System::mixture() const
561 { return mixture_; }
562
563 /*
564 * Get the Interaction (excess free energy model).
565 */
567 {
568 UTIL_ASSERT(interactionPtr_);
569 return *interactionPtr_;
570 }
571
572 /*
573 * Get the Interaction (excess free energy) by const reference.
574 */
575 inline Interaction const & System::interaction() const
576 {
577 UTIL_ASSERT(interactionPtr_);
578 return *interactionPtr_;
579 }
580
581 /*
582 * Get the spatial Domain.
583 */
585 { return domain_; }
586
587 /*
588 * Get the Iterator.
589 */
591 {
592 UTIL_ASSERT(iteratorPtr_);
593 return *iteratorPtr_;
594 }
595
596 /*
597 * Get the FileMaster.
598 */
600 { return fileMaster_; }
601
602 /*
603 * Get an array of all monomer excess chemical potential fields.
604 */
605 inline
607 { return wFields_; }
608
609 /*
610 * Get a const array of all monomer excess chemical potential fields.
611 */
612 inline
614 { return wFields_; }
615
616 /*
617 * Get a single monomer excess chemical potential field.
618 */
619 inline
621 { return wFields_[id]; }
622
623 /*
624 * Get a single const monomer excess chemical potential field.
625 */
626 inline
627 System::WField const & System::wField(int id) const
628 { return wFields_[id]; }
629
630 /*
631 * Get array of all monomer concentration fields.
632 */
633 inline
635 { return cFields_; }
636
637 /*
638 * Get const array of all monomer concentration fields.
639 */
640 inline
642 { return cFields_; }
643
644 /*
645 * Get a single monomer concentration field.
646 */
648 { return cFields_[id]; }
649
650 /*
651 * Get a single const monomer concentration field.
652 */
653 inline System::Field const & System::cField(int id) const
654 { return cFields_[id]; }
655
656 /*
657 * Get precomputed Helmoltz free energy per monomer / kT.
658 */
659 inline double System::fHelmholtz() const
660 { return fHelmholtz_; }
661
662 /*
663 * Get precomputed pressure (units of kT / monomer volume).
664 */
665 inline double System::pressure() const
666 { return pressure_; }
667
668} // namespace R1d
669} // namespace Pscf
670#endif
Interaction model for complex Langevin FTS.
Definition Interaction.h:24
One-dimensional spatial domain and discretization grid.
Read and write fields to file.
Factory for subclasses of Iterator.
Base class for iterative solvers for SCF equations.
Solver and descriptor for a mixture of polymers and solvents.
Default Factory for subclasses of Sweep.
Solve a sequence of problems along a line in parameter space.
DArray< double > Field
Generic Field type.
DArray< Field > & cFields()
Get array of all chemical potential fields.
void compute()
Solve the modified diffusion equation once, without iteration.
DArray< double > CField
Monomer concentration / volume fraction field type.
void readParam()
Read input parameters from default param file.
double fHelmholtz() const
Get precomputed Helmholtz free energy per monomer / kT.
double pressure() const
Get precomputed pressure x monomer volume kT.
void writeC(std::string const &filename) const
Write concentration fields in symmetrized basis format.
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
void writeQSlice(std::string const &filename, int polymerId, int blockId, int directionId, int segmentId) const
Write slice of a propagator at fixed s in r-grid format.
Interaction & interaction()
Get interaction (i.e., excess free energy) by reference.
void computeFreeEnergy()
Compute free energy density and pressure for current fields.
void writeW(std::string const &filename) const
Write chemical potential fields in symmetrized basis format.
void readCommands()
Read commands from default command file.
Iterator & iterator()
Get the Iterator by reference.
Domain & domain()
Get spatial domain (including grid info) by reference.
void writeQAll(std::string const &basename) const
Write all propagators of all blocks, each to a separate file.
FileMaster & fileMaster()
Get FileMaster by reference.
Field & cField(int monomerId)
Get chemical potential field for a specific monomer type.
void setOptions(int argc, char **argv)
Process command line options.
WField & wField(int monomerId)
Get chemical potential field for a specific monomer type.
DArray< WField > & wFields()
Get array of all chemical potential fields.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write one propagator for one block, in r-grid format.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
virtual void readParameters(std::istream &in)
Read input parameters (without opening and closing lines).
void writeBlockC(std::string const &filename) const
Write c-fields for all blocks and solvents in r-grid format.
DArray< double > WField
Monomer chemical potential field type.
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
void writeThermo(std::ostream &out) const
Write thermodynamic properties to a file.
void writeParamNoSweep(std::ostream &out) const
Write parameter file to an ostream, omitting any Sweep block.
Mixture & mixture()
Get Mixture by reference.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
A FileMaster manages input and output files for a simulation.
Definition FileMaster.h:143
ParamComposite()
Constructor.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
SCFT with real 1D fields.
PSCF package top-level namespace.