PSCF v1.3.1
r1d/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#include <util/param/ParamComposite.h> // base class
12#include <r1d/misc/FieldIo.h> // member
13#include <r1d/solvers/Mixture.h> // member
14#include <r1d/domain/Domain.h> // member
15#include <pscf/floryHuggins/Mixture.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
20namespace Pscf {
21
22 class Interaction;
23
24namespace R1d
25{
26
27 class Iterator;
28 class IteratorFactory;
29 class Sweep;
30 class SweepFactory;
31 using namespace Util;
32
64 class System : public ParamComposite
65 {
66
67 public:
68
71
74
77
80
84 System();
85
89 ~System();
90
94
98 void setOptions(int argc, char **argv);
99
105 virtual void readParam(std::istream& in);
106
110 void readParam();
111
117 virtual void readParameters(std::istream& in);
118
124 void readCommands(std::istream& in);
125
129 void readCommands();
130
133
134
150 void compute();
151
163 int iterate(bool isContinuation = false);
164
176 void sweep();
177
179
181
189 void computeFreeEnergy();
190
197 double fHelmholtz() const;
198
205 double pressure() const;
206
208
210
216 void writeParamNoSweep(std::ostream& out) const;
217
227 void writeThermo(std::ostream& out) const;
228
231
232
238 void writeW(std::string const & filename) const;
239
245 void writeC(std::string const & filename) const;
246
257 void writeBlockC(std::string const & filename) const;
258
268 void writeQSlice(std::string const & filename,
269 int polymerId, int blockId,
270 int directionId, int segmentId) const;
271
280 void writeQTail(std::string const & filename, int polymerId,
281 int blockId, int directionId) const;
282
291 void writeQ(std::string const & filename, int polymerId,
292 int blockId, int directionId) const;
293
312 void writeQAll(std::string const & basename) const;
313
315
317
324
330 DArray<WField> const & wFields() const;
331
337 WField& wField(int monomerId);
338
344 WField const & wField(int monomerId) const;
345
352
358 DArray<CField> const & cFields() const;
359
365 CField& cField(int monomerId);
366
372 CField const & cField(int monomerId) const;
373
377
381 Mixture& mixture();
382
386 Mixture const & mixture() const;
387
392
396 Interaction const & interaction() const;
397
401 Domain& domain();
402
407
412
417
419
420 private:
421
425 Mixture mixture_;
426
430 Domain domain_;
431
435 FileMaster fileMaster_;
436
440 FieldIo fieldIo_;
441
445 FloryHuggins::Mixture homogeneous_;
446
450 Interaction* interactionPtr_;
451
455 Iterator* iteratorPtr_;
456
460 IteratorFactory* iteratorFactoryPtr_;
461
465 Sweep* sweepPtr_;
466
470 SweepFactory* sweepFactoryPtr_;
471
477 DArray<WField> wFields_;
478
484 DArray<CField> cFields_;
485
489 mutable DArray<double> f_;
490
494 mutable DArray<double> c_;
495
499 double fHelmholtz_;
500
508 double fIdeal_;
509
513 double fInter_;
514
518 double pressure_;
519
523 bool hasMixture_;
524
528 bool hasDomain_;
529
533 bool hasFields_;
534
538 bool hasSweep_;
539
540 // Private member functions
541
545 void allocateFields();
546
553 void readEcho(std::istream& in, std::string& string) const;
554
555 };
556
557 // Inline member functions
558
559 /*
560 * Get the associated Mixture object by reference.
561 */
563 { return mixture_; }
564
565 /*
566 * Get the associated Mixture object by const reference.
567 */
568 inline Mixture const & System::mixture() const
569 { return mixture_; }
570
571 /*
572 * Get the Interaction (excess free energy model).
573 */
575 {
576 UTIL_ASSERT(interactionPtr_);
577 return *interactionPtr_;
578 }
579
580 /*
581 * Get the Interaction (excess free energy) by const reference.
582 */
583 inline Interaction const & System::interaction() const
584 {
585 UTIL_ASSERT(interactionPtr_);
586 return *interactionPtr_;
587 }
588
589 /*
590 * Get the spatial Domain.
591 */
593 { return domain_; }
594
595 /*
596 * Get the FloryHuggins::Mixture object.
597 */
598 inline
600 { return homogeneous_; }
601
602 /*
603 * Get the Iterator.
604 */
606 {
607 UTIL_ASSERT(iteratorPtr_);
608 return *iteratorPtr_;
609 }
610
611 /*
612 * Get the FileMaster.
613 */
615 { return fileMaster_; }
616
617 /*
618 * Get an array of all monomer excess chemical potential fields.
619 */
620 inline
622 { return wFields_; }
623
624 /*
625 * Get a const array of all monomer excess chemical potential fields.
626 */
627 inline
629 { return wFields_; }
630
631 /*
632 * Get a single monomer excess chemical potential field.
633 */
634 inline
636 { return wFields_[id]; }
637
638 /*
639 * Get a single const monomer excess chemical potential field.
640 */
641 inline
642 System::WField const & System::wField(int id) const
643 { return wFields_[id]; }
644
645 /*
646 * Get array of all monomer concentration fields.
647 */
648 inline
650 { return cFields_; }
651
652 /*
653 * Get const array of all monomer concentration fields.
654 */
655 inline
657 { return cFields_; }
658
659 /*
660 * Get a single monomer concentration field.
661 */
663 { return cFields_[id]; }
664
665 /*
666 * Get a single const monomer concentration field.
667 */
668 inline System::CField const & System::cField(int id) const
669 { return cFields_[id]; }
670
671 /*
672 * Get precomputed Helmoltz free energy per monomer / kT.
673 */
674 inline double System::fHelmholtz() const
675 { return fHelmholtz_; }
676
677 /*
678 * Get precomputed pressure (units of kT / monomer volume).
679 */
680 inline double System::pressure() const
681 { return pressure_; }
682
683} // namespace R1d
684} // namespace Pscf
685#endif
A spatially homogeneous mixture.
Flory-Huggins excess free energy model.
Definition Interaction.h:26
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.
Definition r1d/System.h:70
void compute()
Solve the modified diffusion equation once, without iteration.
DArray< double > CField
Monomer concentration / volume fraction field type.
Definition r1d/System.h:76
void readParam()
Read input parameters from default param file.
double fHelmholtz() const
Get precomputed Helmholtz free energy per monomer / kT.
Definition r1d/System.h:674
double pressure() const
Get precomputed pressure x monomer volume kT.
Definition r1d/System.h:680
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.
Definition r1d/System.h:574
CField & cField(int monomerId)
Get chemical potential field for a specific monomer type.
Definition r1d/System.h:662
DArray< CField > & cFields()
Get array of all chemical potential fields.
Definition r1d/System.h:649
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.
FloryHuggins::Mixture & homogeneous()
Get the homogeneous Flory-Huggins mixture (for reference calculations).
Definition r1d/System.h:599
Iterator & iterator()
Get the Iterator by reference.
Definition r1d/System.h:605
Domain & domain()
Get spatial domain (including grid info) by reference.
Definition r1d/System.h:592
void writeQAll(std::string const &basename) const
Write all propagators of all blocks, each to a separate file.
FileMaster & fileMaster()
Get FileMaster by reference.
Definition r1d/System.h:614
void setOptions(int argc, char **argv)
Process command line options.
WField & wField(int monomerId)
Get chemical potential field for a specific monomer type.
Definition r1d/System.h:635
DArray< WField > & wFields()
Get array of all chemical potential fields.
Definition r1d/System.h:621
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.
Definition r1d/System.h:73
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.
~System()
Destructor.
Mixture & mixture()
Get Mixture by reference.
Definition r1d/System.h:562
System()
Constructor.
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.
Definition param_pc.dox:1