PSCF v1.1
fd1d/System.h
1#ifndef FD1D_SYSTEM_H
2#define FD1D_SYSTEM_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, 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 <fd1d/misc/FieldIo.h> // member
13#include <fd1d/solvers/Mixture.h> // member
14#include <fd1d/domain/Domain.h> // member
15#include <pscf/homogeneous/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 Fd1d
25{
26
27 class Iterator;
28 class IteratorFactory;
29 class Sweep;
30 class SweepFactory;
31 using namespace Util;
32
62 class System : public ParamComposite
63 {
64
65 public:
66
69
72
75
78
82 System();
83
87 ~System();
88
92
96 void setOptions(int argc, char **argv);
97
103 virtual void readParam(std::istream& in);
104
108 void readParam();
109
115 virtual void readParameters(std::istream& in);
116
122 void readCommands(std::istream& in);
123
127 void readCommands();
128
131
132
148 void compute();
149
161 int iterate(bool isContinuation = false);
162
174 void sweep();
175
177
179
187 void computeFreeEnergy();
188
195 double fHelmholtz() const;
196
203 double pressure() const;
204
206
208
214 void writeParamNoSweep(std::ostream& out) const;
215
225 void writeThermo(std::ostream& out);
226
229
230
236 void writeW(std::string const & filename);
237
243 void writeC(std::string const & filename);
244
255 void writeBlockC(std::string const & filename);
256
266 void writeQSlice(std::string const & filename,
267 int polymerId, int blockId,
268 int directionId, int segmentId) const;
269
278 void writeQTail(std::string const & filename, int polymerId,
279 int blockId, int directionId) const;
280
289 void writeQ(std::string const & filename, int polymerId,
290 int blockId, int directionId) const;
291
310 void writeQAll(std::string const & basename);
311
313
315
322
328 WField& wField(int monomerId);
329
336
342 CField& cField(int monomerId);
343
347
351 Mixture& mixture();
352
356 Mixture const & mixture() const;
357
362
366 Interaction const & interaction() const;
367
371 Domain& domain();
372
377
382
387
389
390 private:
391
395 Mixture mixture_;
396
400 Domain domain_;
401
405 FileMaster fileMaster_;
406
410 FieldIo fieldIo_;
411
415 Homogeneous::Mixture homogeneous_;
416
420 Interaction* interactionPtr_;
421
425 Iterator* iteratorPtr_;
426
430 IteratorFactory* iteratorFactoryPtr_;
431
435 Sweep* sweepPtr_;
436
440 SweepFactory* sweepFactoryPtr_;
441
447 DArray<WField> wFields_;
448
454 DArray<CField> cFields_;
455
459 mutable DArray<double> f_;
460
464 mutable DArray<double> c_;
465
469 double fHelmholtz_;
470
478 double fIdeal_;
479
483 double fInter_;
484
488 double pressure_;
489
493 bool hasMixture_;
494
498 bool hasDomain_;
499
503 bool hasFields_;
504
508 bool hasSweep_;
509
510 // Private member functions
511
515 void allocateFields();
516
520 void initHomogeneous();
521
528 void readEcho(std::istream& in, std::string& string) const;
529
530 };
531
532 // Inline member functions
533
534 /*
535 * Get the associated Mixture object by reference.
536 */
538 { return mixture_; }
539
540 /*
541 * Get the associated Mixture object by const reference.
542 */
543 inline Mixture const & System::mixture() const
544 { return mixture_; }
545
546 /*
547 * Get the Interaction (excess free energy model).
548 */
550 {
551 UTIL_ASSERT(interactionPtr_);
552 return *interactionPtr_;
553 }
554
555 /*
556 * Get the Interaction (excess free energy) by const reference.
557 */
558 inline Interaction const & System::interaction() const
559 {
560 UTIL_ASSERT(interactionPtr_);
561 return *interactionPtr_;
562 }
563
564 /*
565 * Get the spatial Domain.
566 */
568 { return domain_; }
569
570 /*
571 * Get the Homogeneous::Mixture object.
572 */
573 inline
575 { return homogeneous_; }
576
577 /*
578 * Get the Iterator.
579 */
581 {
582 UTIL_ASSERT(iteratorPtr_);
583 return *iteratorPtr_;
584 }
585
586 /*
587 * Get the FileMaster.
588 */
590 { return fileMaster_; }
591
592 /*
593 * Get an array of all monomer excess chemical potential fields.
594 */
595 inline
597 { return wFields_; }
598
599 /*
600 * Get a single monomer excess chemical potential field.
601 */
602 inline
604 { return wFields_[id]; }
605
606 /*
607 * Get array of all monomer concentration fields.
608 */
609 inline
611 { return cFields_; }
612
613 /*
614 * Get a single monomer concentration field.
615 */
617 { return cFields_[id]; }
618
619 /*
620 * Get precomputed Helmoltz free energy per monomer / kT.
621 */
622 inline double System::fHelmholtz() const
623 { return fHelmholtz_; }
624
625 /*
626 * Get precomputed pressure (units of kT / monomer volume).
627 */
628 inline double System::pressure() const
629 { return pressure_; }
630
631} // namespace Fd1d
632} // namespace Pscf
633#endif
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.
Mixture of polymers and solvents.
Default Factory for subclasses of Sweep.
Solve a sequence of problems along a line in parameter space.
Main class in SCFT simulation of one system.
Definition: fd1d/System.h:63
void writeThermo(std::ostream &out)
Write thermodynamic properties to a file.
WField & wField(int monomerId)
Get chemical potential field for a specific monomer type.
Definition: fd1d/System.h:603
DArray< double > CField
Monomer concentration / volume fraction field type.
Definition: fd1d/System.h:74
Iterator & iterator()
Get the Iterator by reference.
Definition: fd1d/System.h:580
int iterate(bool isContinuation=false)
Iteratively solve a SCFT problem.
void computeFreeEnergy()
Compute free energy density and pressure for current fields.
DArray< WField > & wFields()
Get array of all chemical potential fields.
Definition: fd1d/System.h:596
Homogeneous::Mixture & homogeneous()
Get homogeneous mixture (for reference calculations).
Definition: fd1d/System.h:574
void compute()
Solve the modified diffusion equation once, without iteration.
~System()
Destructor.
Definition: fd1d/System.cpp:77
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.
void readCommands()
Read commands from default command file.
Domain & domain()
Get spatial domain (including grid info) by reference.
Definition: fd1d/System.h:567
virtual void readParameters(std::istream &in)
Read input parameters (without opening and closing lines).
void sweep()
Sweep in parameter space, solving an SCF problem at each point.
Mixture & mixture()
Get Mixture by reference.
Definition: fd1d/System.h:537
DArray< CField > & cFields()
Get array of all chemical potential fields.
Definition: fd1d/System.h:610
double fHelmholtz() const
Get precomputed Helmholtz free energy per monomer / kT.
Definition: fd1d/System.h:622
System()
Constructor.
Definition: fd1d/System.cpp:40
void setOptions(int argc, char **argv)
Process command line options.
Definition: fd1d/System.cpp:99
void writeBlockC(std::string const &filename)
Write c-fields for all blocks and solvents in r-grid format.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
void readParam()
Read input parameters from default param file.
DArray< double > Field
Generic Field type.
Definition: fd1d/System.h:68
void writeC(std::string const &filename)
Write concentration fields in symmetrized basis format.
void writeParamNoSweep(std::ostream &out) const
Write parameter file to an ostream, omitting any Sweep block.
double pressure() const
Get precomputed pressure x monomer volume kT.
Definition: fd1d/System.h:628
Interaction & interaction()
Get interaction (i.e., excess free energy) by reference.
Definition: fd1d/System.h:549
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write one propagator for one block, in r-grid format.
void writeW(std::string const &filename)
Write chemical potential fields in symmetrized basis 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.
CField & cField(int monomerId)
Get chemical potential field for a specific monomer type.
Definition: fd1d/System.h:616
FileMaster & fileMaster()
Get FileMaster by reference.
Definition: fd1d/System.h:589
DArray< double > WField
Monomer chemical potential field type.
Definition: fd1d/System.h:71
A spatially homogeneous mixture.
Flory-Huggins excess free energy model.
Definition: Interaction.h:26
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:143
An object that can read multiple parameters from file.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1