PSCF v1.4.0
FhMixture.tpp
1#ifndef PSCF_FLORY_HUGGINS_MIXTURE_TPP
2#define PSCF_FLORY_HUGGINS_MIXTURE_TPP
3
4/*
5* PSCF - Molecule Self-Consistent Field Theory
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 "FhMixture.h"
12#include "FhMolecule.h"
13#include "FhClump.h"
14#include <pscf/chem/MixtureBase.h>
15#include <pscf/chem/PolymerSpecies.h>
16#include <pscf/chem/SolventSpecies.h>
17#include <pscf/chem/Edge.h>
18
19namespace Pscf {
20
21 using namespace Util;
22
23 template <typename WT>
25 {
26
27 // Set number of molecular species and monomers
28 int nm = mixture.nMonomer();
29 int np = mixture.nPolymer();
30 int ns = mixture.nSolvent();
31 int nt = np + ns;
32
33 // Check nMonomer, set if necessary
34 if (nMonomer() == 0) {
35 setNMonomer(nm);
36 }
37 UTIL_CHECK(nMonomer() == nm);
38 UTIL_CHECK(c_.capacity() == nm);
39 UTIL_CHECK(w_.capacity() == nm);
40
41 // Check nMolecule, set if necessary
42 if (nMolecule() == 0) {
43 setNMolecule(nt);
44 }
45 UTIL_CHECK(nMolecule() == nt);
46 UTIL_CHECK(molecules_.capacity() == nt);
47 UTIL_CHECK(phi_.capacity() == nt);
48 UTIL_CHECK(mu_.capacity() == nt);
49
50 // Work space of clump sizes
52 c_.allocate(nm);
53
54 int i; // species index
55 int j; // monomer index
56 int k; // block or clump index
57 int nb; // number of blocks
58 int nc; // number of clumps
59
60 // Loop over polymer molecule species
61 if (np > 0) {
62 for (i = 0; i < np; ++i) {
63 PolymerSpecies<WT> const& polymer = mixture.polymerSpecies(i);
64
65 // Initial array of clump sizes
66 for (j = 0; j < nm; ++j) {
67 c_[j] = 0.0;
68 }
69
70 // Compute clump sizes for all monomer types.
71 nb = polymer.nBlock();
72 for (k = 0; k < nb; ++k) {
73 Edge const& edge = polymer.edge(k);
74 j = edge.monomerId();
75 c_[j] += edge.length();
76 }
77
78 // Count the number of clumps of nonzero size
79 nc = 0;
80 for (j = 0; j < nm; ++j) {
81 if (c_[j] > 1.0E-8) {
82 ++nc;
83 }
84 }
85 molecule(i).setNClump(nc);
86
87 // Set clump properties for this FhMolecule
88 k = 0; // Clump index
89 for (j = 0; j < nm; ++j) {
90 if (c_[j] > 1.0E-8) {
92 molecule(i).clump(k).setSize(c_[j]);
93 ++k;
94 }
95 }
96 UTIL_CHECK(k == nc);
98
99 }
100 }
101
102 // Add solvent contributions
103 if (ns > 0) {
104 double size;
105 int monomerId;
106 for (int is = 0; is < ns; ++is) {
107 i = is + np;
108 SolventSpecies<WT> const& solvent = mixture.solventSpecies(is);
109 monomerId = solvent.monomerId();
110 size = solvent.size();
111 molecule(i).setNClump(1);
112 molecule(i).clump(0).setMonomerId(monomerId);
113 molecule(i).clump(0).setSize(size);
115 }
116 }
117
118 }
119
120} // namespace Pscf
121#endif
Descriptor for a block within a block polymer.
Definition Edge.h:59
int monomerId() const
Get the monomer type id for this block.
Definition Edge.h:284
double length() const
Get the length of this block, in the thread model.
Definition Edge.h:311
void setMonomerId(int monomerId)
Set the monomer type id.
Definition FhClump.cpp:23
void setSize(double size)
Set the size of this clump.
Definition FhClump.cpp:29
FhMolecule & molecule(int id)
Get a molecule object (non-const reference).
Definition FhMixture.h:298
void initialize(MixtureBase< WT > const &mixture)
Initialize to properties of a MixtureBase descriptor.
Definition FhMixture.tpp:24
int nMolecule() const
Get number of molecule species (polymer + solvent).
Definition FhMixture.h:332
int nMonomer() const
Get number of monomer types.
Definition FhMixture.h:335
void setNMolecule(int nMolecule)
Set the number of molecular species and allocate memory.
Definition FhMixture.cpp:74
void setNMonomer(int nMonomer)
Set the number of monomer types.
Definition FhMixture.cpp:84
void setNClump(int nClump)
Set the number of clumps, and allocate memory.
FhClump & clump(int id)
Get a specified FhClump.
Definition FhMolecule.h:139
void computeSize()
Compute total molecule size by adding clump sizes.
Abstract descriptor for a mixture of polymer and solvent species.
Definition MixtureBase.h:58
virtual SolventSpecies< WT > const & solventSpecies(int id) const =0
Set a solvent solver object by const reference.
virtual PolymerSpecies< WT > const & polymerSpecies(int id) const =0
Get a PolymerSpecies by const reference.
int nSolvent() const
Get number of solvent (point particle) species.
int nPolymer() const
Get number of polymer species.
int nMonomer() const
Get number of monomer types.
Descriptor for a linear or acyclic branched block polymer.
virtual Edge & edge(int id)=0
Get a specified Edge (block descriptor) by non-const reference.
int nBlock() const
Number of blocks.
Descriptor for a solvent species.
double size() const
Get the size (number of monomers) in this solvent.
int monomerId() const
Get the monomer type id.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
void allocate(int capacity)
Allocate the underlying C array.
Definition DArray.h:269
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.