PSCF v1.3
unitCellHeader.h
1#ifndef PRDC_UNIT_CELL_TPP
2#define PRDC_UNIT_CELL_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
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 "UnitCell.h"
12
13#include <util/format/Dbl.h>
14#include <util/format/Int.h>
15
16#include <iomanip>
17
18namespace Pscf {
19namespace Prdc {
20
21 using namespace Util;
22
37 template <int D>
38 void readUnitCellHeader(std::istream& in, UnitCell<D>& cell);
39
47 template <int D>
48 void writeUnitCellHeader(std::ostream& out, UnitCell<D> const& cell);
49
50 template <int D>
51 void readUnitCellHeader(std::istream& in, UnitCell<D>& cell)
52 {
53 cell.isInitialized_ = false;
54 std::string label;
55 in >> label;
56 UTIL_CHECK(label == "crystal_system");
57 if (cell.lattice_ == UnitCell<D>::LatticeSystem::Null) {
58 in >> cell.lattice_;
59 cell.setNParameter();
60 } else {
62 in >> lattice;
63 UTIL_CHECK(lattice == cell.lattice_);
64 }
65
66 in >> label;
67 UTIL_CHECK(label == "N_cell_param");
68 int nParameter;
69 in >> nParameter;
71
72 in >> label;
73 UTIL_CHECK(label == "cell_param");
74 for (int i = 0; i < cell.nParameter_; ++i) {
75 in >> std::setprecision(15) >> cell.parameters_[i];
76 }
77 cell.setLattice();
78 }
79
80 template <int D>
81 void writeUnitCellHeader(std::ostream& out, UnitCell<D> const & cell)
82 {
83 out << "crystal_system" << std::endl
84 << " " << cell.lattice_<< std::endl;
85 out << "N_cell_param" << std::endl
86 << " " << cell.nParameter_<< std::endl;
87 out << "cell_param " << std::endl;
88 for (int i = 0; i < cell.nParameter_; ++i) {
89 out << " " << Dbl(cell.parameters_[i], 18, 10);
90 }
91 out << std::endl;
92 }
93
94}
95}
96#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.
int nParameter() const
Get the number of parameters in the unit cell.
LatticeSystem lattice() const
Return lattice system enumeration value.
Definition UnitCell.h:161
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
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).
void writeUnitCellHeader(std::ostream &out, UnitCell< D > const &cell)
Write UnitCell<D> to a field file header (fortran PSCF format).
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1