PSCF v1.4.0
cp/system/System.h
1#ifndef PRDC_CL_SYSTEM_H
2#define PRDC_CL_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 <pscf/chem/PolymerModel.h> // member
13
14// Forward declarations
15namespace Util {
16 class FileMaster;
17 template <typename E, int N> class FSArray;
18}
19namespace Pscf {
20 namespace Prdc {
21 template <int D> class UnitCell;
22 }
23}
24
25namespace Pscf {
26namespace Cp {
27
28 // Namespaces that may be used implicitly
29 using namespace Util;
30 using namespace Prdc;
31
72 template <int D, class T>
73 class System : public ParamComposite
74 {
75
76 public:
77
78 // Public type name aliases
79 using MixtureT = typename T::Mixture;
80 using InteractionT = typename T::Interaction;
81 using DomainT = typename T::Domain;
82 using WFieldsT = typename T::WFields; // chemical pot. fields
83 using CFieldsT = typename T::CFields; // concentration fields
84 using CFieldT = typename T::CField; // complex field type
85
88
106 System(typename T::System& system);
107
111 ~System();
112
113 // Suppress several compiler-generated member functions
114 System() = delete;
115 System(System<D,T> const &) = delete;
116 System<D,T>& operator = (System<D,T> const & ) = delete;
117
121
133 void setOptions(int argc, char **argv);
134
140 virtual void readParam(std::istream& in);
141
148 void readParam();
149
155 virtual void readParameters(std::istream& in);
156
162 void readCommands(std::istream& in);
163
170 void readCommands();
171
175
199 void compute(bool needStress = false);
200
212 void simulate(int nStep);
213
222 void clearCFields();
223
227
240 void setUnitCell(UnitCell<D> const & unitCell);
241
255 void setUnitCell(FSArray<double, 6> const & parameters);
256
264 void clearUnitCellData();
265
269
273 typename T::CFields const & c() const;
274
278 typename T::WFields& w();
279
283 typename T::WFields const & w() const;
284
288
292 typename T::Mixture const & mixture() const;
293
294 #if 0 // Delay implementation until needed, if ever
298 typename T::MixtureModifier& mixtureModifier();
299 #endif
300
304 typename T::Interaction& interaction();
305
309 typename T::Interaction const & interaction() const;
310
314 typename T::Domain const & domain() const;
315
316 #if 0 // Delay until Simulator class is finished
320 typename T::Simulator& simulator();
321
325 typename T::Simulator const & simulator() const;
326 #endif
327
334
338 FileMaster const & fileMaster() const;
339
341 #if 0
344
350 void writeTimers(std::ostream& out) const;
351
355 void clearTimers();
356
358 #endif
359
360 protected:
361
377 virtual void setThreadCount(int nThread)
378 {};
379
380 private:
381
382 // Component objects
383
387 typename T::WFields w_;
388
392 typename T::CFields c_;
393
394 // Pointers to associated objects
395
399 typename T::System* systemPtr_;
400
404 typename T::Mixture* mixturePtr_;
405
406 #if 0 // Skip, for now
410 typename T::MixtureModifier* mixtureModifierPtr_;
411 #endif
412
416 typename T::Domain* domainPtr_;
417
421 typename T::Interaction* interactionPtr_;
422
423 #if 0 // Comment out until Simulator class is finished
427 typename T::Simulator* simulatorPtr_;
428 #endif
429
433 FileMaster* fileMasterPtr_;
434
438 PolymerModel::Type polymerModel_;
439
440 // Boolean state variables
441
445 bool isAllocated_;
446
450 bool hasMixture_;
451
452 // Private member functions
453
457 typename T::Mixture & mixture_();
458
462 typename T::Domain& domain_();
463
467 void allocateFields();
468
477 void readEcho(std::istream& in, std::string& string) const;
478
487 void readEcho(std::istream& in, double& value) const;
488
489 };
490
491 // Inline member functions
492
493 // Get the Mixture (const).
494 template <int D, class T> inline
495 typename T::Mixture const & System<D,T>::mixture() const
496 { return *mixturePtr_; }
497
498 #if 0 // Delay or skip
499 // Get the MixtureModifier (non-const).
500 template <int D, class T> inline
501 typename T::MixtureModifier& System<D,T>::mixtureModifier()
502 {
503 UTIL_ASSERT(mixtureModifierPtr_);
504 return *mixtureModifierPtr_;
505 }
506 #endif
507
508 // Get the %Interaction (non-const).
509 template <int D, class T> inline
510 typename T::Interaction& System<D,T>::interaction()
511 {
512 UTIL_ASSERT(interactionPtr_);
513 return *interactionPtr_;
514 }
515
516 // Get the %Interaction (const).
517 template <int D, class T> inline
518 typename T::Interaction const & System<D,T>::interaction() const
519 {
520 UTIL_ASSERT(interactionPtr_);
521 return *interactionPtr_;
522 }
523
524 // Get the Domain (const).
525 template <int D, class T> inline
526 typename T::Domain const & System<D,T>::domain() const
527 { return *domainPtr_; }
528
529 #if 0 // Comment out until Simulator class is finished
530 // Get the Simulator (non-const).
531 template <int D, class T> inline
532 typename T::Simulator& System<D,T>::simulator()
533 {
534 UTIL_ASSERT(simulatorPtr_);
535 return *simulatorPtr_;
536 }
537
538 // Get the Simulator (const).
539 template <int D, class T> inline
540 typename T::Simulator const & System<D,T>::simulator() const
541 {
542 UTIL_ASSERT(simulatorPtr_);
543 return *simulatorPtr_;
544 }
545 #endif
546
547 // Get the FileMaster (non-const).
548 template <int D, class T> inline
550 { return *fileMasterPtr_; }
551
552 // Get the FileMaster (const).
553 template <int D, class T> inline
555 { return *fileMasterPtr_; }
556
557 // Get the container of c fields (const).
558 template <int D, class T> inline
559 typename T::CFields const & System<D,T>::c() const
560 { return c_; }
561
562 // Get the container of w fields (non-const).
563 template <int D, class T> inline
564 typename T::WFields& System<D,T>::w()
565 { return w_; }
566
567 // Get the container of w fields (const).
568 template <int D, class T> inline
569 typename T::WFields const & System<D,T>::w() const
570 { return w_; }
571
572 // Private inline functions:
573
574 // Get the Mixture (non-const).
575 template <int D, class T> inline
576 typename T::Mixture & System<D,T>::mixture_()
577 { return *mixturePtr_; }
578
579 // Get the Domain (non-const).
580 template <int D, class T> inline
581 typename T::Domain & System<D,T>::domain_()
582 { return *domainPtr_; }
583
584} // namespace Cp
585} // namespace Pscf
586#endif
Base class template for a complex CL-FTS system.
void readCommands()
Read and process commands from the default command file.
T::WFields & w()
Get the chemical potential (w) fields (non-const).
void readParam()
Read input parameters from default param file.
FileMaster & fileMaster()
Get the FileMaster (non-const).
virtual void readParameters(std::istream &in)
Read body of parameter block (without opening and closing lines).
T::Domain const & domain() const
Get the Domain (const).
void clearUnitCellData()
Notify System members that unit cell parameters have been modified.
void clearCFields()
Mark c-fields and free energy as outdated or invalid.
T::CFields const & c() const
Get the monomer concentration (c) fields (const).
void compute(bool needStress=false)
Solve the modified diffusion equation once, without iteration.
T::Mixture const & mixture() const
Get the Mixture (const).
virtual void setThreadCount(int nThread)
Set the number of threads given as a command line argument.
void setUnitCell(UnitCell< D > const &unitCell)
Set parameters of the associated unit cell.
void setOptions(int argc, char **argv)
Process command line options.
T::Interaction & interaction()
Get the Interaction (non-const).
System(typename T::System &system)
Constructor.
void simulate(int nStep)
Perform a field theoretic simulation (PS-FTS).
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
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
Type
Scoped enumeration of polymer model types.
Complex-valued periodic fields (class templates).
Definition cp.mod:6
Periodic fields and crystallography.
Definition complex.cpp:11
void allocateFields(DArray< FT > &fields, int n, IntVec< D > const &dimension)
Allocate a DArray of fields.
PSCF package top-level namespace.
Utility classes for scientific computation.