PSCF v1.5.0
r1/system/System.h
1#ifndef R1_SYSTEM_H
2#define R1_SYSTEM_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
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 <r1/field/FieldIo.h> // member
14#include <r1/solvers/Mixture.h> // member
15#include <r1/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 R1 {
24 class Iterator;
25 class IteratorFactory;
26 class Sweep;
27 class SweepFactory;
28 using namespace Util;
29 }
30}
31
32namespace Pscf {
33namespace R1 {
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
131 int readCommands(std::istream& in);
132
138 int readCommands();
139
142
143
159 void compute();
160
172 int iterate(bool isContinuation = false);
173
185 void sweep();
186
188
190
198 void computeFreeEnergy();
199
206 double fHelmholtz() const;
207
214 double pressure() const;
215
217
219
225 void writeParamNoSweep(std::ostream& out) const;
226
236 void writeThermo(std::ostream& out) const;
237
240
241
247 void writeW(std::string const & filename) const;
248
254 void writeC(std::string const & filename) const;
255
266 void writeBlockC(std::string const & filename) const;
267
277 void writeQSlice(std::string const & filename,
278 int polymerId, int blockId,
279 int directionId, int segmentId) const;
280
289 void writeQTail(std::string const & filename, int polymerId,
290 int blockId, int directionId) const;
291
300 void writeQ(std::string const & filename, int polymerId,
301 int blockId, int directionId) const;
302
321 void writeQAll(std::string const & basename) const;
322
324
326
333
339 DArray<WField> const & wFields() const;
340
346 WField& wField(int monomerId);
347
353 WField const & wField(int monomerId) const;
354
361
367 DArray<Field> const & cFields() const;
368
374 Field& cField(int monomerId);
375
381 Field const & cField(int monomerId) const;
382
386
390 Mixture& mixture();
391
395 Mixture const & mixture() const;
396
401
405 Interaction const & interaction() const;
406
410 Domain& domain();
411
416
421
423
424 private:
425
429 Mixture mixture_;
430
434 Domain domain_;
435
439 FileMaster fileMaster_;
440
444 FieldIo fieldIo_;
445
449 Interaction* interactionPtr_;
450
454 Iterator* iteratorPtr_;
455
459 IteratorFactory* iteratorFactoryPtr_;
460
464 Sweep* sweepPtr_;
465
469 SweepFactory* sweepFactoryPtr_;
470
476 DArray<WField> wFields_;
477
483 DArray<Field> cFields_;
484
488 mutable DArray<double> f_;
489
493 mutable DArray<double> c_;
494
498 double fHelmholtz_;
499
507 double fIdeal_;
508
512 double fInter_;
513
517 double pressure_;
518
522 bool hasMixture_;
523
527 bool hasDomain_;
528
532 bool hasFields_;
533
538 bool hasCFields_;
539
543 bool hasSweep_;
544
545 // Private member functions
546
550 void allocateFields();
551
558 void readEcho(std::istream& in, std::string& string) const;
559
560 };
561
562 // Inline member functions
563
564 /*
565 * Get the associated Mixture object by reference.
566 */
568 { return mixture_; }
569
570 /*
571 * Get the associated Mixture object by const reference.
572 */
573 inline Mixture const & System::mixture() const
574 { return mixture_; }
575
576 /*
577 * Get the Interaction (excess free energy model).
578 */
580 {
581 UTIL_ASSERT(interactionPtr_);
582 return *interactionPtr_;
583 }
584
585 /*
586 * Get the Interaction (excess free energy) by const reference.
587 */
588 inline Interaction const & System::interaction() const
589 {
590 UTIL_ASSERT(interactionPtr_);
591 return *interactionPtr_;
592 }
593
594 /*
595 * Get the spatial Domain.
596 */
598 { return domain_; }
599
600 /*
601 * Get the Iterator.
602 */
604 {
605 UTIL_ASSERT(iteratorPtr_);
606 return *iteratorPtr_;
607 }
608
609 /*
610 * Get the FileMaster.
611 */
613 { return fileMaster_; }
614
615 /*
616 * Get an array of all monomer excess chemical potential fields.
617 */
618 inline
620 { return wFields_; }
621
622 /*
623 * Get a const array of all monomer excess chemical potential fields.
624 */
625 inline
627 { return wFields_; }
628
629 /*
630 * Get a single monomer excess chemical potential field.
631 */
632 inline
634 { return wFields_[id]; }
635
636 /*
637 * Get a single const monomer excess chemical potential field.
638 */
639 inline
640 System::WField const & System::wField(int id) const
641 { return wFields_[id]; }
642
643 /*
644 * Get array of all monomer concentration fields.
645 */
646 inline
648 { return cFields_; }
649
650 /*
651 * Get const array of all monomer concentration fields.
652 */
653 inline
655 { return cFields_; }
656
657 /*
658 * Get a single monomer concentration field.
659 */
661 { return cFields_[id]; }
662
663 /*
664 * Get a single const monomer concentration field.
665 */
666 inline System::Field const & System::cField(int id) const
667 { return cFields_[id]; }
668
669 /*
670 * Get precomputed Helmoltz free energy per monomer / kT.
671 */
672 inline double System::fHelmholtz() const
673 { return fHelmholtz_; }
674
675 /*
676 * Get precomputed pressure (units of kT / monomer volume).
677 */
678 inline double System::pressure() const
679 { return pressure_; }
680
681} // namespace R1
682} // namespace Pscf
683#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.
Field & cField(int monomerId)
Get chemical potential field for a specific monomer type.
FileMaster & fileMaster()
Get FileMaster by reference.
DArray< double > CField
Monomer concentration / volume fraction field type.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write one propagator for one block, in r-grid format.
void compute()
Solve the modified diffusion equation once, without iteration.
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.
DArray< double > WField
Monomer chemical potential field type.
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 setOptions(int argc, char **argv)
Process command line options.
void writeW(std::string const &filename) const
Write chemical potential fields in symmetrized basis format.
Mixture & mixture()
Get Mixture by reference.
void writeParamNoSweep(std::ostream &out) const
Write parameter file to an ostream, omitting any Sweep block.
Iterator & iterator()
Get the Iterator by reference.
DArray< Field > & cFields()
Get array of all chemical potential fields.
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
double pressure() const
Get precomputed pressure x monomer volume kT.
void computeFreeEnergy()
Compute free energy density and pressure for current fields.
int readCommands(std::istream &in)
Read command script.
WField & wField(int monomerId)
Get chemical potential field for a specific monomer type.
DArray< WField > & wFields()
Get array of all chemical potential fields.
virtual void readParam(std::istream &in)
Read input parameters (with opening and closing lines).
void writeQAll(std::string const &basename) const
Write all propagators of all blocks, each to a separate file.
Interaction & interaction()
Get interaction (i.e., excess free energy) by reference.
void writeBlockC(std::string const &filename) const
Write c-fields for all blocks and solvents in r-grid format.
Domain & domain()
Get spatial domain (including grid info) by reference.
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.
DArray< double > Field
Generic Field type.
double fHelmholtz() const
Get precomputed Helmholtz free energy per monomer / kT.
void writeC(std::string const &filename) const
Write concentration fields in symmetrized basis format.
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.