PSCF v1.3
UnitCell1.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "UnitCell.h"
9#include <util/math/Constants.h>
10
11namespace Pscf {
12namespace Prdc {
13
14 using namespace Util;
15
16 // Member functions of UnitCell<1>
17
18 /*
19 * Constructor.
20 */
22 : lattice_(Null)
23 {}
24
25 /*
26 * Set nParameter based on the lattice system.
27 */
29 {
30 UTIL_CHECK(lattice_ != UnitCell<1>::Null);
31 if (lattice_ == UnitCell<1>::Lamellar) {
32 nParameter_ = 1;
33 } else {
34 UTIL_THROW("Invalid lattice system value");
35 }
36 }
37
38 /*
39 * Set the Bravais and reciprocal lattice parameters.
40 */
41 void UnitCell<1>::setBasis()
42 {
43 UTIL_CHECK(lattice_ != UnitCell<1>::Null);
44 UTIL_CHECK(nParameter_ == 1);
45
46 rBasis_[0][0] = parameters_[0];
47 kBasis_[0][0] = 2.0*Constants::Pi/parameters_[0];
48 drBasis_[0](0,0) = 1.0;
49 }
50
51 /*
52 * Assignment operator.
53 */
55 {
56 if (lattice_ != UnitCell<1>::Null) {
57 UTIL_CHECK(other.lattice_ == lattice_);
58 }
59 isInitialized_ = false;
60 lattice_ = other.lattice_;
61 setNParameter();
63 for (int i = 0; i < nParameter_; ++i) {
64 parameters_[i] = other.parameters_[i];
65 }
66 setLattice();
67 return *this;
68 }
69
70 /*
71 * Set the lattice system, but not unit cell parameters.
72 */
74 {
76 if (lattice_ != UnitCell<1>::Null) {
77 UTIL_CHECK(lattice == lattice_);
78 }
79 isInitialized_ = false;
80 lattice_ = lattice;
81 setNParameter();
82 }
83
84 /*
85 * Set state of the unit cell (lattice system and parameters).
86 */
89 {
90 set(lattice);
92 for (int i = 0; i < nParameter_; ++i) {
93 parameters_[i] = parameters[i];
94 }
95 setLattice();
96 }
97
98 /*
99 * Get the length of the unit cell.
100 */
101 double UnitCell<1>::volume() const
102 {
103 return rBasis_[0][0];
104 }
105
106 // UnitCell<1>::LatticeSystem stream IO operators
107
108 /*
109 * Extract a UnitCell<1>::LatticeSystem from an istream as a string.
110 */
111 std::istream& operator >> (std::istream& in,
113 {
114
115 std::string buffer;
116 in >> buffer;
117 if (buffer == "Lamellar" || buffer == "lamellar") {
118 lattice = UnitCell<1>::Lamellar;
119 } else {
120 UTIL_THROW("Invalid UnitCell<1>::LatticeSystem value input");
121 }
122 return in;
123 }
124
125 /*
126 * Insert a UnitCell<1>::LatticeSystem to an ostream as a string.
127 */
128 std::ostream& operator << (std::ostream& out,
130 {
131 if (lattice == UnitCell<1>::Lamellar) {
132 out << "lamellar";
133 } else
134 if (lattice == UnitCell<1>::Null) {
135 out << "Null";
136 } else {
137 UTIL_THROW("Invalid value of UnitCell<1>::Lamellar");
138 }
139 return out;
140 }
141
142}
143}
bool isInitialized_
Has this unit cell been fully initialized?
FArray< RealVec< D >, D > rBasis_
Array of Bravais lattice basis vectors.
FSArray< double, 6 > parameters() const
Get the parameters of this unit cell.
FArray< double, 6 > parameters_
Parameters used to describe the unit cell.
void setLattice()
Compute all protected data, given latticeSystem and parameters.
int nParameter_
Number of parameters required to specify unit cell.
LatticeSystem lattice() const
Return lattice system enumeration value.
Definition UnitCell.h:161
void set(UnitCell< 1 >::LatticeSystem lattice)
Set the lattice system, but not unit cell parameters.
Definition UnitCell1.cpp:73
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
static const double Pi
Trigonometric constant Pi.
Definition Constants.h:35
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition Pair.h:57