Loading [MathJax]/extensions/TeX/AMSmath.js
PSCF v1.2
UnitCell.tpp
1#ifndef PRDC_UNIT_CELL_TPP
2#define PRDC_UNIT_CELL_TPP
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 "UnitCell.h"
12#include <util/format/Dbl.h>
13#include <util/format/Int.h>
14#include <iomanip>
15
16namespace Pscf {
17namespace Prdc {
18
19 using namespace Util;
20
21 template <int D>
22 std::istream& operator >> (std::istream& in,
23 UnitCell<D>& cell)
24 {
25 typename UnitCell<D>::LatticeSystem lattice;
26 in >> lattice;
27 cell.set(lattice);
28 for (int i = 0; i < cell.nParameter_; ++i) {
29 in >> cell.parameters_[i];
30 }
31 cell.setLattice();
32 return in;
33 }
34
35 template <int D>
36 std::ostream& operator << (std::ostream& out,
37 UnitCell<D> const & cell)
38 {
39 out << cell.lattice_;
40 for (int i = 0; i < cell.nParameter_; ++i) {
41 out << Dbl(cell.parameters_[i], 18, 10);
42 }
43 return out;
44 }
45
46 /*
47 * Serialize to/from an archive.
48 */
49 template <class Archive, int D>
50 void serialize(Archive& ar, UnitCell<D>& cell,
51 const unsigned int version)
52 {
53 serializeEnum(ar, cell.lattice_, version);
54 ar & cell.nParameter_;
55 for (int i = 0; i < cell.nParameter_; ++i) {
56 ar & cell.parameters_[i];
57 }
58 }
59
60 template <int D>
61 void readUnitCellHeader(std::istream& in, UnitCell<D>& cell)
62 {
63 cell.isInitialized_ = false;
64 std::string label;
65 in >> label;
66 UTIL_CHECK(label == "crystal_system");
67 if (cell.lattice_ == UnitCell<D>::LatticeSystem::Null) {
68 in >> cell.lattice_;
69 cell.setNParameter();
70 } else {
71 typename UnitCell<D>::LatticeSystem lattice;
72 in >> lattice;
73 UTIL_CHECK(lattice == cell.lattice_);
74 }
75
76 in >> label;
77 UTIL_CHECK(label == "N_cell_param");
78 int nParameter;
79 in >> nParameter;
80 UTIL_CHECK(nParameter == cell.nParameter_);
81
82 in >> label;
83 UTIL_CHECK(label == "cell_param");
84 for (int i = 0; i < cell.nParameter_; ++i) {
85 in >> std::setprecision(15) >> cell.parameters_[i];
86 }
87 cell.setLattice();
88 }
89
90 template <int D>
91 void writeUnitCellHeader(std::ostream& out, UnitCell<D> const& cell)
92 {
93 out << "crystal_system" << std::endl
94 << " " << cell.lattice_<< std::endl;
95 out << "N_cell_param" << std::endl
96 << " " << cell.nParameter_<< std::endl;
97 out << "cell_param " << std::endl;
98 for (int i = 0; i < cell.nParameter_; ++i) {
99 out << " " << Dbl(cell.parameters_[i], 18, 10);
100 }
101 out << std::endl;
102 }
103
104}
105}
106#endif
bool isInitialized_
Has this unit cell been fully initialized?
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.
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition rpg/System.h:34
Wrapper for a double precision number, for formatted ostream output.
Definition Dbl.h:40
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void readUnitCellHeader(std::istream &in, UnitCell< D > &cell)
Read UnitCell<D> from a field file header (fortran PSCF format).
Definition UnitCell.tpp:61
void writeUnitCellHeader(std::ostream &out, UnitCell< D > const &cell)
Write UnitCell<D> to a field file header (fortran PSCF format).
Definition UnitCell.tpp:91
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
Definition serialize.h:59
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.
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