PSCF v1.5.0
unitCellHeader.h
1#ifndef PSCF_UNIT_CELL_TPP
2#define PSCF_UNIT_CELL_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "UnitCell.h"
12
13#include <util/format/Dbl.h>
14#include <util/format/Int.h>
15
16#include <iomanip>
17
18namespace Pscf {
19
20 using namespace Util;
21
36 template <int D>
37 void readUnitCellHeader(std::istream& in, UnitCell<D>& cell);
38
46 template <int D>
47 void writeUnitCellHeader(std::ostream& out, UnitCell<D> const& cell);
48
49 template <int D>
50 void readUnitCellHeader(std::istream& in, UnitCell<D>& cell)
51 {
52 cell.isInitialized_ = false;
53 std::string label;
54 in >> label;
55 UTIL_CHECK(label == "crystal_system");
56 if (cell.lattice_ == UnitCell<D>::LatticeSystem::Null) {
57 in >> cell.lattice_;
58 cell.setNParameter();
59 } else {
61 in >> lattice;
62 UTIL_CHECK(lattice == cell.lattice_);
63 }
64
65 in >> label;
66 UTIL_CHECK(label == "N_cell_param");
67 int nParameter;
68 in >> nParameter;
70
71 in >> label;
72 UTIL_CHECK(label == "cell_param");
73 for (int i = 0; i < cell.nParameter_; ++i) {
74 in >> std::setprecision(15) >> cell.parameters_[i];
75 }
76 cell.setLattice();
77 }
78
79 template <int D>
80 void writeUnitCellHeader(std::ostream& out, UnitCell<D> const & cell)
81 {
82 out << "crystal_system" << std::endl
83 << " " << cell.lattice_<< std::endl;
84 out << "N_cell_param" << std::endl
85 << " " << cell.nParameter_<< std::endl;
86 out << "cell_param " << std::endl;
87 for (int i = 0; i < cell.nParameter_; ++i) {
88 out << " " << Dbl(cell.parameters_[i], 18, 10);
89 }
90 out << std::endl;
91 }
92
93}
94#endif
int nParameter_
Number of parameters required to specify unit cell.
FArray< double, 6 > parameters_
Parameters used to describe the unit cell.
int nParameter() const
Get the number of parameters in the unit cell.
void setLattice()
Compute all protected data, given latticeSystem and parameters.
bool isInitialized_
Has this unit cell been fully initialized?
UnitCell()
Constructor.
Definition UnitCell1.cpp:20
LatticeSystem lattice() const
Return lattice system enumeration value.
Definition UnitCell.h:160
friend void readUnitCellHeader(std::istream &, UnitCell< D > &)
Read UnitCell<D> from a field file header (fortran PSCF format).
friend void writeUnitCellHeader(std::ostream &, UnitCell< D > const &)
Write UnitCell<D> to a field file header (fortran PSCF format).
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:55
Dbl()
Default constructor.
Definition Dbl.cpp:17
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void writeUnitCellHeader(std::ostream &out, UnitCell< D > const &cell)
Write UnitCell<D> to a field file header (fortran PSCF format).
void readUnitCellHeader(std::istream &in, UnitCell< D > &cell)
Read UnitCell<D> from a field file header (fortran PSCF format).
PSCF package top-level namespace.