PSCF v1.1
UnitCell1.cpp
1/*
2* PSCF - Polymer Self-Consistent Field Theory
3*
4* Copyright 2016 - 2022, 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
12{
13
14 using namespace Util;
15
16 /*
17 * Constructor.
18 */
20 : lattice_(Null)
21 {}
22
23 /*
24 * Set nParameter based on the lattice system.
25 */
27 {
28 UTIL_CHECK(lattice_ != UnitCell<1>::Null);
29 if (lattice_ == UnitCell<1>::Lamellar) {
30 nParameter_ = 1;
31 } else {
32 UTIL_THROW("Invalid lattice system value");
33 }
34 }
35
36 /*
37 * Set the Bravais and reciprocal lattice parameters.
38 */
39 void UnitCell<1>::setBasis()
40 {
41 UTIL_CHECK(lattice_ != UnitCell<1>::Null);
42 UTIL_CHECK(nParameter_ == 1);
43
44 rBasis_[0][0] = parameters_[0];
45 kBasis_[0][0] = 2.0*Constants::Pi/parameters_[0];
46 drBasis_[0](0,0) = 1.0;
47 }
48
49 /*
50 * Extract a UnitCell<1>::LatticeSystem from an istream as a string.
51 */
52 std::istream& operator >> (std::istream& in,
54 {
55
56 std::string buffer;
57 in >> buffer;
58 if (buffer == "Lamellar" || buffer == "lamellar") {
59 lattice = UnitCell<1>::Lamellar;
60 } else {
61 UTIL_THROW("Invalid UnitCell<1>::LatticeSystem value input");
62 }
63 return in;
64 }
65
66 /*
67 * Insert a UnitCell<1>::LatticeSystem to an ostream as a string.
68 */
69 std::ostream& operator << (std::ostream& out,
71 {
72 if (lattice == UnitCell<1>::Lamellar) {
73 out << "lamellar";
74 } else
75 if (lattice == UnitCell<1>::Null) {
76 out << "Null";
77 } else {
78 UTIL_THROW("Invalid value of UnitCell<1>::Lamellar");
79 }
80 return out;
81 }
82
83 /*
84 * Assignment operator.
85 */
87 {
88 isInitialized_ = false;
89 lattice_ = other.lattice_;
90 setNParameter();
91 UTIL_CHECK(nParameter_ == other.nParameter_);
92 for (int i = 0; i < nParameter_; ++i) {
93 parameters_[i] = other.parameters_[i];
94 }
95 setLattice();
96 return *this;
97 }
98
99 /*
100 * Set the lattice system, but not unit cell parameters.
101 */
103 {
104 isInitialized_ = false;
105 lattice_ = lattice;
106 setNParameter();
107 }
108
109 /*
110 * Set state of the unit cell (lattice system and parameters).
111 */
113 FSArray<double, 6> const & parameters)
114 {
115 isInitialized_ = false;
116 lattice_ = lattice;
117 setNParameter();
118 for (int i = 0; i < nParameter_; ++i) {
119 parameters_[i] = parameters[i];
120 }
121 setLattice();
122 }
123
124}
int nParameter_
Number of parameters required to specify unit cell.
Definition: UnitCellBase.h:198
FArray< double, 6 > parameters_
Parameters used to describe the unit cell.
Definition: UnitCellBase.h:193
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition: UnitCell.h:44
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:51
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod: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