id
int64 0
877k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
66
| repo_stars
int64 94
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 11
values | repo_extraction_date
stringclasses 197
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,535,106
|
MeshTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/mesh/MeshTestComposite.h
|
#ifndef PSCF_TEST_MESH_TEST_COMPOSITE_H
#define PSCF_TEST_MESH_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "MeshTest.h"
#include "MeshIteratorTest.h"
TEST_COMPOSITE_BEGIN(MeshTestComposite)
TEST_COMPOSITE_ADD_UNIT(MeshTest);
TEST_COMPOSITE_ADD_UNIT(MeshIteratorTest);
TEST_COMPOSITE_END
#endif
| 318
|
C++
|
.h
| 10
| 30.4
| 42
| 0.838816
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,107
|
ChemTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/chem/ChemTestComposite.h
|
#ifndef PSCF_TESTS_CHEM_TEST_COMPOSITE_H
#define PSCF_TESTS_CHEM_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "MonomerTest.h"
#include "VertexTest.h"
#include "BlockDescriptorTest.h"
#include "PolymerTypeTest.h"
TEST_COMPOSITE_BEGIN(ChemTestComposite)
TEST_COMPOSITE_ADD_UNIT(MonomerTest);
TEST_COMPOSITE_ADD_UNIT(VertexTest);
TEST_COMPOSITE_ADD_UNIT(BlockDescriptorTest);
TEST_COMPOSITE_ADD_UNIT(PolymerTypeTest);
TEST_COMPOSITE_END
#endif
| 464
|
C++
|
.h
| 14
| 31.857143
| 45
| 0.840807
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,108
|
PolymerTypeTest.h
|
dmorse_pscfpp/src/pscf/tests/chem/PolymerTypeTest.h
|
#ifndef POLYMER_TYPE_TEST_H
#define POLYMER_TYPE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/chem/PolymerType.h>
#include <fstream>
using namespace Pscf;
using namespace Util;
class PolymerTypeTest : public UnitTest
{
public:
void setUp()
{
//setVerbose(1);
}
void tearDown()
{
setVerbose(0);
}
void testReadWrite() {
printMethod(TEST_FUNC);
std::ifstream in;
openInputFile("in/PolymerType", in);
PolymerType::Enum b;
in >> b;
TEST_ASSERT(b == PolymerType::Branched);
if (verbose() > 0) {
printEndl();
std::cout << b << " ";
}
in >> b;
TEST_ASSERT(b == PolymerType::Linear);
if (verbose() > 0) {
std::cout << b << std::endl ;
}
// If uncommented out, this one fails to read "Thingy"
//in >> b;
}
};
TEST_BEGIN(PolymerTypeTest)
TEST_ADD(PolymerTypeTest, testReadWrite)
TEST_END(PolymerTypeTest)
#endif
| 1,003
|
C++
|
.h
| 43
| 18.534884
| 60
| 0.622222
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,109
|
BlockDescriptorTest.h
|
dmorse_pscfpp/src/pscf/tests/chem/BlockDescriptorTest.h
|
#ifndef BLOCK_DESCRIPTOR_TEST_H
#define BLOCK_DESCRIPTOR_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/chem/BlockDescriptor.h>
#include <fstream>
using namespace Pscf;
using namespace Util;
class BlockDescriptorTest : public UnitTest
{
public:
void setUp()
{
// setVerbose(1);
}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
BlockDescriptor v;
}
void testReadWrite() {
printMethod(TEST_FUNC);
std::ifstream in;
openInputFile("in/BlockDescriptor", in);
BlockDescriptor v;
TEST_ASSERT(v.polymerType() == PolymerType::Branched);
v.setId(5);
in >> v;
TEST_ASSERT(v.id() == 5);
TEST_ASSERT(v.monomerId() == 0);
TEST_ASSERT(v.vertexId(0) == 3);
TEST_ASSERT(v.vertexId(1) == 4);
TEST_ASSERT(eq(v.length(), 2.0));
TEST_ASSERT(v.polymerType() == PolymerType::Branched);
if (verbose() > 0) {
printEndl();
std::cout << v << std::endl ;
}
v.setPolymerType(PolymerType::Linear);
v.setId(2);
in >> v;
TEST_ASSERT(v.id() == 2);
TEST_ASSERT(v.monomerId() == 1);
v.setVertexIds(2,3);
TEST_ASSERT(v.vertexId(0) == 2);
TEST_ASSERT(v.vertexId(1) == 3);
TEST_ASSERT(eq(v.length(), 3.0));
TEST_ASSERT(v.polymerType() == PolymerType::Linear);
if (verbose() > 0) {
std::cout << v << std::endl ;
}
v.setPolymerType(PolymerType::Branched);
TEST_ASSERT(v.polymerType() == PolymerType::Branched);
if (verbose() > 0) {
std::cout << v << std::endl ;
}
}
};
TEST_BEGIN(BlockDescriptorTest)
TEST_ADD(BlockDescriptorTest, testConstructor)
TEST_ADD(BlockDescriptorTest, testReadWrite)
TEST_END(BlockDescriptorTest)
#endif
| 1,839
|
C++
|
.h
| 65
| 22.784615
| 60
| 0.62065
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,110
|
VertexTest.h
|
dmorse_pscfpp/src/pscf/tests/chem/VertexTest.h
|
#ifndef VERTEX_TEST_H
#define VERTEX_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/chem/BlockDescriptor.h>
#include <pscf/chem/Vertex.h>
#include <fstream>
using namespace Pscf;
//using namespace Util;
class VertexTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Vertex v;
}
void testAddBlock() {
printMethod(TEST_FUNC);
//printEndl();
std::ifstream in;
openInputFile("in/BlockDescriptor", in);
BlockDescriptor b;
b.setId(5);
in >> b;
TEST_ASSERT(b.id() == 5);
TEST_ASSERT(b.monomerId() == 0);
TEST_ASSERT(b.vertexId(0) == 3);
TEST_ASSERT(b.vertexId(1) == 4);
TEST_ASSERT(eq(b.length(), 2.0));
//std::cout << b << std::endl;
Vertex v;
v.setId(3);
v.addBlock(b);
TEST_ASSERT(v.size() == 1);
TEST_ASSERT(v.outPropagatorId(0)[0] == 5);
TEST_ASSERT(v.outPropagatorId(0)[1] == 0);
TEST_ASSERT(v.inPropagatorId(0)[0] == 5);
TEST_ASSERT(v.inPropagatorId(0)[1] == 1);
//std::cout << v.inPropagatorId(0)[0] << " "
// << v.inPropagatorId(0)[1] << "\n";
//std::cout << v.outPropagatorId(0)[0] << " "
// << v.outPropagatorId(0)[1] << "\n";
}
};
TEST_BEGIN(VertexTest)
TEST_ADD(VertexTest, testConstructor)
TEST_ADD(VertexTest, testAddBlock)
TEST_END(VertexTest)
#endif
| 1,498
|
C++
|
.h
| 54
| 22.722222
| 53
| 0.602257
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,111
|
MonomerTest.h
|
dmorse_pscfpp/src/pscf/tests/chem/MonomerTest.h
|
#ifndef MONOMER_TEST_H
#define MONOMER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/chem/Monomer.h>
#include <fstream>
using namespace Pscf;
using namespace Util;
class MonomerTest : public UnitTest
{
public:
void setUp()
{
//setVerbose(1);
}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Monomer v;
}
void testReadWrite() {
printMethod(TEST_FUNC);
Monomer v;
std::ifstream in;
openInputFile("in/Monomer", in);
in >> v;
TEST_ASSERT(eq(v.kuhn(), 5.0));
if (verbose() > 0) {
printEndl();
std::cout << v << std::endl ;
}
}
};
TEST_BEGIN(MonomerTest)
TEST_ADD(MonomerTest, testConstructor)
TEST_ADD(MonomerTest, testReadWrite)
TEST_END(MonomerTest)
#endif
| 845
|
C++
|
.h
| 40
| 16.775
| 38
| 0.651842
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,112
|
SpaceSymmetryTest.h
|
dmorse_pscfpp/src/pscf/tests/crystal/SpaceSymmetryTest.h
|
#ifndef PSCF_SPACE_SYMMETRY_TEST_H
#define PSCF_SPACE_SYMMETRY_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/crystal/SpaceSymmetry.h>
#include <util/math/Constants.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
class SpaceSymmetryTest : public UnitTest
{
public:
void setUp()
{
//setVerbose(1);
}
void tearDown()
{ setVerbose(0); }
template <int D>
bool isValid(SpaceSymmetry<D> cell)
{
return true;
}
void test2DIdentity()
{
printMethod(TEST_FUNC);
SpaceSymmetry<2> E = SpaceSymmetry<2>::identity();
TEST_ASSERT(E.R(0,0) == 1);
TEST_ASSERT(E.R(1,0) == 0);
TEST_ASSERT(E.R(0,1) == 0);
TEST_ASSERT(E.R(1,1) == 1);
TEST_ASSERT(E.t(0) == 0);
TEST_ASSERT(E.t(1) == 0);
//std::cout << std::endl;
//std::cout << SpaceSymmetry<2>::identity() << std::endl;
}
void test2DConstruct()
{
printMethod(TEST_FUNC);
SpaceSymmetry<2> A;
A.R(0,0) = 0;
A.R(0,1) = -1;
A.R(1,0) = 1;
A.R(1,1) = 0;
A.t(0) = 0;
A.t(1) = Rational(1, 2);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << A << std::endl;
}
}
void test2DRead()
{
printMethod(TEST_FUNC);
std::ifstream in;
openInputFile("in/Symmetry2D", in);
SpaceSymmetry<2> A;
in >> A;
TEST_ASSERT(A.R(0,0) == 0);
TEST_ASSERT(A.R(0,1) == 1);
TEST_ASSERT(A.R(1,0) == -1);
TEST_ASSERT(A.R(1,1) == 0);
TEST_ASSERT(A.t(0) == Rational(1,2));
TEST_ASSERT(A.t(1) == 0);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << A << std::endl;
}
}
void test2DEquality()
{
printMethod(TEST_FUNC);
// std::cout << std::endl();
SpaceSymmetry<2> A;
A.R(0,0) = 0;
A.R(1,0) = 1;
A.R(0,1) = -1;
A.R(1,1) = 0;
A.t(0) = 0;
A.t(1) = Rational(1, 2);
//std::cout << A << std::endl;
SpaceSymmetry<2> B = A;
//std::cout << B << std::endl;
TEST_ASSERT(A == B);
B.t(0) = Rational(1, 2);
TEST_ASSERT(A != B);
A.t(0) = Rational(1, 2);
TEST_ASSERT(A == B);
A.R(0,0) = 2;
TEST_ASSERT(A != B);
}
void test2DInvertMultiply()
{
printMethod(TEST_FUNC);
// std::cout << std::endl();
SpaceSymmetry<2> A;
A.R(0,0) = 0;
A.R(1,0) = 1;
A.R(0,1) = -1;
A.R(1,1) = 0;
A.t(0) = 0;
A.t(1) = Rational(1, 2);
//std::cout << A << std::endl;
SpaceSymmetry<2> B;
B = A.inverse();
//std::cout << B << std::endl;
SpaceSymmetry<2> C;
C = A*B;
//std::cout << C << std::endl;
TEST_ASSERT(C == A*B);
TEST_ASSERT(C == SpaceSymmetry<2>::identity());
SpaceSymmetry<2> D;
D = A*B;
TEST_ASSERT(D == C);
SpaceSymmetry<2> E;
E = A*A;
//std::cout << E << std::endl;
TEST_ASSERT(A == B*E);
TEST_ASSERT(A == E*B);
}
void test3DInvertMultiply()
{
printMethod(TEST_FUNC);
//std::cout << std::endl();
SpaceSymmetry<3> A;
A.R(0,0) = 0;
A.R(0,1) = -1;
A.R(0,2) = 0;
A.R(1,0) = 1;
A.R(1,1) = 0;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = 0;
A.t(1) = Rational(1,2);
A.t(2) = Rational(-1,4);
//std::cout << A << std::endl;
SpaceSymmetry<3> B = A.inverse();
//std::cout << B << std::endl;
SpaceSymmetry<3> C = A*B;
// std::cout << C << std::endl;
TEST_ASSERT(C == SpaceSymmetry<3>::identity());
A.R(0,0) = 1;
A.R(0,1) = -1;
A.R(0,2) = 0;
A.R(1,0) = 0;
A.R(1,1) = -1;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = 0;
A.t(1) = Rational(1,2);
A.t(2) = Rational(-1,4);
//std::cout << A << std::endl;
B = A.inverse();
//std::cout << B << std::endl;
C = A*B;
//std::cout << C << std::endl;
TEST_ASSERT(C == SpaceSymmetry<3>::identity());
A.R(0,0) = 0;
A.R(0,1) = 1;
A.R(0,2) = 0;
A.R(1,0) = 0;
A.R(1,1) = 0;
A.R(1,2) = 1;
A.R(2,0) = 1;
A.R(2,1) = 0;
A.R(2,2) = 0;
A.t(0) = 0;
A.t(1) = Rational(-3,2);
A.t(2) = Rational(-1,4);
B = A.inverse();
//std::cout << B << std::endl;
C = A*B;
TEST_ASSERT(C == SpaceSymmetry<3>::identity());
}
void testShiftOrigin()
{
printMethod(TEST_FUNC);
SpaceSymmetry<3> A;
A.R(0,0) = 0;
A.R(0,1) = -1;
A.R(0,2) = 0;
A.R(1,0) = 1;
A.R(1,1) = 0;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = 0;
A.t(1) = Rational(1,2);
A.t(2) = Rational(-1,4);
A.normalize();
SpaceSymmetry<3> B = A;
TEST_ASSERT(B == A);
//TEST_ASSERT(A == B);
SpaceSymmetry<3>::Translation origin;
origin[0] = Rational(1, 8);
origin[1] = Rational(-3, 4);
origin[2] = Rational(0, 1);
B.shiftOrigin(origin);
TEST_ASSERT(A != B);
origin[0] = Rational(-1, 8);
origin[1] = Rational(3, 4);
origin[2] = Rational(0, 1);
B.shiftOrigin(origin);
TEST_ASSERT(A == B);
}
};
TEST_BEGIN(SpaceSymmetryTest)
TEST_ADD(SpaceSymmetryTest, test2DIdentity)
TEST_ADD(SpaceSymmetryTest, test2DConstruct)
TEST_ADD(SpaceSymmetryTest, test2DRead)
TEST_ADD(SpaceSymmetryTest, test2DEquality)
TEST_ADD(SpaceSymmetryTest, test2DInvertMultiply)
TEST_ADD(SpaceSymmetryTest, test3DInvertMultiply)
TEST_ADD(SpaceSymmetryTest, testShiftOrigin)
TEST_END(SpaceSymmetryTest)
#endif
| 5,840
|
C++
|
.h
| 222
| 19.990991
| 63
| 0.49577
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,113
|
CrystalTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/crystal/CrystalTestComposite.h
|
#ifndef PSCF_TEST_CRYSTAL_TEST_COMPOSITE_H
#define PSCF_TEST_CRYSTAL_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "UnitCellTest.h"
#include "SpaceSymmetryTest.h"
#include "SpaceGroupTest.h"
#include "BasisTest.h"
TEST_COMPOSITE_BEGIN(CrystalTestComposite)
TEST_COMPOSITE_ADD_UNIT(UnitCellTest);
TEST_COMPOSITE_ADD_UNIT(SpaceSymmetryTest);
TEST_COMPOSITE_ADD_UNIT(SpaceGroupTest);
TEST_COMPOSITE_ADD_UNIT(BasisTest);
TEST_COMPOSITE_END
#endif
| 465
|
C++
|
.h
| 14
| 31.928571
| 43
| 0.841163
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,114
|
BasisTest.h
|
dmorse_pscfpp/src/pscf/tests/crystal/BasisTest.h
|
#ifndef PSSP_BASIS_TEST_H
#define PSSP_BASIS_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
//#include <pssp/field/RField.h>
//#include <pssp/field/RFieldDft.h>
//#include <pssp/field/FFT.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/TWave.h>
#include <pscf/crystal/groupFile.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/mesh/MeshIterator.h>
#include <util/containers/DArray.h>
#include <util/math/Constants.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
class BasisTest : public UnitTest
{
public:
void setUp()
{
setVerbose(2);
}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
// printEndl();
Basis<3> sampleBasis;
TEST_ASSERT(eq(sampleBasis.nWave(),0));
TEST_ASSERT(eq(sampleBasis.nStar(),0));
TEST_ASSERT(eq(sampleBasis.nBasis(),0));
}
void testMake1DBasis_I() {
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<1> unitCell;
std::ifstream in;
openInputFile("in/Lamellar", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<1> d;
d[0] = 8;
Mesh<1> mesh(d);
// Construct basis object using identity space group
Basis<1> basis;
TEST_ASSERT(!basis.isInitialized());
std::string spaceGroup = "I";
basis.makeBasis(mesh, unitCell, spaceGroup);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(eq(basis.nWave(), 8));
TEST_ASSERT(eq(basis.nStar(), 8));
TEST_ASSERT(eq(basis.nBasis(),8));
#if 0
basis.outputWaves(std::cout);
basis.outputStars(std::cout);
#endif
}
void testMake1DBasis_Ib() {
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<1> unitCell;
std::ifstream in;
openInputFile("in/Lamellar", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<1> d;
d[0] = 8;
Mesh<1> mesh(d);
// Read space group
SpaceGroup<1> group;
openInputFile("in/Group_1D_Symmetric", in);
in >> group;
in.close();
TEST_ASSERT(group.size() == 2);
// Construct basis object using identity space group
Basis<1> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(eq(basis.nWave(), 8));
TEST_ASSERT(eq(basis.nStar(), 5));
TEST_ASSERT(eq(basis.nBasis(), 5));
#if 0
if (verbose() > 1) {
basis.outputWaves(std::cout);
basis.outputStars(std::cout);
}
#endif
}
void testMake2DBasis_square_33()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<2> unitCell;
std::ifstream in;
openInputFile("in/Square", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<2> d;
d[0] = 3;
d[1] = 3;
Mesh<2> mesh(d);
// Construct basis object using identity space group
Basis<2> basis;
std::string spaceGroup = "I";
basis.makeBasis(mesh, unitCell, spaceGroup);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(eq(basis.nWave(), 9));
TEST_ASSERT(eq(basis.nStar(),9));
#if 0
basis.outputWaves(std::cout);
basis.outputStars(std::cout);
#endif
}
void testMake2DBasis_square_44()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<2> unitCell;
std::ifstream in;
openInputFile("in/Square", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<2> d;
d[0] = 4;
d[1] = 4;
Mesh<2> mesh(d);
// Read space group
SpaceGroup<2> group;
openInputFile("in/Group_2D_CenteredSquare", in);
in >> group;
// Make basis
Basis<2> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(eq(basis.nWave(), 16));
TEST_ASSERT(eq(basis.nStar(), 6));
TEST_ASSERT(eq(basis.nBasis(), 4));
TEST_ASSERT(basis.isValid());
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/Square_44", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
}
}
void testMake2DBasis_hex()
{
printMethod(TEST_FUNC);
// printEndl();
// Read UnitCell
UnitCell<2> unitCell;
std::ifstream in;
openInputFile("in/Hexagonal2D", in);
in >> unitCell;
in.close();
// Make Mesh object
IntVec<2> d;
d[0] = 24;
d[1] = 24;
Mesh<2> mesh(d);
// Read space group
SpaceGroup<2> group;
openInputFile("in/p_6_m_m", in);
in >> group;
in.close();
// Make basis
Basis<2> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
//TEST_ASSERT(eq(basis.nWave(), 16));
//TEST_ASSERT(eq(basis.nStar(), 6));
//TEST_ASSERT(eq(basis.nBasis(), 4));
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/p_6_m_m", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
}
}
void testMake3DBasis_I()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 3;
d[1] = 3;
d[2] = 3;
Mesh<3> mesh(d);
// Construct basis object
Basis<3> basis;
std::string spaceGroup = "I";
basis.makeBasis(mesh, unitCell, spaceGroup);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(eq(basis.nWave(), 27));
TEST_ASSERT(eq(basis.nStar(), 27));
TEST_ASSERT(basis.isValid());
}
void testMake3DBasis_I_m_3b_m()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 8;
d[1] = 8;
d[2] = 8;
Mesh<3> mesh(d);
// Read group
SpaceGroup<3> group;
openInputFile("in/I_m_-3_m", in);
in >> group;
in.close();
// Construct basis object
Basis<3> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
TEST_ASSERT(eq(basis.nWave(), 512));
// Check basisFunction
int i, j;
j = 0;
for (i = 0; i < basis.nStar(); ++i) {
if (!(basis.star(i).cancel)) {
TEST_ASSERT(&basis.star(i) == &basis.basisFunction(j));
++j;
}
}
TEST_ASSERT(j == basis.nBasis());
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/I_m_3b_m", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
}
}
void testMake3DBasis_I_a_3b_d()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 8;
d[1] = 8;
d[2] = 8;
Mesh<3> mesh(d);
// Read group
SpaceGroup<3> group;
openInputFile("in/I_a_-3_d", in);
in >> group;
in.close();
// Construct basis object
Basis<3> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
TEST_ASSERT(eq(basis.nWave(), 512));
// Compare star and basisFunction accessors
int i, j;
j = 0;
for (i = 0; i < basis.nStar(); ++i) {
if (!(basis.star(i).cancel)) {
TEST_ASSERT(&basis.star(i) == &basis.basisFunction(j));
++j;
}
}
TEST_ASSERT(j == basis.nBasis());
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/I_a_3b_d", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
}
}
void testMake3DBasis_F_d_3b_m_2()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 8;
d[1] = 8;
d[2] = 8;
Mesh<3> mesh(d);
// Read group
SpaceGroup<3> group;
openInputFile("in/F_d_-3_m:2", in);
// This is a centro-symmetric setting for the C15 Laves phase
in >> group;
in.close();
// Construct basis object
Basis<3> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
TEST_ASSERT(eq(basis.nWave(), 512));
// Compare star and basisFunction accessors
int i, j;
j = 0;
for (i = 0; i < basis.nStar(); ++i) {
if (!(basis.star(i).cancel)) {
TEST_ASSERT(&basis.star(i) == &basis.basisFunction(j));
++j;
}
}
TEST_ASSERT(j == basis.nBasis());
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/F_d_-3_m:2", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
out.close();
}
}
void testMake3DBasis_F_d_3b_m_1()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 8;
d[1] = 8;
d[2] = 8;
Mesh<3> mesh(d);
// Read group
SpaceGroup<3> group;
openInputFile("in/F_d_-3_m:1", in);
// This is a non-centro-symmetric setting for the C15 Laves phase
in >> group;
in.close();
// Construct basis object
Basis<3> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
TEST_ASSERT(eq(basis.nWave(), 512));
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/F_d_-3_m:1", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
out.close();
}
}
void testMake3DBasis_I_41_3_2()
{
printMethod(TEST_FUNC);
// printEndl();
// Make unitcell
UnitCell<3> unitCell;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> unitCell;
in.close();
// Make mesh object
IntVec<3> d;
d[0] = 16;
d[1] = 16;
d[2] = 16;
Mesh<3> mesh(d);
// Read group
SpaceGroup<3> group;
openInputFile("in/I_41_3_2", in);
// This is a non-centro-symmetric alternating gyroid group
in >> group;
in.close();
// Construct basis object
Basis<3> basis;
basis.makeBasis(mesh, unitCell, group);
TEST_ASSERT(basis.isInitialized());
TEST_ASSERT(basis.isValid());
TEST_ASSERT(eq(basis.nWave(), 4096));
if (verbose() > 1) {
std::ofstream out;
openOutputFile("out/I_41_3_2", out);
out << "nBasis = " << basis.nBasis() << std::endl;
basis.outputWaves(out);
basis.outputStars(out);
out.close();
}
}
};
TEST_BEGIN(BasisTest)
TEST_ADD(BasisTest, testConstructor)
TEST_ADD(BasisTest, testMake1DBasis_I)
TEST_ADD(BasisTest, testMake1DBasis_Ib)
TEST_ADD(BasisTest, testMake2DBasis_square_33)
TEST_ADD(BasisTest, testMake2DBasis_square_44)
TEST_ADD(BasisTest, testMake2DBasis_hex)
TEST_ADD(BasisTest, testMake3DBasis_I)
TEST_ADD(BasisTest, testMake3DBasis_I_m_3b_m)
TEST_ADD(BasisTest, testMake3DBasis_I_a_3b_d)
TEST_ADD(BasisTest, testMake3DBasis_F_d_3b_m_2)
TEST_ADD(BasisTest, testMake3DBasis_F_d_3b_m_1)
TEST_ADD(BasisTest, testMake3DBasis_I_41_3_2)
TEST_END(BasisTest)
#endif
| 12,794
|
C++
|
.h
| 448
| 21.524554
| 71
| 0.568092
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,115
|
UnitCellTest.h
|
dmorse_pscfpp/src/pscf/tests/crystal/UnitCellTest.h
|
#ifndef PSCF_UNIT_CELL_TEST_H
#define PSCF_UNIT_CELL_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/crystal/shiftToMinimum.h>
#include <util/math/Constants.h>
#include <util/format/Int.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
class UnitCellTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
template <int D>
bool isValidReciprocal(UnitCell<D> const & cell, bool verbose = false)
{
double sum;
double twoPi = 2.0*Constants::Pi;
bool isValid = true;
int i, j, k;
if (verbose) {
std::cout << std::endl;
}
for (i = 0; i < D; ++i ) {
for (j = 0; j < D; ++j ) {
sum = 0.0;
for (k=0; k < D; ++k ) {
sum += cell.rBasis(i)[k]*cell.kBasis(j)[k];
}
sum = sum/twoPi;
if (verbose) {
std::cout << Dbl(sum, 15, 5);
}
if (i == j) {
sum -= 1.0;
}
if (std::abs(sum) > 1.0E-8) {
isValid = false;
}
}
if (verbose) {
std::cout << std::endl;
}
}
return isValid;
}
template <int D>
bool isValidDerivative(UnitCell<D> const & cell)
{
double sum;
double nParams = cell.nParameter();
int i, j, k, m;
for (k = 0; k < nParams; ++k) {
for (i = 0; i < D; ++i) {
for (j = 0; j < D; ++j) {
sum = 0.0;
for (m = 0; m < D; ++m) {
sum += cell.drBasis(k, i, m)*cell.kBasis(j)[m];
sum += cell.dkBasis(k, j, m)*cell.rBasis(i)[m];
}
}
if (std::abs(sum) > 1.0E-8) {
return false;
}
}
}
return true;
}
void test1DLamellar()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<1> v;
std::ifstream in;
openInputFile("in/Lamellar", in);
in >> v;
double param = v.parameter(0);
double twoPi = 2.0*Constants::Pi;
TEST_ASSERT(eq(v.rBasis(0)[0], param));
TEST_ASSERT(eq(v.kBasis(0)[0], twoPi/param));
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
// Test ksq function
IntVec<1> x;
int m = -3;
x[0] = m;
double xSq = v.ksq(x);
double y = (twoPi*m)/param;
TEST_ASSERT(eq(xSq, y*y));
// Test assignment
UnitCell<1> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
TEST_ASSERT(eq(u.rBasis(0)[0], param));
TEST_ASSERT(eq(u.drBasis(0,0,0), 1.0));
TEST_ASSERT(eq(u.kBasis(0)[0], twoPi/param));
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
#if 0
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
std::cout << v.rBasis(0) << std::endl;
std::cout << v.kBasis(0) << std::endl;
#endif
}
void test2DSquare()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<2> v;
std::ifstream in;
openInputFile("in/Square", in);
in >> v;
TEST_ASSERT(v.nParameter() == 1);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
#if 0
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
std::cout << "a(0) = " << v.rBasis(0) << std::endl;
std::cout << "a(1) = " << v.rBasis(1) << std::endl;
std::cout << "b(0) = " << v.kBasis(0) << std::endl;
std::cout << "b(1) = " << v.kBasis(1) << std::endl;
#endif
double param = v.parameter(0);
double twoPi = 2.0*Constants::Pi;
double b, dbb;
int i, j, k;
for (k = 0; k < v.nParameter(); ++k) {
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
if (i == j) {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 2.0*param));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
if (i == j) {
b = twoPi/param;
dbb = -2.0*b*b/param;
TEST_ASSERT(eq(v.dkkBasis(k, i, j), dbb));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
}
// Test assignment
UnitCell<2> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 1);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test2DHexagonal()
{
printMethod(TEST_FUNC);
UnitCell<2> v;
std::ifstream in;
openInputFile("in/Hexagonal2D", in);
in >> v;
TEST_ASSERT(v.nParameter() == 1);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
#if 0
printEndl();
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
std::cout << "a(0) = " << v.rBasis(0) << std::endl;
std::cout << "a(1) = " << v.rBasis(1) << std::endl;
std::cout << "b(0) = " << v.kBasis(0) << std::endl;
std::cout << "b(1) = " << v.kBasis(1) << std::endl;
#endif
IntVec<2> d;
d[0] = 8;
d[1] = 8;
IntVec<2> x;
x[0] = -4;
x[1] = +5;
IntVec<2> y;
// Test shiftToMinimum function
y = shiftToMinimum(x, d, v);
TEST_ASSERT(y[0] == 4);
TEST_ASSERT(y[1] == -3);
y = shiftToMinimum(y, d, v);
TEST_ASSERT(y[0] == 4);
TEST_ASSERT(y[1] == -3);
// Test assignment
UnitCell<2> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 1);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j;
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
TEST_ASSERT(eq(u.drBasis(0, i, j), v.drBasis(0, i, j)));
TEST_ASSERT(eq(u.dkBasis(0, i, j), v.dkBasis(0, i, j)));
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test2DRectangular()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<2> v;
std::ifstream in;
openInputFile("in/Rectangular", in);
in >> v;
TEST_ASSERT(v.nParameter() == 2);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<2> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 2);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test2DRhombic()
{
printMethod(TEST_FUNC);
UnitCell<2> v;
std::ifstream in;
openInputFile("in/Rhombic", in);
in >> v;
TEST_ASSERT(v.nParameter() == 2);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<2> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 2);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j;
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
TEST_ASSERT(eq(u.drBasis(0, i, j), v.drBasis(0, i, j)));
TEST_ASSERT(eq(u.dkBasis(0, i, j), v.dkBasis(0, i, j)));
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test2DOblique()
{
printMethod(TEST_FUNC);
UnitCell<2> v;
std::ifstream in;
openInputFile("in/Oblique", in);
in >> v;
TEST_ASSERT(v.nParameter() == 3);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<2> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 3);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j;
for (i = 0; i < 2; ++i) {
for (j = 0; j < 2; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
TEST_ASSERT(eq(u.drBasis(0, i, j), v.drBasis(0, i, j)));
TEST_ASSERT(eq(u.dkBasis(0, i, j), v.dkBasis(0, i, j)));
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DCubic()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Cubic", in);
in >> v;
TEST_ASSERT(v.nParameter() == 1);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
#if 0
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
std::cout << "a(0) = " << v.rBasis(0) << std::endl;
std::cout << "a(1) = " << v.rBasis(1) << std::endl;
std::cout << "a(2) = " << v.rBasis(2) << std::endl;
std::cout << "b(0) = " << v.kBasis(0) << std::endl;
std::cout << "b(1) = " << v.kBasis(1) << std::endl;
std::cout << "b(2) = " << v.kBasis(2) << std::endl;
#endif
#if 0
double param, b, dbb;
double twoPi = 2.0*Constants::Pi;
int i, j, k;
for (k = 0; k < v.nParameter(); ++k) {
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
if (i == j && i == k) {
param = v.parameter(i);
TEST_ASSERT(eq(v.drrBasis(k, i, j), 2.0*param));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
if (i == j && i == k) {
param = v.parameter(i);
b = twoPi/param;
dbb = -2.0*b*b/param;
TEST_ASSERT(eq(v.dkkBasis(k, i, j), dbb));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
}
#endif
IntVec<3> d;
d[0] = 8;
d[1] = 8;
d[2] = 8;
IntVec<3> x;
x[0] = -4;
x[1] = +4;
x[2] = 7;
IntVec<3> y;
//std::cout << "Before shift " << x << std::endl;
y = shiftToMinimum(x, d, v);
TEST_ASSERT(y[0] == 4);
TEST_ASSERT(y[1] == 4);
TEST_ASSERT(y[2] == -1);
//std::cout << "After shift " << y << std::endl;
//y = shiftToMinimum(y, d, v);
//std::cout << "After again " << y << std::endl;
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 1);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DTetragonal()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Tetragonal", in);
in >> v;
TEST_ASSERT(v.nParameter() == 2);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 2);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DOrthorhombic()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Orthorhombic", in);
in >> v;
TEST_ASSERT(v.nParameter() == 3);
TEST_ASSERT(isValidReciprocal(v));
TEST_ASSERT(isValidDerivative(v));
#if 0
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
std::cout << "a(0) = " << v.rBasis(0) << std::endl;
std::cout << "a(1) = " << v.rBasis(1) << std::endl;
std::cout << "a(2) = " << v.rBasis(2) << std::endl;
std::cout << "b(0) = " << v.kBasis(0) << std::endl;
std::cout << "b(1) = " << v.kBasis(1) << std::endl;
std::cout << "b(2) = " << v.kBasis(2) << std::endl;
#endif
double param, b, dbb;
double twoPi = 2.0*Constants::Pi;
int i, j, k;
for (k = 0; k < v.nParameter(); ++k) {
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
if (i == j && i == k) {
param = v.parameter(i);
TEST_ASSERT(eq(v.drrBasis(k, i, j), 2.0*param));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
if (i == j && i == k) {
param = v.parameter(i);
b = twoPi/param;
dbb = -2.0*b*b/param;
TEST_ASSERT(eq(v.dkkBasis(k, i, j), dbb));
} else {
TEST_ASSERT(eq(v.drrBasis(k, i, j), 0.0));
}
}
}
}
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 3);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DHexagonal()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Hexagonal3D", in);
in >> v;
TEST_ASSERT(v.nParameter() == 2);
bool isReciprocal = isValidReciprocal(v); // Quiet test
//bool isReciprocal = isValidReciprocal(v, true); // Verbose test
TEST_ASSERT(isReciprocal);
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 2);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DRhombohedral()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Rhombohedral", in);
in >> v;
TEST_ASSERT(v.nParameter() == 2);
// Check rBasis, and interpretation of parameter a and beta
double a = v.parameter(0);
double beta = v.parameter(1);
double sum00 = 0.0;
double sum11 = 0.0;
double sum22 = 0.0;
double sum01 = 0.0;
double sum12 = 0.0;
for (int i=0; i < 3; ++i) {
sum00 += v.rBasis(0)[i]*v.rBasis(0)[i];
sum11 += v.rBasis(1)[i]*v.rBasis(1)[i];
sum22 += v.rBasis(2)[i]*v.rBasis(2)[i];
sum01 += v.rBasis(0)[i]*v.rBasis(1)[i];
sum12 += v.rBasis(1)[i]*v.rBasis(2)[i];
}
TEST_ASSERT(eq(sum00, a*a));
TEST_ASSERT(eq(sum11, a*a));
TEST_ASSERT(eq(sum22, a*a));
TEST_ASSERT(eq(sum01, a*a*cos(beta)));
TEST_ASSERT(eq(sum12, a*a*cos(beta)));
bool isReciprocal = isValidReciprocal(v); // Quiet test
//bool isReciprocal = isValidReciprocal(v, true); // Verbose test
TEST_ASSERT(isReciprocal);
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 2);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DMonoclinic()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Monoclinic", in);
in >> v;
TEST_ASSERT(v.nParameter() == 4);
bool isReciprocal = isValidReciprocal(v); // Quiet test
//bool isReciprocal = isValidReciprocal(v, true); // Verbose test
TEST_ASSERT(isReciprocal);
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 4);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
void test3DTriclinic()
{
printMethod(TEST_FUNC);
// printEndl();
UnitCell<3> v;
std::ifstream in;
openInputFile("in/Triclinic", in);
in >> v;
TEST_ASSERT(v.nParameter() == 6);
bool isReciprocal = isValidReciprocal(v); // Quiet test
//bool isReciprocal = isValidReciprocal(v, true); // Verbose test
TEST_ASSERT(isReciprocal);
TEST_ASSERT(isValidDerivative(v));
// Test assignment
UnitCell<3> u;
u = v;
TEST_ASSERT(u.lattice() == v.lattice());
TEST_ASSERT(u.nParameter() == v.nParameter());
TEST_ASSERT(u.nParameter() == 6);
for (int i = 0; i < u.nParameter(); ++i) {
TEST_ASSERT(eq(u.parameter(i), v.parameter(i)));
}
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
TEST_ASSERT(eq(u.rBasis(i)[j], v.rBasis(i)[j]));
TEST_ASSERT(eq(u.kBasis(i)[j], v.kBasis(i)[j]));
for (k = 0; k < 3; ++k) {
TEST_ASSERT(eq(u.drBasis(k,i,j), v.drBasis(k, i, j)));
TEST_ASSERT(eq(u.dkBasis(k,i,j), v.dkBasis(k, i, j)));
}
}
}
TEST_ASSERT(isValidReciprocal(u));
TEST_ASSERT(isValidDerivative(u));
}
};
TEST_BEGIN(UnitCellTest)
TEST_ADD(UnitCellTest, test1DLamellar)
TEST_ADD(UnitCellTest, test2DSquare)
TEST_ADD(UnitCellTest, test2DHexagonal)
TEST_ADD(UnitCellTest, test2DRectangular)
TEST_ADD(UnitCellTest, test2DRhombic)
TEST_ADD(UnitCellTest, test2DOblique)
TEST_ADD(UnitCellTest, test3DCubic)
TEST_ADD(UnitCellTest, test3DTetragonal)
TEST_ADD(UnitCellTest, test3DOrthorhombic)
TEST_ADD(UnitCellTest, test3DHexagonal)
TEST_ADD(UnitCellTest, test3DRhombohedral)
TEST_ADD(UnitCellTest, test3DMonoclinic)
TEST_ADD(UnitCellTest, test3DTriclinic)
TEST_END(UnitCellTest)
#endif
| 22,436
|
C++
|
.h
| 681
| 24.537445
| 73
| 0.497967
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,116
|
SpaceGroupTest.h
|
dmorse_pscfpp/src/pscf/tests/crystal/SpaceGroupTest.h
|
#ifndef PSCF_SPACE_GROUP_TEST_H
#define PSCF_SPACE_GROUP_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/crystal/SpaceGroup.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
class SpaceGroupTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void test2DmakeIdentity()
{
printMethod(TEST_FUNC);
//printEndl();
SpaceGroup<2> G;
G.makeCompleteGroup();
TEST_ASSERT(1 == G.size());
//std::cout << G << std::endl;
}
void test2Dmake1()
{
printMethod(TEST_FUNC);
//printEndl();
SpaceGroup<2> G;
SpaceSymmetry<2> A;
A.R(0,0) = 0;
A.R(1,0) = 1;
A.R(0,1) = -1;
A.R(1,1) = 0;
A.t(0) = 0;
A.t(1) = Rational(1, 2);
G.add(A);
G.makeCompleteGroup();
TEST_ASSERT(4 == G.size());
//std::cout << G << std::endl;
}
void test2Dmake2()
{
printMethod(TEST_FUNC);
//printEndl();
SpaceGroup<2> G;
// Below: Add generating elements of simple Hexagonal group
SpaceSymmetry<2> A;
A.R(0,0) = -1;
A.R(1,0) = 0;
A.R(0,1) = 0;
A.R(1,1) = -1;
A.t(0) = 0;
A.t(1) = 0;
G.add(A);
A.R(0,0) = -1;
A.R(1,0) = 1;
A.R(0,1) = 0;
A.R(1,1) = 1;
A.t(0) = 0;
A.t(1) = 0;
G.add(A);
A.R(0,0) = 0;
A.R(1,0) = 1;
A.R(0,1) = -1;
A.R(1,1) = 1;
A.t(0) = 0;
A.t(1) = 0;
G.add(A);
G.makeCompleteGroup();
//std::cout << G << std::endl;
TEST_ASSERT(12 == G.size());
}
void test2Dmake3()
{
printMethod(TEST_FUNC);
//printEndl();
SpaceGroup<2> G;
SpaceSymmetry<2> A;
A.R(0,0) = 0;
A.R(1,0) = 1;
A.R(0,1) = 1;
A.R(1,1) = 0;
A.t(0) = 0;
A.t(1) = 0;
G.add(A);
A.R(0,0) = -1;
A.R(1,0) = 0;
A.R(0,1) = 0;
A.R(1,1) = 1;
A.t(0) = 0;
A.t(1) = 0;
G.add(A);
A.R(0,0) = 1;
A.R(1,0) = 0;
A.R(0,1) = 0;
A.R(1,1) = 1;
A.t(0) = Rational(1, 2);
A.t(1) = A.t(0);
G.add(A);
G.makeCompleteGroup();
//std::cout << G << std::endl;
TEST_ASSERT(16 == G.size());
}
void test3Dmake()
{
printMethod(TEST_FUNC);
//printEndl();
SpaceGroup<3> G;
// Below: Add generating elements of BCC group
SpaceSymmetry<3> A;
A.R(0,0) = -1;
A.R(0,1) = 0;
A.R(0,2) = 0;
A.R(1,0) = 0;
A.R(1,1) = 1;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = 0;
A.t(1) = 0;
A.t(2) = 0;
//std::cout << A << std::endl;
G.add(A);
//G.makeCompleteGroup();
//std::cout << G << std::endl;
A.R(0,0) = 0;
A.R(0,1) = 1;
A.R(0,2) = 0;
A.R(1,0) = 1;
A.R(1,1) = 0;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = 0;
A.t(1) = 0;
A.t(2) = 0;
G.add(A);
//G.makeCompleteGroup();
//std::cout << G << std::endl;
A.R(0,0) = 0;
A.R(0,1) = 0;
A.R(0,2) = 1;
A.R(1,0) = 0;
A.R(1,1) = 1;
A.R(1,2) = 0;
A.R(2,0) = 1;
A.R(2,1) = 0;
A.R(2,2) = 0;
A.t(0) = 0;
A.t(1) = 0;
A.t(2) = 0;
G.add(A);
//G.makeCompleteGroup();
//std::cout << G << std::endl;
//std::cout << "size =" << G.size() << std::endl;
A.R(0,0) = 1;
A.R(0,1) = 0;
A.R(0,2) = 0;
A.R(1,0) = 0;
A.R(1,1) = 1;
A.R(1,2) = 0;
A.R(2,0) = 0;
A.R(2,1) = 0;
A.R(2,2) = 1;
A.t(0) = Rational(1,2);
A.t(1) = Rational(1,2);
A.t(2) = Rational(1,2);
G.add(A);
G.makeCompleteGroup();
TEST_ASSERT(96 == G.size());
//std::cout << G << std::endl;
}
void test2Dread()
{
printMethod(TEST_FUNC);
//printEndl();
std::ifstream in;
openInputFile("in/p_6_m_m", in);
SpaceGroup<2> g;
in >> g;
TEST_ASSERT(12 == g.size());
TEST_ASSERT(g.isValid());
// std::cout << std::endl;
//std::cout << g << std::endl;
}
void test3D_I_a_3b_d()
{
printMethod(TEST_FUNC);
//printEndl();
std::ifstream in;
openInputFile("in/I_a_-3_d", in);
SpaceGroup<3> g;
in >> g;
TEST_ASSERT(96 == g.size());
TEST_ASSERT(g.isValid());
// std::cout << std::endl;
// std::cout << g << std::endl;
bool hasInversionCenter;
typename SpaceSymmetry<3>::Translation center;
hasInversionCenter = g.hasInversionCenter(center);
if (hasInversionCenter) {
for (int i = 0; i < 3; ++i) {
TEST_ASSERT(center[i] == 0);
//std::cout << " " << center[i];
}
//std::cout << std::endl;
}
}
void test3D_F_d_3b_m()
{
printMethod(TEST_FUNC);
//printEndl();
std::ifstream in;
bool hasInversionCenter;
SpaceGroup<3> g1;
typename SpaceSymmetry<3>::Translation center1;
openInputFile("in/F_d_-3_m:1", in);
in >> g1;
// std::cout << std::endl;
// std::cout << g << std::endl;
TEST_ASSERT(192 == g1.size());
TEST_ASSERT(g1.isValid());
hasInversionCenter = g1.hasInversionCenter(center1);
if (hasInversionCenter) {
// std::cout << std::endl;
for (int i = 0; i < 3; ++i) {
TEST_ASSERT(center1[i] == Rational(1, 8));
// std::cout << " " << center1[i];
}
// std::cout << std::endl;
}
in.close();
SpaceGroup<3> g2;
typename SpaceSymmetry<3>::Translation center2;
openInputFile("in/F_d_-3_m:2", in);
in >> g2;
// std::cout << std::endl;
// std::cout << g << std::endl;
TEST_ASSERT(192 == g2.size());
TEST_ASSERT(g2.isValid());
hasInversionCenter = g2.hasInversionCenter(center2);
if (hasInversionCenter) {
for (int i = 0; i < 3; ++i) {
TEST_ASSERT(center2[i] == 0);
// std::cout << " " << center2[i];
}
// std::cout << std::endl;
}
in.close();
TEST_ASSERT(g1 != g2);
// Shift origin to inversion center of setting 1
g1.shiftOrigin(center1);
// Show that settings 1 and 2 differ only in shift of origin
TEST_ASSERT(g1 == g2);
}
};
TEST_BEGIN(SpaceGroupTest)
TEST_ADD(SpaceGroupTest, test2DmakeIdentity)
TEST_ADD(SpaceGroupTest, test2Dmake1)
TEST_ADD(SpaceGroupTest, test2Dmake2)
TEST_ADD(SpaceGroupTest, test2Dmake3)
TEST_ADD(SpaceGroupTest, test3Dmake)
TEST_ADD(SpaceGroupTest, test2Dread)
TEST_ADD(SpaceGroupTest, test3D_I_a_3b_d)
TEST_ADD(SpaceGroupTest, test3D_F_d_3b_m)
TEST_END(SpaceGroupTest)
#endif
| 6,895
|
C++
|
.h
| 271
| 18.785978
| 66
| 0.483552
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,117
|
MixtureTest.h
|
dmorse_pscfpp/src/pscf/tests/homogeneous/MixtureTest.h
|
#ifndef PSCF_HOMOGENEOUS_MIXTURE_TEST_H
#define PSCF_HOMOGENEOUS_MIXTURE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/homogeneous/Mixture.h>
#include <pscf/homogeneous/Molecule.h>
#include <pscf/inter/Interaction.h>
#include <util/containers/DArray.h>
#include <util/misc/Log.h>
#include <fstream>
using namespace Pscf;
using namespace Util;
class MixtureTest : public UnitTest
{
public:
void setUp()
{
//setVerbose(1);
}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Homogeneous::Mixture mixture;
}
void testReadWrite() {
printMethod(TEST_FUNC);
Homogeneous::Mixture mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
TEST_ASSERT(mixture.nMolecule() == 2);
TEST_ASSERT(eq(mixture.molecule(0).size(), 5.0));
TEST_ASSERT(mixture.molecule(0).nClump() == 2);
TEST_ASSERT(mixture.molecule(0).clump(0).monomerId() == 0);
TEST_ASSERT(eq(mixture.molecule(0).clump(0).size(), 2.0));
TEST_ASSERT(mixture.molecule(0).clump(1).monomerId() == 1);
TEST_ASSERT(eq(mixture.molecule(0).clump(1).size(), 3.0));
TEST_ASSERT(eq(mixture.molecule(1).size(), 1.0));
TEST_ASSERT(mixture.molecule(1).nClump() == 1);
TEST_ASSERT(mixture.molecule(1).clump(0).monomerId() == 0);
TEST_ASSERT(eq(mixture.molecule(1).clump(0).size(), 1.0));
if (verbose() > 0) {
printEndl();
mixture.writeParam(Log::file());
}
}
void testSetComposition() {
printMethod(TEST_FUNC);
Homogeneous::Mixture mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
DArray<double> phi;
phi.allocate(2);
phi[0] = 0.6;
phi[1] = 0.4;
mixture.setComposition(phi);
TEST_ASSERT(eq(mixture.phi(0), 0.6));
TEST_ASSERT(eq(mixture.phi(1), 0.4));
TEST_ASSERT(eq(mixture.c(0), 0.64));
TEST_ASSERT(eq(mixture.c(1), 0.36));
}
void testComputeMu() {
printMethod(TEST_FUNC);
Homogeneous::Mixture mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
in.close();
Interaction interaction;
interaction.setNMonomer(mixture.nMonomer());
openInputFile("in/Interaction", in);
interaction.readParam(in);
in.close();
DArray<double> phi;
phi.allocate(2);
phi[0] = 0.6;
phi[1] = 0.4;
mixture.setComposition(phi);
double xi = 3.0;
mixture.computeMu(interaction, xi);
TEST_ASSERT(eq(mixture.phi(0), 0.6));
TEST_ASSERT(eq(mixture.phi(1), 0.4));
TEST_ASSERT(eq(mixture.c(0), 0.64));
TEST_ASSERT(eq(mixture.c(1), 0.36));
double mu0, mu1, w0, w1, chi;
chi = 2.0;
w0 = mixture.c(1)*chi;
w1 = mixture.c(0)*chi;
mu0 = log(0.6) + w0*2.0 + w1*3.0 + xi*5.0;
TEST_ASSERT(eq(mixture.mu(0), mu0));
mu1 = log(0.4) + w0*1.0 + xi*1.0;
TEST_ASSERT(eq(mixture.mu(1), mu1));
}
void testComputePhi() {
printMethod(TEST_FUNC);
Homogeneous::Mixture mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
in.close();
Interaction interaction;
interaction.setNMonomer(mixture.nMonomer());
openInputFile("in/Interaction", in);
interaction.readParam(in);
in.close();
DArray<double> phi;
phi.allocate(2);
phi[0] = 0.6;
phi[1] = 0.4;
mixture.setComposition(phi);
double xi = 3.0;
mixture.computeMu(interaction, xi);
TEST_ASSERT(eq(mixture.phi(0), 0.6));
TEST_ASSERT(eq(mixture.phi(1), 0.4));
TEST_ASSERT(eq(mixture.c(0), 0.64));
TEST_ASSERT(eq(mixture.c(1), 0.36));
DArray<double> mu;
mu.allocate(2);
mu[0] = mixture.mu(0) + 0.10;
mu[1] = mixture.mu(1) - 0.05;
xi = 0.0;
mixture.computePhi(interaction, mu, phi, xi);
// Note: Throw exception if convergence fails, so
// normal completion already indicates success.
TEST_ASSERT(eq(mixture.mu(0), mu[0]));
TEST_ASSERT(eq(mixture.mu(1), mu[1]));
mixture.computeFreeEnergy(interaction);
if (verbose() > 0) {
printEndl();
Log::file() << "fHelmholtz = " << mixture.fHelmholtz() << "\n";
Log::file() << "pressure = " << mixture.pressure() << "\n";
}
}
};
TEST_BEGIN(MixtureTest)
TEST_ADD(MixtureTest, testConstructor)
TEST_ADD(MixtureTest, testReadWrite)
TEST_ADD(MixtureTest, testSetComposition)
TEST_ADD(MixtureTest, testComputeMu)
TEST_ADD(MixtureTest, testComputePhi)
TEST_END(MixtureTest)
#endif
| 4,745
|
C++
|
.h
| 145
| 26.641379
| 72
| 0.623738
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,118
|
ClumpTest.h
|
dmorse_pscfpp/src/pscf/tests/homogeneous/ClumpTest.h
|
#ifndef PSCF_CLUMP_TEST_H
#define PSCF_CLUMP_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/homogeneous/Clump.h>
#include <util/misc/Log.h>
#include <fstream>
using namespace Pscf;
using namespace Util;
class ClumpTest : public UnitTest
{
public:
void setUp()
{
//setVerbose(1);
}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Homogeneous::Clump clump;
}
void testSetters()
{
printMethod(TEST_FUNC);
Homogeneous::Clump clump;
clump.setMonomerId(0);
clump.setSize(2.0);
TEST_ASSERT(clump.monomerId() == 0);
TEST_ASSERT(eq(clump.size(), 2.0));
}
void testReadWrite() {
printMethod(TEST_FUNC);
Homogeneous::Clump clump;
std::ifstream in;
openInputFile("in/Clump", in);
in >> clump;
TEST_ASSERT(clump.monomerId() == 0);
TEST_ASSERT(eq(clump.size(), 2.0));
if (verbose() > 0) {
printEndl();
Log::file() << clump << std::endl ;
}
}
};
TEST_BEGIN(ClumpTest)
TEST_ADD(ClumpTest, testConstructor)
TEST_ADD(ClumpTest, testSetters)
TEST_ADD(ClumpTest, testReadWrite)
TEST_END(ClumpTest)
#endif
| 1,227
|
C++
|
.h
| 52
| 19
| 44
| 0.652249
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,119
|
HomogeneousTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/homogeneous/HomogeneousTestComposite.h
|
#ifndef PSCF_HOMOGENEOUS_TEST_COMPOSITE_H
#define PSCF_HOMOGENEOUS_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "ClumpTest.h"
#include "MoleculeTest.h"
#include "MixtureTest.h"
TEST_COMPOSITE_BEGIN(HomogeneousTestComposite)
TEST_COMPOSITE_ADD_UNIT(ClumpTest);
TEST_COMPOSITE_ADD_UNIT(MoleculeTest);
TEST_COMPOSITE_ADD_UNIT(MixtureTest);
TEST_COMPOSITE_END
#endif
| 386
|
C++
|
.h
| 12
| 30.833333
| 46
| 0.843243
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,120
|
MoleculeTest.h
|
dmorse_pscfpp/src/pscf/tests/homogeneous/MoleculeTest.h
|
#ifndef PSCF_HOMOGENEOUS_MOLECULE_TEST_H
#define PSCF_HOMOGENEOUS_MOLECULE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/homogeneous/Molecule.h>
#include <util/misc/Log.h>
#include <fstream>
using namespace Pscf;
//using namespace Util;
class MoleculeTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Homogeneous::Molecule molecule;
}
void testReadWrite() {
printMethod(TEST_FUNC);
Homogeneous::Molecule molecule;
std::ifstream in;
openInputFile("in/Molecule", in);
molecule.readParam(in);
TEST_ASSERT(molecule.nClump() == 2);
TEST_ASSERT(molecule.clump(0).monomerId() == 0);
TEST_ASSERT(eq(molecule.clump(0).size(), 2.0));
TEST_ASSERT(molecule.clump(1).monomerId() == 1);
TEST_ASSERT(eq(molecule.clump(1).size(), 3.0));
TEST_ASSERT(eq(molecule.size(), 5.0));
if (verbose() > 0) {
printEndl();
molecule.writeParam(Log::file());
}
}
void testSetters()
{
printMethod(TEST_FUNC);
Homogeneous::Molecule molecule;
molecule.setNClump(2);
molecule.clump(0).setMonomerId(0);
molecule.clump(0).setSize(2.0);
molecule.clump(1).setMonomerId(1);
molecule.clump(1).setSize(3.0);
molecule.computeSize();
TEST_ASSERT(molecule.nClump() == 2);
TEST_ASSERT(molecule.clump(0).monomerId() == 0);
TEST_ASSERT(eq(molecule.clump(0).size(), 2.0));
TEST_ASSERT(molecule.clump(1).monomerId() == 1);
TEST_ASSERT(eq(molecule.clump(1).size(), 3.0));
TEST_ASSERT(eq(molecule.size(), 5.0));
}
};
TEST_BEGIN(MoleculeTest)
TEST_ADD(MoleculeTest, testConstructor)
TEST_ADD(MoleculeTest, testReadWrite)
TEST_ADD(MoleculeTest, testSetters)
TEST_END(MoleculeTest)
#endif
| 1,889
|
C++
|
.h
| 62
| 25.403226
| 54
| 0.667774
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,121
|
InteractionTest.h
|
dmorse_pscfpp/src/pscf/tests/inter/InteractionTest.h
|
#ifndef CHI_INTERACTION_TEST_H
#define CHI_INTERACTION_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/inter/Interaction.h>
#include <util/param/BracketPolicy.h>
#include <fstream>
using namespace Pscf;
//using namespace Util;
class InteractionTest : public UnitTest
{
public:
void setUp()
{ BracketPolicy::set(BracketPolicy::Optional); }
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Interaction v;
v.setNMonomer(2);
}
void testReadWrite1()
{
printMethod(TEST_FUNC);
Interaction v;
const int nMonomer = 2;
v.setNMonomer(nMonomer);
std::ifstream in;
openInputFile("in/Interaction", in);
v.readParam(in);
if (verbose() > 0){
printEndl();
v.writeParam(std::cout);
}
TEST_ASSERT(eq(v.chi(0,0), 0.0));
TEST_ASSERT(eq(v.chi(1,1), 0.0));
TEST_ASSERT(eq(v.chi(0,1), 1.0));
TEST_ASSERT(eq(v.chi(1,0), 1.0));
TEST_ASSERT(eq(v.chi(1,0), v.chi(0,1)));
TEST_ASSERT(eq(v.chiInverse(0,0), 0.0));
TEST_ASSERT(eq(v.chiInverse(1,1), 0.0));
TEST_ASSERT(eq(v.chiInverse(0,1), 1.0));
TEST_ASSERT(eq(v.chiInverse(1,0), 1.0));
int i, j, k;
double sum;
for (i = 0; i < nMonomer; ++i) {
for (j = 0; j < nMonomer; ++j) {
sum = 0.0;
for (k = 0; k < nMonomer; ++k) {
sum += v.chi(i,k)*v.chiInverse(k,j);
}
if (i == j) {
TEST_ASSERT(eq(sum, 1.0));
} else {
TEST_ASSERT(eq(sum, 0.0));
}
}
}
}
void testReadWrite2()
{
printMethod(TEST_FUNC);
Interaction v;
const int nMonomer = 2;
v.setNMonomer(nMonomer);
std::ifstream in;
openInputFile("in/Interaction2", in);
v.readParam(in);
if (verbose() > 0){
printEndl();
v.writeParam(std::cout);
}
TEST_ASSERT(eq(v.chi(0,0), 0.5));
TEST_ASSERT(eq(v.chi(1,1), 1.5));
TEST_ASSERT(eq(v.chi(0,1), 2.0));
TEST_ASSERT(eq(v.chi(1,0), 2.0));
TEST_ASSERT(eq(v.chi(1,0), v.chi(0,1)));
int i, j, k;
double sum;
for (i = 0; i < nMonomer; ++i) {
for (j = 0; j < nMonomer; ++j) {
sum = 0.0;
for (k = 0; k < nMonomer; ++k) {
sum += v.chi(i,k)*v.chiInverse(k,j);
}
if (i == j) {
TEST_ASSERT(eq(sum, 1.0));
} else {
TEST_ASSERT(eq(sum, 0.0));
}
}
}
}
void testReadWrite3()
{
printMethod(TEST_FUNC);
Interaction v;
const int nMonomer = 3;
v.setNMonomer(nMonomer);
std::ifstream in;
openInputFile("in/Interaction3", in);
v.readParam(in);
if (verbose() > 0){
printEndl();
v.writeParam(std::cout);
}
TEST_ASSERT(eq(v.chi(1,0), v.chi(0,1)));
TEST_ASSERT(eq(v.chi(1,2), v.chi(2,1)));
TEST_ASSERT(eq(v.chi(0,2), v.chi(2,0)));
int i, j, k;
double sum;
for (i = 0; i < nMonomer; ++i) {
for (j = 0; j < nMonomer; ++j) {
sum = 0.0;
for (k = 0; k < nMonomer; ++k) {
sum += v.chi(i,k)*v.chiInverse(k,j);
}
if (i == j) {
TEST_ASSERT(eq(sum, 1.0));
} else {
TEST_ASSERT(eq(sum, 0.0));
}
}
}
}
void testComputeW()
{
printMethod(TEST_FUNC);
//printEndl();
Interaction v;
v.setNMonomer(2);
std::ifstream in;
openInputFile("in/Interaction", in);
v.readParam(in);
// Test computeW
DArray<double> c;
DArray<double> w;
c.allocate(2);
w.allocate(2);
c[0] = 0.3;
c[1] = 0.7;
v. computeW(c, w);
TEST_ASSERT(eq(w[0], 0.7));
TEST_ASSERT(eq(w[1], 0.3));
// Test computeC
w[0] += 0.4;
w[1] += 0.4;
double xi;
v.computeC(w, c, xi);
TEST_ASSERT(eq(c[0], 0.3));
TEST_ASSERT(eq(c[1], 0.7));
TEST_ASSERT(eq(0.4, xi));
}
};
TEST_BEGIN(InteractionTest)
TEST_ADD(InteractionTest, testConstructor)
TEST_ADD(InteractionTest, testReadWrite1)
TEST_ADD(InteractionTest, testReadWrite2)
TEST_ADD(InteractionTest, testReadWrite3)
TEST_ADD(InteractionTest, testComputeW)
TEST_END(InteractionTest)
#endif
| 4,471
|
C++
|
.h
| 163
| 19.91411
| 51
| 0.520028
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,122
|
AmbdInteractionTest.h
|
dmorse_pscfpp/src/pscf/tests/inter/AmbdInteractionTest.h
|
#ifndef AMBD_INTERACTION_TEST_H
#define AMBD_INTERACTION_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/inter/Interaction.h>
#include <pscf/iterator/AmbdInteraction.h>
#include <util/param/BracketPolicy.h>
#include <fstream>
using namespace Pscf;
//using namespace Util;
class AmbdInteractionTest : public UnitTest
{
public:
void setUp()
{ BracketPolicy::set(BracketPolicy::Optional); }
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
AmbdInteraction v;
v.setNMonomer(2);
}
void testReadWrite2()
{
printMethod(TEST_FUNC);
Interaction v;
const int nMonomer = 2;
v.setNMonomer(nMonomer);
std::ifstream in;
openInputFile("in/Interaction2", in);
v.readParam(in);
AmbdInteraction u;
u.setNMonomer(nMonomer);
u.update(v);
TEST_ASSERT(eq(u.chi(0,0), 0.5));
TEST_ASSERT(eq(u.chi(1,1), 1.5));
TEST_ASSERT(eq(u.chi(0,1), 2.0));
TEST_ASSERT(eq(u.chi(1,0), 2.0));
TEST_ASSERT(eq(u.chi(1,0), u.chi(0,1)));
int i, j, k;
double sum;
for (i = 0; i < nMonomer; ++i) {
for (j = 0; j < nMonomer; ++j) {
TEST_ASSERT(eq(u.chi(i,j), v.chi(i,j)));
TEST_ASSERT(eq(u.chiInverse(i,j), v.chiInverse(i,j)));
sum = 0.0;
for (k = 0; k < nMonomer; ++k) {
sum += u.chi(i,k)*u.chiInverse(k,j);
}
if (i == j) {
TEST_ASSERT(eq(sum, 1.0));
} else {
TEST_ASSERT(eq(sum, 0.0));
}
}
}
}
void testReadWrite3()
{
printMethod(TEST_FUNC);
Interaction v;
const int nMonomer = 3;
v.setNMonomer(nMonomer);
std::ifstream in;
openInputFile("in/Interaction3", in);
v.readParam(in);
AmbdInteraction u;
u.setNMonomer(nMonomer);
u.update(v);
TEST_ASSERT(eq(u.chi(1,0), u.chi(0,1)));
TEST_ASSERT(eq(u.chi(1,2), u.chi(2,1)));
TEST_ASSERT(eq(u.chi(0,2), u.chi(2,0)));
int i, j, k;
double sum;
for (i = 0; i < nMonomer; ++i) {
for (j = 0; j < nMonomer; ++j) {
sum = 0.0;
for (k = 0; k < nMonomer; ++k) {
sum += u.chi(i,k)*u.chiInverse(k,j);
}
if (i == j) {
TEST_ASSERT(eq(sum, 1.0));
} else {
TEST_ASSERT(eq(sum, 0.0));
}
}
}
}
};
TEST_BEGIN(AmbdInteractionTest)
TEST_ADD(AmbdInteractionTest, testConstructor)
TEST_ADD(AmbdInteractionTest, testReadWrite2)
TEST_ADD(AmbdInteractionTest, testReadWrite3)
TEST_END(AmbdInteractionTest)
#endif
| 2,737
|
C++
|
.h
| 96
| 21.270833
| 66
| 0.556662
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,123
|
InterTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/inter/InterTestComposite.h
|
#ifndef PSCF_INTER_TEST_COMPOSITE_H
#define PSCF_INTER_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "InteractionTest.h"
#include "AmbdInteractionTest.h"
TEST_COMPOSITE_BEGIN(InterTestComposite)
TEST_COMPOSITE_ADD_UNIT(InteractionTest);
TEST_COMPOSITE_ADD_UNIT(AmbdInteractionTest);
TEST_COMPOSITE_END
#endif
| 331
|
C++
|
.h
| 10
| 31.7
| 45
| 0.851735
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,124
|
RealVecTest.h
|
dmorse_pscfpp/src/pscf/tests/math/RealVecTest.h
|
#ifndef PSCF_REAL_VEC_TEST_H
#define PSCF_REAL_VEC_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/math/RealVec.h>
#include <iostream>
#include <fstream>
using namespace Pscf;
class RealVecTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor1()
{
printMethod(TEST_FUNC);
double a[3] = {1.1, 3.0, -2.2};
RealVec<3> v(a);
TEST_ASSERT(1.1 == v[0]);
TEST_ASSERT(3.0 == v[1]);
TEST_ASSERT(-2.2 == v[2]);
}
void testConstructor2()
{
printMethod(TEST_FUNC);
RealVec<3> v(3.0);
TEST_ASSERT(3 == v[0]);
TEST_ASSERT(3 == v[1]);
TEST_ASSERT(3 == v[2]);
double a[3] = {3.0, 3.0, 3.0};
RealVec<3> u(a);
TEST_ASSERT(u == v);
}
void testCopyConstructor()
{
printMethod(TEST_FUNC);
double va[3] = {1.0, -3.0, 2.2};
RealVec<3> v(va);
RealVec<3> u(v);
TEST_ASSERT(u == v);
}
void testEquality()
{
printMethod(TEST_FUNC);
double a[3] = {1.3, -4.8, 2.0};
RealVec<3> v(a);
RealVec<3> u(v);
TEST_ASSERT(v == u);
v[0] = v[0] + 5.0;
TEST_ASSERT(v != u);
}
void testAssignment()
{
printMethod(TEST_FUNC);
double a[3] = {1.0, -3.2, 2.0 };
RealVec<3> v(a);
RealVec<3> u = v;
TEST_ASSERT(v == u);
v[0] = v[0] + 1.9;
TEST_ASSERT(v != u);
}
void testAdd()
{
printMethod(TEST_FUNC);
double ua[3] = {1.4, 4.1, 2.0};
double va[3] = {2.3, 1.0, -2.0};
double ea[3] = {3.7, 5.1, 0.0};
RealVec<3> u(ua);
RealVec<3> v(va);
RealVec<3> e(ea);
RealVec<3> r;
r.add(u,v);
TEST_ASSERT(r == e);
}
void testSubtract()
{
printMethod(TEST_FUNC);
double ua[3] = {1.0, -4.0, 2.0};
double va[3] = {3.2, 1.0, -6.2};
double ea[3] = {-2.2, -5.0, 8.2};
RealVec<3> u(ua);
RealVec<3> v(va);
RealVec<3> e(ea);
RealVec<3> r;
r.subtract(u,v);
TEST_ASSERT(r == e);
}
void testMultiply()
{
printMethod(TEST_FUNC);
double ua[3] = {1.0, -4.0, 2.2};
double ea[3] = {3.0, -12.0, 6.6};
RealVec<3> u(ua);
RealVec<3> e(ea);
RealVec<3> r;
r.multiply(u, 3);
TEST_ASSERT(r == e);
}
void testDot()
{
printMethod(TEST_FUNC);
double a[3] = {1.0, -2.0, 2.0};
double b[3] = {2.0, 3.0, 4.0 };
double d;
RealVec<3> v(a);
RealVec<3> u(b);
d = dot(u, v);
TEST_ASSERT(eq(d,4.0));
}
#if 0
void testReadWrite() {
printMethod(TEST_FUNC);
printEndl();
RealVec<3> v;
std::ifstream in;
openInputFile("in/RealVec", in);
in >> v;
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
}
#endif
};
TEST_BEGIN(RealVecTest)
TEST_ADD(RealVecTest, testConstructor1)
TEST_ADD(RealVecTest, testConstructor2)
TEST_ADD(RealVecTest, testCopyConstructor)
TEST_ADD(RealVecTest, testEquality)
TEST_ADD(RealVecTest, testAssignment)
TEST_ADD(RealVecTest, testAdd)
TEST_ADD(RealVecTest, testSubtract)
TEST_ADD(RealVecTest, testMultiply)
TEST_ADD(RealVecTest, testDot)
//TEST_ADD(RealVecTest, testReadWrite)
TEST_END(RealVecTest)
#endif
| 3,332
|
C++
|
.h
| 138
| 18.753623
| 42
| 0.550221
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,125
|
LuSolverTest.h
|
dmorse_pscfpp/src/pscf/tests/math/LuSolverTest.h
|
#ifndef LU_SOLVER_TEST_H
#define LU_SOLVER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/math/LuSolver.h>
#include <util/containers/DMatrix.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
class LuSolverTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
LuSolver solver;
solver.allocate(3);
}
void testDecompose()
{
printMethod(TEST_FUNC);
DMatrix<double> a;
a.allocate(3, 3);
a(0,0) = 1.0;
a(1,1) = 3.0;
a(2,2) = 4.0;
a(0,1) = 2.0;
a(1,0) = 2.0;
a(1,2) = 5.0;
a(2,1) = 5.0;
a(0,2) = 0.0;
a(2,0) = 0.0;
LuSolver solver;
solver.allocate(3);
solver.computeLU(a);
}
void testSolve()
{
printMethod(TEST_FUNC);
DMatrix<double> a;
a.allocate(3,3);
a(0,0) = 1.0;
a(1,1) = 3.0;
a(2,2) = 4.0;
a(0,1) = 2.0;
a(1,0) = 2.0;
a(1,2) = 5.0;
a(2,1) = 5.0;
a(0,2) = 0.0;
a(2,0) = 0.0;
DArray<double> b, x, y;
b.allocate(3);
x.allocate(3);
y.allocate(3);
b[0] = 1.0;
b[1] = 2.0;
b[2] = 3.0;
LuSolver solver;
solver.allocate(3);
solver.computeLU(a);
solver.solve(b, x);
int i, j;
for (i = 0; i < 3; ++i) {
y[i] = 0.0;
for (j = 0; j < 3; ++j) {
y[i] += a(i,j)*x[j];
}
}
// std::cout << "y = " << y[0] << " " << y[1] << " " << y[2] << "\n";
TEST_ASSERT(eq(b[0], y[0]));
TEST_ASSERT(eq(b[1], y[1]));
TEST_ASSERT(eq(b[2], y[2]));
}
};
TEST_BEGIN(LuSolverTest)
TEST_ADD(LuSolverTest, testConstructor)
TEST_ADD(LuSolverTest, testDecompose)
TEST_ADD(LuSolverTest, testSolve)
TEST_END(LuSolverTest)
#endif
| 1,891
|
C++
|
.h
| 84
| 16.857143
| 77
| 0.512619
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,126
|
TridiagonalSolverTest.h
|
dmorse_pscfpp/src/pscf/tests/math/TridiagonalSolverTest.h
|
#ifndef TRIDIAGONAL_SOLVER_TEST_H
#define TRIDIAGONAL_SOLVER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/math/TridiagonalSolver.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
class TridiagonalSolverTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
}
void testSymmetricDecompose()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u;
d.allocate(3);
u.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
solver.computeLU(d, u);
}
void testSymmetricMultiply()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u;
d.allocate(3);
u.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
solver.computeLU(d, u);
DArray<double> b, x;
b.allocate(3);
x.allocate(3);
// std::cout << "\n";
b[0] = 1.0;
b[1] = 0.0;
b[2] = 0.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 1.0));
TEST_ASSERT(eq(x[1], 2.0));
TEST_ASSERT(eq(x[2], 0.0));
b[0] = 0.0;
b[1] = 1.0;
b[2] = 0.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 2.0));
TEST_ASSERT(eq(x[1], 3.0));
TEST_ASSERT(eq(x[2], 5.0));
b[0] = 0.0;
b[1] = 0.0;
b[2] = 1.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 0.0));
TEST_ASSERT(eq(x[1], 5.0));
TEST_ASSERT(eq(x[2], 4.0));
}
void testSymmetricSolve()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u;
d.allocate(3);
u.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
solver.computeLU(d, u);
DArray<double> b, x, y;
b.allocate(3);
x.allocate(3);
b[0] = 1.0;
b[1] = 2.0;
b[2] = 3.0;
solver.solve(b, x);
y.allocate(3);
solver.multiply(x, y);
// std::cout << y[0] << " " << y[1] << " " << y[2] << "\n";
TEST_ASSERT(eq(b[0], y[0]));
TEST_ASSERT(eq(b[1], y[1]));
TEST_ASSERT(eq(b[2], y[2]));
}
void testDecompose()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u, l;
d.allocate(3);
u.allocate(2);
l.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
l[0] = 1.0;
l[1] = -3.0;
solver.computeLU(d, u, l);
}
void testMultiply()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u, l;
d.allocate(3);
u.allocate(2);
l.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
l[0] = 1.0;
l[1] = -3.0;
solver.computeLU(d, u, l);
DArray<double> b, x;
b.allocate(3);
x.allocate(3);
// std::cout << "\n";
b[0] = 1.0;
b[1] = 0.0;
b[2] = 0.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 1.0));
TEST_ASSERT(eq(x[1], 1.0));
TEST_ASSERT(eq(x[2], 0.0));
b[0] = 0.0;
b[1] = 1.0;
b[2] = 0.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 2.0));
TEST_ASSERT(eq(x[1], 3.0));
TEST_ASSERT(eq(x[2], -3.0));
b[0] = 0.0;
b[1] = 0.0;
b[2] = 1.0;
solver.multiply(b, x);
// std::cout << x[0] << " " << x[1] << " " << x[2] << "\n";
TEST_ASSERT(eq(x[0], 0.0));
TEST_ASSERT(eq(x[1], 5.0));
TEST_ASSERT(eq(x[2], 4.0));
}
void testSolve()
{
printMethod(TEST_FUNC);
TridiagonalSolver solver;
solver.allocate(3);
DArray<double> d, u, l;
d.allocate(3);
u.allocate(2);
l.allocate(2);
d[0] = 1.0;
d[1] = 3.0;
d[2] = 4.0;
u[0] = 2.0;
u[1] = 5.0;
l[0] = 1.0;
l[1] = -3.0;
solver.computeLU(d, u, l);
DArray<double> b, x, y;
b.allocate(3);
x.allocate(3);
b[0] = 1.0;
b[1] = 2.0;
b[2] = 3.0;
solver.solve(b, x);
y.allocate(3);
solver.multiply(x, y);
// std::cout << y[0] << " " << y[1] << " " << y[2] << "\n";
TEST_ASSERT(eq(b[0], y[0]));
TEST_ASSERT(eq(b[1], y[1]));
TEST_ASSERT(eq(b[2], y[2]));
}
#if 0
#endif
};
TEST_BEGIN(TridiagonalSolverTest)
TEST_ADD(TridiagonalSolverTest, testConstructor)
TEST_ADD(TridiagonalSolverTest, testSymmetricDecompose)
TEST_ADD(TridiagonalSolverTest, testSymmetricMultiply)
TEST_ADD(TridiagonalSolverTest, testSymmetricSolve)
TEST_ADD(TridiagonalSolverTest, testDecompose)
TEST_ADD(TridiagonalSolverTest, testMultiply)
TEST_ADD(TridiagonalSolverTest, testSolve)
TEST_END(TridiagonalSolverTest)
#endif
| 5,476
|
C++
|
.h
| 215
| 19.293023
| 67
| 0.492155
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,127
|
IntVecTest.h
|
dmorse_pscfpp/src/pscf/tests/math/IntVecTest.h
|
#ifndef PSCF_INT_VEC_TEST_H
#define PSCF_INT_VEC_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pscf/math/IntVec.h>
#include <iostream>
#include <fstream>
using namespace Pscf;
class IntVecTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor1()
{
printMethod(TEST_FUNC);
int a[3] = {1, 3, 2};
IntVec<3> v(a);
TEST_ASSERT(1 == v[0]);
TEST_ASSERT(3 == v[1]);
TEST_ASSERT(2 == v[2]);
}
void testConstructor2()
{
printMethod(TEST_FUNC);
IntVec<3> v(3);
TEST_ASSERT(3 == v[0]);
TEST_ASSERT(3 == v[1]);
TEST_ASSERT(3 == v[2]);
int a[3] = {3, 3, 3};
IntVec<3> u(a);
TEST_ASSERT(u == v);
}
void testCopyConstructor()
{
printMethod(TEST_FUNC);
int va[3] = {1, -3, 2};
IntVec<3> v(va);
IntVec<3> u(v);
TEST_ASSERT(u == v);
}
void testEquality()
{
printMethod(TEST_FUNC);
int a[3] = {1, -4, 2 };
IntVec<3> v(a);
IntVec<3> u(v);
TEST_ASSERT(v == u);
v[0] = v[0] + 5;
TEST_ASSERT(v != u);
}
void testComparison()
{
printMethod(TEST_FUNC);
int a[3] = {2, -3, 2};
int b[3] = {2, -3, 1};
int c[3] = {1, -3, 1};
int d[3] = {-2, -3, 1};
IntVec<3> va(a);
IntVec<3> vb(b);
IntVec<3> vc(c);
IntVec<3> vd(d);
TEST_ASSERT(vc < va);
TEST_ASSERT(va > vc);
TEST_ASSERT(!(vc > va));
TEST_ASSERT(!(va < vc));
TEST_ASSERT(!(vc < vc));
TEST_ASSERT(!(vc > vc));
TEST_ASSERT(vc < vb);
TEST_ASSERT(vb > vc);
TEST_ASSERT(!(vc > vb));
TEST_ASSERT(!(vb < vc));
TEST_ASSERT(!(vb < vb));
TEST_ASSERT(!(vb > vb));
TEST_ASSERT(vb < va);
TEST_ASSERT(va > vb);
TEST_ASSERT(!(vb > va));
TEST_ASSERT(!(va < vb));
TEST_ASSERT(vb > vd);
TEST_ASSERT(vb >= vd);
TEST_ASSERT(!(vb < vd));
TEST_ASSERT(!(vb <= vd));
TEST_ASSERT(vb != vd);
TEST_ASSERT(vd != vb);
}
void testAssignment()
{
printMethod(TEST_FUNC);
int a[3] = { 1, -3, 2 };
IntVec<3> v(a);
IntVec<3> u = v;
TEST_ASSERT(v == u);
v[0] = v[0] + 1;
TEST_ASSERT(v != u);
}
void testAdd()
{
printMethod(TEST_FUNC);
int ua[3] = {1, 4, 2};
int va[3] = {2, 1, -2};
int ea[3] = {3, 5, 0};
IntVec<3> u(ua);
IntVec<3> v(va);
IntVec<3> e(ea);
IntVec<3> r;
r.add(u,v);
TEST_ASSERT(r == e);
TEST_ASSERT(u + v == e);
}
void testSubtract()
{
printMethod(TEST_FUNC);
int ua[3] = {1, -4, 2};
int va[3] = {3, 1, -6};
int ea[3] = {-2, -5, 8};
IntVec<3> u(ua);
IntVec<3> v(va);
IntVec<3> e(ea);
IntVec<3> r;
r.subtract(u,v);
TEST_ASSERT(r == e);
}
void testMultiply()
{
printMethod(TEST_FUNC);
int ua[3] = {1, -4, 2};
int ea[3] = {3, -12, 6};
IntVec<3> u(ua);
IntVec<3> e(ea);
IntVec<3> r;
r.multiply(u, 3);
TEST_ASSERT(r == e);
}
void testNegate()
{
printMethod(TEST_FUNC);
int ua[3] = {1, -4, 0};
IntVec<3> u(ua);
IntVec<3> r;
r.negate(u);
TEST_ASSERT(r[0] == -1);
TEST_ASSERT(r[1] == 4);
TEST_ASSERT(r[2] == 0);
TEST_ASSERT(r == u.negate());
}
void testDot()
{
printMethod(TEST_FUNC);
int a[3] = { 1, -2, 2 };
int b[3] = { 2, 3, 4 };
int d;
IntVec<3> v(a);
IntVec<3> u(b);
d = dot(u, v);
TEST_ASSERT(d == 4);
}
#if 0
void testReadWrite() {
printMethod(TEST_FUNC);
printEndl();
IntVec<3> v;
std::ifstream in;
openInputFile("in/IntVec", in);
in >> v;
std::cout.width(20);
std::cout.precision(6);
std::cout << v << std::endl ;
}
#endif
};
TEST_BEGIN(IntVecTest)
TEST_ADD(IntVecTest, testConstructor1)
TEST_ADD(IntVecTest, testConstructor2)
TEST_ADD(IntVecTest, testCopyConstructor)
TEST_ADD(IntVecTest, testEquality)
TEST_ADD(IntVecTest, testComparison)
TEST_ADD(IntVecTest, testAssignment)
TEST_ADD(IntVecTest, testAdd)
TEST_ADD(IntVecTest, testSubtract)
TEST_ADD(IntVecTest, testMultiply)
TEST_ADD(IntVecTest, testNegate)
TEST_ADD(IntVecTest, testDot)
//TEST_ADD(IntVecTest, testReadWrite)
TEST_END(IntVecTest)
#endif
| 4,472
|
C++
|
.h
| 187
| 18.213904
| 41
| 0.520828
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,128
|
MathTestComposite.h
|
dmorse_pscfpp/src/pscf/tests/math/MathTestComposite.h
|
#ifndef PSCF_TEST_MATH_TEST_COMPOSITE_H
#define PSCF_TEST_MATH_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "IntVecTest.h"
#include "RealVecTest.h"
#include "TridiagonalSolverTest.h"
#include "LuSolverTest.h"
TEST_COMPOSITE_BEGIN(MathTestComposite)
TEST_COMPOSITE_ADD_UNIT(IntVecTest);
TEST_COMPOSITE_ADD_UNIT(RealVecTest);
TEST_COMPOSITE_ADD_UNIT(TridiagonalSolverTest);
TEST_COMPOSITE_ADD_UNIT(LuSolverTest);
TEST_COMPOSITE_END
#endif
| 460
|
C++
|
.h
| 14
| 31.571429
| 47
| 0.839367
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,129
|
Clump.h
|
dmorse_pscfpp/src/pscf/homogeneous/Clump.h
|
#ifndef PSCF_HOMOGENEOUS_CLUMP_H
#define PSCF_HOMOGENEOUS_CLUMP_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/Pair.h>
#include <iostream>
namespace Pscf {
namespace Homogeneous {
using namespace Util;
/**
* Collection of all monomers of a single type in a molecule.
*
* A clump has a monomer id and a size. The size of a clump is
* the volume occupied by all monomers of the specified type in
* a particular molecular species, divided by a monomer reference
* volume.
*
* For a block copolymer, a clump is generally different than
* a block because a clump may include the monomers in two or
* more blocks of the same monomer type. Hompolymer and point
* solvent molecular species each have only one clump.
*
* \ingroup Pscf_Homogeneous_Module
*/
class Clump
{
public:
/**
* Constructor.
*/
Clump();
/**
* Serialize to/from archive.
*
* \param ar input or output Archive
* \param versionId archive format version index
*/
template <class Archive>
void serialize(Archive& ar, unsigned int versionId);
/// \name Setters
//@{
/**
* Set the monomer id.
*
* \param monomerId integer id of monomer type (>=0)
*/
void setMonomerId(int monomerId);
/**
* Set the size of this block.
*
* The ``size" is steric volume / reference volume.
*
* \param size block size (number of monomers).
*/
void setSize(double size);
//@}
/// \name Accessors (getters)
//@{
/**
* Get the monomer type id.
*/
int monomerId() const;
/**
* Get the size (number of monomers) in this block.
*/
double size() const;
//@}
private:
/// Identifier for the associated monomer type.
int monomerId_;
/// Size = volume / monomer reference volume.
double size_;
friend
std::istream& operator >> (std::istream& in, Clump &block);
friend
std::ostream& operator << (std::ostream& out, const Clump &block);
};
/**
* istream extractor for a Clump.
*
* \param in input stream
* \param block Clump to be read from stream
* \return modified input stream
*/
std::istream& operator >> (std::istream& in, Clump &block);
/**
* ostream inserter for a Clump.
*
* \param out output stream
* \param block Clump to be written to stream
* \return modified output stream
*/
std::ostream& operator << (std::ostream& out, const Clump &block);
// Inline member functions
/*
* Get the monomer type id.
*/
inline int Clump::monomerId() const
{ return monomerId_; }
/*
* Get the size (number of monomers) in this block.
*/
inline double Clump::size() const
{ return size_; }
/*
* Serialize to/from an archive.
*/
template <class Archive>
void Clump::serialize(Archive& ar, unsigned int)
{
ar & monomerId_;
ar & size_;
}
}
}
#endif
| 3,279
|
C++
|
.h
| 120
| 21.825
| 72
| 0.625524
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,130
|
Mixture.h
|
dmorse_pscfpp/src/pscf/homogeneous/Mixture.h
|
#ifndef PSCF_HOMOGENEOUS_MIXTURE_H
#define PSCF_HOMOGENEOUS_MIXTURE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <pscf/chem/Monomer.h> // Member template argument
#include <pscf/homogeneous/Molecule.h> // Member template argument
#include <util/containers/DArray.h> // Member template
#include <util/containers/DMatrix.h> // Member template
namespace Pscf {
class Interaction;
class LuSolver;
}
namespace Pscf {
namespace Homogeneous {
using namespace Util;
/**
* A spatially homogeneous mixture.
*
* \ingroup Pscf_Homogeneous_Module
*/
class Mixture : public ParamComposite
{
public:
/**
* Constructor.
*/
Mixture();
/**
* Destructor.
*/
~Mixture();
/// \name Initialization.
//@{
/**
* Read parameters from file and initialize.
*
* \param in input parameter file
*/
virtual void readParameters(std::istream& in);
/**
* Set the number of molecular species and allocate memory.
*
* \param nMolecule number of molecular species (polymer and solvent)
*/
void setNMolecule(int nMolecule);
/**
* Set the number of monomer types.
*
* \param nMonomer number of monomer types.
*/
void setNMonomer(int nMonomer);
//@}
/// \name Thermodynamics Computations
//@{
/**
* Set system composition.
*
* \param phi array of molecular volume fractions.
*/
void setComposition(DArray<double> const & phi);
/**
* Compute chemical potential from preset composition.
*
* Precondition: setComposition must be called prior.
* Postcondition: Upon return, mu array is set.
*
* \param interaction excess free energy model (input)
* \param xi Lagrange multiplier field (input)
*/
void computeMu(Interaction const & interaction, double xi = 0.0);
/**
* Compute composition from chemical potentials.
*
* \param interaction excess free energy model (input)
* \param mu target molecular chemical potentials (input)
* \param phi guess of molecular volume fractions (input)
* \param xi Lagrange multiplier field (input/output)
*/
void computePhi(Interaction const & interaction,
DArray<double> const & mu,
DArray<double> const & phi,
double& xi);
/**
* Compute Helmholtz free energy and pressure.
*
* Preconditions and postconditions:
*
* \pre setComposition must be called prior.
* \pre computeMu must be called prior.
* \post fHelmholtz and pressure are set.
*
* \param interaction excess free energy model (input)
*/
void computeFreeEnergy(Interaction const & interaction);
//@}
/// \name Accessors
//@{
/**
* Get a molecule object (non-const reference).
*
* \param id integer molecule species index (0 <= id < nMolecule)
*/
Molecule& molecule(int id);
/**
* Return chemical potential for one species.
*
* \param id integer molecule species index (0 <= id < nMolecule)
*/
double mu(int id) const;
/**
* Return molecular volume fraction for one species.
*
* \param id integer molecule species index (0 <= id < nMolecule)
*/
double phi(int id) const;
/**
* Return monomer volume fraction for one monomer type.
*
* \param id monomer type index (0 <= id < nMonomer)
*/
double c(int id) const;
/**
* Return Helmholtz free energy per monomer / kT.
*/
double fHelmholtz() const;
/**
* Return pressure in units of kT / monomer volume.
*/
double pressure() const;
/**
* Get number of molecule species (polymer + solvent).
*/
int nMolecule() const;
/**
* Get number of monomer types.
*/
int nMonomer() const;
//@}
/**
* Validate all data structures.
*
* Throw an exception if an error is found.
*/
void validate() const;
private:
/**
* Array of molecule species solver objects.
*
* Array capacity = nMolecule.
*/
DArray<Molecule> molecules_;
/**
* Array of molecular chemical potentials.
*/
DArray<double> mu_;
/**
* Array of molecular volume fractions.
*/
DArray<double> phi_;
/**
* Array of monomer volume fractions.
*/
DArray<double> c_;
/**
* Array of monomer excess chemical potentials.
*/
DArray<double> w_;
/**
* Residual array for used by computePhi function.
*/
DArray<double> residual_;
/**
* Change in input variables (phi, xi)
*/
DArray<double> dX_;
/**
* Derivatives of W with respect to monomer fractions.
*/
DMatrix<double> dWdC_;
/**
* Derivatives of W with respect to molecule fractions.
*/
DMatrix<double> dWdPhi_;
/**
* Jacobian matrix for use by computePhi function.
*/
DMatrix<double> jacobian_;
/**
* Array of old molecular volume fractions, for use in computePhi.
*/
DArray<double> phiOld_;
/**
* Free energy per monomer / kT.
*/
double fHelmholtz_;
/**
* Pressure x monomer volume / kT.
*/
double pressure_;
/**
* Pointer to LUSolver.
*/
LuSolver* solverPtr_;
/**
* Number of molecule species (polymers and solvent).
*/
int nMolecule_;
/**
* Number of monomer types (maximum monomer id + 1).
*/
int nMonomer_;
/**
* Initialized false, set true by setComposition().
*/
bool hasComposition_;
/**
* Compute monomer concentrations from phi_.
*/
void computeC();
/**
* Adjust xi to minimize mean-squared residual.
*/
void adjustXi(DArray<double> const & mu, double& xi);
/**
* Compute residual array and return max error.
*/
void computeResidual(DArray<double> const & mu,
double& error);
};
// Inline member functions
inline Molecule& Mixture::molecule(int id)
{
UTIL_ASSERT(id >= 0);
UTIL_ASSERT(id < nMolecule_);
return molecules_[id];
}
inline double Mixture::mu(int id) const
{
UTIL_ASSERT(id >= 0);
UTIL_ASSERT(id < nMolecule_);
return mu_[id];
}
inline double Mixture::phi(int id) const
{
UTIL_ASSERT(id >= 0);
UTIL_ASSERT(id < nMolecule_);
return phi_[id];
}
inline double Mixture::c(int id) const
{
UTIL_ASSERT(id >= 0);
UTIL_ASSERT(id < nMonomer_);
return c_[id];
}
inline double Mixture::fHelmholtz() const
{ return fHelmholtz_; }
inline double Mixture::pressure() const
{ return pressure_; }
inline int Mixture::nMolecule() const
{ return nMolecule_; }
inline int Mixture::nMonomer() const
{ return nMonomer_; }
} // namespace Homogeneous
} // namespace Pscf
#endif
| 7,575
|
C++
|
.h
| 270
| 21.233333
| 74
| 0.588918
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,131
|
Molecule.h
|
dmorse_pscfpp/src/pscf/homogeneous/Molecule.h
|
#ifndef PSCF_HOMOGENEOUS_MOLECULE_H
#define PSCF_HOMOGENEOUS_MOLECULE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <pscf/homogeneous/Clump.h> // member template argument
#include <util/containers/Pair.h> // member template
#include <util/containers/DArray.h> // member template
#include <cmath>
namespace Pscf {
namespace Homogeneous {
using namespace Util;
/**
* Descriptor of a molecular species in a homogeneous mixture.
*
* A Homogeneous::Molecule has:
*
* - An array of Homogeneous::Clump objects
* - An overall size (volume/monomer volume)
*
* Each Clump has a monomer type id and a size. The size is the
* total volume of monomers of that type in a molecule of this
* species.
*
* \ingroup Pscf_Homogeneous_Module
*/
class Molecule : public Util::ParamComposite
{
public:
/**
* Constructor.
*/
Molecule();
/**
* Destructor.
*/
~Molecule();
/**
* Read and initialize.
*
* Call either this or setNClump to initialize, not both.
*
* \param in input parameter stream
*/
virtual void readParameters(std::istream& in);
/**
* Set the number of clumps, and allocate memory.
*
* Call either this or readParameters to initialize, not both.
* If this is used to allocate memory, all clump properties
* must be set using Clump::setMonomerId() and Clump::setSize().
*/
void setNClump(int nClump);
/**
* Compute total molecule size by adding clump sizes.
*/
void computeSize();
/// \name Accessors
//@{
/**
* Get a specified Clump.
*
* \param id clump index, 0 <= id < nClump
*/
Clump& clump(int id);
/**
* Get a specified Clump.
*
* \param id clump index, 0 <= id < nClump
*/
Clump const & clump(int id) const;
/**
* Number of monomer clumps (monomer types).
*/
int nClump() const;
/**
* Total molecule size = volume / reference volume.
*/
double size() const;
//@}
private:
/// Array of Clump objects in this polymer.
DArray<Clump> clumps_;
/// Number of clumps in this polymer
int nClump_;
/// Total size of all clumps (in units of reference size).
double size_;
/// Flag set when computeSize is called.
bool hasSize_;
};
}
/*
* Number of clumps.
*/
inline int Homogeneous::Molecule::nClump() const
{ return nClump_; }
/*
* Total size of all clumps = volume / reference volume
*/
inline double Homogeneous::Molecule::size() const
{
UTIL_CHECK(hasSize_);
return size_;
}
/*
* Get a specified Clump (non-constant reference)
*/
inline Homogeneous::Clump& Homogeneous::Molecule::clump(int id)
{ return clumps_[id]; }
/*
* Get a specified Clump (constant reference)
*/
inline const Homogeneous::Clump& Homogeneous::Molecule::clump(int id) const
{ return clumps_[id]; }
}
#endif
| 3,628
|
C++
|
.h
| 120
| 22.333333
| 78
| 0.579456
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,132
|
Interaction.h
|
dmorse_pscfpp/src/pscf/inter/Interaction.h
|
#ifndef PSCF_INTERACTION_H
#define PSCF_INTERACTION_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <util/containers/Array.h> // argument (template)
#include <util/containers/Matrix.h> // argument (template)
#include <util/global.h>
namespace Pscf {
using namespace Util;
/**
* Flory-Huggins excess free energy model.
*
* \ingroup Pscf_Inter_Module
*/
class Interaction : public ParamComposite
{
public:
/**
* Constructor.
*/
Interaction();
/**
* Destructor.
*/
virtual ~Interaction();
/**
* Set the number of monomer types.
*
* \param nMonomer number of monomer types.
*/
void setNMonomer(int nMonomer);
/**
* Read chi parameters.
*
* Must be called after setNMonomer.
*/
virtual void readParameters(std::istream& in);
/**
* Change one element of the chi matrix.
*
* \param i row index
* \param j column index
* \param chi input value of chi
*/
void setChi(int i, int j, double chi);
/**
* Compute excess Helmholtz free energy per monomer.
*
* \param c array of concentrations, for each type (input)
*/
virtual
double fHelmholtz(Array<double> const & c) const;
/**
* Compute chemical potential from concentration.
*
* \param c array of concentrations, for each type (input)
* \param w array of chemical potentials for types (ouptut)
*/
virtual
void computeW(Array<double> const & c, Array<double>& w)
const;
/**
* Compute concentration from chemical potential fields.
*
* \param w array of chemical potentials for types (inut)
* \param c array of vol. fractions, for each type (output)
* \param xi Langrange multiplier pressure (output)
*/
virtual
void computeC(Array<double> const & w, Array<double>& c, double& xi)
const;
/**
* Compute Langrange multiplier xi from chemical potential fields.
*
* \param w array of chemical potentials for types (inut)
* \param xi Langrange multiplier pressure (output)
*/
virtual
void computeXi(Array<double> const & w, double& xi)
const;
/**
* Compute second derivatives of free energy.
*
* Upon return, the elements of the square matrix dWdC, are
* given by derivatives dWdC(i,j) = dW(i)/dC(j), which are
* also second derivatives of the interaction free energy.
* For this Flory-Huggins chi parameter model, this is simply
* given by the chi matrix dWdC(i,j) = chi(i, j).
*
* \param c array of concentrations, for each type (input)
* \param dWdC matrix of derivatives (output)
*/
virtual
void computeDwDc(Array<double> const & c, Matrix<double>& dWdC)
const;
/**
* Return one element of the chi matrix.
*
* \param i row index
* \param j column index
*/
double chi(int i, int j) const;
/**
* Return one element of the inverse chi matrix.
*
* \param i row index
* \param j column index
*/
double chiInverse(int i, int j) const;
/**
* Get number of monomer types.
*/
int nMonomer() const;
private:
// Symmetric matrix of interaction parameters.
DMatrix<double> chi_;
// Inverse of matrix chi_.
DMatrix<double> chiInverse_;
/// Number of monomers
int nMonomer_;
/**
* Compute the inverse of the chi matrix.
* Must be called after making any changes to the chi matrix.
*/
void updateMembers();
};
// Inline function
inline int Interaction::nMonomer() const
{ return nMonomer_; }
inline double Interaction::chi(int i, int j) const
{ return chi_(i, j); }
inline double Interaction::chiInverse(int i, int j) const
{ return chiInverse_(i, j); }
} // namespace Pscf
#endif
| 4,283
|
C++
|
.h
| 140
| 24.192857
| 74
| 0.616582
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,133
|
FieldComparison.h
|
dmorse_pscfpp/src/pscf/math/FieldComparison.h
|
#ifndef PSCF_FIELD_COMPARISON_H
#define PSCF_FIELD_COMPARISON_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/DArray.h>
namespace Pscf {
using namespace Util;
/**
* Comparison of element-by-element differences between field arrays.
*
* The template argument FT may be RField<D> for representations of a
* field or fields on an r-grid or DArray<double> for representation
* using a symmetry-adapted basis.
*
* \ingroup Pscf_Math_Module
*/
template <class FT>
class FieldComparison {
public:
/**
* Default constructor.
*
* Initializes maxDiff and rmsDiff to zero.
*
* \param begin first element of array/field to compare.
*/
FieldComparison(int begin = 0);
// Use compiler defined destructor and assignment operator.
/**
* Compare individual fields.
*
* Array dimensions must agree. An Exception is thrown if the
* capacities of fields a and b are not equal.
*
* \param a 1st field
* \param b 2nd field
* \return maximum element-by-element difference (maxDiff)
*/
double compare(FT const& a, FT const& b);
/**
* Compare arrays of fields associated with different monomer types.
*
* All array dimensions must agree.
*
* An exception is thrown if the capacities of the enclosing
* DArrays (the number of monomers) are not equal or if the
* capacities of any pair of individual fields (number of grid
* points or basis functions) are not equal.
*
* \param a 1st DArray of field
* \param b 2nd DArray of field
* \return maximum element-by-element difference (maxDiff)
*/
double compare(DArray<FT> const& a, DArray<FT> const& b);
/**
* Return the precomputed maximum element-by-element difference.
*
* This function returns the maximum difference between corresponding
* field array elements found by the most recent comparison.
*/
double maxDiff() const
{ return maxDiff_; }
/**
* Return the precomputed root-mean-squared difference.
*
* This function returns the root-mean-squared difference between
* corresponding elements found by the most recent comparison.
*/
double rmsDiff() const
{ return rmsDiff_; }
protected:
// Maximum element-by-element difference.
double maxDiff_;
// Room-mean-squared element-by-element difference.
double rmsDiff_;
// Index of first element (0 or 1)
int begin_;
};
} // namespace Pscf
#include "FieldComparison.tpp"
#endif
| 2,855
|
C++
|
.h
| 85
| 27.588235
| 74
| 0.665086
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,134
|
Field.h
|
dmorse_pscfpp/src/pscf/math/Field.h
|
#ifndef PSCF_FIELD_H
#define PSCF_FIELD_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/DArray.h>
namespace Pscf {
using namespace Util;
/**
* Base class template for a field defined on a spatial grid.
*
* Derived from DArray<T>, and provides useful arithmetic operations.
*
* \ingroup Pscf_Math_Module
*/
template <typename T = double>
class Field : public DArray<T>
{
public:
/**
* Constructor.
*/
Field();
/**
* Copy constructor.
*/
Field(Field<T> const & other);
/**
* Assignment operator.
*/
Field<T>& operator = (Field<T> const & other);
/**
* Assignment - assign all elements to a common scalar.
*/
Field<T>& operator = (T& scalar);
/**
* Increment operator - add one field by another.
*/
Field<T>& operator += (Field<T>& other);
/**
* Decrement operator - subtract one field from another.
*/
Field<T>& operator -= (Field<T>& other);
/**
* Multiplication operator - multiply one field by a scalar.
*/
Field<T>& operator *= (T scalar);
/**
* Pointwise multipication of one field by another.
*/
Field<T>& operator *= (Field<T>& other);
/**
* Set all elements to zero.
*/
void setToZero();
/**
* Compute and return average of all elements.
*/
T average() const;
using Array<T>::operator [];
using Array<T>::capacity;
using DArray<T>::allocate;
using DArray<T>::deallocate;
using DArray<T>::isAllocated;
protected:
using Array<T>::capacity_;
using Array<T>::data_;
};
/*
* Copy constructor.
*
* Allocates new memory and copies all elements by value.
*
*\param other the Field to be copied.
*/
template <class T>
Field<T>::Field(Field<T> const & other)
: DArray<T>()
{
if (!other.isAllocated()) {
UTIL_THROW("Other Field not allocated.");
}
Memory::allocate(data_, other.capacity_);
capacity_ = other.capacity_;
for (int i = 0; i < capacity_; ++i) {
data_[i] = other.data_[i];
}
}
/*
* Assignment from another Field, element-by-element.
*
* This operator will allocate memory if not allocated previously.
*
* \throw Exception if other Field is not allocated.
* \throw Exception if both Fields are allocated with unequal capacities.
*
* \param other the rhs Field
*/
template <class T>
Field<T>& Field<T>::operator = (Field<T> const & other)
{
// Check for self assignment
if (this == &other) return *this;
// Precondition
if (!other.isAllocated()) {
UTIL_THROW("Other Field not allocated.");
}
if (!isAllocated()) {
allocate(other.capacity());
} else if (capacity_ != other.capacity_) {
UTIL_THROW("Fields of unequal capacity");
}
// Copy elements
for (int i = 0; i < capacity_; ++i) {
data_[i] = other[i];
}
return *this;
}
/*
* Assignment - assign all elements to a common scalar.
*/
template <typename T>
Field<T>& Field<T>::operator = (T& scalar)
{
if (!isAllocated()) {
UTIL_THROW("Field not allocated.");
}
for (int i = 0; i < capacity_; ++i) {
data_[i] = scalar;
}
return *this;
}
/*
* Increment& Field<T>::operator, add one field by another.
*/
template <typename T>
Field<T>& Field<T>::operator += (Field<T>& other)
{
if (!other.isAllocated()) {
UTIL_THROW("Other Field no allocated.");
}
if (!isAllocated()) {
UTIL_THROW("This Field not allocated.");
}
if (capacity_ != other.capacity_) {
UTIL_THROW("Fields of unequal capacity");
}
for (int i = 0; i < capacity_; ++i) {
data_[i] += other.data_[i];
}
return *this;
}
/*
* Decrement& Field<T>::operator, subtract one field from another.
*/
template <typename T>
Field<T>& Field<T>::operator -= (Field<T>& other)
{
// Preconditions
if (!other.isAllocated()) {
UTIL_THROW("Other Field not allocated.");
}
if (!isAllocated()) {
UTIL_THROW("This Field not allocated.");
}
if (capacity_ != other.capacity_) {
UTIL_THROW("Fields of unequal capacity");
}
for (int i = 0; i < capacity_; ++i) {
data_[i] -= other.data_[i];
}
return *this;
}
/*
* Multiplication& Field<T>::operator - multiply one field by a scalar.
*/
template <typename T>
Field<T>& Field<T>::operator *= (T scalar)
{
// Precondition
if (!isAllocated()) {
UTIL_THROW("Field not allocated.");
}
for (int i = 0; i < capacity_; ++i) {
data_[i] *= scalar;
}
return *this;
}
/*
* Pointwise multipication of field& Field<T>::operator.
*/
template <typename T>
Field<T>& Field<T>::operator *= (Field<T>& other)
{
// Preconditions
if (!other.isAllocated()) {
UTIL_THROW("Other Field not allocated.");
}
if (!isAllocated()) {
UTIL_THROW("This Field not allocated.");
}
if (capacity_ != other.capacity_) {
UTIL_THROW("Unequal capacity");
}
for (int i = 0; i < capacity_; ++i) {
data_[i] *= other.data_[i];
}
return *this;
}
/*
* Set to zero.
*/
template <typename T>
void Field<T>::setToZero()
{
for (int i = 0; i < capacity_; ++i) {
data_[i] *= 0.0;
}
}
/*
* Compute and return average of all elements.
*/
template <typename T>
T Field<T>::average() const
{
double value = 0.0;
for (int i = 0; i < capacity_; ++i) {
value += data_[i];
}
return value/T(capacity_);
}
}
#endif
| 6,176
|
C++
|
.h
| 236
| 19.983051
| 75
| 0.557296
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,135
|
IntVec.h
|
dmorse_pscfpp/src/pscf/math/IntVec.h
|
#ifndef PSCF_INT_VEC_H
#define PSCF_INT_VEC_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Vec.h"
#include <iostream>
#include <util/global.h>
namespace Pscf
{
/**
* An IntVec<D, T> is a D-component vector of elements of integer type T.
*
* Default of type T is T = int.
*
* \ingroup Pscf_Math_Module
*/
template <int D, typename T = int>
class IntVec : public Vec<D, T>
{
public:
/// \name Constructors
//@{
/**
* Default constructor
*/
IntVec<D, T>()
: Vec<D, T>()
{}
/**
* Copy constructor
*
* \param v IntVec<D, T> to be copied
*/
IntVec<D, T>(const IntVec<D, T>& v)
: Vec<D, T>(v)
{}
/**
* Construct from C array.
*
* \param v C array to be copied
*/
IntVec<D, T>(T const * v)
: Vec<D, T>(v)
{}
/**
* Constructor, initialize all elements to a scalar value.
*
* \param s scalar initial value for all elements.
*/
explicit IntVec<D, T>(T s)
: Vec<D, T>(s)
{}
/// Width of field per Cartesian coordinate in stream IO
static const int Width = 10;
};
// Friend functions and operators
/**
* istream extractor for a IntVec<D, T>.
*
* Input elements of a vector from stream, without line breaks.
*
* \param in input stream
* \param vector IntVec<D, T> to be read from stream
* \return modified input stream
*/
template <int D, typename T>
std::istream& operator >> (std::istream& in, IntVec<D, T> &vector)
{
for (int i = 0; i < D; ++i) {
in >> vector[i];
}
return in;
}
/**
* ostream inserter for a IntVec<D, T>.
*
* Output a IntVec<D, T> to an ostream, without line breaks.
*
* Output elements of a vector to stream, without line breaks.
* \param out output stream
* \param vector IntVec<D, T> to be written to stream
* \return modified output stream
*/
template <int D, typename T>
std::ostream& operator << (std::ostream& out, const IntVec<D, T> &vector)
{
for (int i = 0; i < D; ++i) {
out.width(IntVec<D, T>::Width);
out << vector[i];
}
return out;
}
/**
* Equality of two IntVec<D> objects.
*
* \return true if v1 == v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator == (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{
for (int i = 0; i < D; ++i) {
if (v1[i] != v2[i]) {
return false;
}
}
return true;
}
/**
* Equality of an IntVec<D> and a Vec<D, T>
*
* \return true if v1 == v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator == (const IntVec<D, T>& v1, const Vec<D, T>& v2)
{
for (int i = 0; i < D; ++i) {
if (v1[i] != v2[i]) {
return false;
}
}
return true;
}
/**
* Equality of an Vec<D, T> and an IntVec<D, T>
*
* \return true if v1 == v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator == (const Vec<D, T>& v1, const IntVec<D, T>& v2)
{ return (v2 == v1); }
/**
* Inequality of two IntVec<D, T> objects.
*
* \return true if v1 != v2, false if v1 == v2.
*/
template <int D, typename T>
inline
bool operator != (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{ return !(v1 == v2); }
/**
* Inequality of an IntVec<D> and a Vec<D, T>
*
* \return true if v1 == v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator != (const IntVec<D, T>& v1, const Vec<D, T>& v2)
{ return !(v1 == v2); }
/**
* Inequality of a Vec<D, T> and an IntVec<D, T>
*
* \return true if v1 == v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator != (const Vec<D, T>& v1, const IntVec<D, T>& v2)
{ return !(v2 == v1); }
/**
* Less than comparison for two IntVec<D, T>s.
*
* Elements with lower array indices are treated as more signficant.
*
* \return true if v1 < v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator < (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{
for (int i = 0; i < D; ++i) {
if (v1[i] > v2[i]) {
return false;
} else
if (v1[i] < v2[i]) {
return true;
}
// This point is reached iff v1[i] == v2[i]
}
// If loop completes, the vectors are equal
return false;
}
/**
* Less than or equal to comparison for two IntVec<D, T>s.
*
* Elements with lower array indices are more signficant digits.
*
* \return true if v1 < v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator <= (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{
for (int i = 0; i < D; ++i) {
if (v1[i] > v2[i]) {
return false;
} else
if (v1[i] < v2[i]) {
return true;
}
// This point is reached iff v1[i] == v2[i]
}
// If loop completes, the vectors are equal
return true;
}
/**
* Greater than comparison for two IntVec<D, T>s.
*
* \return true if v1 > v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator > (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{ return !(v1 <= v2); }
/**
* Greater than or equal to comparison for two IntVec<D, T>s.
*
* \return true if v1 >= v2, false otherwise.
*/
template <int D, typename T>
inline
bool operator >= (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
{ return !(v1 < v2); }
}
#endif
| 5,925
|
C++
|
.h
| 230
| 20.434783
| 76
| 0.552478
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,136
|
RealVec.h
|
dmorse_pscfpp/src/pscf/math/RealVec.h
|
#ifndef PSCF_REAL_VEC_H
#define PSCF_REAL_VEC_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Vec.h"
#include <iostream>
#include <util/global.h>
namespace Pscf
{
/**
* A RealVec<D, T> is D-component vector with elements of floating type T.
*
* Default of type T is T = double.
*
* \ingroup Pscf_Math_Module
*/
template <int D, typename T = double>
class RealVec : public Vec<D, T>
{
public:
/// \name Constructors
//@{
/**
* Default constructor
*/
RealVec<D, T>()
: Vec<D, T>()
{}
/**
* Copy constructor
*
* \param v RealVec<D, T> to be copied
*/
RealVec<D, T>(const RealVec<D, T>& v)
: Vec<D, T>(v)
{}
/**
* Construct from C array.
*
* \param v C array to be copied
*/
RealVec<D, T>(T const * v)
: Vec<D, T>(v)
{}
/**
* Constructor, initialize all elements to a scalar value.
*
* \param s scalar initial value for all elements.
*/
explicit RealVec<D, T>(T s)
: Vec<D, T>(s)
{}
/// Width of field per Cartesian coordinate in stream IO
static const int Width = 25;
/// Precision in stream IO of RealVec<D, T> coordinates
static const int Precision = 17;
};
// Friend functions and operators
/**
* istream extractor for a RealVec<D, T>.
*
* Input elements of a vector from stream, without line breaks.
*
* \param in input stream
* \param vector RealVec<D, T> to be read from stream
* \return modified input stream
*/
template <int D, typename T>
std::istream& operator >> (std::istream& in, RealVec<D, T> &vector)
{
for (int i = 0; i < D; ++i) {
in >> vector[i];
}
return in;
}
/**
* ostream inserter for a RealVec<D, T>.
*
* Output a RealVec<D, T> to an ostream, without line breaks.
*
* Output elements of a vector to stream, without line breaks.
* \param out output stream
* \param vector RealVec<D, T> to be written to stream
* \return modified output stream
*/
template <int D, typename T>
std::ostream& operator << (std::ostream& out, const RealVec<D, T> &vector)
{
for (int i = 0; i < D; ++i) {
out.setf(std::ios::scientific);
out.width(RealVec<D>::Width);
out.precision(RealVec<D>::Precision);
out << vector[i];
}
return out;
}
// Equality operators
#define PSCF_REALVEC_EPSILON 1.0E-8
template <int D, typename T>
bool operator==(const RealVec<D, T>& v1, const RealVec<D, T>& v2)
{
for (int i = 0; i < D; ++i) {
if ( fabs(v1[i] - v2[i]) > PSCF_REALVEC_EPSILON) {
return false;
}
}
return true;
}
#undef PSCF_REALVEC_EPSILON
template <int D, typename T>
bool operator!=(const RealVec<D, T>& v1, const RealVec<D, T>& v2)
{ return !(v1 == v2); }
}
#endif
| 3,154
|
C++
|
.h
| 118
| 21.177966
| 77
| 0.581279
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,137
|
Vec.h
|
dmorse_pscfpp/src/pscf/math/Vec.h
|
#ifndef PSCF_VEC_H
#define PSCF_VEC_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/global.h>
#include <util/accumulators/setToZero.h>
#include <iostream>
using namespace Util;
namespace Pscf
{
/**
* A Vec<D, T><D,T> is a D-component vector with elements of type T.
*
* The elements of a Vec<D, T> can be accessed using subscript operator,
* as for a built in array.
*
* The arithmetic assignment operators +=, -=, and *= are overloaded
* to allow vector-vector addition and subtraction and vector-scalar
* multiplication.
*
* All other unary and binary mathematical operations are implemented
* as methods or free functions. Operations that yield a Vec<D, T>, such
* as addition, are implemented by methods that assign the result to the
* invoking Vec object, and return this object by reference. For example,
* \code
*
* Vec<3, double> a, b, c;
*
* a[0] = 0.0
* a[1] = 1.0
* a[2] = 2.0
*
* b[0] = 0.5
* b[1] = -0.5
* b[2] = -1.5
*
* // Set a = a + b
* a += b
*
* // Set b = b*2
* b *= 2.0;
*
* // Set c = a + b
* c.add(a, b);
*
* \endcode
* This syntax for functions that yield a vector makes the allocation of
* a temporary Vec<D, T> object explicit, by requiring that the invoking
* function be a member of an object that will hold the result.
*
* For efficiency, all member functions are declared inline.
*
* \ingroup Pscf_Math_Module
*/
template <int D, typename T>
class Vec
{
public:
/// \name Constructors
//@{
/**
* Default constructor
*/
Vec<D, T>();
/**
* Copy constructor
*
* \param v Vec<D, T> to be copied
*/
Vec<D, T>(const Vec<D, T>& v);
/**
* Constructor from a C-array.
*
* \param v array to be copied
*/
explicit Vec<D, T>(T const * v);
/**
* Constructor, initialize all elements to a common scalar value.
*
* \param s initial value for all elements.
*/
explicit Vec<D, T>(T s);
//@}
/// \name Assignment and Initialization
//@{
/**
* Copy assignment.
*
* \param v Vec<D, T> to assign.
* \return this object, after modification
*/
Vec<D, T>& operator = (const Vec<D, T>& v);
/**
* Assignment all elements to the same scalar T value.
*
* \param s scalar value
* \return this object, after modification
*/
Vec<D, T>& operator = (T s);
/**
* Set all elements to zero.
*
* \return this object, after modification
*/
Vec<D, T>& setToZero();
//@}
/// \name Arithmetic Assignment
//@{
/**
* Add vector dv to this vector.
*
* Upon return, *this = this + dv.
*
* \param dv vector increment (input)
*/
void operator += (const Vec<D, T>& dv);
/**
* Subtract vector dv from this vector.
*
* Upon return, *this = this + dv.
*
* \param dv vector increment (input)
*/
void operator -= (const Vec<D, T>& dv);
/**
* Add a common scalar to all components.
*
* \param s scalar additive constant (input)
*/
void operator += (T s);
/**
* Subtract a common scalar from all components.
*
* \param s scalar subtractive constant (input)
*/
void operator -= (T s);
/**
* Multiply this vector by scalar s.
*
* Upon return, *this = (*this)*s.
*
* \param s scalar multiplier
*/
void operator *= (T s);
//@}
/// \name Array Subscript
//@{
/**
* Return one Cartesian element by value.
*
* \param i element index
* \return element i of the vector
*/
const T& operator [] (int i) const;
/**
* Return one element of the vector by references.
*
* \param i element index
* \return element i of this vector
*/
T& operator [] (int i);
//@}
/// \name Vec<D, T> valued functions (assigned to invoking object)
//@{
/**
* Add vectors v1 and v2.
*
* Upon return, *this = v1 + v2.
*
* \param v1 vector (input)
* \param v2 vector (input)
* \return modified invoking vector
*/
Vec<D, T>& add(const Vec<D, T>& v1, const Vec<D, T>& v2);
/**
* Subtract vector v2 from v1.
*
* Upon return, *this = v1 - v2.
*
* \param v1 vector (input)
* \param v2 vector (input)
* \return modified invoking vector
*/
Vec<D, T>& subtract(const Vec<D, T>& v1, const Vec<D, T>& v2);
/**
* Multiply a vector v by a scalar s.
*
* Upon return, *this = v*s.
*
* \param v vector input
* \param s scalar input
* \return modified invoking vector
*/
Vec<D, T>& multiply(const Vec<D, T>& v, T s);
/**
* Return negative of vector v.
*
* Upon return, *this = -v;
*
* \param v vector input
* \return modified invoking vector
*/
Vec<D, T>& negate(const Vec<D, T>& v);
/**
* Negate all elements of this vector.
*
* Upon return, all elements of this have been negated (reversed)
*
* \return this object, after modification
*/
Vec<D, T>& negate();
//@}
/**
* Serialize to/from an archive.
*
* Implementation uses syntax of Boost::serialize.
*
* \param ar archive
* \param version archive version id
*/
template <class Archive>
void serialize(Archive& ar, const unsigned int version);
private:
/// Width of field per Cartesian coordinate in stream IO
static const int Width = 25;
/// Precision in stream IO of Vec<D, T> coordinates
static const int Precision = 17;
/// Elements of the vector.
T elem_[D];
};
// Associated functions
/**
* Return dot product of two vectors.
*
* \param v1 first input vector
* \param v2 second input vector
* \return dot product v1.v2
*/
template <int D, typename T>
inline
T dot(Vec<D, T> const & v1, Vec<D, T> const & v2)
{
T value;
setToZero(value);
for (int i = 0; i < D; ++i) {
value += v1[i]*v2[i];
}
return value;
}
/**
* Return the sum of two vectors.
*
* \param v1 first input vector
* \param v2 second input vector
* \return sum v1 + v2
*/
template <int D, typename T>
inline
Vec<D, T> operator + (Vec<D, T> const & v1, Vec<D, T> const & v2)
{
Vec<D, T> value;
value.add(v1, v2);
return value;
}
// Inline method definitions
/*
* Default constructor
*/
template <int D, typename T>
inline Vec<D, T>::Vec()
{}
/*
* Copy constructor
*/
template <int D, typename T>
inline Vec<D, T>::Vec(const Vec<D, T>& v)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v.elem_[i];
}
}
/*
* Constructor, from C-Array.
*/
template <int D, typename T>
inline Vec<D, T>::Vec(T const * v)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v[i];
}
}
/*
* Constructor, initialize all elements to a scalar value s.
*/
template <int D, typename T>
inline Vec<D, T>::Vec(T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] = s;
}
}
/*
* Assignment.
*/
template <int D, typename T>
inline Vec<D, T>& Vec<D, T>::operator = (const Vec<D, T>& v)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v.elem_[i];
}
return *this;
}
/*
* Assign all elements to a common scalar value.
*/
template <int D, typename T>
inline Vec<D, T>& Vec<D, T>::operator = (T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] = s;
}
return *this;
}
/*
* Set all elements of a 3D vector to zero.
*/
template <int D, typename T>
inline Vec<D, T>& Vec<D, T>::setToZero()
{
for (int i = 0; i < D; ++i) {
setToZero(elem_[i]);
}
return *this;
}
/*
* Add vector dv to this vector.
*/
template <int D, typename T>
inline void Vec<D, T>::operator += (const Vec<D, T>& dv)
{
for (int i = 0; i < D; ++i) {
elem_[i] += dv.elem_[i];
}
}
/*
* Subtract vector dv from this vector.
*/
template <int D, typename T>
inline void Vec<D, T>::operator -= (const Vec<D, T>& dv)
{
for (int i = 0; i < D; ++i) {
elem_[i] -= dv.elem_[i];
}
}
/*
* Add a common scalar to all components.
*/
template <int D, typename T>
inline void Vec<D, T>::operator += (T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] += s;
}
}
/*
* Subtract a common scalar from all components.
*/
template <int D, typename T>
inline void Vec<D, T>::operator -= (T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] -= s;
}
}
/*
* Multiply this vector by scalar s.
*/
template <int D, typename T>
inline void Vec<D, T>::operator *= (T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] *= s;
}
}
/*
* Return one Cartesian element by value.
*/
template <int D, typename T>
inline const T& Vec<D, T>::operator [] (int i) const
{
assert(i >=0);
assert(i < D);
return elem_[i];
}
/*
* Return a reference to one element of the vector.
*/
template <int D, typename T>
inline T& Vec<D, T>::operator [] (int i)
{
assert(i >=0);
assert(i < D);
return elem_[i];
}
/*
* Add vectors v1 and v2.
*
* Upon return, *this = v1 + v2.
*/
template <int D, typename T>
inline
Vec<D, T>& Vec<D, T>::add(Vec<D, T> const & v1,
Vec<D, T> const & v2)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v1.elem_[i] + v2.elem_[i];
}
return *this;
}
/*
* Subtract vector v2 from v1.
*
* Upon return, *this = v1 - v2.
* \return modified invoking vector
*/
template <int D, typename T>
inline
Vec<D, T>& Vec<D, T>::subtract(Vec<D, T> const & v1, Vec<D, T> const & v2)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v1.elem_[i] - v2.elem_[i];
}
return *this;
}
/*
* Multiply a vector v by a scalar s.
*
* Upon return, *this = v*s.
*/
template <int D, typename T>
inline
Vec<D, T>& Vec<D, T>::multiply(Vec<D, T> const & v, T s)
{
for (int i = 0; i < D; ++i) {
elem_[i] = v.elem_[i]*s;
}
return *this;
}
/*
* Compute and return negation of a vector.
*
* Upon return, *this = -v.
*/
template <int D, typename T>
inline
Vec<D, T>& Vec<D, T>::negate(Vec<D, T> const & v)
{
for (int i = 0; i < D; ++i) {
elem_[i] = -v.elem_[i];
}
return *this;
}
/*
* Negate (reverse sign) of this vector.
*
* Upon return, *this = -v.
*/
template <int D, typename T>
inline
Vec<D, T>& Vec<D, T>::negate()
{
for (int i = 0; i < D; ++i) {
elem_[i] = -elem_[i];
}
return *this;
}
/*
* Serialize to/from an archive.
*/
template <int D, typename T>
template <class Archive>
inline
void Vec<D, T>::serialize(Archive& ar, const unsigned int version)
{
for (int i = 0; i < D; ++i) {
ar & elem_[i];
}
}
}
#endif
| 11,910
|
C++
|
.h
| 494
| 18.364372
| 77
| 0.522769
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,138
|
TridiagonalSolver.h
|
dmorse_pscfpp/src/pscf/math/TridiagonalSolver.h
|
#ifndef PSCF_TRIDIAGONAL_SOLVER_H
#define PSCF_TRIDIAGONAL_SOLVER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/DArray.h>
#include <string>
#include <iostream>
namespace Pscf
{
using namespace Util;
/**
* Solver for Ax=b with tridiagonal matrix A.
*
* \ingroup Pscf_Math_Module
*/
class TridiagonalSolver
{
public:
/**
* Constructor.
*/
TridiagonalSolver();
/**
* Destructor.
*/
~TridiagonalSolver();
/**
* Allocate memory.
*
* \param n dimension of n x n square array.
*/
void allocate(int n);
/**
* Compute LU decomposition of a symmetric tridiagonal matrix.
*
* \param d diagonal elements of n x n matrix matrix (0,..,n-1)
* \param u upper off-diagonal elements (0,..,n-2)
*/
void computeLU(const DArray<double>& d, const DArray<double>& u);
/**
* Compute LU decomposition of a general tridiagonal matrix.
*
* \param d diagonal elements of n x n matrix matrix (0,..,n-1)
* \param u upper off-diagonal elements (0,..,n-2)
* \param l lower off-diagonal elements (0,..,n-2)
*/
void computeLU(const DArray<double>& d,
const DArray<double>& u,
const DArray<double>& l);
/**
* Evaluate product Ab = x for known b to compute x.
*
* \param b known vector to be multiplied (input)
* \param x result of multiplication Ab = x (output)
*/
void multiply(const DArray<double>& b, DArray<double>& x);
/**
* Solve Ax = b for known b to compute x.
*
* \param b known vector on RHS (input)
* \param x unknown solution vector of Ax = b (output)
*/
void solve(const DArray<double>& b, DArray<double>& x);
private:
// Diagonal elements
DArray<double> d_;
// Upper off-diagonal elements (unmodified by computeLU)
DArray<double> u_;
// Lower off-diagonal elements (replaced by multipliers)
DArray<double> l_;
// Work space.
DArray<double> y_;
int n_;
// Apply Gauss elimination to private arrays d_, u_, l_.
void gaussElimination();
};
}
#endif
| 2,420
|
C++
|
.h
| 82
| 23.317073
| 71
| 0.608639
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,139
|
LuSolver.h
|
dmorse_pscfpp/src/pscf/math/LuSolver.h
|
#ifndef PSCF_LU_SOLVER_H
#define PSCF_LU_SOLVER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/Array.h>
#include <util/containers/Matrix.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_permutation.h>
namespace Pscf
{
using namespace Util;
/**
* Solve Ax=b by LU decomposition of A.
*
* This class is a simple wrapper for the functions provided by
* the Gnu Scientific Library (GSL).
*
* \ingroup Pscf_Math_Module
*/
class LuSolver
{
public:
/**
* Constructor.
*/
LuSolver();
/**
* Destructor.
*/
~LuSolver();
/**
* Allocate memory.
*
* \param n dimension of n x n square array.
*/
void allocate(int n);
/**
* Compute the LU decomposition for later use.
*
* \param A the square matrix A in problem Ax=b.
*/
void computeLU(const Matrix<double>& A);
/**
* Solve Ax = b for known b to compute x.
*
* \param b the RHS vector
* \param x the solution vector
*/
void solve(Array<double>& b, Array<double>& x);
/**
* Compute inverse of matrix A.
*
* \param inv inverse of matrix A (output)
*/
void inverse (Matrix<double>& inv);
private:
/// RHS vector of Ax=b.
gsl_vector b_;
/// Solution vector of Ax=b.
gsl_vector x_;
/// Pointer to LU decomposition matrix.
gsl_matrix* luPtr_;
/// Pointer to inverse matrix.
gsl_matrix* gMatInverse_;
/// Pointer to permutation in LU decomposition.
gsl_permutation* permPtr_;
/// Sign of permutation in LU decomposition.
int signum_;
/// Number of rows and columns in matrix.
int n_;
};
}
#endif
| 1,974
|
C++
|
.h
| 78
| 19.782051
| 67
| 0.607791
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,140
|
System.h
|
dmorse_pscfpp/src/fd1d/System.h
|
#ifndef FD1D_SYSTEM_H
#define FD1D_SYSTEM_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <fd1d/misc/FieldIo.h> // member
#include <fd1d/solvers/Mixture.h> // member
#include <fd1d/domain/Domain.h> // member
#include <pscf/homogeneous/Mixture.h> // member
#include <util/misc/FileMaster.h> // member
#include <util/containers/DArray.h> // member template
#include <util/containers/Array.h> // function parameter
namespace Pscf {
class Interaction;
namespace Fd1d
{
class Iterator;
class IteratorFactory;
class Sweep;
class SweepFactory;
using namespace Util;
/**
* Main class in SCFT simulation of one system.
*
* A System has (among other components):
*
* - a Mixture (a container for polymer and solvent solvers)
* - an Interaction (list of binary chi parameters)
* - a Domain (description of the unit cell and discretization)
* - monomer chemical potential fields
* - monomer concentration fields
* - An Iterator
*
* A system may also optionally contain a Sweep object.
*
* A minimal main program that uses this class to implement a program
* might look something like this:
* \code
* int main(int argc, char **argv) {
* Pscf::Fd1d::System system;
* system.setOptions(argc, argv);
* system.readParam();
* system.readCommands();
* }
* \endcode
* The actual main program is given in the file pscf_fd.cpp.
*
* \ref user_param_fd_page "Parameter File Format"
* \ingroup Pscf_Fd1d_Module
*/
class System : public ParamComposite
{
public:
/// Generic Field type.
typedef DArray<double> Field;
/// Monomer chemical potential field type.
typedef DArray<double> WField;
/// Monomer concentration / volume fraction field type.
typedef DArray<double> CField;
/// \name Construction and Destruction
///@{
/**
* Constructor.
*/
System();
/**
* Destructor.
*/
~System();
///@}
/// \name Lifetime (Actions)
///@{
/**
* Process command line options.
*/
void setOptions(int argc, char **argv);
/**
* Read input parameters (with opening and closing lines).
*
* \param in input parameter stream
*/
virtual void readParam(std::istream& in);
/**
* Read input parameters from default param file.
*/
void readParam();
/**
* Read input parameters (without opening and closing lines).
*
* \param in input parameter stream
*/
virtual void readParameters(std::istream& in);
/**
* Read command script.
*
* \param in command script file.
*/
void readCommands(std::istream& in);
/**
* Read commands from default command file.
*/
void readCommands();
///@}
/// \name Primary SCFT Computations
//@{
/**
* Solve the modified diffusion equation once, without iteration.
*
* This function calls the Mixture::compute() function to solve
* the statistical mechanics problem for a non-interacting system
* subjected to the currrent chemical potential fields (wFields).
* This requires solution of the modified diffusion equation for
* all polymers, computation of Boltzmann weights for all solvents,
* computation of molecular partition functions for all species,
* computation of concentration fields for blocks and solvents, and
* computation of overall concentrations for all monomer types.
* This function does not compute the canonical (Helmholtz) free
* energy or grand-canonical free energy (i.e., pressure).
* Upon return, the flag hasCFields is set true.
*/
void compute();
/**
* Iteratively solve a SCFT problem.
*
* This function calls the iterator to attempt to solve the SCFT
* problem for the current mixture and system parameters, using
* the current chemical potential fields (wFields) as initial
* guesses.
*
* \param isContinuation true if continuation within a sweep.
* \return returns 0 for successful convergence, 1 for failure.
*/
int iterate(bool isContinuation = false);
/**
* Sweep in parameter space, solving an SCF problem at each point.
*
* This function uses a Sweep object that was initialized in the
* parameter file to solve the SCF problem at a sequence of points
* along a line in parameter space. The nature of this sequence of
* points is determined by implementation of a subclass of Sweep
* and the parameters passed to the sweep object in the parameter
* file. The Iterator that is initialized in the parameter file
* is called at each state point.
*/
void sweep();
//@}
/// \name Thermodynamic Properties
///@{
/**
* Compute free energy density and pressure for current fields.
*
* This function should be called after a successful call of
* iterator().solve(). Resulting values are returned by the
* freeEnergy() and pressure() accessor functions.
*/
void computeFreeEnergy();
/**
* Get precomputed Helmholtz free energy per monomer / kT.
*
* The value retrieved by this function is computed by the
* computeFreeEnergy() function.
*/
double fHelmholtz() const;
/**
* Get precomputed pressure x monomer volume kT.
*
* The value retrieved by this function is computed by the
* computeFreeEnergy() function.
*/
double pressure() const;
//@}
/// \name Thermodynamic Data Output
///@{
/**
* Write parameter file to an ostream, omitting any Sweep block.
*
* \param out output stream
*/
void writeParamNoSweep(std::ostream& out) const;
/**
* Write thermodynamic properties to a file.
*
* This function outputs Helmholtz free energy per monomer,
* pressure (in units of kT per monomer volume), and the volume
* fraction phi and chemical potential mu of each species.
*
* \param out output stream
*/
void writeThermo(std::ostream& out);
///@}
/// \name Field Output
//@{
/**
* Write chemical potential fields in symmetrized basis format.
*
* \param filename name of output file
*/
void writeW(std::string const & filename);
/**
* Write concentration fields in symmetrized basis format.
*
* \param filename name of output file
*/
void writeC(std::string const & filename);
/**
* Write c-fields for all blocks and solvents in r-grid format.
*
* Writes concentrations for all blocks of all polymers and all
* solvent species in r-grid format. Columns associated with blocks
* appear ordered by polymer id and then by block id, followed by
* solvent species ordered by solvent id.
*
* \param filename name of output file
*/
void writeBlockC(std::string const & filename);
/**
* Write slice of a propagator at fixed s in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
* \param segmentId integer integration step index
*/
void writeQSlice(std::string const & filename,
int polymerId, int blockId,
int directionId, int segmentId) const;
/**
* Write the final slice of a propagator in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
*/
void writeQTail(std::string const & filename, int polymerId,
int blockId, int directionId) const;
/**
* Write one propagator for one block, in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
*/
void writeQ(std::string const & filename, int polymerId,
int blockId, int directionId) const;
/**
* Write all propagators of all blocks, each to a separate file.
*
* Write all propagators for both directions for all blocks
* of all polymers, with each propagator in a separate file.
* The function writeQ is called internally for each propagator,
* and is passed an automatically generated file name. The file
* name for each propagator is given by a string of the form
* (basename)_(ip)_(ib)_(id), where (basename) denotes the value
* of the std::string function parameter basename, and where
* (ip), (ib), and (id) denote the string representations of
* a polymer indiex ip, a block index ib, and direction index id,
* with id = 0 or 1. For example, if basename == "out/q", then
* the file name of the propagator for direction 1 of block 2
* of polymer 0 would be "out/q_0_2_1".
*
* \param basename common prefix for output file names
*/
void writeQAll(std::string const & basename);
//@}
/// \name Field Accessors
///@{
/**
* Get array of all chemical potential fields.
*
* The array capacity is equal to the number of monomer types.
*/
DArray<WField>& wFields();
/**
* Get chemical potential field for a specific monomer type.
*
* \param monomerId integer monomer type index
*/
WField& wField(int monomerId);
/**
* Get array of all chemical potential fields.
*
* The array capacity is equal to the number of monomer types.
*/
DArray<CField>& cFields();
/**
* Get chemical potential field for a specific monomer type.
*
* \param monomerId integer monomer type index
*/
CField& cField(int monomerId);
///@}
/// \name Member object accessors
///@{
/**
* Get Mixture by reference.
*/
Mixture& mixture();
/**
* Get Mixture by reference.
*/
Mixture const & mixture() const;
/**
* Get interaction (i.e., excess free energy) by reference.
*/
Interaction & interaction();
/**
* Get interaction (i.e., excess free energy) by const reference.
*/
Interaction const & interaction() const;
/**
* Get spatial domain (including grid info) by reference.
*/
Domain& domain();
/**
* Get the Iterator by reference.
*/
Iterator& iterator();
/**
* Get homogeneous mixture (for reference calculations).
*/
Homogeneous::Mixture& homogeneous();
/**
* Get FileMaster by reference.
*/
FileMaster& fileMaster();
///@}
private:
/**
* Mixture object (solves MDE for all species).
*/
Mixture mixture_;
/**
* Spatial domain and grid definition.
*/
Domain domain_;
/**
* Filemaster (holds paths to associated I/O files).
*/
FileMaster fileMaster_;
/**
* FieldIo (field input-output operations).
*/
FieldIo fieldIo_;
/**
* Homogeneous mixture, for reference.
*/
Homogeneous::Mixture homogeneous_;
/**
* Pointer to Interaction (excess free energy model).
*/
Interaction* interactionPtr_;
/**
* Pointer to associated iterator.
*/
Iterator* iteratorPtr_;
/**
* Pointer to associated Iterator factory.
*/
IteratorFactory* iteratorFactoryPtr_;
/**
* Pointer to associated Sweep object
*/
Sweep* sweepPtr_;
/**
* Pointer to associated Sweep factory.
*/
SweepFactory* sweepFactoryPtr_;
/**
* Array of chemical potential fields for monomer types.
*
* Indexed by monomer typeId, size = nMonomer.
*/
DArray<WField> wFields_;
/**
* Array of concentration fields for monomer types.
*
* Indexed by monomer typeId, size = nMonomer.
*/
DArray<CField> cFields_;
/**
* Work array (size = # of grid points).
*/
mutable DArray<double> f_;
/**
* Work array (size = # of monomer types).
*/
mutable DArray<double> c_;
/**
* Helmholtz free energy per monomer / kT.
*/
double fHelmholtz_;
/**
* Ideal gas contribution to fHelmholtz_.
*
* This encompasses the internal energy and entropy of
* non-interacting free chains in their corresponding
* potential fields defined by w_.
*/
double fIdeal_;
/**
* Multi-chain interaction contribution to fHelmholtz_.
*/
double fInter_;
/**
* Pressure times monomer volume / kT.
*/
double pressure_;
/**
* Has the mixture been initialized?
*/
bool hasMixture_;
/**
* Has the Domain been initialized?
*/
bool hasDomain_;
/**
* Have initial chemical potential fields been read from file?
*/
bool hasFields_;
/**
* Does this system have a Sweep object?
*/
bool hasSweep_;
// Private member functions
/**
* Allocate memory for fields (private)
*/
void allocateFields();
/**
* Initialize Homogeneous::Mixture object.
*/
void initHomogeneous();
/**
* Read a string (e.g., a filename) and echo it to the log file.
*
* \param in input stream from which to read
* \param string string variable to read and echo
*/
void readEcho(std::istream& in, std::string& string) const;
};
// Inline member functions
/*
* Get the associated Mixture object by reference.
*/
inline Mixture& System::mixture()
{ return mixture_; }
/*
* Get the associated Mixture object by const reference.
*/
inline Mixture const & System::mixture() const
{ return mixture_; }
/*
* Get the Interaction (excess free energy model).
*/
inline Interaction & System::interaction()
{
UTIL_ASSERT(interactionPtr_);
return *interactionPtr_;
}
/*
* Get the Interaction (excess free energy) by const reference.
*/
inline Interaction const & System::interaction() const
{
UTIL_ASSERT(interactionPtr_);
return *interactionPtr_;
}
/*
* Get the spatial Domain.
*/
inline Domain& System::domain()
{ return domain_; }
/*
* Get the Homogeneous::Mixture object.
*/
inline
Homogeneous::Mixture& System::homogeneous()
{ return homogeneous_; }
/*
* Get the Iterator.
*/
inline Iterator& System::iterator()
{
UTIL_ASSERT(iteratorPtr_);
return *iteratorPtr_;
}
/*
* Get the FileMaster.
*/
inline FileMaster& System::fileMaster()
{ return fileMaster_; }
/*
* Get an array of all monomer excess chemical potential fields.
*/
inline
DArray< System::WField >& System::wFields()
{ return wFields_; }
/*
* Get a single monomer excess chemical potential field.
*/
inline
System::WField& System::wField(int id)
{ return wFields_[id]; }
/*
* Get array of all monomer concentration fields.
*/
inline
DArray< System::CField >& System::cFields()
{ return cFields_; }
/*
* Get a single monomer concentration field.
*/
inline System::CField& System::cField(int id)
{ return cFields_[id]; }
/*
* Get precomputed Helmoltz free energy per monomer / kT.
*/
inline double System::fHelmholtz() const
{ return fHelmholtz_; }
/*
* Get precomputed pressure (units of kT / monomer volume).
*/
inline double System::pressure() const
{ return pressure_; }
} // namespace Fd1d
} // namespace Pscf
#endif
| 16,801
|
C++
|
.h
| 534
| 24.966292
| 73
| 0.619425
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,141
|
SystemAccess.h
|
dmorse_pscfpp/src/fd1d/SystemAccess.h
|
#ifndef FD1D_SYSTEM_ACCESS_H
#define FD1D_SYSTEM_ACCESS_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "System.h" // member
namespace Pscf {
namespace Fd1d {
using namespace Util;
/**
* Concise accesss to an associated System
*
* This class is intended to be a base class for classes that
* maintain a pointer to an associated system, and that implement
* code that frequently accesses the main members of that System.
*
* \ingroup Pscf_Fd1d_Module
*/
class SystemAccess
{
public:
/**
* Default constructor.
*/
SystemAccess();
/**
* Constructor.
*/
SystemAccess(System& system);
/**
* Destructor.
*/
~SystemAccess();
/**
* Set the system after construction.
*/
virtual void setSystem(System& system);
/// \name Accessors (get objects by reference)
///@{
/**
* Get parent System by reference.
*/
const System& system() const;
/**
* Get parent System by reference.
*/
System& system();
/**
* Get Mixture by reference.
*/
const Mixture& mixture() const;
/**
* Get Mixture by reference.
*/
Mixture& mixture();
/**
* Get spatial domain (including grid info) by reference.
*/
const Domain& domain() const;
/**
* Get spatial domain (including grid info) by reference.
*/
Domain& domain();
/**
* Get interaction (i.e., excess free energy model) by reference.
*/
const Interaction& interaction() const;
/**
* Get interaction (i.e., excess free energy model) by reference.
*/
Interaction& interaction();
/**
* Get homogeneous mixture (for reference calculations).
*/
const Homogeneous::Mixture& homogeneous() const;
/**
* Get homogeneous mixture (for reference calculations).
*/
Homogeneous::Mixture& homogeneous();
/**
* Get FileMaster by reference.
*/
FileMaster& fileMaster();
///@}
/// \name Fields
///@{
/**
* Get array of all chemical potential fields.
*
* The array capacity is equal to the number of monomer types.
*/
DArray<System::WField>& wFields();
/**
* Get chemical potential field for a specific monomer type.
*
* \param monomerId integer monomer type index
*/
System::WField& wField(int monomerId);
/**
* Get array of all chemical potential fields.
*
* The array capacity is equal to the number of monomer types.
*/
DArray<System::CField>& cFields();
/**
* Get chemical potential field for a specific monomer type.
*
* \param monomerId integer monomer type index
*/
System::CField& cField(int monomerId);
///@}
private:
/**
* Mixture object (solves MDE for all species).
*/
System* systemPtr_;
};
// Inline member functions
/*
* Get the parent System object.
*/
inline const System& SystemAccess::system() const
{
UTIL_ASSERT(systemPtr_);
return *systemPtr_;
}
/*
* Get the parent System object.
*/
inline System& SystemAccess::system()
{
UTIL_ASSERT(systemPtr_);
return *systemPtr_;
}
/*
* Get the associated Mixture object.
*/
inline const Mixture& SystemAccess::mixture() const
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->mixture();
}
/*
* Get the associated Mixture object.
*/
inline Mixture& SystemAccess::mixture()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->mixture();
}
/*
* Get the spatial Domain.
*/
inline const Domain& SystemAccess::domain() const
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->domain();
}
/*
* Get the spatial Domain.
*/
inline Domain& SystemAccess::domain()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->domain();
}
/*
* Get the Interaction (excess free energy model).
*/
inline const Interaction& SystemAccess::interaction() const
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->interaction();
}
/*
* Get the Interaction (excess free energy model).
*/
inline Interaction& SystemAccess::interaction()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->interaction();
}
/*
* Get the FileMaster.
*/
inline FileMaster& SystemAccess::fileMaster()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->fileMaster();
}
/*
* Get the Homogeneous::Mixture object.
*/
inline
Homogeneous::Mixture& SystemAccess::homogeneous()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->homogeneous();
}
/*
* Get an array of all monomer excess chemical potential fields.
*/
inline
DArray< System::WField >& SystemAccess::wFields()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->wFields();
}
/*
* Get a single monomer excess chemical potential field.
*/
inline
System::WField& SystemAccess::wField(int id)
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->wField(id);
}
/*
* Get array of all monomer concentration fields.
*/
inline
DArray< System::CField >& SystemAccess::cFields()
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->cFields();
}
/*
* Get a single monomer concentration field.
*/
inline System::CField& SystemAccess::cField(int id)
{
UTIL_ASSERT(systemPtr_);
return systemPtr_->cField(id);
}
} // namespace Fd1d
} // namespace Pscf
#endif
| 5,951
|
C++
|
.h
| 240
| 19.070833
| 70
| 0.606815
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,142
|
NrIterator.h
|
dmorse_pscfpp/src/fd1d/iterator/NrIterator.h
|
#ifndef FD1D_NR_ITERATOR_H
#define FD1D_NR_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Iterator.h"
#include <fd1d/solvers/Mixture.h>
#include <pscf/math/LuSolver.h>
#include <util/containers/Array.h>
#include <util/containers/DArray.h>
#include <util/containers/DMatrix.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/**
* Newton-Raphson Iterator for SCF equations.
*
* \ingroup Fd1d_Iterator_Module
*/
class NrIterator : public Iterator
{
public:
/**
* Monomer chemical potential field.
*/
typedef Mixture::WField WField;
/**
* Monomer concentration / volume fraction field.
*/
typedef Mixture::CField CField;
/**
* Default constructor.
*/
NrIterator();
/**
* Constructor.
*
* \param system parent System object.
*/
NrIterator(System& system);
/**
* Destructor.
*/
virtual ~NrIterator();
/**
* Read all parameters and initialize.
*
* \param in input parameter stream
*/
void readParameters(std::istream& in);
/**
* Iterate self-consistent field equations to solution.
*
* \param isContinuation True if part of sweep, and not first step.
* \return error code: 0 for success, 1 for failure.
*/
int solve(bool isContinuation = false);
private:
/// Solver for linear system Ax = b.
LuSolver solver_;
/// Perturbed chemical potential fields (work space).
DArray<WField> wFieldsNew_;
/// Perturbed monomer concentration fields (work space).
DArray<WField> cFieldsNew_;
/// Concentrations at one point (work space).
DArray<double> cArray_;
/// Chemical potentials at one point (work space).
DArray<double> wArray_;
/// Residual vector. size = nr = (# monomers)x(# grid points).
DArray<double> residual_;
/// Jacobian matrix. Dimensions nr x nr.
DMatrix<double> jacobian_;
/// Perturbed residual. size = nr.
DArray<double> residualNew_;
/// Change in field
DArray<double> dOmega_;
/// Error tolerance.
double epsilon_;
/// Maximum number of iterations
int maxItr_;
/// Have arrays been allocated?
bool isAllocated_;
/// Has the Jacobian been calculated at current state?
bool newJacobian_;
/// Does the Jacobian need to be re-calculated ?
bool needsJacobian_;
/// Is the ensemble canonical for all species ?
bool isCanonical_;
// Private member functions
/**
* Allocate required memory (called in readParameters).
*/
void setup();
/**
* Compute the residual vector.
*
* \param wFields monomer chemical potential fields (input)
* \param cFields monomer concentration fields (input)
* \param residual vector of residuals (errors) (output)
*/
void computeResidual(Array<WField> const & wFields,
Array<WField> const & cFields,
Array<double>& residual);
/**
* Compute and return norm of a residual vector.
*
* \param residual vector of residuals (errors) (input)
*/
double residualNorm(Array<double> const & residual) const;
/**
* Compute the Jacobian matrix (stored in class member).
*/
void computeJacobian();
/**
* Increment the chemical potential fields
*
* \param wOld array of old chemical potential fields
* \param dW array of increments, indexed as in residual columns
* \param wNew array of new chemical potential fields
*/
void incrementWFields(Array<WField> const & wOld,
Array<double> const & dW,
Array<WField>& wNew);
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 4,104
|
C++
|
.h
| 131
| 24.534351
| 72
| 0.625
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,143
|
Iterator.h
|
dmorse_pscfpp/src/fd1d/iterator/Iterator.h
|
#ifndef FD1D_ITERATOR_H
#define FD1D_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <fd1d/SystemAccess.h> // base class
#include <util/global.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/**
* Base class for iterative solvers for SCF equations.
*
* \ingroup Fd1d_Iterator_Module
*/
class Iterator : public ParamComposite, public SystemAccess
{
public:
/**
* Default constructor.
*/
Iterator();
/**
* Constructor.
*
* \param system parent System object
*/
Iterator(System& system);
/**
* Destructor.
*/
~Iterator();
/**
* Iterate to solution.
*
* \param isContinuation true iff part of sweep, and not first step.
* \return error code: 0 for success, 1 for failure.
*/
virtual int solve(bool isContinuation = false) = 0;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 1,197
|
C++
|
.h
| 48
| 20.041667
| 73
| 0.632366
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,144
|
BinaryRelaxIterator.h
|
dmorse_pscfpp/src/fd1d/iterator/BinaryRelaxIterator.h
|
#ifndef FD1D_BINARY_RELAX_ITERATOR_H
#define FD1D_BINARY_RELAX_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Iterator.h"
#include <fd1d/solvers/Mixture.h>
#include <pscf/math/LuSolver.h>
#include <util/containers/Array.h>
#include <util/containers/DArray.h>
#include <util/containers/DMatrix.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/**
* Relaxation iterator for SCF equations for two-monomer system.
*
* This class implements the simple Picard-type relaxation iterator
* for systems with two monomer types that was introduced by Drolet and
* Fredrickson (PRL, 1999).
*
* Reference:
* F. Drolet & G.H. Fredrickson, Phys. Rev. Lett. vol. 83, 4317 (1999).
*
* \ingroup Fd1d_Iterator_Module
*/
class BinaryRelaxIterator : public Iterator
{
public:
/**
* Monomer chemical potential field.
*/
typedef Mixture::WField WField;
/**
* Monomer concentration / volume fraction field.
*/
typedef Mixture::CField CField;
/**
* Constructor.
*
* \param system parent System object.
*/
BinaryRelaxIterator(System& system);
/**
* Destructor.
*/
virtual ~BinaryRelaxIterator();
/**
* Read all parameters and initialize.
*
* \param in input parameter stream
*/
void readParameters(std::istream& in);
/**
* Iterate self-consistent field equations to solution.
*
* \param isContinuation True if part of sweep, and not first step.
* \return error code: 0 for success, 1 for failure.
*/
int solve(bool isContinuation = false);
private:
/// Perturbed chemical potential fields (work space).
DArray<WField> wFieldsNew_;
/// Perturbed monomer concentration fields (work space).
DArray<WField> cFieldsNew_;
/// Concentrations at one point (work space).
DArray<double> cArray_;
/// Chemical potentials at one point (work space).
DArray<double> wArray_;
/// Residual vector. size = nr = (# monomers)x(# grid points).
DArray<double> residual_;
/// Perturbed residual. size = nr.
DArray<double> residualNew_;
/// Perturbed DW
DArray<WField> dW_;
DArray<WField> dWNew_;
/// Norm of change field
double dWNorm_;
double dWNormNew_;
/// Error tolerance.
double epsilon_;
/// Mixing parameter for Wplus
double lambdaPlus_;
/// Mixing parameter for Wminus
double lambdaMinus_;
/// Max number of iterations
int maxItr_;
/// Have arrays been allocated?
bool isAllocated_;
/// Is the ensemble canonical for all species ?
bool isCanonical_;
/**
* Allocate required memory.
*/
void allocate();
/**
* Compute residuals and increments of chemical potential fields.
*
* \param wOld array of old chemical potential fields (input)
* \param cFields monomer concentration fields (input)
* \param dW change of w fields (output)
* \param dWNorm scalar residual (output)
*/
void computeDW(Array<WField> const & wOld,
Array<CField> const & cFields,
Array<WField> & dW,
double & dWNorm);
/**
* Update the chemical potential fields
*
* \param wold array of old chemical potential fields (input)
* \param dW_ array of increment of chemical potential fields (input)
* \param wNew array of new chemical potential fields (output)
*/
void updateWFields(Array<WField> const & wOld,
Array<WField> const & dW_,
Array<WField> & wNew);
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 4,165
|
C++
|
.h
| 125
| 25.432
| 74
| 0.63362
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,145
|
AmIterator.h
|
dmorse_pscfpp/src/fd1d/iterator/AmIterator.h
|
#ifndef FD1D_AM_ITERATOR_H
#define FD1D_AM_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2019, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Iterator.h"
#include <fd1d/solvers/Mixture.h>
#include <pscf/iterator/AmbdInteraction.h>
#include <pscf/iterator/AmIteratorTmpl.h>
namespace Pscf {
namespace Fd1d
{
class System;
using namespace Util;
/**
* Anderson-Mixing iterator.
*
* \ingroup Fd1d_Iterator_Module
*/
class AmIterator : public AmIteratorTmpl<Iterator, DArray<double> >
{
public:
/**
* Constructor.
*
* \param system System object associated with this iterator.
*/
AmIterator(System& system);
/**
* Destructor.
*/
~AmIterator();
/**
* Read all parameters and initialize.
*
* \param in input filestream
*/
void readParameters(std::istream& in);
// Inherited public member functions
using AmIteratorTmpl<Iterator,DArray<double> >::solve;
using AmIteratorTmpl<Iterator,DArray<double> >::setClassName;
protected:
// Inherited protected members
using Iterator::system;
/**
* Setup iterator just before entering iteration loop.
*
* \param isContinuation Is this a continuation within a sweep?
*/
void setup(bool isContinuation);
private:
// Local copy of interaction, adapted for use AMBD residual definition
AmbdInteraction interaction_;
// -- Virtual functions used to implement AM algorithm -- //
/**
* Assign one field to another.
*
* \param a the field to be set (lhs of assignment)
* \param b the field for it to be set to (rhs of assigment)
*/
void setEqual(DArray<double>& a, DArray<double> const & b);
/**
* Find L2 norm of a residual vector.
*/
double
dotProduct(DArray<double> const & a, DArray<double> const & b);
/**
* Find the maximum magnitude element of a residual vector.
*/
double maxAbs(DArray<double> const & hist);
/**
* Update the basis for residual or field vectors.
*
* \param basis RingBuffer of residual or field basis vectors
* \param hists RingBuffer of past residual or field vectors
*/
void updateBasis(RingBuffer<DArray<double> > & basis,
RingBuffer<DArray<double> > const & hists);
/**
* Add linear combination of basis vectors to trial field.
*
* \param trial trial vector (input-output)
* \param basis RingBuffer of basis vectors
* \param coeffs array of coefficients of basis vectors
* \param nHist number of histories stored at this iteration
*/
void addHistories(DArray<double>& trial,
RingBuffer<DArray<double> > const & basis,
DArray<double> coeffs,
int nHist);
/**
* Add predicted error to field trial.
*
* \param fieldTrial trial field (in-out)
* \param resTrial predicted error for current trial
* \param lambda Anderson-Mixing mixing
*/
void addPredictedError(DArray<double>& fieldTrial,
DArray<double> const & resTrial,
double lambda);
// -- Virtual funtions to exchange data with parent System -- //
/**
* Checks if the system has an initial guess.
*/
bool hasInitialGuess();
/**
* Compute and returns the number residuals and unknowns.
*
* Called during allocation and then stored.
*/
int nElements();
/**
* Gets the current field vector from the system.
*
* \param curr current field vector
*/
void getCurrent(DArray<double>& curr);
/**
* Have the system perform a computation using new field.
*
* Solves the modified diffusion equations, computes concentrations,
* and optionally computes stress components.
*/
void evaluate();
/**
* Compute the residual vector.
*
* \param resid current residual vector value
*/
void getResidual(DArray<double>& resid);
/**
* Updates the system field with the new trial field.
*
* \param newGuess trial field vector
*/
void update(DArray<double>& newGuess);
/**
* Outputs relevant system details to the iteration log.
*/
void outputToLog();
/**
* Return true iff all species are treated in closed ensemble.
*/
bool isCanonical();
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 4,785
|
C++
|
.h
| 151
| 24.662252
| 76
| 0.625217
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,146
|
IteratorFactory.h
|
dmorse_pscfpp/src/fd1d/iterator/IteratorFactory.h
|
#ifndef FD1D_ITERATOR_FACTORY_H
#define FD1D_ITERATOR_FACTORY_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/Factory.h>
#include <fd1d/iterator/Iterator.h>
#include <fd1d/System.h>
#include <string>
namespace Pscf {
namespace Fd1d {
using namespace Util;
/**
* Factory for subclasses of Iterator.
*
* The default iterator, invoked by className Iterator, is the
* Anderson mixing iterator (className AmIterator).
*
* \ingroup Fd1d_Iterator_Module
*/
class IteratorFactory : public Factory<Iterator>
{
public:
/**
* Constructor
*
* \param system parent System object
*/
IteratorFactory(System& system);
/**
* Method to create any Iterator supplied with PSCF.
*
* \param className name of the Iterator subclass
* \return Iterator* pointer to new instance of className
*/
Iterator* factory(const std::string &className) const;
using Factory< Iterator >::trySubfactories;
private:
/// Pointer to the parent system.
System* sysPtr_;
};
}
}
#endif
| 1,262
|
C++
|
.h
| 47
| 22.510638
| 67
| 0.691667
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,147
|
Polymer.h
|
dmorse_pscfpp/src/fd1d/solvers/Polymer.h
|
#ifndef FD1D_POLYMER_H
#define FD1D_POLYMER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Block.h"
#include <pscf/solvers/PolymerTmpl.h>
namespace Pscf {
namespace Fd1d
{
/**
* Descriptor and solver for a branched polymer species.
*
* The block concentrations stored in the constituent Block
* objects contain the block concentrations (i.e., volume
* fractions) computed in the most recent call of the compute
* function.
*
* The phi() and mu() accessor functions, which are inherited
* from PolymerTmp<Block>, return the value of phi (spatial
* average volume fraction of a species) or mu (chemical
* potential) computed in the last call of the compute function.
* If the ensemble for this species is closed, phi is read from
* the parameter file and mu is computed. If the ensemble is
* open, mu is read from the parameter file and phi is computed.
*
* \ref user_param_polymer_sec "Parameter File Format"
* \ingroup Fd1d_Solver_Module
*/
class Polymer : public PolymerTmpl<Block>
{
public:
/**
* Default constructor.
*/
Polymer();
/**
* Destructor.
*/
~Polymer();
/**
* Set volume fraction (if ensemble is closed).
*
* \param phi new volume fraction for this species
*/
void setPhi(double phi);
/**
* Set chemical potential mu (if ensemble is open).
*
* \param mu new chemical potential for this species
*/
void setMu(double mu);
/**
* Compute solution to modified diffusion equation.
*
* Upon return, q functions and block concentration fields
* are computed for all propagators and blocks.
*
* \param wFields array of chemica potential fields.
*/
void compute(DArray<Block::WField> const & wFields);
};
}
}
#endif
| 2,039
|
C++
|
.h
| 68
| 25.088235
| 67
| 0.669729
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,148
|
Propagator.h
|
dmorse_pscfpp/src/fd1d/solvers/Propagator.h
|
#ifndef FD1D_PROPAGATOR_H
#define FD1D_PROPAGATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/solvers/PropagatorTmpl.h> // base class template
#include <util/containers/DArray.h> // member template
namespace Pscf {
namespace Fd1d
{
class Block;
using namespace Util;
/**
* MDE solver for one-direction of one block.
*
* \ingroup Fd1d_Solver_Module
*/
class Propagator : public PropagatorTmpl<Propagator>
{
public:
// Public typedefs
/**
* Generic field (function of position).
*/
typedef DArray<double> Field;
/**
* Chemical potential field type.
*/
typedef DArray<double> WField;
/**
* Monomer concentration field type.
*/
typedef DArray<double> CField;
/**
* Propagator q-field type.
*/
typedef DArray<double> QField;
// Member functions
/**
* Constructor.
*/
Propagator();
/**
* Destructor.
*/
~Propagator();
/**
* Associate this propagator with a block.
*
* \param block associated Block object.
*/
void setBlock(Block& block);
/**
* Set discretization and allocate memory.
*
* \param ns number of contour length steps
* \param nx number of spatial steps
*/
void allocate(int ns, int nx);
/**
* Reallocate memory used by this propagator.
*
* This function is used when the value of ns is changed,
* which occurs during some parameter sweeps.
*
* The parameter ns is the number of values of s at which
* q(r,s) is calculated, including the end values at the
* terminating vertices. This is one more than the number
* of contour variable steps.
*
* \param ns number of slices (including end points)
*/
void reallocate(int ns);
/**
* Solve the modified diffusion equation (MDE) for this block.
*
* This function computes an initial QField at the head of this
* block, and then solves the modified diffusion equation for
* the block to propagate from the head to the tail. The initial
* QField at the head is computed by pointwise multiplication of
* of the tail QFields of all source propagators.
*/
void solve();
/**
* Solve the MDE for a specified initial condition.
*
* This function solves the modified diffusion equation for this
* block with a specified initial condition, which is given by
* head parameter of the function. The function is intended for
* use in testing.
*
* \param head initial condition of QField at head of block
*/
void solve(const QField& head);
/**
* Compute and return partition function for the molecule.
*
* This function computes the partition function Q for the
* molecule as a spatial average of the initial/head Qfield
* for this propagator and the final/tail Qfield of its
* partner.
*/
double computeQ();
/**
* Return q-field at specified step.
*
* \param i step index
*/
QField const & q(int i) const;
/**
* Return q-field at beginning of block (initial condition).
*/
QField const & head() const;
/**
* Return q-field at end of block.
*/
QField const & tail() const;
/**
* Number of values of s (or slices), including head and tail.
*
* The value of ns is the number of values of s at which q(r,s) is
* calculated, including the end values at the terminating vertices
* (the head and tail). This is one more than the number of contour
* variable steps.
*/
int ns() const;
/**
* Has memory been allocated for this propagator?
*/
bool isAllocated() const;
private:
/// Array of statistical weight fields
DArray<QField> qFields_;
/// Workspace
QField work_;
/// Pointer to associated Block.
Block* blockPtr_;
/// Number of contour length steps = # grid points - 1.
int ns_;
/// Number of spatial grid points.
int nx_;
/// Is this propagator allocated?
bool isAllocated_;
/**
* Get the associated Block object by reference.
*/
Block & block();
/**
* Compute initial QField at head from tail QFields of sources.
*/
void computeHead();
};
// Inline member functions
/*
* Return q-field at beginning of block.
*/
inline Propagator::QField const& Propagator::head() const
{ return qFields_[0]; }
/*
* Return q-field at end of block, after solution.
*/
inline Propagator::QField const& Propagator::tail() const
{ return qFields_[ns_-1]; }
/*
* Return q-field at specified step.
*/
inline Propagator::QField const& Propagator::q(int i) const
{ return qFields_[i]; }
/*
* Get the associated Block object.
*/
inline Block& Propagator::block()
{
assert(blockPtr_);
return *blockPtr_;
}
/*
* Get the number of counter grid points.
*/
inline int Propagator::ns() const
{ return ns_; }
/*
* Associate this propagator with a block and direction
*/
inline void Propagator::setBlock(Block& block)
{ blockPtr_ = █ }
}
}
#endif
| 5,635
|
C++
|
.h
| 192
| 23.088542
| 74
| 0.621029
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,149
|
Block.h
|
dmorse_pscfpp/src/fd1d/solvers/Block.h
|
#ifndef FD1D_BLOCK_H
#define FD1D_BLOCK_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Propagator.h" // base class argument
#include <fd1d/domain/GeometryMode.h> // argument (enum)
#include <pscf/solvers/BlockTmpl.h> // base class template
#include <pscf/math/TridiagonalSolver.h> // member
namespace Pscf {
namespace Fd1d
{
class Domain;
using namespace Util;
/**
* Block within a branched polymer.
*
* Derived from BlockTmpl<Propagator>. A BlockTmpl<Propagator> has two
* Propagator members and is derived from BlockDescriptor.
*
* \ingroup Fd1d_Solver_Module
*/
class Block : public BlockTmpl<Propagator>
{
public:
/**
* Constructor.
*/
Block();
/**
* Destructor.
*/
~Block();
/**
* Initialize discretization and allocate required memory.
*
* \param domain associated Domain object, with grid info
* \param ds desired (optimal) value for contour length step
*/
void setDiscretization(Domain const & domain, double ds);
/**
* Set length and readjust ds_ accordingly.
*
* \param newLength length (# of monomers) for this block
*/
virtual void setLength(double newLength);
/**
* Set Crank-Nicholson solver for this block.
*
* \param w Chemical potential field (input)
*/
void setupSolver(DArray<double> const & w);
/**
* Compute concentration for block by integration.
*
* Upon return, grid point r of array cField() contains the
* integral int ds q(r,s)q^{*}(r,L-s) times the prefactor,
* where q(r,s) is the solution obtained from propagator(0),
* and q^{*} is the solution of propagator(1), and s is
* a contour variable that is integrated over the domain
* 0 < s < length(), where length() is the block length.
*
* \param prefactor constant prefactor multiplying integral
*/
void computeConcentration(double prefactor);
/**
* Compute one step of integration loop, from i to i+1.
*
* \param q propagator slice at step i (input)
* \param qNew propagator slice at step i + 1 (output)
*/
void step(DArray<double> const & q, DArray<double>& qNew);
/**
* Return associated domain by reference.
*/
Domain const & domain() const;
/**
* Number of contour length steps.
*/
int ns() const;
private:
/// Solver used in Crank-Nicholson algorithm
TridiagonalSolver solver_;
// Arrays dA_, uA_, lB_ dB_, uB_, luB_ contain elements of the
// the tridiagonal matrices A and B used in propagation from
// step i to i + 1, which requires solution of a linear system
// of the form: A q(i+1) = B q(i).
/// Diagonal elements of matrix A
DArray<double> dA_;
/// Off-diagonal upper elements of matrix A
DArray<double> uA_;
/// Off-diagonal lower elements of matrix A
DArray<double> lA_;
/// Diagonal elements of matrix B
DArray<double> dB_;
/// Off-diagonal upper elements of matrix B
DArray<double> uB_;
/// Off-diagonal lower elements of matrix B
DArray<double> lB_;
/// Work vector
DArray<double> v_;
/// Pointer to associated Domain object.
Domain const * domainPtr_;
/// Contour length step size (actual step size for this block).
double ds_;
// Contour length step size (value input in param file).
double dsTarget_;
/// Number of contour length steps = # grid points - 1.
int ns_;
};
// Inline member functions
/// Get Domain by reference.
inline Domain const & Block::domain() const
{
UTIL_ASSERT(domainPtr_);
return *domainPtr_;
}
/// Get number of contour steps.
inline int Block::ns() const
{ return ns_; }
}
}
#endif
| 4,126
|
C++
|
.h
| 126
| 26.753968
| 73
| 0.630013
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,150
|
Mixture.h
|
dmorse_pscfpp/src/fd1d/solvers/Mixture.h
|
#ifndef FD1D_MIXTURE_H
#define FD1D_MIXTURE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Polymer.h"
#include "Solvent.h"
#include <pscf/solvers/MixtureTmpl.h>
#include <pscf/inter/Interaction.h>
#include <util/containers/DArray.h>
namespace Pscf {
namespace Fd1d
{
class Domain;
/**
* Mixture of polymers and solvents.
*
* A Mixture contains a list of Polymer and Solvent objects. Each
* such object can solve the single-molecule statistical mechanics
* problem for an ideal gas of the associated species in a set of
* specified chemical potential fields, and thereby compute
* concentrations and single-molecule partition functions. A
* Mixture is thus both a chemistry descriptor and an ideal-gas
* solver.
*
* A Mixture is associated with a Domain object, which models a
* spatial domain and a spatial discretization. Knowledge of the
* domain and discretization is needed to solve the ideal-gas
* problem.
*
* \ref user_param_mixture_page "Parameter File Format"
* \ingroup Fd1d_Solver_Module
*/
class Mixture : public MixtureTmpl<Polymer, Solvent>
{
public:
// Public typedefs
/**
* Monomer chemical potential field type.
*/
typedef Propagator::WField WField;
/**
* Monomer concentration or volume fraction field type.
*/
typedef Propagator::CField CField;
// Public member functions
/**
* Constructor.
*/
Mixture();
/**
* Destructor.
*/
~Mixture();
/**
* Read all parameters and initialize.
*
* This function reads in a complete description of
* the chemical composition and structure of all species,
* as well as the target contour length step size ds.
*
* \param in input parameter stream
*/
void readParameters(std::istream& in);
/**
* Create an association with the domain and allocate memory.
*
* The domain parameter must have already been initialized,
* e.g., by reading its parameters from a file, so that the
* domain dimensions are known on entry.
*
* \param domain associated Domain object (stores address).
*/
void setDomain(Domain const & domain);
/**
* Reset statistical segment length for one monomer type.
*
* This function resets the kuhn or statistical segment length value
* for a monomer type, and updates the associcated value in every
* block of that monomer type.
*
* \param monomerId monomer type id
* \param kuhn new value for the statistical segment length
*/
void setKuhn(int monomerId, double kuhn);
/**
* Compute concentrations.
*
* This function calls the compute function of every molecular
* species, and then adds the resulting block concentration
* fields for blocks of each type to compute a total monomer
* concentration (or volume fraction) for each monomer type.
* Upon return, values are set for volume fraction and chemical
* potential (mu) members of each species, and for the
* concentration fields for each Block and Solvent. The total
* concentration for each monomer type is returned in the
* cFields output parameter.
*
* The arrays wFields and cFields must each have size nMonomer(),
* and contain fields that are indexed by monomer type index.
*
* \param wFields array of chemical potential fields (input)
* \param cFields array of monomer concentration fields (output)
*/
void
compute(DArray<WField> const & wFields, DArray<CField>& cFields);
// Inherited public member functions with non-dependent names
using MixtureTmpl< Polymer, Solvent >::nMonomer;
using MixtureTmpl< Polymer, Solvent >::nPolymer;
using MixtureTmpl< Polymer, Solvent >::nSolvent;
using MixtureTmpl< Polymer, Solvent >::nBlock;
using MixtureTmpl< Polymer, Solvent >::polymer;
using MixtureTmpl< Polymer, Solvent >::monomer;
using MixtureTmpl< Polymer, Solvent >::solvent;
using MixtureTmpl< Polymer, Solvent >::vMonomer;
protected:
// Inherited protected member functions with non-dependent names
using MixtureTmpl< Polymer, Solvent >::setClassName;
using ParamComposite::read;
using ParamComposite::readOptional;
private:
/// Optimal contour length step size.
double ds_;
/// Pointer to associated Domain object.
Domain const * domainPtr_;
/// Return associated domain by reference.
Domain const & domain() const;
};
// Inline member function
/*
* Get Domain by constant reference (private).
*/
inline Domain const & Mixture::domain() const
{
UTIL_ASSERT(domainPtr_);
return *domainPtr_;
}
} // namespace Fd1d
} // namespace Pscf
#endif
| 5,108
|
C++
|
.h
| 143
| 29.909091
| 73
| 0.683006
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,151
|
Solvent.h
|
dmorse_pscfpp/src/fd1d/solvers/Solvent.h
|
#ifndef FD1D_SOLVENT_H
#define FD1D_SOLVENT_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/chem/SolventDescriptor.h> // base class
//#include <pscf/chem/Species.h> // base class
//#include <util/param/ParamComposite.h> // base class
#include <fd1d/solvers/Propagator.h>
#include <fd1d/domain/Domain.h>
namespace Pscf {
namespace Fd1d {
using namespace Util;
/**
* Solver and descriptor for a solvent species.
*
* \ref user_param_solvent_sec "Parameter File Format"
* \ingroup Fd1d_Solver_Module
*/
//class Solvent : public Species, public ParamComposite
class Solvent : public SolventDescriptor
{
public:
/**
* Monomer concentration field type.
*/
typedef typename Propagator::CField CField;
/**
* Monomer chemical potential field type.
*/
typedef typename Propagator::WField WField;
/**
* Constructor.
*/
Solvent();
/**
* Constructor.
*/
~Solvent();
/**
* Set association with Domain and allocate concentration field array.
*
* \param domain associated Domain object
*/
void setDiscretization(Domain const & domain);
/**
* Compute monomer concentration field, q and phi and/or mu.
*
* Upon return, cField, phi, mu, and q are all set.
*
* \param wField monomer chemical potential field of relevant type.
*/
void compute(WField const & wField );
/// \name Accessors (getters)
///@{
/**
* Return associated domain by reference.
*/
Domain const & domain() const;
/**
* Get monomer concentration field for this solvent.
*/
const CField& cField() const;
///@}
// Inherited accessor functions
using Pscf::Species::phi;
using Pscf::Species::mu;
using Pscf::Species::q;
using Pscf::Species::ensemble;
protected:
// Inherited data members
using Pscf::Species::phi_;
using Pscf::Species::mu_;
using Pscf::Species::q_;
using Pscf::Species::ensemble_;
using Pscf::SolventDescriptor::monomerId_;
using Pscf::SolventDescriptor::size_;
private:
// Concentration field for this solvent
CField cField_;
// Pointer to associated domain
Domain const * domainPtr_;
};
// Inline member functions
/// Get monomer concentration field for this solvent.
inline const typename Solvent::CField& Solvent::cField() const
{ return cField_; }
/// Get associated Domain by reference.
inline Domain const & Solvent::domain() const
{
UTIL_ASSERT(domainPtr_);
return *domainPtr_;
}
}
}
#endif
| 2,902
|
C++
|
.h
| 99
| 23.606061
| 75
| 0.643038
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,152
|
SweepParameter.h
|
dmorse_pscfpp/src/fd1d/sweep/SweepParameter.h
|
#ifndef FD1D_SWEEP_PARAMETER_H
#define FD1D_SWEEP_PARAMETER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/DArray.h>
#include <iostream>
using namespace Util;
namespace Pscf {
namespace Fd1d {
class System;
/**
* Class for storing data about an individual sweep parameter.
*
* This class stores the information required to sweep a single
* parameter value of any of several types. The type of parameter
* is indicated in the public interface and parameter file format
* by a string identifier with any of several allowed values.
* Each parameter is also identified by one or two associated index
* values, denoted here by id(0) and id(1), that specify the index
* or indices for a subobject or array element with which the
* parameter is associated applied. Allowed string representations
* and meanings of parameter types are given below, along with the
* meaning of any associated index value or pair of values.
* To indicate the meaning of index values, we use mId to denote
* a monomer type index, pId to denote a polymer species index,
* bId to denote the index of a block within a polymer, sId to
* denote a solvent species index, and lId to denote a lattice
* parameter index:
* \code
* | Type | Meaning | id(0) | id(1)
* | ----------- | --------------------------- | ----- | -----
* | kuhn | monomer segment length | mId |
* | chi | Flory-Huggins parameter | mId | mId
* | block | block length | pId | bId
* | solvent | solvent size | sId |
* | phi_polymer | polymer volume fraction | pId |
* | mu_polymer | polymer chemical potential | pId |
* | phi_solvent | solvent volume fraction | sId |
* | mu_solvent | solvent chemical potential | sId |
* \endcode
* The two indices for a Flory-Huggins chi parameter refer to indices
* in the chi matrix maintained by Interaction. Changes to element
* chi(i, j) automatically also update chi(j, i) for i !\ j, thus
* maintaining the symmetry of the matrix.
*
* Each SweepParameter also has a "change" value that gives the
* intended difference between the final and initial value of the
* parameter over the course of a sweep, corresponding to a change
* sweep parameter s over the range [0,1]. The initial value of each
* parameter is obtained from a query of the state of the parent
* system at the beginning of a sweep, and thus does not need to
* be supplied as part of the text format for a SweepParameter.
*
* A SweepParameter<D> object is initialized by reading the parameter
* type, index or index and change value from a parameter file as a
* a single line. An overloaded >> operator is defined that allows
* a SweepParameter<D> object named "parameter" to be read from an
* istream named "in" using the syntax "in >> parameter".
*
* The text format for a parameter of a type that requires a single
* index id(0) is:
*
* type id(0) change
*
* where type indicates a type string, id(0) is an integer index value,
* and change is the a floating point value for the change in parameter
* value. The corresponding format for a parameter that requires two
* indices (e.g., block or chi) is instead: "type id(0) id(1) change".
*
* \ingroup Fd1d_Sweep_Module
*/
class SweepParameter
{
public:
/**
* Default constructor.
*/
SweepParameter();
/**
* Constructor that stores a pointer to parent system.
*
* \param system parent system
*/
SweepParameter(System& system);
/**
* Set the system associated with this object.
*
* Invoke this function on objects created with the default
* constructor to create an association with a parent system.
*
* \param system parent system
*/
void setSystem(System& system)
{ systemPtr_ = &system;}
/**
* Store the pre-sweep value of the corresponding parameter.
*/
void getInitial();
/**
* Update the corresponding parameter value in the system.
*
* \param newVal new value for the parameter (input)
*/
void update(double newVal);
/**
* Return a string representation of the parameter type.
*/
std::string type() const;
/**
* Write the parameter type to an output stream.
*
* \param out output file stream
*/
void writeParamType(std::ostream& out) const;
/**
* Get a id for a sub-object or element to which this is applied.
*
* This function returns a value from the id_ array. Elements
* of this array store indices associating the parameter with
* a particular subobject or value. Different types of parameters
* require either 1 or 2 such identifiers. The number of required
* identifiers is denoted by private variable nID_.
*
* \param i array index to access
*/
int id(int i) const
{ return id_[i];}
/**
* Return the current system parameter value.
*/
double current()
{ return get_(); }
/**
* Return the initial system parameter value.
*/
double initial() const
{ return initial_; }
/**
* Return the total change planned for this parameter during sweep.
*/
double change() const
{ return change_; }
/**
* Serialize to or from an archive.
*
* \param ar Archive object
* \param version archive format version index
*/
template <class Archive>
void serialize(Archive ar, const unsigned int version);
private:
/// Enumeration of allowed parameter types.
enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
Mu_Polymer, Mu_Solvent, Solvent, Cell_Param, Null};
/// Type of parameter associated with an object of this class.
ParamType type_;
/// Number of identifiers needed for this parameter type.
int nID_;
/// Identifier indices.
DArray<int> id_;
/// Initial parameter value, retrieved from system at start of sweep.
double initial_;
/// Change in parameter
double change_;
/// Pointer to the parent system.
System* systemPtr_;
/**
* Read type of parameter being swept, and set number of identifiers.
*
* \param in input stream from param file.
*/
void readParamType(std::istream& in);
/**
* Gets the current system parameter value.
*/
double get_();
/**
* Set the system parameter value.
*
* \param newVal new value for this parameter.
*/
void set_(double newVal);
// friends:
friend
std::istream& operator >> (std::istream&, SweepParameter&);
friend
std::ostream&
operator << (std::ostream&, SweepParameter const &);
};
template <class Archive>
void SweepParameter::serialize(Archive ar, const unsigned int version)
{
serializeEnum(ar, type_, version);
ar & nID_;
for (int i = 0; i < nID_; ++i) {
ar & id_[i];
}
ar & initial_;
ar & change_;
}
}
}
#endif
| 7,570
|
C++
|
.h
| 207
| 30.705314
| 75
| 0.63655
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,153
|
SweepFactory.h
|
dmorse_pscfpp/src/fd1d/sweep/SweepFactory.h
|
#ifndef FD1D_SWEEP_FACTORY_H
#define FD1D_SWEEP_FACTORY_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/Factory.h>
#include "Sweep.h"
#include <string>
namespace Pscf {
namespace Fd1d {
using namespace Util;
/**
* Default Factory for subclasses of Sweep.
*
* \ingroup Fd1d_Sweep_Module
*/
class SweepFactory : public Factory<Sweep>
{
public:
/**
* Constructor.
*
* \param system parent System object
*/
SweepFactory(System& system);
/**
* Method to create any Sweep subclass.
*
* \param className name of the Sweep subclass
* \return Sweep* pointer to new instance of speciesName
*/
Sweep* factory(std::string const & className) const;
private:
System* systemPtr_;
};
}
}
#endif
| 974
|
C++
|
.h
| 41
| 19.512195
| 67
| 0.672826
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,154
|
LinearSweep.h
|
dmorse_pscfpp/src/fd1d/sweep/LinearSweep.h
|
#ifndef FD1D_LINEAR_SWEEP_H
#define FD1D_LINEAR_SWEEP_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Sweep.h" // base class
#include "SweepParameter.h" // member
#include <util/containers/DArray.h>
#include <util/global.h>
#include <iostream>
namespace Pscf {
namespace Fd1d {
class System;
using namespace Util;
/**
* Base class for a sweep in parameter space where parameters change
* linearly with the sweep variable.
*
* \ref user_param_sweep_linear_sec "Parameter File Format"
* \ingroup Fd1d_Sweep_Module
*/
class LinearSweep : public Sweep
{
public:
/**
* Constructor.
* \param system parent System object
*/
LinearSweep(System& system);
/**
* Read parameters from param file.
*
* \param in Input stream from param file.
*/
void readParameters(std::istream& in);
/**
* Setup operation at the beginning of a sweep. Gets initial
* values of individual parameters.
*/
void setup();
/**
* Set the state before an iteration. Called with each new iteration
* in SweepTempl::sweep()
*
* \param s path length coordinate, in [0,1]
*/
void setParameters(double s);
/**
* Output data to a running summary.
*
* \param out output file, open for writing
*/
void outputSummary(std::ostream& out);
protected:
using Sweep::system;
private:
/// Number of parameters being swept.
int nParameter_;
/// Array of SweepParameter objects.
DArray< SweepParameter > parameters_;
};
}
}
#endif
| 1,848
|
C++
|
.h
| 67
| 22.253731
| 74
| 0.638334
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,155
|
Sweep.h
|
dmorse_pscfpp/src/fd1d/sweep/Sweep.h
|
#ifndef FD1D_SWEEP_H
#define FD1D_SWEEP_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/sweep/SweepTmpl.h> // base class
#include <fd1d/SystemAccess.h> // base class
#include <fd1d/misc/HomogeneousComparison.h> // member
#include <fd1d/misc/FieldIo.h> // member
#include <util/containers/DArray.h> // member
#include <util/global.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/**
* Solve a sequence of problems along a line in parameter space.
*
* \ingroup Fd1d_Sweep_Module
*/
class Sweep : public SweepTmpl< DArray<System::WField> >,
public SystemAccess
{
public:
typedef DArray<System::WField> State;
typedef SweepTmpl<State> Base;
/**
* Constructor.
*
* \param system parent System object.
*/
Sweep(System& system);
/**
* Destructor.
*/
~Sweep();
/**
* Read ns and baseFileName parameters.
*
* \param in input stream
*/
virtual void readParameters(std::istream& in);
/**
* Output information after obtaining a converged solution.
*
* \param stateFileName base name of output files
*/
virtual void outputSolution(std::string const & stateFileName);
/**
* Output data to a running summary.
*
* \param outFile output log file, open for writing
*/
virtual void outputSummary(std::ostream& outFile);
protected:
/// Mode for comparison to homogeneous system (none -> -1)
int homogeneousMode_;
/**
* Check allocation of w fields in one state, allocate if needed.
*
* \param state one stored state of the system.
*/
virtual void checkAllocation(State & state);
/**
* Setup operation at beginning sweep.
*/
virtual void setup();
/**
* Set non-adjustable system parameters to new values.
*
* \param s new value of contour coordinate, in range [0,1]
*/
virtual void setParameters(double s);
/**
* Create initial guess for new w fields by polynomial extrapolation.
*
* \param s new value of contour coordinate, in range [0,1]
*/
virtual void extrapolate(double s);
/**
* Call the current iterator to solve one SCFT problem.
*
* Return 0 for sucessful solution, 1 on failure to converge.
*/
virtual int solve(bool isContinuation);
/**
* Reset system to previous solution after iterature failure.
*
* The implementation of this function resets the system state to
* correspond to that stored in state(0).
*/
virtual void reset();
/**
* Update state(0) and output data after successful convergence
*
* The implementation of this function should copy the current
* system state into state(0) and output any desired information
* about the current converged solution.
*/
virtual void getSolution();
/**
* Close log file after end of sweep.
*/
virtual void cleanup();
private:
/// Algorithm for comparing to a homogeneous system
HomogeneousComparison comparison_;
/// FieldIo object for writing output files
FieldIo fieldIo_;
/// Summary log file
std::ofstream logFile_;
/// Assign state rhs = lhs
void assignFields(State& lhs, State const & rhs) const;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 3,724
|
C++
|
.h
| 120
| 24.958333
| 74
| 0.632242
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,156
|
SystemTest.h
|
dmorse_pscfpp/src/fd1d/tests/SystemTest.h
|
#ifndef FD1D_SYSTEM_TEST_H
#define FD1D_SYSTEM_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <fd1d/System.h>
#include <fd1d/domain/Domain.h>
#include <fd1d/solvers/Mixture.h>
#include <fd1d/iterator/Iterator.h>
#include <fd1d/misc/FieldIo.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Fd1d;
class SystemTest : public UnitTest
{
private:
std::ofstream logFile_;
public:
void setUp()
{}
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
ParamComponent::setEcho(false);
setVerbose(0);
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
ParamComponent::setEcho(true);
}
void testConstructor()
{
printMethod(TEST_FUNC);
System sys;
}
void testReadParameters()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestReadParameters.log");
std::ifstream in;
openInputFile("in/planar_nr1.prm", in);
System sys;
sys.readParam(in);
Log::file() << "\n";
sys.writeParam(Log::file());
TEST_ASSERT(sys.domain().mode() == Planar);
}
void testSolveMdePlanar()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestSolveMdePlanar.log");
std::ifstream in;
openInputFile("in/planar_nr1.prm", in);
System sys;
sys.readParam(in);
Log::file() << "\n";
sys.writeParam(Log::file());
Mixture& mix = sys.mixture();
Domain& domain = sys.domain();
double nx = (double)domain.nx();
double cs;
for (int i = 0; i < nx; ++i) {
cs = cos(2.0*Constants::Pi*(double(i)+0.5)/double(nx-1));
sys.wField(0)[i] = 0.5 + cs;
sys.wField(1)[i] = 0.7 - cs;
}
mix.compute(sys.wFields(), sys.cFields());
// Test if same Q is obtained from different methods
double q00 = mix.polymer(0).propagator(0, 0).computeQ();
double q01 = mix.polymer(0).propagator(0, 1).computeQ();
double q10 = mix.polymer(0).propagator(1, 0).computeQ();
double q11 = mix.polymer(0).propagator(1, 1).computeQ();
setVerbose(1);
if (verbose() > 0) {
Log::file() << q00 << "\n";
Log::file() << q01 << "\n";
Log::file() << q10 << "\n";
Log::file() << q11 << "\n";
}
UTIL_ASSERT(abs((q01 - q00)/q00) < 1.0E-6);
UTIL_ASSERT(abs((q10 - q00)/q00) < 1.0E-6);
UTIL_ASSERT(abs((q11 - q00)/q00) < 1.0E-6);
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(sys.cField(0));
double sum1 = domain.spatialAverage(sys.cField(1));
Log::file() << "Volume fraction of block 0 = " << sum0 << "\n";
Log::file() << "Volume fraction of block 1 = " << sum1 << "\n";
TEST_ASSERT(eq(mix.polymer(0).length(), 5.0));
}
void testSolveMdeSpherical()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestSolveMdeSpherical.log");
std::ifstream in;
openInputFile("in/spherical_nr1.prm", in);
System sys;
sys.readParam(in);
TEST_ASSERT( !sys.domain().isShell() );
Log::file() << "\n";
sys.writeParam(Log::file());
Mixture& mix = sys.mixture();
Domain& domain = sys.domain();
double nx = (double)domain.nx();
double cs;
for (int i = 0; i < nx; ++i) {
cs = cos(2.0*Constants::Pi*double(i)/double(nx-1));
sys.wField(0)[i] = -cs;
sys.wField(1)[i] = +cs;
}
mix.compute(sys.wFields(), sys.cFields());
// Test if same Q is obtained from different methods
Log::file() << mix.polymer(0).propagator(0, 0).computeQ() << "\n";
Log::file() << mix.polymer(0).propagator(1, 0).computeQ() << "\n";
Log::file() << mix.polymer(0).propagator(1, 1).computeQ() << "\n";
Log::file() << mix.polymer(0).propagator(0, 1).computeQ() << "\n";
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(sys.cField(0));
double sum1 = domain.spatialAverage(sys.cField(1));
Log::file() << "Volume fraction of block 0 = " << sum0 << "\n";
Log::file() << "Volume fraction of block 1 = " << sum1 << "\n";
}
/*
* Test NR iterator on input field generated within function.
*/
void testIteratorPlanarNr1()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorPlanarNr1.log");
std::ifstream in;
openInputFile("in/planar_nr2.prm", in);
System sys;
sys.readParam(in);
FieldIo fieldIo;
fieldIo.associate(sys.domain(), sys.fileMaster());
Log::file() << "\n";
sys.writeParam(Log::file());
Mixture& mix = sys.mixture();
Domain& domain = sys.domain();
double nx = (double)domain.nx();
double cs;
double chi = 20.0;
for (int i = 0; i < nx; ++i) {
cs = cos(Constants::Pi*double(i)/double(nx-1));
sys.wField(0)[i] = chi*(-0.5*cs + 0.25*cs*cs);
sys.wField(1)[i] = chi*(+0.5*cs + 0.25*cs*cs);
}
double shift = sys.wField(1)[nx-1];
for (int i = 0; i < nx; ++i) {
sys.wField(0)[i] -= shift;
sys.wField(1)[i] -= shift;
}
// Compute initial state
mix.compute(sys.wFields(), sys.cFields());
std::ofstream out;
openOutputFile("out/initialPlanarNr1.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/initialPlanarNr1.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
sys.iterator().solve();
openOutputFile("out/finalPlanarNr1.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/finalPlanarNr1.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
}
/*
* Test NR iterator on input w field read from file.
*/
void testIteratorPlanarNr2()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorPlanarNr2.log");
std::ifstream in;
openInputFile("in/planar_nr2.prm", in);
System sys;
sys.readParam(in);
in.close();
FieldIo fieldIo;
fieldIo.associate(sys.domain(), sys.fileMaster());
Log::file() << "\n";
// sys.writeParam(Log::file());
openInputFile("in/planar.w", in);
fieldIo.readFields(sys.wFields(), in);
in.close();
sys.iterator().solve();
std::ofstream out;
out.open("out/planarNr2.c");
fieldIo.writeFields(sys.cFields(), out);
out.close();
}
/*
* Test NR iterator controlled by a command file.
*/
void testIteratorPlanarNr3()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorPlanarNr3.log");
System sys;
std::ifstream in;
Log::file() << "\n";
openInputFile("in/planar_nr2.prm", in);
sys.readParam(in);
in.close();
// Set System filemaster prefixes to unit test file prefix
sys.fileMaster().setInputPrefix(filePrefix());
sys.fileMaster().setOutputPrefix(filePrefix());
openInputFile("in/planar_nr.cmd", in);
sys.readCommands(in);
in.close();
}
/*
* Test NR iterator on input field generated within function.
*/
void testIteratorSphericalNr1()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorSphericalNr1.log");
std::ifstream in;
openInputFile("in/spherical_nr1.prm", in);
System sys;
sys.readParam(in);
Log::file() << "\n";
sys.writeParam(Log::file());
Mixture& mix = sys.mixture();
Domain& domain = sys.domain();
FieldIo fieldIo;
fieldIo.associate(sys.domain(), sys.fileMaster());
// Create initial chemical potential fields
double nx = (double)domain.nx();
double cs;
double chi = 80.0;
for (int i = 0; i < nx; ++i) {
cs = cos(Constants::Pi*double(i)/double(nx-1));
sys.wField(0)[i] = -chi*cs/2.0;
sys.wField(1)[i] = +chi*cs/2.0;
}
double shift = sys.wField(1)[nx-1];
for (int i = 0; i < nx; ++i) {
sys.wField(0)[i] -= shift;
sys.wField(1)[i] -= shift;
}
// Solve MDE for initial fields
mix.compute(sys.wFields(), sys.cFields());
Log::file() << "Average fraction 0 = "
<< domain.spatialAverage(sys.cField(0)) << "\n";
Log::file() << "Average fraction 1 = "
<< domain.spatialAverage(sys.cField(1)) << "\n";
std::ofstream out;
openOutputFile("out/initialSphericalNr1.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/initialSphericalNr1.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
sys.iterator().solve();
openOutputFile("out/finalSphericalNr1.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/finalSphericalNr1.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
}
void testIteratorSphericalNr3()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorSphericalNr3.log");
System sys;
std::ifstream in;
Log::file() << "\n";
openInputFile("in/spherical_nr2.prm", in);
sys.readParam(in);
in.close();
TEST_ASSERT(!sys.domain().isShell());
// Set System filemaster prefixes to unit test file prefix
sys.fileMaster().setInputPrefix(filePrefix());
sys.fileMaster().setOutputPrefix(filePrefix());
openInputFile("in/spherical_nr.cmd", in);
sys.readCommands(in);
in.close();
}
void testIteratorPlanarAm1()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorPlanarAm.log");
std::ifstream in;
openInputFile("in/planar_am2.prm", in);
System sys;
sys.readParam(in);
FieldIo fieldIo;
fieldIo.associate(sys.domain(), sys.fileMaster());
Log::file() << "\n";
sys.writeParam(Log::file());
Mixture& mix = sys.mixture();
Domain& domain = sys.domain();
double nx = (double)domain.nx();
double cs;
double chi = 20.0;
for (int i = 0; i < nx; ++i) {
cs = cos(Constants::Pi*double(i)/double(nx-1));
sys.wField(0)[i] = chi*(-0.5*cs + 0.25*cs*cs);
sys.wField(1)[i] = chi*(+0.5*cs + 0.25*cs*cs);
}
double shift = sys.wField(1)[nx-1];
for (int i = 0; i < nx; ++i) {
sys.wField(0)[i] -= shift;
sys.wField(1)[i] -= shift;
}
// Compute initial state
mix.compute(sys.wFields(), sys.cFields());
std::ofstream out;
openOutputFile("out/initialPlanarAm.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/initialPlanarAm.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
sys.iterator().solve();
openOutputFile("out/finalPlanarAm.w", out);
fieldIo.writeFields(sys.wFields(), out);
out.close();
openOutputFile("out/finalPlanarAm.c", out);
fieldIo.writeFields(sys.cFields(), out);
out.close();
}
/*
* Test AM iterator controlled by a command file.
*/
void testIteratorPlanarAm3()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestIteratorPlanarAm3.log");
System sys;
std::ifstream in;
Log::file() << "\n";
openInputFile("in/planar_am2.prm", in);
sys.readParam(in);
in.close();
// Set System filemaster prefixes to unit test file prefix
sys.fileMaster().setInputPrefix(filePrefix());
sys.fileMaster().setOutputPrefix(filePrefix());
openInputFile("in/planar_am.cmd", in);
sys.readCommands(in);
in.close();
}
void testSweepSpherical()
{
printMethod(TEST_FUNC);
openLogFile("out/SystemTestSweepSpherical.log");
System sys;
std::ifstream in;
Log::file() << "\n";
openInputFile("in/spherical3_nr.prm", in);
sys.readParam(in);
in.close();
sys.writeParam(Log::file());
TEST_ASSERT( !sys.domain().isShell() );
// Set System filemaster prefixes to unit test file prefix
sys.fileMaster().setInputPrefix(filePrefix());
sys.fileMaster().setOutputPrefix(filePrefix());
openInputFile("in/sphericalSweep.cmd", in);
sys.readCommands(in);
in.close();
}
};
TEST_BEGIN(SystemTest)
TEST_ADD(SystemTest, testConstructor)
TEST_ADD(SystemTest, testReadParameters)
TEST_ADD(SystemTest, testSolveMdePlanar)
TEST_ADD(SystemTest, testSolveMdeSpherical)
TEST_ADD(SystemTest, testIteratorPlanarNr1)
TEST_ADD(SystemTest, testIteratorPlanarNr2)
TEST_ADD(SystemTest, testIteratorPlanarNr3)
TEST_ADD(SystemTest, testIteratorSphericalNr1)
TEST_ADD(SystemTest, testIteratorSphericalNr3)
TEST_ADD(SystemTest, testIteratorPlanarAm1)
TEST_ADD(SystemTest, testIteratorPlanarAm3)
TEST_ADD(SystemTest, testSweepSpherical)
TEST_END(SystemTest)
#endif
| 13,138
|
C++
|
.h
| 386
| 27.46114
| 72
| 0.611441
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,157
|
MixtureTest.h
|
dmorse_pscfpp/src/fd1d/tests/MixtureTest.h
|
#ifndef FD1D_MIXTURE_TEST_H
#define FD1D_MIXTURE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <fd1d/solvers/Mixture.h>
#include <util/tests/LogFileUnitTest.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Fd1d;
class MixtureTest : public LogFileUnitTest
{
public:
void setUp()
{ ParamComponent::setEcho(true); }
void tearDown()
{
closeLogFile();
ParamComponent::setEcho(false);
}
void testConstructor()
{
printMethod(TEST_FUNC);
Mixture mix;
}
void testReadParameters()
{
printMethod(TEST_FUNC);
openLogFile("out/MixtureTestReadParameters.log");
std::ifstream in;
openInputFile("in/Mixture", in);
Mixture mix;
mix.readParam(in);
Domain domain;
domain.readParam(in);
mix.setDomain(domain);
Log::file() << "\n";
mix.writeParam(Log::file());
domain.writeParam(Log::file());
}
void testReadParameters2()
{
printMethod(TEST_FUNC);
openLogFile("out/MixtureTestReadParameters2.log");
std::ifstream in;
openInputFile("in/Mixture2", in);
Mixture mix;
mix.readParam(in);
Domain domain;
domain.readParam(in);
mix.setDomain(domain);
TEST_ASSERT(eq(mix.vMonomer(), 0.05));
Log::file() << "\n";
mix.writeParam(Log::file());
domain.writeParam(Log::file());
}
void testSolve()
{
printMethod(TEST_FUNC);
openLogFile("out/MixtureTestSolve.log");
std::ifstream in;
openInputFile("in/Mixture", in);
Mixture mix;
Domain domain;
mix.readParam(in);
domain.readParam(in);
mix.setDomain(domain);
Log::file() << "\n";
mix.writeParam(Log::file());
domain.writeParam(Log::file());
int nMonomer = mix.nMonomer();
DArray<Mixture::WField> wFields;
DArray<Mixture::CField> cFields;
wFields.allocate(nMonomer);
cFields.allocate(nMonomer);
double nx = (double)domain.nx();
for (int i = 0; i < nMonomer; ++i) {
wFields[i].allocate(nx);
cFields[i].allocate(nx);
}
double cs;
for (int i = 0; i < nx; ++i) {
//cs = cos(2.0*Constants::Pi*(double(i)+0.5)/nx);
cs = cos(2.0*Constants::Pi*double(i)/double(nx-1));
wFields[0][i] = 0.5 + cs;
wFields[1][i] = 0.5 - cs;
}
mix.compute(wFields, cFields);
double q00 = mix.polymer(0).propagator(0, 0).computeQ();
double q01 = mix.polymer(0).propagator(0, 1).computeQ();
double q10 = mix.polymer(0).propagator(1, 0).computeQ();
double q11 = mix.polymer(0).propagator(1, 1).computeQ();
TEST_ASSERT(abs(q01 - q00) < 1.0E-5);
TEST_ASSERT(abs(q10 - q00) < 1.0E-5);
TEST_ASSERT(abs(q11 - q00) < 1.0E-5);
// Test if same Q is obtained from different methods
Log::file() << "Propagator(0,0), Q = " << q00 << "\n";
Log::file() << "Propagator(0,1), Q = " << q10 << "\n";
Log::file() << "Propagator(1,0), Q = " << q01 << "\n";
Log::file() << "Propagator(0,1), Q = " << q11 << "\n";
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(cFields[0]);
double sum1 = domain.spatialAverage(cFields[1]);
Log::file() << "Volume fraction of block 0 = " << sum0 << "\n";
Log::file() << "Volume fraction of block 1 = " << sum1 << "\n";
}
};
TEST_BEGIN(MixtureTest)
TEST_ADD(MixtureTest, testConstructor)
TEST_ADD(MixtureTest, testReadParameters)
TEST_ADD(MixtureTest, testReadParameters2)
TEST_ADD(MixtureTest, testSolve)
TEST_END(MixtureTest)
#endif
| 3,696
|
C++
|
.h
| 114
| 26.473684
| 69
| 0.616817
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,158
|
Fd1dTestComposite.h
|
dmorse_pscfpp/src/fd1d/tests/Fd1dTestComposite.h
|
#ifndef FD1D_TEST_COMPOSITE_H
#define FD1D_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "DomainTest.h"
#include "PropagatorTest.h"
#include "MixtureTest.h"
#include "SystemTest.h"
TEST_COMPOSITE_BEGIN(Fd1dTestComposite)
TEST_COMPOSITE_ADD_UNIT(DomainTest);
TEST_COMPOSITE_ADD_UNIT(PropagatorTest);
TEST_COMPOSITE_ADD_UNIT(MixtureTest);
TEST_COMPOSITE_ADD_UNIT(SystemTest);
TEST_COMPOSITE_END
#endif
| 422
|
C++
|
.h
| 14
| 28.857143
| 40
| 0.834158
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,159
|
PropagatorTest.h
|
dmorse_pscfpp/src/fd1d/tests/PropagatorTest.h
|
#ifndef FD1D_PROPAGATOR_TEST_H
#define FD1D_PROPAGATOR_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <fd1d/domain/Domain.h>
#include <fd1d/solvers/Block.h>
#include <fd1d/solvers/Propagator.h>
#include <util/math/Constants.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Fd1d;
class PropagatorTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Block block;
}
/*
* Test solution for a homogeneous field, homogeneous initial condition.
*/
void testPlanarSolve1()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMin = 0.0;
double xMax = 1.0;
int nx = 11;
Domain domain;
domain.setPlanarParameters(xMin, xMax, nx);
TEST_ASSERT(eq(domain.volume(), xMax - xMin));
// Create and initialize block
Block b;
b.setId(0);
double length = 2.0;
double ds = 0.02;
double step = sqrt(6.0);
b.setLength(length);
b.setMonomerId(1);
b.setKuhn(step);
b.setDiscretization(domain, ds);
// Create W field
DArray<double> w;
w.allocate(nx);
double wc = 0.3;
for (int i = 0; i < nx; ++i) {
w[i] = wc;
}
// Solve
b.setupSolver(w);
b.propagator(0).solve();
//std::cout << "\n Head:\n";
for (int i = 0; i < nx; ++i) {
TEST_ASSERT(abs(b.propagator(0).head()[i] - 1.0) < 1.0E-8);
//std::cout << " " << b.propagator(0).head()[i];
}
//std::cout << "\n";
//std::cout << "\n Tail:\n";
double expected = exp(-wc*b.length());
for (int i = 0; i < nx; ++i) {
//std::cout << " " << b.propagator(0).tail()[i];
TEST_ASSERT(abs(b.propagator(0).tail()[i] - expected) < 1.0E-5);
}
//std::cout << "\n";
//std::cout << exp(-wc*b.length()) << "\n";
}
/*
* Test for a homogeneous field, sinusoidal initial condition.
*/
void testPlanarSolve2()
{
printMethod(TEST_FUNC);
// Setup Domain
double xMin = 0.0;
double xMax = 1.0;
int nx = 33;
Domain domain;
domain.setPlanarParameters(xMin, xMax, nx);
TEST_ASSERT(eq(domain.volume(), xMax - xMin));
// Setup Block
Block b;
double length = 0.5;
double ds = 0.00005;
double step = 1.0;
b.setId(0);
b.setMonomerId(1);
b.setLength(length);
b.setKuhn(step);
b.setDiscretization(domain, ds);
DArray<double> q, w;
q.allocate(nx);
w.allocate(nx);
double wc = 0.5;
for (int i = 0; i < nx; ++i) {
q[i] = cos(2.0*Constants::Pi*double(i)/double(nx-1));
w[i] = wc;
}
b.setupSolver(w);
b.propagator(0).solve(q);
#if 0
std::cout << "\n Head:\n";
for (int i = 0; i < nx; ++i) {
std::cout << " " << b.propagator(0).head()[i];
}
std::cout << "\n";
#endif
double dx = (xMax - xMin)/double(nx - 1);
double k = 2.0*sin(Constants::Pi/double(nx-1))/dx;
double f = k*k*step*step/6.0 + wc;
double expected = exp(-f*length);
//std::cout << "\n Tail:\n";
double head, tail, ratio;
for (int i = 0; i < nx; ++i) {
head = b.propagator(0).head()[i];
if (abs(head) > 1.0E-6) {
tail = b.propagator(0).tail()[i];
ratio = tail/head;
//std::cout << " " << ratio ;
TEST_ASSERT( abs(ratio - expected) < 1.0E-5 );
}
}
//std::cout << "\n";
//std::cout << expected << "\n";
//std::cout << "\n";
}
void testCylinderSolve1()
{
printMethod(TEST_FUNC);
// Setup Domain
//double xMin = 0.0;
double xMax = 1.0;
int nx = 33;
Domain domain;
domain.setCylinderParameters(xMax, nx);
double volume = Constants::Pi*xMax*xMax;
TEST_ASSERT(eq(domain.volume(), volume));
// Setup Block
Block b;
double length = 0.5;
double ds = 0.00005;
double step = 1.0;
b.setId(0);
b.setMonomerId(1);
b.setLength(length);
b.setKuhn(step);
b.setDiscretization(domain, ds);
int ns = b.ns();
// Create example W field and initial q field
DArray<double> q, w;
q.allocate(nx);
w.allocate(nx);
double wc = 0.5;
for (int i = 0; i < nx; ++i) {
q[i] = 1.0;
w[i] = wc;
}
b.setupSolver(w);
b.propagator(0).solve(q);
//std::cout << "\n";
double final = exp(-length*wc);
double value;
for (int i = 0; i < nx; ++i) {
value = b.propagator(0).tail()[i];
// std::cout << " " << value;
TEST_ASSERT(eq(value, final));
}
// std::cout << "\n";
int m = ns/2;
double sum0 = domain.spatialAverage( b.propagator(0).tail() );
double sum1 = domain.innerProduct( b.propagator(0).q(m),
b.propagator(0).q(ns-1-m) );
TEST_ASSERT(eq(sum0, sum1));
//std::cout << "Average m eq 0 " << sum0 << "\n";
//std::cout << "Average m neq 0 " << sum1 << "\n";
}
void testCylinderSolve2()
{
printMethod(TEST_FUNC);
// Setup Domain
//double xMin = 0.0;
double xMax = 1.0;
int nx = 33;
Domain domain;
domain.setCylinderParameters(xMax, nx);
double volume = Constants::Pi*xMax*xMax;
TEST_ASSERT(eq(domain.volume(), volume));
// Setup Block
Block b;
double length = 0.5;
double ds = 0.00005;
double step = 1.0;
b.setId(0);
b.setMonomerId(1);
b.setLength(length);
b.setKuhn(step);
b.setDiscretization(domain, ds);
int ns = b.ns();
// Create W and initial q fields
DArray<double> q, w;
q.allocate(nx);
w.allocate(nx);
double wc = 0.5;
for (int i = 0; i < nx; ++i) {
q[i] = 1.0;
w[i] = wc*cos(2.0*Constants::Pi*double(i)/double(nx-1));
}
b.setupSolver(w);
b.propagator(0).solve(q);
int m = ns/2;
double sum0 = domain.spatialAverage( b.propagator(0).tail() );
double sum1 = domain.innerProduct( b.propagator(0).q(m),
b.propagator(0).q(ns-1-m) );
// std::cout << "Average m eq 0 " << sum0 << "\n";
// std::cout << "Average m neq 0 " << sum1 << "\n";
TEST_ASSERT(eq(sum0, sum1));
}
void testSphereSolve1()
{
printMethod(TEST_FUNC);
// Setup Domain
//double xMin = 0.0;
double xMax = 1.0;
int nx = 33;
Domain domain;
domain.setSphereParameters(xMax, nx);
double volume = 4.0*Constants::Pi*xMax*xMax*xMax/3.0;
TEST_ASSERT(eq(domain.volume(), volume));
// Setup Block
Block b;
double length = 0.5;
double ds = 0.00005;
double step = 1.0;
b.setId(0);
b.setMonomerId(1);
b.setLength(length);
b.setKuhn(step);
b.setDiscretization(domain, ds);
int ns = b.ns();
// Setup W and Initial Q
DArray<double> q, w;
q.allocate(nx);
w.allocate(nx);
double wc = 0.5;
for (int i = 0; i < nx; ++i) {
q[i] = 1.0;
w[i] = wc;
}
b.setupSolver(w);
b.propagator(0).solve(q);
// std::cout << "\n";
double final = exp(-length*wc);
double value;
for (int i = 0; i < nx; ++i) {
value = b.propagator(0).tail()[i];
// std::cout << " " << value;
TEST_ASSERT(eq(value, final));
}
// std::cout << "\n";
int m = ns/2;
double sum0 = domain.spatialAverage( b.propagator(0).tail() );
double sum1 = domain.innerProduct( b.propagator(0).q(m),
b.propagator(0).q(ns-1-m) );
TEST_ASSERT(eq(sum0, sum1));
//std::cout << "Average m eq 0 " << sum0 << "\n";
//std::cout << "Average m neq 0 " << sum1 << "\n";
}
void testSphereSolve2()
{
printMethod(TEST_FUNC);
// Setup Domain
//double xMin = 0.0;
double xMax = 1.0;
int nx = 33;
Domain domain;
domain.setSphereParameters(xMax, nx);
double volume = 4.0*Constants::Pi*xMax*xMax*xMax/3.0;
TEST_ASSERT(eq(domain.volume(), volume));
Block b;
double length = 0.5;
double ds = 0.00005;
double step = 1.0;
b.setId(0);
b.setMonomerId(1);
b.setLength(length);
b.setKuhn(step);
b.setDiscretization(domain, ds);
int ns = b.ns();
DArray<double> q, w;
q.allocate(nx);
w.allocate(nx);
double wc = 0.5;
for (int i = 0; i < nx; ++i) {
q[i] = 1.0;
w[i] = wc*cos(2.0*Constants::Pi*double(i)/double(nx-1));
}
b.setupSolver(w);
b.propagator(0).solve(q);
int m = ns/2;
double sum0 = domain.spatialAverage( b.propagator(0).tail() );
double sum1 = domain.innerProduct( b.propagator(0).q(m),
b.propagator(0).q(ns-1-m) );
// std::cout << "Average m eq 0 " << sum0 << "\n";
// std::cout << "Average m neq 0 " << sum1 << "\n";
TEST_ASSERT(eq(sum0, sum1));
}
};
TEST_BEGIN(PropagatorTest)
TEST_ADD(PropagatorTest, testConstructor)
TEST_ADD(PropagatorTest, testPlanarSolve1)
TEST_ADD(PropagatorTest, testPlanarSolve2)
TEST_ADD(PropagatorTest, testCylinderSolve1)
TEST_ADD(PropagatorTest, testCylinderSolve2)
TEST_ADD(PropagatorTest, testSphereSolve1)
TEST_ADD(PropagatorTest, testSphereSolve2)
TEST_END(PropagatorTest)
#endif
| 9,708
|
C++
|
.h
| 322
| 23.015528
| 74
| 0.537233
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,160
|
DomainTest.h
|
dmorse_pscfpp/src/fd1d/tests/DomainTest.h
|
#ifndef FD1D_DOMAIN_TEST_H
#define FD1D_DOMAIN_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <fd1d/domain/Domain.h>
#include <fd1d/domain/GeometryMode.h>
#include <util/math/Constants.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Fd1d;
class DomainTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
Domain domain;
}
void testPlanarVolume()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMin = 0.7;
double xMax = 2.5;
int nx = 101;
Domain domain;
domain.setPlanarParameters(xMin, xMax, nx);
TEST_ASSERT(eq(domain.volume(), xMax - xMin));
}
void testCylinderVolume()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMax = 2.0;
int nx = 101;
Domain domain;
domain.setCylinderParameters(xMax, nx);
double pi = Constants::Pi;
double volume = pi*xMax*xMax;
TEST_ASSERT(eq(domain.volume(), volume));
}
void testCylinderShellVolume()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMin = 1.5;
double xMax = 2.0;
int nx = 101;
Domain domain;
domain.setShellParameters(GeometryMode::Cylindrical, xMin, xMax, nx);
double pi = Constants::Pi;
double volume = pi*(xMax*xMax - xMin*xMin);
TEST_ASSERT(eq(domain.volume(), volume));
}
void testSphereVolume()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMax = 2.0;
int nx = 101;
Domain domain;
domain.setSphereParameters(xMax, nx);
double pi = Constants::Pi;
double volume = 4.0*pi*xMax*xMax*xMax/3.0;
TEST_ASSERT(eq(domain.volume(), volume));
}
void testSphericalShellVolume()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
double xMin = 1.5;
double xMax = 2.0;
int nx = 101;
Domain domain;
domain.setShellParameters(GeometryMode::Spherical, xMin, xMax, nx);
double pi = Constants::Pi;
double volume = 4.0*pi*(xMax*xMax*xMax - xMin*xMin*xMin)/3.0;
TEST_ASSERT(eq(domain.volume(), volume));
}
void testCylindricalAverageUniform()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
int nx = 101;
double xMax = 1.7;
//double dx = xMax/double(nx-1);
Domain domain;
domain.setCylinderParameters(xMax, nx);
DArray<double> f;
f.allocate(nx);
//double x;
double A = 1.3;
for (int i=0; i < nx; ++i) {
//x = dx*double(i);
f[i] = A;
}
if (verbose() > 0) {
std::cout << "\n A = " << A ;
std::cout << "\n Average = " << domain.spatialAverage(f);
}
TEST_ASSERT(eq(domain.spatialAverage(f), A));
}
void testSphericalAverageUniform()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
int nx = 101;
double xMax = 1.7;
//double dx = xMax/double(nx-1);
Domain domain;
domain.setSphereParameters(xMax, nx);
DArray<double> f;
f.allocate(nx);
//double x;
double A = 1.3;
for (int i=0; i < nx; ++i) {
//x = dx*double(i);
f[i] = A;
}
if (verbose() > 0) {
std::cout << "\n A = " << A ;
std::cout << "\n Average = " << domain.spatialAverage(f);
}
TEST_ASSERT(eq(domain.spatialAverage(f), A));
}
void testCylindricalAverageLinear()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
int nx = 801;
double xMax = 1.7;
double dx = xMax/double(nx-1);
Domain domain;
domain.setCylinderParameters(xMax, nx);
DArray<double> f;
f.allocate(nx);
double x;
double B = 0.7;
for (int i=0; i < nx; ++i) {
x = dx*double(i);
f[i] = B*x;
}
double computed = domain.spatialAverage(f);
double predicted = 2.0*B*xMax/3.0;
//setVerbose(1);
if (verbose() > 0) {
std::cout << "\n computed = " << computed;
std::cout << "\n predicted = " << predicted;
}
TEST_ASSERT(std::abs(computed - predicted) < 1.0E-4);
}
void testSphericalAverageLinear()
{
printMethod(TEST_FUNC);
// Create and initialize Domain
int nx = 801;
double xMax = 1.7;
double dx = xMax/double(nx-1);
Domain domain;
domain.setSphereParameters(xMax, nx);
DArray<double> f;
f.allocate(nx);
double x;
double B = 0.7;
for (int i=0; i < nx; ++i) {
x = dx*double(i);
f[i] = B*x;
}
double computed = domain.spatialAverage(f);
double predicted = 0.75*B*xMax;
//setVerbose(1);
if (verbose() > 0) {
std::cout << "\n computed = " << computed;
std::cout << "\n predicted = " << predicted;
}
TEST_ASSERT(std::abs(computed - predicted) < 1.0E-4);
}
};
TEST_BEGIN(DomainTest)
TEST_ADD(DomainTest, testConstructor)
TEST_ADD(DomainTest, testPlanarVolume)
TEST_ADD(DomainTest, testCylinderVolume)
TEST_ADD(DomainTest, testCylinderShellVolume)
TEST_ADD(DomainTest, testSphereVolume)
TEST_ADD(DomainTest, testSphericalShellVolume)
TEST_ADD(DomainTest, testCylindricalAverageUniform)
TEST_ADD(DomainTest, testSphericalAverageUniform)
TEST_ADD(DomainTest, testCylindricalAverageLinear)
TEST_ADD(DomainTest, testSphericalAverageLinear)
TEST_END(DomainTest)
#endif
| 5,650
|
C++
|
.h
| 196
| 22.75
| 75
| 0.607981
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,161
|
HomogeneousComparison.h
|
dmorse_pscfpp/src/fd1d/misc/HomogeneousComparison.h
|
#ifndef FD1D_HOMOGENEOUS_COMPARISON_H
#define FD1D_HOMOGENEOUS_COMPARISON_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <fd1d/SystemAccess.h> // base class
namespace Pscf {
namespace Fd1d {
/**
* Command to compute properties of homogeneous reference system.
*
* \ingroup Pscf_Fd1d_Module
*/
class HomogeneousComparison : public SystemAccess
{
public:
/**
* Default constructor.
*/
HomogeneousComparison();
/**
* Constructor.
*/
HomogeneousComparison(System& system);
/**
* Destructor.
*/
~HomogeneousComparison();
/**
* Compute properties of a homogeneous reference system.
*
* This function should be called after iterator().solve()
* to compute properties of a homogeneous reference system
* to which the properties of the system of interest can
* be compared. The value of the mode parameter controls
* the choice of homogeneous reference system used for this
* comparison.
*
* Mode parameter values:
*
* - mode = 0 : homogeneous system with same phi's
* - mode = 1,2 : homogeneous system with same mu's
*
* The difference between mode indices 1 and 2 is the
* initial guess used in the iterative computation of
* the composition of the homogeneous reference system:
*
* - mode = 1 : composition at last grid point (nx -1)
* - mode = 2 : composition at first grid point (0)
*
* Mode indices 1 and 2 are intended to be used for
* calculation of excess properties in, e.g., computation
* of properties of a micelle or an interface.
*
* \param mode mode index
*/
void compute(int mode);
/**
* Output comparison to a homogeneous reference system.
*
* \param mode mode index
* \param out output stream
*/
void output(int mode, std::ostream& out);
private:
/**
* Work array (size = # of grid points).
*/
DArray<double> f_;
/**
* Work array (size = # of monomer types).
*/
DArray<double> c_;
/**
* Work array (size = # of molecular species).
*/
DArray<double> p_;
/**
* Work array (size = # of molecular species).
*/
DArray<double> m_;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 2,599
|
C++
|
.h
| 88
| 23.579545
| 67
| 0.617482
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,162
|
FieldIo.h
|
dmorse_pscfpp/src/fd1d/misc/FieldIo.h
|
#ifndef FD1D_FIELD_IO_H
#define FD1D_FIELD_IO_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/containers/DArray.h> // member
namespace Util { class FileMaster; }
namespace Pscf {
namespace Fd1d {
class Domain;
class Mixture;
using namespace Util;
/**
* Read and write fields to file.
*
* \ingroup Pscf_Fd1d_Module
*/
class FieldIo
{
public:
typedef DArray<double> Field;
/**
* Constructor.
*/
FieldIo();
/**
* Destructor.
*/
~FieldIo();
/**
* Get and store addresses of associated objects.
*
* \param domain associated spatial domain
* \param fileMaster associated FileMaster (for file paths)
*/
void associate(Domain const & domain,
FileMaster const & fileMaster);
/**
* Read a set of fields, one per monomer type.
*
* \pre File in must be open for reading.
*
* \param fields array of fields to read, indexed by monomer id
* \param in input stream, open for reading.
*/
void readFields(DArray<Field>& fields, std::istream &in);
/**
* Read a set of fields, one per monomer type.
*
* This function uses the associated FileMaster to open an input
* file named filename before reading, and closes the file after
* reading.
*
* \param fields array of fields to read, indexed by monomer id.
* \param filename name of input file
*/
void readFields(DArray<Field>& fields, std::string const& filename);
/**
* Write a single field to an output stream.
*
* \pre Stream out must be open for writing.
*
* \param field field defined on r-space grid (input)
* \param out output stream
* \param writeHeader write file header iff this bool is true
*/
void writeField(Field const& field, std::ostream& out,
bool writeHeader = true) const;
/**
* Write a single field to a file.
*
* This function uses the associated FileMaster to open an output
* file named filename before writing, and closes the file after
* writing.
*
* \param field field defined on r-space grid (input)
* \param filename output filename
* \param writeHeader write file header iff this bool is true
*/
void writeField(Field const& field, std::string const& filename,
bool writeHeader= true) const;
/**
* Write a set of fields, one per monomer type, to an output stream.
*
* \pre Stream out must be open for writing.
*
* \param fields set of fields to written.
* \param out output stream
* \param writeHeader write file header iff this bool is true
*/
void writeFields(DArray<Field> const& fields, std::ostream& out,
bool writeHeader= true);
/**
* Write a set of fields, one per monomer type, to a named file.
*
* This function uses the associated FileMaster to open an output
* file named filename before writing, and closes the file after
* writing.
*
* \param fields array of fields to read, indexed by monomer id
* \param filename output filename
* \param writeHeader write header iff this bool is true
*/
void writeFields(DArray<Field> const& fields,
std::string const& filename, bool writeHeader= true);
/**
* Write block concentration fields for all blocks to an output stream.
*
* \pre Stream out must be open for writing.
*
* \param mixture associated Mixture MDE solver object
* \param out output stream
*/
void writeBlockCFields(Mixture const& mixture, std::ostream& out);
/**
* Write block concentration fields for all blocks to a named file.
*
* This function uses the associated FileMaster to open an output
* file named filename before writing, and closes the file after
* writing.
*
*
* \param mixture associated Mixture MDE solver object
* \param filename name of output file
*/
void writeBlockCFields(Mixture const& mixture,
std::string const& filename);
/**
* Write product of incoming q fields for one vertex to stream.
*
* \pre Stream out must be open for writing.
*
* \param mixture associated Mixture MDE solver object
* \param polymerId integer id of polymer species
* \param vertexId integer id of vertex (end or junction)
* \param out output stream
*/
void writeVertexQ(Mixture const& mixture,
int polymerId, int vertexId, std::ostream& out);
/**
* Write incoming q fields for a specified vertex.
*
* \param mixture associated Mixture MDE solver object
* \param polymerId integer id of polymer species
* \param vertexId integer id of vertex (end or junction)
* \param filename name of output file
*/
void writeVertexQ(Mixture const& mixture,
int polymerId, int vertexId,
std::string const& filename);
/**
* Interpolate an array of fields onto a new mesh and write to stream.
*
* \param fields field to be remeshed
* \param nx number of grid points in new mesh
* \param out output stream for remeshed field
*/
void remesh(DArray<Field> const& fields, int nx, std::ostream& out);
/**
* Interpolate an array of fields onto a new mesh and write to file.
*
* \param fields field to be remeshed
* \param nx number of grid points in new mesh
* \param filename name of output file for remeshed field
*/
void remesh(DArray<Field> const& fields, int nx,
std::string const& filename);
/**
* Add points to the end of a field mesh and write to stream.
*
* Values at the added mesh points are taken to be the same as
* those at the last mesh point of the original mesh.
*
* \param fields array of fields to be extended
* \param m number of added grid points
* \param out output stream for extended field
*/
void extend(DArray<Field> const& fields, int m, std::ostream& out);
/**
* Add points to the end of a field mesh and write to a file.
*
* Values at the added mesh points are taken to be the same as
* those at the last mesh point of the original mesh.
*
* \param fields field to be remeshed
* \param m number of added grid points
* \param filename name of output file for remeshed field
*/
void extend(DArray<Field> const& fields, int m,
std::string const& filename);
private:
/// Work array (capacity = # of monomer types).
mutable DArray<double> w_;
// Pointers to associated objects.
/// Pointer to spatial discretization domain.
Domain const * domainPtr_;
/// Pointer to Filemaster (holds paths to associated I/O files).
FileMaster const * fileMasterPtr_;
// Private accessor functions:
/// Get spatial discretization domain by const reference.
Domain const& domain() const
{
UTIL_ASSERT(domainPtr_);
return *domainPtr_;
}
/// Get FileMaster by reference.
FileMaster const & fileMaster() const
{
UTIL_ASSERT(fileMasterPtr_);
return *fileMasterPtr_;
}
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 7,920
|
C++
|
.h
| 218
| 28.692661
| 76
| 0.622681
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,163
|
Domain.h
|
dmorse_pscfpp/src/fd1d/domain/Domain.h
|
#ifndef FD1D_DOMAIN_H
#define FD1D_DOMAIN_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include "GeometryMode.h" // member
#include <util/containers/DArray.h> // function parameter
namespace Pscf {
namespace Fd1d {
using namespace Util;
/**
* One-dimensional spatial domain and discretization grid.
*
* \ref fd1d_Domain_page "Parameter File Format"
* \ingroup Fd1d_Domain_Module
*/
class Domain : public ParamComposite
{
public:
/**
* Generic field type (base class)
*/
typedef DArray<double> Field;
/**
* Constructor.
*/
Domain();
/**
* Destructor.
*/
~Domain();
/// \name Initialize parameters
///@{
/**
* Read all parameters and initialize.
*/
void readParameters(std::istream& in);
/**
* Set grid parameters for a planar domain.
*
* \param xMin minimum normal coordinate value
* \param xMax maximum normal coordinate value
* \param nx number of grid points, including endpoints
*/
void setPlanarParameters(double xMin, double xMax, int nx);
/**
* Set grid parameters for a cylindrical or spherical shell.
*
* \param mode enumeration (Llamellar, Cylindrical or Spherical)
* \param xMin minimum radius
* \param xMax maximum radius
* \param nx number of grid points, including endpoints
*/
void setShellParameters(GeometryMode mode,
double xMin, double xMax,
int nx);
/**
* Set grid parameters for a cylinder.
*
* \param xMax maximum radius
* \param nx number of grid points, including endpoints
*/
void setCylinderParameters(double xMax, int nx);
/**
* Set grid parameters for a sphere.
*
* \param xMax maximum radius
* \param nx number of grid points, including endpoints
*/
void setSphereParameters(double xMax, int nx);
///@}
/// \name Accessors
///@{
/**
* Get minimum spatial coordinate.
*/
double xMin() const;
/**
* Get maximum spatial coordinate.
*/
double xMax() const;
/**
* Get generalized volume of domain.
*
* Returns volume of spherical domain, area of cylindrical
* domain, or a length of a planar domain.
*/
double volume() const;
/**
* Get spatial grid step size.
*/
double dx() const;
/**
* Get number of spatial grid points, including both endpoints.
*/
int nx() const;
/**
* Get coordinate system flag (Planar, Cylindrical or Spherical).
*/
GeometryMode const & mode() const;
/**
* Is this a cylindrical or spherical shell?
*
* This value is relevant only if the geometry mode is spherical or
* cylindrical. If so, isShell is set true if the optional parameter
* xMin is present and assigned a positive value in the parameter
* file. If geometryMode is planar or xMin is absent, then isShell
* is false.
*/
bool isShell() const;
///@}
/// \name Spatial integrals
///@{
/**
* Compute spatial average of a field.
*
* \param f a field that depends on one spatial coordinate
* \return spatial average of field f
*/
double spatialAverage(Field const & f) const;
/**
* Compute inner product of two real fields.
*
* \param f first field
* \param g second field
* \return spatial average of product of two fields.
*/
double innerProduct(Field const & f, Field const & g) const;
///@}
private:
/**
* Lower bound of spatial coordinate.
*/
double xMin_;
/**
* Upper bound of spatial coordinate.
*/
double xMax_;
/**
* Spatial discretization step.
*/
double dx_;
/**
* Generalized D-dimensional volume of simulation cell.
*/
double volume_;
/**
* Number of grid points.
*/
int nx_;
/**
* Coordinate system flag (=Planar, Cylindrical, or Spherical).
*/
GeometryMode mode_;
/**
* Is this a cylindrical or spherical shell?
*/
bool isShell_;
/**
* Work space vector.
*/
mutable DArray<double> work_;
/**
* Compute generalized volume, called by each set function.
*/
void computeVolume();
};
// Inline member functions
inline int Domain::nx() const
{ return nx_; }
inline double Domain::dx() const
{ return dx_; }
inline double Domain::xMin() const
{ return xMin_; }
inline double Domain::xMax() const
{ return xMax_; }
inline double Domain::volume() const
{ return volume_; }
inline GeometryMode const & Domain::mode() const
{ return mode_; }
inline bool Domain::isShell() const
{ return isShell_; }
} // namespace Fd1d
} // namespace Pscf
#endif
| 5,353
|
C++
|
.h
| 189
| 21.730159
| 73
| 0.595387
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,164
|
GeometryMode.h
|
dmorse_pscfpp/src/fd1d/domain/GeometryMode.h
|
#ifndef FD1D_GEOMETRY_MODE_H
#define FD1D_GEOMETRY_MODE_H
/*
* Simpatico - Simulation Package for Polymeric and Molecular Liquids
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/archives/serialize.h>
#include <iostream>
namespace Pscf{
namespace Fd1d
{
/**
* Enumeration of geometrical modes for functions of one coordinate.
*
* Allowed values are: Planar, Cylindrical Spherical.
*
* GeometryMode values can be read from or written to iostream using
* overloaded extractor (>>) and inserter (<<) operators. The text
* representations of the three values are "planar", "cylindrical" and
* "spherical".
*
* \ingroup Fd1d_Domain_Module
*/
enum GeometryMode {Planar, Cylindrical, Spherical};
/**
* istream extractor for a GeometryMode.
*
* \param in input stream
* \param mode GeometryMode to be read
* \return modified input stream
*/
std::istream& operator >> (std::istream& in, GeometryMode& mode);
/**
* ostream inserter for an GeometryMode.
*
* \param out output stream
* \param mode GeometryMode to be written
* \return modified output stream
*/
std::ostream& operator << (std::ostream& out, GeometryMode mode);
/**
* Serialize a GeometryMode value.
*
* \param ar archive object
* \param mode value to be serialized
* \param version archive version id
*/
template <class Archive>
void serialize(Archive& ar, GeometryMode& mode, const unsigned int version)
{ serializeEnum(ar, mode, version); }
}
}
#endif
| 1,660
|
C++
|
.h
| 55
| 26.909091
| 78
| 0.705698
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,165
|
System.h
|
dmorse_pscfpp/src/pspc/System.h
|
#ifndef PSPC_SYSTEM_H
#define PSPC_SYSTEM_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <pspc/solvers/Mixture.h> // member
#include <pspc/field/Domain.h> // member
#include <pspc/field/FieldIo.h> // member
#include <pspc/field/WFieldContainer.h> // member
#include <pspc/field/CFieldContainer.h> // member
#include <pspc/field/Mask.h> // member
#include <pspc/field/RField.h> // member
#include <pspc/field/RFieldDft.h> // member
#include <pscf/homogeneous/Mixture.h> // member
#include <util/misc/FileMaster.h> // member
#include <util/containers/DArray.h> // member template
#include <util/containers/FSArray.h> // member template
namespace Pscf {
class Interaction;
namespace Pspc
{
template <int D> class Iterator;
template <int D> class IteratorFactory;
template <int D> class Sweep;
template <int D> class SweepFactory;
using namespace Util;
/**
* Main class for SCFT simulation of one system.
*
* A System has (among other components):
*
* - a Mixture (a container for polymer and solvent solvers)
* - an Interaction (list of binary chi parameters)
* - a Domain (description of the unit cell and discretization)
* - a container of monomer chemical potential fields
* - a container of monomer concentration fields
*
* A system may also optionally contain Iterator and Sweep objects.
* In a parameter file format, the main block is a System{...} block
* that contains subblocks for sub-objects.
*
* A minimal main program that uses this class template to implement a
* program for 3-dimensional structures (D=3) looks something like this:
* \code
* int main(int argc, char **argv) {
* Pscf::Pspc::System<3> system;
* system.setOptions(argc, argv);
* system.readParam();
* system.readCommands();
* }
* \endcode
* This main program is given for D=1, 2, and 3 dimensional structures
* in the files pscf_pc1.cpp, pscf_pc2.cpp, and pscf_pc3.cpp
*
* \ref user_param_pc_page "Parameter File Format"
* \ingroup Pscf_Pspc_Module
*/
template <int D>
class System : public ParamComposite
{
public:
/// \name Construction and Destruction
///@{
/**
* Constructor.
*/
System();
/**
* Destructor.
*/
~System();
///@}
/// \name Lifetime (Actions)
///@{
/**
* Process command line options.
*
* This function takes the same arguments as any C/C++ main program
* function. The arguments of the main function should d be passed
* to this function unaltered, to allow this function to process the
* command line options.
*
* \param argc number of command line arguments
* \param argv array of pointers to command line arguments
*/
void setOptions(int argc, char **argv);
/**
* Read input parameters (with opening and closing lines).
*
* \param in input parameter stream
*/
virtual void readParam(std::istream& in);
/**
* Read input parameters from default param file.
*
* This function reads the parameter file set by the -p command
* line option.
*/
void readParam();
/**
* Read body of parameter block (without opening and closing lines).
*
* \param in input parameter stream
*/
virtual void readParameters(std::istream& in);
/**
* Read command script from a file.
*
* \param in command script file.
*/
void readCommands(std::istream& in);
/**
* Read commands from default command file.
*
* This function reads the parameter file set by the -c command
* line option.
*/
void readCommands();
///@}
/// \name W Field Modifiers
///@{
/**
* Read chemical potential fields in symmetry adapted basis format.
*
* This function opens and reads the file with the name given by the
* "filename" string parameter, which must contain chemical potential
* fields in symmetry-adapted basis format. The function sets the
* system w fields equal to those given in this file, by copying
* elements of the representation in basis format and computing the
* representation in r-grid format. On exit, both w().basis() and
* w().rgrid() have been reset, w().hasData and w().isSymmetric()
* are true, and hasCFields() is false.
*
* \param filename name of input w-field basis file
*/
void readWBasis(const std::string & filename);
/**
* Read chemical potential fields in real space grid (r-grid) format.
*
* This function opens and reads the file with the name given by the
* "filename" string, which must contain chemical potential fields
* in real space grid (r-grid) format. The function sets values for
* system w fields in r-grid format. It does not set attempt to set
* field values in symmetry-adapted basis format, because it cannot
* be known whether the r-grid field exhibits the declared space
* group symmetry. On exit, w().rgrid() is reset and w().hasData()
* is true, while w().isSymmetric() and hasCFields() are false.
*
* \param filename name of input w-field basis file
*/
void readWRGrid(const std::string & filename);
/**
* Set chemical potential fields, in symmetry-adapted basis format.
*
* This function sets values for w fields in both symmetry adapted
* and r-grid format. On exit, values of both w().basis() and
* w().rgrid() are reset, w().hasData() and w().isSymmetric() are
* true, and hasCFields() is false.
*
* \param fields array of new w (chemical potential) fields
*/
void setWBasis(DArray< DArray<double> > const & fields);
/**
* Set new w fields, in real-space (r-grid) format.
*
* This function set values for w fields in r-grid format, but does
* not set components the symmetry-adapted basis format. On return,
* w.rgrid() is reset, w().hasData() is true, w().isSymmetric() is
* false, and hasCFields() is false.
*
* \param fields array of new w (chemical potential) fields
*/
void setWRGrid(DArray< RField<D> > const & fields);
/**
* Construct trial w-fields from c-fields.
*
* This function reads concentration fields in symmetrized basis
* format and constructs an initial guess for corresponding chemical
* potential fields by setting the Lagrange multiplier field xi to
* zero. The result is stored in the System w fields container
*
* Upon return, w().hasData() and w().isSymmetric() are set true,
* while hasCFields is set false.
*
* \param filename name of input c-field file (basis format)
*/
void estimateWfromC(const std::string& filename);
///@}
/// \name Unit Cell Modifiers
///@{
/**
* Set parameters of the associated unit cell.
*
* The lattice set in this UnitCell must agree with any lattice
* value that was set previously in the parameter file.
*
* \param unitCell new UnitCell<D> (i.e., new parameters)
*/
void setUnitCell(UnitCell<D> const & unitCell);
/**
* Set state of the associated unit cell.
*
* The lattice parameter must agree with any lattice value that
* was set previously in the parameter file.
*
* \param lattice lattice system
* \param parameters array of new unit cell parameters.
*/
void setUnitCell(typename UnitCell<D>::LatticeSystem lattice,
FSArray<double, 6> const & parameters);
/**
* Set parameters of the associated unit cell.
*
* The size of the FSArray<double> parameters must match the
* expected number of parameters for the current lattice type.
*
* \param parameters array of new unit cell parameters.
*/
void setUnitCell(FSArray<double, 6> const & parameters);
///@}
/// \name Primary SCFT Computations
///@{
/**
* Solve the modified diffusion equation once, without iteration.
*
* This function calls the Mixture::compute() function to solve
* the statistical mechanics problem for a non-interacting system
* subjected to the currrent chemical potential fields. This
* requires solution of the modified diffusion equation for all
* polymers, computation of Boltzmann weights for all solvents,
* computation of molecular partition functions for all species,
* computation of concentration fields for blocks and solvents,
* and computation of overall concentrations for all monomer types.
* This function does not compute the canonical (Helmholtz) free
* energy or grand-canonical free energy (i.e., pressure). Upon
* return, the flag hasCFields is set true.
*
* If argument needStress == true, then this function also calls
* Mixture<D>::computeStress() to compute the stress.
*
* \pre The w().hasData() flag must be true on entry, to confirm
* that chemical potential fields have been set.
*
* \param needStress true if stress is needed, false otherwise
*/
void compute(bool needStress = false);
/**
* Iteratively solve a SCFT problem.
*
* This function calls the iterator to attempt to solve the SCFT
* problem for the current mixture and system parameters, using
* the current chemical potential fields and current unit cell
* parameter values as initial guesses. On exit, hasCFields is
* set true whether or not convergence is obtained to within the
* desired tolerance. The Helmholtz free energy and pressure are
* computed if and only if convergence is obtained.
*
* \pre The w().hasData() flag must be true on entry, to confirm
* that chemical potential fields have been set.
*
* \pre The w().isSymmetric() flag must be set true if the chosen
* iterator uses a basis representation, and thus requires this.
*
* \param isContinuation true if continuation within a sweep.
* \return returns 0 for successful convergence, 1 for failure.
*/
int iterate(bool isContinuation = false);
/**
* Sweep in parameter space, solving an SCF problem at each point.
*
* This function uses a Sweep object that was initialized in the
* parameter file to solve the SCF problem at a sequence of points
* along a line in parameter space. The nature of this sequence of
* points is determined by implementation of a subclass of Sweep
* and the parameters passed to the sweep object in the parameter
* file. The Iterator that is initialized in the parameter file
* is called at each state point.
*
* An Exception is thrown if this is called when no Sweep has been
* created (i.e., if hasSweep() == false).
*/
void sweep();
///@}
/// \name Thermodynamic Properties
///@{
/**
* Compute free energy density and pressure for current fields.
*
* This function should be called after a successful call of
* System::iterate() or Iterator::solve(). Resulting values are
* stored and then accessed by the fHelmholtz() and pressure()
* functions.
*/
void computeFreeEnergy();
/**
* Get precomputed Helmoltz free energy per monomer / kT.
*
* The value retrieved by this function is computed by the
* computeFreeEnergy() function.
*/
double fHelmholtz() const;
/**
* Get precomputed pressure x monomer volume kT.
*
* The value retrieved by this function is computed by the
* computeFreeEnergy() function.
*/
double pressure() const;
///@}
/// \name Thermodynamic Data Output
///@{
/**
* Write parameter file to an ostream, omitting any sweep block.
*
* This function omits the Sweep block of the parameter file, if
* any, in order to allow the output produced during a sweep to refer
* only to parameters relevant to a single state point, and to be
* rerunnable as a parameter file for a single SCFT calculation.
*
* \param out output stream
*/
void writeParamNoSweep(std::ostream& out) const;
/**
* Write thermodynamic properties to a file.
*
* This function outputs Helmholtz free energy per monomer, pressure
* (in units of kT per monomer volume), the volume fraction and
* chemical potential of each species, and all unit cell parameters.
*
* If parameter "out" is a file that already exists, this function
* will append this information to the end of the file, rather than
* overwriting that file. Calling writeParamNoSweep and writeThermo
* in succession with the same file will thus produce a single file
* containing both input parameters and resulting thermodynanic
* properties.
*
* \param out output stream
*/
void writeThermo(std::ostream& out);
///@}
/// \name Field Output
///@{
/**
* Write chemical potential fields in symmetrized basis format.
*
* \param filename name of output file
*/
void writeWBasis(const std::string & filename) const;
/**
* Write chemical potential fields in real space grid (r-grid) format.
*
* \param filename name of output file
*/
void writeWRGrid(const std::string & filename) const;
/**
* Write concentration fields in symmetrized basis format.
*
* \param filename name of output file
*/
void writeCBasis(const std::string & filename) const;
/**
* Write concentration fields in real space grid (r-grid) format.
*
* \param filename name of output file
*/
void writeCRGrid(const std::string & filename) const;
/**
* Write c-fields for all blocks and solvents in r-grid format.
*
* Writes concentrations for all blocks of all polymers and all
* solvent species in r-grid format. Columns associated with blocks
* appear ordered by polymer id and then by block id, with blocks
* of the same polymer listed sequentially, followed by columns
* associated with solvent species ordered by solvent id.
*
* \param filename name of output file
*/
void writeBlockCRGrid(const std::string & filename) const;
///@}
/// \name Propagator Output
///@{
/**
* Write slice of a propagator at fixed s in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
* \param segmentId integer integration step index
*/
void writeQSlice(std::string const & filename,
int polymerId, int blockId,
int directionId, int segmentId) const;
/**
* Write the final slice of a propagator in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
*/
void writeQTail(std::string const & filename, int polymerId,
int blockId, int directionId) const;
/**
* Write one propagator for one block, in r-grid format.
*
* \param filename name of output file
* \param polymerId integer id of the polymer
* \param blockId integer id of the block within the polymer
* \param directionId integer id of the direction (0 or 1)
*/
void writeQ(std::string const & filename, int polymerId,
int blockId, int directionId) const;
/**
* Write all propagators of all blocks, each to a separate file.
*
* Write all propagators for both directions for all blocks
* of all polymers, with each propagator in a separate file.
* The function writeQ is called internally for each propagator,
* and is passed an automatically generated file name. The file
* name for each propagator is given by a string of the form
* (basename)_(ip)_(ib)_(id), where (basename) denotes the value
* of the std::string function parameter basename, and where
* (ip), (ib), and (id) denote the string representations of
* a polymer indiex ip, a block index ib, and direction index id,
* with id = 0 or 1. For example, if basename == "out/q", then
* the file name of the propagator for direction 1 of block 2
* of polymer 0 would be "out/q_0_2_1".
*
* \param basename common prefix for output file names
*/
void writeQAll(std::string const & basename);
///@}
/// \name Crystallographic Information
///@{
/**
* Output information about stars and symmetrized basis functions.
*
* This function opens a file with the specified filename, calls
* Basis<D>::outputStars, and closes the file before returning.
*
* \param filename name of output file
*/
void writeStars(std::string const & filename) const;
/**
* Output information about waves.
*
* This function opens a file with the specified filename, calls
* Basis<D>::outputWaves, and closes the file before returning.
*
* \param filename name of output file
*/
void writeWaves(std::string const & filename) const;
/**
* Output all elements of the space group.
*
* \param filename name of output file
*/
void writeGroup(std::string const & filename) const;
///@}
/// \name Field File Manipulations
///@{
/**
* Convert a field from symmetrized basis format to r-grid format.
*
* This function reads a field file in basis format, converts the
* fields to r-grid format, and writes the fields in r-grid format
* to a different file.
*
* This and other field conversion functions do not change the w
* or c fields stored by this System - all required calculations
* are performed using temporary or mutable memory.
*
* \param inFileName name of input file (basis format)
* \param outFileName name of output file (r-grid format)
*/
void basisToRGrid(const std::string & inFileName,
const std::string & outFileName);
/**
* Convert a field from real-space grid to symmetrized basis format.
*
* This function checks if the input fields have the declared space
* group symmetry, and prints a warning if it detects deviations
* that exceed some small threshhold, but proceeds to attempt the
* conversion even if such an error is detected. Converting a field
* that does not have the declared space group symmetry to basis
* format is a destructive operation that modifies the field in
* unpredictable ways.
*
* \param inFileName name of input file (r-grid format)
* \param outFileName name of output file (basis format)
*/
void rGridToBasis(const std::string & inFileName,
const std::string & outFileName);
/**
* Convert fields from Fourier (k-grid) to real-space (r-grid) format.
*
* \param inFileName name of input file (k-grid format)
* \param outFileName name of output file (r-grid format)
*/
void kGridToRGrid(const std::string& inFileName,
const std::string& outFileName);
/**
* Convert fields from real-space (r-grid) to Fourier (k-grid) format.
*
* \param inFileName name of input file (r-grid format)
* \param outFileName name of output file (k-grid format)
*/
void rGridToKGrid(const std::string & inFileName,
const std::string & outFileName);
/**
* Convert fields from Fourier (k-grid) to symmetrized basis format.
*
* This function checks if the input fields have the declared space
* group symmetry, and prints a warning if it detects deviations
* that exceed some small threshhold, but proceeds to attempt the
* conversion even if such an error is detected. Converting a field
* that does not have the declared space group symmetry to basis
* format is a destructive operation that modifies the field in
* unpredictable ways.
*
* \param inFileName name of input file (k-grid format)
* \param outFileName name of output file (basis format)
*/
void kGridToBasis(const std::string& inFileName,
const std::string& outFileName);
/**
* Convert fields from symmetrized basis to Fourier (k-grid) format.
*
* \param inFileName name of input file (basis format)
* \param outFileName name of output file (k-grid format)
*/
void basisToKGrid(const std::string & inFileName,
const std::string & outFileName);
/**
* Compare two field files in symmetrized basis format.
*
* Outputs maximum and root-mean-squared differences.
*
* \param field1 first array of fields (basis format)
* \param field2 second array of fields (basis format)
*/
void compare(const DArray< DArray<double> > field1,
const DArray< DArray<double> > field2);
/**
* Compare two field files in symmetrized basis format.
*
* Outputs maximum and root-mean-squared differences.
*
* \param field1 first array of fields (r-grid format)
* \param field2 second array of fields (r-grid format)
*/
void compare(const DArray< RField<D> > field1,
const DArray< RField<D> > field2);
/**
* Check if r-grid fields have the declared space group symmetry.
*
* \param inFileName name of input file
* \param epsilon error threshold used when testing for symmetry
* \return true if fields all have symmetry, false otherwise
*/
bool checkRGridFieldSymmetry(const std::string & inFileName,
double epsilon = 1.0E-8);
///@}
/// \name Field Accessors
///@{
/**
* Get all of the chemical potential fields (const reference).
*/
WFieldContainer<D> const & w() const;
/**
* Get all of the monomer concentration fields (const reference).
*/
CFieldContainer<D> const & c() const;
/**
* Get all of the external potential fields (reference).
*/
WFieldContainer<D>& h();
/**
* Get the mask (field to which total density is constrained).
*/
Mask<D>& mask();
///@}
/// \name Member Object Accessors
///@{
/**
* Get the Mixture by non-const reference.
*/
Mixture<D>& mixture();
/**
* Get the Mixture by const reference.
*/
Mixture<D> const & mixture() const;
/**
* Get Interaction (excess free energy model) by reference.
*/
Interaction& interaction();
/**
* Get Interaction (excess free energy model) by const reference.
*/
Interaction const & interaction() const;
/**
* Get Domain by const reference.
*/
Domain<D> const & domain() const;
/**
* Get UnitCell (i.e., type and parameters) by const reference.
*/
UnitCell<D> const & unitCell() const;
/**
* Get the spatial discretization mesh by const reference.
*/
Mesh<D> const & mesh() const;
/**
* Get the Basis by const reference.
*/
Basis<D> const & basis() const;
/**
* Get associated FFT object by const reference.
*/
FFT<D> const & fft() const;
/**
* Get associated FieldIo object by const reference.
*/
FieldIo<D> const & fieldIo() const;
/**
* Get the iterator.
*/
Iterator<D>& iterator();
/**
* Get the iterator by const reference.
*/
Iterator<D> const & iterator() const;
/**
* Get homogeneous mixture (for reference calculations).
*/
Homogeneous::Mixture& homogeneous();
/**
* Get const homogeneous mixture (for reference calculations).
*/
Homogeneous::Mixture const & homogeneous() const;
/**
* Get the FileMaster.
*
* Access by non-const reference is used in some unit tests.
*/
FileMaster& fileMaster();
/**
* Get the FileMaster by const reference.
*/
FileMaster const & fileMaster() const;
/**
* Get the group name string.
*/
std::string groupName() const;
///@}
/// \name Queries
///@{
/**
* Have c fields been computed from the current w fields?
*/
bool hasCFields() const;
/**
* Has the free energy been computed from the current w fields?
*/
bool hasFreeEnergy() const;
/**
* Does this system have external potential fields?
*/
bool hasExternalFields() const;
/**
* Does this system have a mask (inhomogeneous density constraint)
*/
bool hasMask() const;
/**
* Does this system have a Sweep object?
*/
bool hasSweep() const;
///@}
private:
// Private member variables
/**
* Mixture object (solves MDE for all species).
*/
Mixture<D> mixture_;
/**
* Domain object (unit cell, space group, mesh, and basis).
*/
Domain<D> domain_;
/**
* Filemaster (holds paths to associated I/O files).
*/
FileMaster fileMaster_;
/**
* Homogeneous mixture, for reference.
*/
Homogeneous::Mixture homogeneous_;
/**
* Pointer to Interaction (free energy model).
*/
Interaction* interactionPtr_;
/**
* Pointer to an iterator.
*/
Iterator<D>* iteratorPtr_;
/**
* Pointer to iterator factory object
*/
IteratorFactory<D>* iteratorFactoryPtr_;
/**
* Pointer to a Sweep object
*/
Sweep<D>* sweepPtr_;
/**
* Pointer to SweepFactory object
*/
SweepFactory<D>* sweepFactoryPtr_;
/**
* Chemical potential fields.
*/
WFieldContainer<D> w_;
/**
* Monomer concentration / volume fraction fields.
*/
CFieldContainer<D> c_;
/**
* External potential fields.
*/
WFieldContainer<D> h_;
/**
* Field to which the total density is constrained.
*/
Mask<D> mask_;
/**
* Work array of field coefficients for all monomer types.
*
* Indexed by monomer typeId, size = nMonomer.
*/
mutable DArray< DArray<double> > tmpFieldsBasis_;
/**
* Work array of fields on real space grid.
*
* Indexed by monomer typeId, size = nMonomer.
*/
mutable DArray< RField<D> > tmpFieldsRGrid_;
/**
* Work array of fields on Fourier grid (k-grid).
*
* Indexed by monomer typeId, size = nMonomer.
*/
mutable DArray< RFieldDft<D> > tmpFieldsKGrid_;
/**
* Helmholtz free energy per monomer / kT.
*/
double fHelmholtz_;
/**
* Ideal gas contribution to fHelmholtz_.
*
* This encompasses the internal energy and entropy of
* non-interacting free chains in their corresponding
* potential fields defined by w_.
*/
double fIdeal_;
/**
* Multi-chain interaction contribution to fHelmholtz_.
*/
double fInter_;
/**
* External field contribution to fHelmholtz_.
*/
double fExt_;
/**
* Pressure times monomer volume / kT.
*
* This quantity is -1 times the grand-canonical free energy per
* monomer, divided by kT.
*/
double pressure_;
/**
* Has the mixture been initialized?
*/
bool hasMixture_;
/**
* Has memory been allocated for fields in grid format?
*/
bool isAllocatedRGrid_;
/**
* Has memory been allocated for fields in symmetrized basis format?
*/
bool isAllocatedBasis_;
/**
* Have c fields been computed for the current w fields?
*
* Set true when c fields are computed by solving the MDEs for
* all blocks, and set false whenever w fields or the unit cell
* parameters are reset. When hasCFields_ is true, both the
* c fields for individual blocks and solvent species in the
* Mixture and the fields for different monomer types the
* System::c_ container are those obtained from the current w
* fields in System::w_ container.
*/
bool hasCFields_;
/**
* Has the free energy been computed for the current w and c fields?
*/
bool hasFreeEnergy_;
// Private member functions
/**
* Allocate memory for fields in grid formats (private)
*/
void allocateFieldsGrid();
/**
* Allocate memory for fields in basis format (private)
*/
void allocateFieldsBasis();
/**
* Read a field file header, make the basis if not done previously.
*
* Used to peek at a file header to get initial unit cell parameters,
* use this to initialize basis if not done previously.
*
* \param filename name of field file
*/
void readFieldHeader(std::string filename);
/**
* Read a string and echo to log file.
*
* Used to read filenames in readCommands.
*
* \param in input stream (i.e., input file)
* \param string string to read and echo
*/
void readEcho(std::istream& in, std::string& string) const;
/**
* Read a floating point number and echo to log file.
*
* Used to read filenames in readCommands.
*
* \param in input stream (i.e., input file)
* \param value number to read and echo
*/
void readEcho(std::istream& in, double& value) const;
/**
* Initialize Homogeneous::Mixture object.
*/
void initHomogeneous();
};
// Inline member functions
// Get the Mixture object.
template <int D>
inline Mixture<D>& System<D>::mixture()
{ return mixture_; }
// Get the Mixture by const reference.
template <int D>
inline Mixture<D> const & System<D>::mixture() const
{ return mixture_; }
// Get the Domain by const reference.
template <int D>
inline Domain<D> const & System<D>::domain() const
{ return domain_; }
// Get the UnitCell by const reference.
template <int D>
inline UnitCell<D> const & System<D>::unitCell() const
{ return domain_.unitCell(); }
// Get the Mesh by const reference.
template <int D>
inline Mesh<D> const & System<D>::mesh() const
{ return domain_.mesh(); }
// Get the Basis<D> object.
template <int D>
inline Basis<D> const & System<D>::basis() const
{ return domain_.basis(); }
// Get the FFT object by const reference.
template <int D>
inline FFT<D> const & System<D>::fft() const
{ return domain_.fft(); }
// Get the FieldIo<D> by const reference.
template <int D>
inline FieldIo<D> const & System<D>::fieldIo() const
{ return domain_.fieldIo(); }
// Get the groupName string by value.
template <int D>
inline std::string System<D>::groupName() const
{ return domain_.groupName(); }
// Get the FileMaster by non-const reference.
template <int D>
inline FileMaster& System<D>::fileMaster()
{ return fileMaster_; }
// Get the FileMaster by const reference.
template <int D>
inline FileMaster const & System<D>::fileMaster() const
{ return fileMaster_; }
// Get the Homogeneous::Mixture object.
template <int D>
inline Homogeneous::Mixture& System<D>::homogeneous()
{ return homogeneous_; }
// Get the const Homogeneous::Mixture object.
template <int D>
inline Homogeneous::Mixture const & System<D>::homogeneous() const
{ return homogeneous_; }
// Get the Interaction (excess free energy model).
template <int D>
inline Interaction& System<D>::interaction()
{
UTIL_ASSERT(interactionPtr_);
return *interactionPtr_;
}
// Get the Interaction by const reference.
template <int D>
inline Interaction const & System<D>::interaction() const
{
UTIL_ASSERT(interactionPtr_);
return *interactionPtr_;
}
// Get the Iterator.
template <int D>
inline Iterator<D>& System<D>::iterator()
{
UTIL_ASSERT(iteratorPtr_);
return *iteratorPtr_;
}
// Get the Iterator by const reference.
template <int D>
inline Iterator<D> const & System<D>::iterator() const
{
UTIL_ASSERT(iteratorPtr_);
return *iteratorPtr_;
}
// Get container of chemical potential fields (const reference)
template <int D>
inline
WFieldContainer<D> const & System<D>::w() const
{ return w_; }
// Get container of monomer concentration fields (const reference)
template <int D>
inline
CFieldContainer<D> const & System<D>::c() const
{ return c_; }
// Get container of external potential fields (reference)
template <int D>
inline WFieldContainer<D>& System<D>::h()
{ return h_; }
// Get mask field (reference)
template <int D>
inline Mask<D>& System<D>::mask()
{ return mask_; }
// Does the system have a Sweep object?
template <int D>
inline bool System<D>::hasSweep() const
{ return (sweepPtr_ != 0); }
// Does this system have external potential fields?
template <int D>
inline bool System<D>::hasExternalFields() const
{ return h_.hasData(); }
// Does this system have a mask?
template <int D>
inline bool System<D>::hasMask() const
{ return mask_.hasData(); }
// Have the c fields been computed for the current w fields?
template <int D>
inline bool System<D>::hasCFields() const
{ return hasCFields_; }
// Get the precomputed Helmoltz free energy per monomer / kT.
template <int D>
inline double System<D>::fHelmholtz() const
{
UTIL_CHECK(hasFreeEnergy_);
return fHelmholtz_;
}
// Get the precomputed pressure (units of kT / monomer volume).
template <int D>
inline double System<D>::pressure() const
{
UTIL_CHECK(hasFreeEnergy_);
return pressure_;
}
// Has the free energy been computed for the current w fields?
template <int D>
inline bool System<D>::hasFreeEnergy() const
{ return hasFreeEnergy_; }
#ifndef PSPC_SYSTEM_TPP
// Suppress implicit instantiation
extern template class System<1>;
extern template class System<2>;
extern template class System<3>;
#endif
} // namespace Pspc
} // namespace Pscf
#endif
| 35,994
|
C++
|
.h
| 993
| 29.44713
| 75
| 0.632439
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,166
|
FilmIterator.h
|
dmorse_pscfpp/src/pspc/iterator/FilmIterator.h
|
#ifndef PSPC_FILM_ITERATOR_H
#define PSPC_FILM_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2021, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "FilmIteratorBase.h"
namespace Pscf {
namespace Pspc
{
template <int D>
class System;
using namespace Util;
/**
* Iterator for a thin film (empty base template).
*
* The parent FilmIteratorBase class template defines all traits of a
* FilmIterator that do not depend on D, the dimension of space. This
* FilmIterator class template is an empty template that is replaced
* by partial specializations for D=1, 2 and 3.
*
* If the user chooses a FilmIterator as their iterator, then the
* system will contain two parallel hard surfaces ("walls"), confining
* the polymers/solvents to a "thin film" region of the unit cell.
* This only affects the iterator, not the rest of SCFT, so we isolate
* the imposition of the thin film constraint to this subclass of
* iterator. This is essentially a wrapper for any other type of
* iterator (e.g., AmIterator), that adds the additional functionality
* required to impose the thin film constraint properly.
*
* FilmIterator is generalized to be compatible with any iterator within
* it, as long as the iterator can impose 1) a mask that confines the
* polymers/solvents to a certain region of space, and 2) an external
* field. A FilmIterator object in the param file is created by appending
* "Film" to the end of the name of the iterator that is stored inside of
* FilmIterator (e.g., "AmIteratorFilm{" will create a FilmIterator with
* an AmIterator object inside of it).
*
* \ingroup Pspc_Iterator_Module
*/
template <int D, typename IteratorType>
class FilmIterator : public FilmIteratorBase<D,IteratorType>
{};
// Partial Specializations
/**
* FilmIterator specialization for 1D problems.
*/
template <typename IteratorType>
class FilmIterator<1, IteratorType>
: public FilmIteratorBase<1, IteratorType>
{
public:
/**
* Constructor.
*/
FilmIterator(System<1>& system);
/**
* Modifies flexibleParams_ to be compatible with thin film constraint.
*
* Construct an array indicating whether each lattice parameter is
* flexible, based on normalVecId and unitCell definitions in param
* file as well as the optional user input flexibleParams. Store this
* array in flexibleParams_ member of this object, as well the
* flexibleParams_ member of the iterator within this object.
* Uses the flexibleParams_ member of the iterator within this object
* as a starting point.
*
* In 1D, a thin film can not have flexible lattice parameters, so
* this will always set flexibleParams_ to an array of zeroes.
*/
void setFlexibleParams();
/**
* Check compatibility of lattice with thin film constraint.
*
* Check that the user-defined lattice basis vectors in the
* associated Domain<D> object are compatible with the thin
* film constraint
*/
void checkLatticeVectors() const;
using FilmIteratorBase<1,IteratorType>::setClassName;
using FilmIteratorBase<1,IteratorType>::normalVecId;
protected:
using FilmIteratorBase<1,IteratorType>::system;
using FilmIteratorBase<1,IteratorType>::iterator;
using Iterator<1>::setFlexibleParams;
};
/**
* FilmIterator specialization for 2D problems (confined to strip).
*/
template <typename IteratorType>
class FilmIterator<2,IteratorType>
: public FilmIteratorBase<2,IteratorType>
{
public:
/**
* Constructor.
*/
FilmIterator(System<2>& system);
/**
* Modifies flexibleParams_ to be compatible with thin film constraint.
*
* Construct an array indicating whether each lattice parameter is
* flexible, based on normalVecId and unitCell definitions in param
* file as well as the optional user input flexibleParams. Store this
* array in flexibleParams_ member of this object, as well the
* flexibleParams_ member of the iterator within this object.
* Uses the flexibleParams_ member of the iterator within this object
* as a starting point.
*/
void setFlexibleParams();
/**
* Check compatibility of lattice with thin film constraint.
*
* Check that the user-defined lattice basis vectors in the
* associated Domain<D> object are compatible with the thin
* film constraint
*/
void checkLatticeVectors() const;
using FilmIteratorBase<2,IteratorType>::setClassName;
using FilmIteratorBase<2,IteratorType>::normalVecId;
using Iterator<2>::nFlexibleParams;
protected:
using FilmIteratorBase<2,IteratorType>::system;
using FilmIteratorBase<2,IteratorType>::iterator;
using Iterator<2>::setFlexibleParams;
};
/**
* FilmIterator specialization for 3D problems (confined to slit).
*/
template <typename IteratorType>
class FilmIterator<3,IteratorType>
: public FilmIteratorBase<3,IteratorType>
{
public:
/**
* Constructor.
*/
FilmIterator(System<3>& system);
/**
* Modifies flexibleParams_ to be compatible with thin film constraint.
*
* Construct an array indicating whether each lattice parameter is
* flexible, based on normalVecId and unitCell definitions in param
* file as well as the optional user input flexibleParams. Store this
* array in flexibleParams_ member of this object, as well the
* flexibleParams_ member of the iterator within this object.
* Uses the flexibleParams_ member of the iterator within this object
* as a starting point.
*/
void setFlexibleParams();
/**
* Check compatibility of lattice with thin film constraint.
*
* Check that the user-defined lattice basis vectors in the
* associated Domain<D> object are compatible with the thin
* film constraint
*/
void checkLatticeVectors() const;
using FilmIteratorBase<3,IteratorType>::setClassName;
using FilmIteratorBase<3,IteratorType>::normalVecId;
using Iterator<3>::nFlexibleParams;
protected:
using FilmIteratorBase<3,IteratorType>::system;
using FilmIteratorBase<3,IteratorType>::iterator;
using Iterator<3>::setFlexibleParams;
};
} // namespace Pspc
} // namespace Pscf
#endif
| 6,706
|
C++
|
.h
| 171
| 33.327485
| 76
| 0.707517
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,167
|
Iterator.h
|
dmorse_pscfpp/src/pspc/iterator/Iterator.h
|
#ifndef PSPC_ITERATOR_H
#define PSPC_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/ParamComposite.h> // base class
#include <util/containers/FSArray.h>
#include <util/global.h>
namespace Pscf {
namespace Pspc
{
template <int D>
class System;
using namespace Util;
/**
* Base class for iterative solvers for SCF equations.
*
* \ingroup Pspc_Iterator_Module
*/
template <int D>
class Iterator : public ParamComposite
{
public:
/**
* Default constructor.
*/
Iterator();
/**
* Constructor.
*
* \param system parent System object
*/
Iterator(System<D>& system);
/**
* Destructor.
*/
~Iterator();
/**
* Iterate to solution.
*
* \param isContinuation true iff a continuation within a sweep
* \return error code: 0 for success, 1 for failure.
*/
virtual int solve(bool isContinuation) = 0;
/**
* Return true iff unit cell has any flexible lattice parameters.
*/
bool isFlexible() const
{ return (isFlexible_); }
/**
* Get the array indicating which lattice parameters are flexible.
*
* This array should be nParameters long, where the i-th entry is a
* boolean indicating whether parameter i is flexible.
*/
FSArray<bool,6> flexibleParams() const
{ return flexibleParams_; }
/**
* Get the number of flexible lattice parameters.
*/
int nFlexibleParams() const;
protected:
/**
* Get parent system by const reference.
*/
System<D> const & system() const
{ return *sysPtr_; }
/**
* Get parent system by non-const reference.
*/
System<D>& system()
{ return *sysPtr_; }
/// Are any lattice parameters flexible during iteration?
bool isFlexible_;
/**
* Set the array indicating which lattice parameters are flexible.
*
* \param flexParams array of indices of flexible lattice parameters
*/
void setFlexibleParams(FSArray<bool,6> const & flexParams);
/**
* Array of indices of the lattice parameters that are flexible.
*/
FSArray<bool,6> flexibleParams_;
private:
/// Pointer to the associated system object.
System<D>* sysPtr_;
};
// Inline member functions
// Default constructor
template <int D>
inline Iterator<D>::Iterator()
{ setClassName("Iterator"); }
// Constructor
template <int D>
Iterator<D>::Iterator(System<D>& system)
: sysPtr_(&system)
{ setClassName("Iterator"); }
// Destructor
template <int D>
Iterator<D>::~Iterator()
{}
// Get the number of flexible lattice parameters
template <int D>
int Iterator<D>::nFlexibleParams() const
{
UTIL_CHECK(flexibleParams_.size() == system().unitCell().nParameter());
int nFlexParams = 0;
for (int i = 0; i < flexibleParams_.size(); i++) {
if (flexibleParams_[i]) nFlexParams++;
}
return nFlexParams;
}
// Set the array indicating which lattice parameters are flexible.
template <int D>
void Iterator<D>::setFlexibleParams(FSArray<bool,6> const & flexParams)
{
flexibleParams_ = flexParams;
if (nFlexibleParams() == 0) {
isFlexible_ = false;
} else {
isFlexible_ = true;
}
}
} // namespace Pspc
} // namespace Pscf
#endif
| 3,675
|
C++
|
.h
| 130
| 22.4
| 77
| 0.626104
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,168
|
AmIterator.h
|
dmorse_pscfpp/src/pspc/iterator/AmIterator.h
|
#ifndef PSPC_AM_ITERATOR_H
#define PSPC_AM_ITERATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Iterator.h" // base class
#include <pscf/iterator/AmIteratorTmpl.h> // base class template
#include <pscf/iterator/AmbdInteraction.h> // member variable
namespace Pscf {
namespace Pspc
{
template <int D>
class System;
using namespace Util;
/**
* Pspc implementation of the Anderson Mixing iterator.
*
* \ingroup Pspc_Iterator_Module
*/
template <int D>
class AmIterator : public AmIteratorTmpl<Iterator<D>, DArray<double> >
{
public:
/**
* Constructor.
*
* \param system System object associated with this iterator.
*/
AmIterator(System<D>& system);
/**
* Destructor.
*/
~AmIterator();
/**
* Read all parameters and initialize.
*
* \param in input filestream
*/
void readParameters(std::istream& in);
// Inherited public member functions
using AmIteratorTmpl<Iterator<D>, DArray<double> >::solve;
using Iterator<D>::isFlexible;
using Iterator<D>::flexibleParams;
using Iterator<D>::setFlexibleParams;
using Iterator<D>::nFlexibleParams;
protected:
// Inherited protected members
using ParamComposite::readOptional;
using ParamComposite::readOptionalFSArray;
using ParamComposite::setClassName;
using AmIteratorTmpl< Iterator<D>, DArray<double> >::verbose;
using Iterator<D>::system;
using Iterator<D>::isFlexible_;
using Iterator<D>::flexibleParams_;
/**
* Setup iterator just before entering iteration loop.
*
* \param isContinuation Is this a continuation within a sweep?
*/
void setup(bool isContinuation);
private:
// Local copy of interaction, adapted for use AMBD residual definition
AmbdInteraction interaction_;
/// How are stress residuals scaled in error calculation?
double scaleStress_;
/**
* Assign one field to another.
*
* \param a the field to be set (lhs of assignment)
* \param b the field for it to be set to (rhs of assigment)
*/
void setEqual(DArray<double>& a, DArray<double> const & b);
/**
* Compute the inner product of two vectors
*/
double dotProduct(DArray<double> const & a, DArray<double> const & b);
/**
* Find the maximum magnitude element of a residual vector.
*/
double maxAbs(DArray<double> const & hist);
/**
* Update the basis for residual or field vectors.
*
* \param basis RingBuffer of residual or field basis vectors
* \param hists RingBuffer of past residual or field vectors
*/
void updateBasis(RingBuffer<DArray<double> > & basis,
RingBuffer<DArray<double> > const & hists);
/**
* Add linear combination of basis vectors to trial field.
*
* \param trial trial vector (input-output)
* \param basis RingBuffer of basis vectors
* \param coeffs array of coefficients of basis vectors
* \param nHist number of histories stored at this iteration
*/
void addHistories(DArray<double>& trial,
RingBuffer<DArray<double> > const & basis,
DArray<double> coeffs,
int nHist);
/**
* Add predicted error to field trial.
*
* \param fieldTrial trial field (in-out)
* \param resTrial predicted error for current trial
* \param lambda Anderson-Mixing mixing
*/
void addPredictedError(DArray<double>& fieldTrial,
DArray<double> const & resTrial,
double lambda);
/**
* Does the system has an initial guess for the field?
*/
bool hasInitialGuess();
/**
* Compute and returns the number of elements in field vector.
*
* Called during allocation and then stored.
*/
int nElements();
/**
* Gets the current field vector from the system.
*
* \param curr current field vector
*/
void getCurrent(DArray<double>& curr);
/**
* Have the system perform a computation using new field.
*
* Solves the modified diffusion equations, computes concentrations,
* and optionally computes stress components.
*/
void evaluate();
/**
* Compute the residual vector.
*
* \param resid current residual vector value
*/
void getResidual(DArray<double>& resid);
/**
* Updates the system field with the new trial field.
*
* \param newGuess trial field vector
*/
void update(DArray<double>& newGuess);
/**
* Outputs relevant system details to the iteration log.
*/
void outputToLog();
};
} // namespace Pspc
} // namespace Pscf
#endif
| 5,196
|
C++
|
.h
| 156
| 25.961538
| 83
| 0.627306
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,169
|
FilmIteratorBase.h
|
dmorse_pscfpp/src/pspc/iterator/FilmIteratorBase.h
|
#ifndef PSPC_FILM_ITERATOR_BASE_H
#define PSPC_FILM_ITERATOR_BASE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2021, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "pspc/iterator/Iterator.h" // base class
#include "util/containers/FSArray.h" // container
#include <string>
#include <iostream>
namespace Pscf {
namespace Pspc
{
template <int D>
class System;
using namespace Util;
/**
* Descriptor for a FilmIterator object. This base class template defines
* all traits of a FilmIterator that do not depend on D, the dimension of
* the system. The subclasses of FilmIteratorBase are the partial
* specializations of FilmIterator for 1D, 2D, and 3D.
*
* If the user chooses a FilmIterator as their iterator, then the
* system will contain two parallel hard surfaces ("walls"), confining
* the polymers/solvents to a "thin film" region of the unit cell.
* This only affects the iterator, not the rest of SCFT, so we isolate
* the imposition of the thin film constraint to this subclass of
* iterator. This is essentially a wrapper for any other type of iterator
* (e.g., AmIterator), that adds the additional functionality required
* to impose the thin film constraint properly.
*
* FilmIterator is generalized to be compatible with any iterator within
* it, as long as the iterator can impose 1) a mask that confines the
* polymers/solvents to a certain region of space, and 2) an external
* field. A FilmIterator object in the param file is created by appending
* "Film" to the end of the name of the iterator that is stored inside of
* FilmIterator (e.g., "AmIteratorFilm{" will create a FilmIterator with
* an AmIterator object inside of it).
*
* \ingroup Pspc_Iterator_Module
*/
template <int D, typename IteratorType>
class FilmIteratorBase : public Iterator<D>
{
public:
/**
* Constructor.
*/
FilmIteratorBase(System<D>& system);
/**
* Destructor.
*/
~FilmIteratorBase();
/**
* Read and initialize.
*
* \param in input parameter stream
*/
void readParameters(std::istream& in);
/**
* Iterate to a solution
*
* \param isContinuation true iff continuation within a sweep
*/
int solve(bool isContinuation = false);
/**
* Return const reference to the real iterator within this FilmIterator
*/
IteratorType const & iterator() const;
/**
* Modifies flexibleParams_ to be compatible with thin film constraint.
*
* Modifies the flexibleParams_ array to be compatible with the thin
* film constraint. Stores resulting array in flexibleParams_ member
* of this object, as well as the flexibleParams_ member of the
* iterator within this object.
*
* This function varies depending on D, the dimensionality of the
* system. Therefore, it is implemented in the partial class
* specializations in FilmIterator, rather than in this base class.
*/
virtual void setFlexibleParams() = 0;
/**
* Check that lattice vectors are compatible with thin film constraint.
*
* Check that user-defined lattice basis vectors (stored in the
* Domain<D> object associated with this FilmIterator class)
* are compatible with the thin film constraint. All lattice basis
* vectors must be either parallel or perpendicular to the walls.
*
* This function varies depending on D, the dimensionality of the
* system. Therefore, it is implemented in the partial class
* specializations in FilmIterator, rather than in this base class.
*/
virtual void checkLatticeVectors() const = 0;
/**
* Generates mask and external field for the walls and stores in System.
*
* Generates the field representation of the walls, based on the values
* of wallThickness and interfaceThickness that were input by the user.
* Then, stores this wall field in system().mask() to be used
* as a mask during iteration, and also passes the corresponding
* external potential fields into system().h() if isAthermal() = false.
*/
void generateWallFields();
/**
* Updates the mask and external fields for the walls if needed.
*
* Checks whether the lattice parameters have been updated since the
* last call of generateWallFields(), and if the parameters have
* changed then calls generateWallFields() again to update them.
*
* Also updates the external fields if the wall/polymer chi parameters
* have been updated since external fields were last generated.
*/
void updateWallFields();
/**
* Check that space group is compatible with the thin film constraint.
*/
void checkSpaceGroup() const;
/**
* Are the walls chemically identical?
*
* This is the case when chiBottom is equal to chiTop.
*/
bool isSymmetric() const;
/**
* Are the walls athermal?
*
* This is only true if all values in chiBottom and chiTop are zero.
*/
bool isAthermal() const;
/**
* Set the value of chi between species s and the bottom wall.
*
* \param s species index, 0 <= id < nVertex
* \param chi value of chi(s,w)
*/
void setChiBottom(int s, double chi);
/**
* Set the value of chi between species s and the top wall.
*
* \param s species index, 0 <= id < nVertex
* \param chi value of chi(s,w)
*/
void setChiTop(int s, double chi);
/**
* Get value of normalVecId
*/
int normalVecId() const;
/**
* Get value of interfaceThickness
*/
double interfaceThickness() const;
/**
* Get value of wallThickness
*/
double wallThickness() const;
/**
* Get const chiBottom matrix by reference
*/
DArray<double> const & chiTop() const;
/**
* Get const chiTop array by reference
*/
DArray<double> const & chiBottom() const;
/**
* Get the chi parameter between the bottom wall and species s
*
* \param s species index, 0 <= id < nVertex
*/
double chiBottom(int s) const;
/**
* Get the chi parameter between the top wall and species s
*
* \param s species index, 0 <= id < nVertex
*/
double chiTop(int s) const;
using Iterator<D>::isFlexible;
protected:
/**
* Initialize just before entry to iterative loop.
*
* Allocate required memory, perform necessary checks to ensure user
* input is compatible with a film constraint, and create the mask /
* external fields that will be used to represent the walls during
* iteration.
*/
void setup();
/**
* Return reference to the real iterator within this FilmIterator
*/
IteratorType& iterator();
/**
* Generate external fields for the walls.
*
* Generate external fields only, and pass them into System for use
* during calculation. This is called by generateWallFields().
*/
void generateExternalFields();
using Iterator<D>::system;
using Iterator<D>::setClassName;
using Iterator<D>::isFlexible_;
using ParamComposite::read;
using ParamComposite::readOptional;
using ParamComposite::readDArray;
using ParamComposite::setParent;
using ParamComposite::addComponent;
private:
/// The actual iterator that does all the work
IteratorType iterator_;
/// Lattice parameters associated with the current maskBasis
FSArray<double, 6> parameters_;
/// Lattice basis vector that is normal to the walls
int normalVecId_;
/// Interface thickness
double t_;
/// Wall thickness
double T_;
/// chiBottom array
DArray<double> chiBottom_;
/// chiTop array
DArray<double> chiTop_;
/// Wall chiBottom array associated with the current system().h() field
DArray<double> chiBottomCurrent_;
/// Wall chiTop array associated with the current system().h() field
DArray<double> chiTopCurrent_;
/// Flag indicating whether the wall fields are currently ungenerated
bool ungenerated_;
};
// Inline member functions
// Return reference to iterator within this FilmIterator
template <int D, typename IteratorType>
inline IteratorType& FilmIteratorBase<D, IteratorType>::iterator()
{ return iterator_; }
// Return const reference to iterator within this FilmIterator
template <int D, typename IteratorType>
inline
IteratorType const & FilmIteratorBase<D, IteratorType>::iterator() const
{ return iterator_; }
// Set value of chi between species s and the bottom wall
template <int D, typename IteratorType>
inline
void FilmIteratorBase<D, IteratorType>::setChiBottom(int s, double chi)
{ chiBottom_[s] = chi; }
// Set value of chi between species s and the top wall
template <int D, typename IteratorType>
inline
void FilmIteratorBase<D, IteratorType>::setChiTop(int s, double chi)
{ chiTop_[s] = chi; }
// Get value of normalVecId
template <int D, typename IteratorType>
inline int FilmIteratorBase<D, IteratorType>::normalVecId() const
{ return normalVecId_; }
// Get value of interfaceThickness
template <int D, typename IteratorType>
inline double FilmIteratorBase<D, IteratorType>::interfaceThickness()
const
{ return t_; }
// Get value of wallThickness
template <int D, typename IteratorType>
inline double FilmIteratorBase<D, IteratorType>::wallThickness() const
{ return T_; }
// Get chiBottom array by const reference
template <int D, typename IteratorType>
inline
DArray<double> const & FilmIteratorBase<D, IteratorType>::chiBottom()
const
{ return chiBottom_; }
// Get chiTop array by const reference
template <int D, typename IteratorType>
inline
DArray<double> const & FilmIteratorBase<D, IteratorType>::chiTop()
const
{ return chiTop_; }
// Get the chi parameter between the bottom wall and species s
template <int D, typename IteratorType>
inline double FilmIteratorBase<D, IteratorType>::chiBottom(int s)
const
{ return chiBottom_[s]; }
// Get the chi parameter between the top wall and species s
template <int D, typename IteratorType>
inline double FilmIteratorBase<D, IteratorType>::chiTop(int s)
const
{ return chiTop_[s]; }
} // namespace Pspc
} // namespace Pscf
#include "FilmIteratorBase.tpp"
#endif
| 10,936
|
C++
|
.h
| 291
| 31.536082
| 77
| 0.676751
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,170
|
IteratorFactory.h
|
dmorse_pscfpp/src/pspc/iterator/IteratorFactory.h
|
#ifndef PSPC_ITERATOR_FACTORY_H
#define PSPC_ITERATOR_FACTORY_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/Factory.h>
#include <pspc/iterator/Iterator.h>
#include <pspc/System.h>
#include <string>
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Factory for subclasses of Iterator.
*
* \ingroup Pspc_Iterator_Module
*/
template <int D>
class IteratorFactory : public Factory< Iterator<D> >
{
public:
/// Constructor
IteratorFactory(System<D>& system);
/**
* Method to create any Iterator supplied with PSCF.
*
* \param className name of the Iterator subclass
* \return Iterator* pointer to new instance of className
*/
Iterator<D>* factory(const std::string &className) const;
using Factory< Iterator<D> >::trySubfactories;
private:
/// Pointer to the parent system.
System<D>* sysPtr_;
};
#ifndef PSPC_ITERATOR_FACTORY_TPP
// Suppress implicit instantiation
extern template class IteratorFactory<1>;
extern template class IteratorFactory<2>;
extern template class IteratorFactory<3>;
#endif
}
}
#endif
| 1,326
|
C++
|
.h
| 47
| 24.12766
| 67
| 0.70863
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,171
|
Polymer.h
|
dmorse_pscfpp/src/pspc/solvers/Polymer.h
|
#ifndef PSPC_POLYMER_H
#define PSPC_POLYMER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Block.h"
#include <pscf/solvers/PolymerTmpl.h>
#include <pspc/field/RField.h>
#include <util/containers/FArray.h> // member template
namespace Pscf {
namespace Pspc {
/**
* Descriptor and solver for one polymer species.
*
* The phi() and mu() accessor functions, which are inherited from
* PolymerTmp< Block<D> >, return the value of phi (spatial average
* volume fraction of a species) or mu (species chemical potential)
* computed in the most recent call of the compute() function.
* If the ensemble for this species is closed, phi is read from the
* parameter file and mu is computed. If the ensemble is open, mu
* is read from the parameter file and phi is computed.
*
* The block concentrations stored in the constituent Block<D> objects
* contain the block concentrations (i.e., volume fractions) computed
* in the most recent call of the compute function. These can be
* accessed using the Block<D>::cField() function.
*
* \ref user_param_polymer_sec "Parameter File Format"
*
* \ingroup Pspc_Solver_Module
*/
template <int D>
class Polymer : public PolymerTmpl< Block<D> >
{
public:
/**
* Base class typedef (PolymerTmpl instance)
*/
typedef PolymerTmpl< Block<D> > Base;
/**
* Default constructor.
*/
Polymer();
/**
* Destructor.
*/
~Polymer();
/**
* Set value of phi (volume fraction), if ensemble is closed.
*
* An initial value for phi or mu is normally read from a parameter
* file. This function is provided for use by a sweep or other
* procedure in which phi for a species with a closed enesmble is
* modified after initialization. It is an error to call setPhi
* for a polymer species with an open ensemble.
*
* \throw Exception if ensemble is open
* \param phi new volume fraction value for this species
*/
void setPhi(double phi);
/**
* Set value of mu (chemical potential), if ensemble is closed.
*
* An initial value for phi or mu is normally read from a parameter
* file. This function is provided for use in a sweep or other
* procedure in which mu for a species with an open enesmble is
* modified after initialization. It is an error to call setMu
* for a polymer species with a closed ensemble.
*
* \throw Exception if ensemble is closed
* \param mu new chemical potential value for this species
*/
void setMu(double mu);
/**
* Set up the unit cell after a change in unit cell parameters.
*
* This function should be called after each change in the unit
* cell. It sets unit cell information for all blocks in this
* polymer.
*
* \param unitCell crystallographic unit cell
*/
void setupUnitCell(UnitCell<D> const & unitCell);
/**
* Compute solution to MDE and block concentrations.
*
* This function sets up w-fields in the MDE solvers for all blocks
* and then calls the base class PolymerTmpl solve function. This
* solves the MDE for all propagators and computes the properly
* scaled volume fraction fields for all blocks. After this function
* is called, the associated Block objects store pre-computed
* propagator solutions and block volume fraction fields.
*
* The parameter phiTot is only relevant to problems such as thin
* films in which the material is excluded from part of the unit
* cell by imposing an inhogeneous constraint on the sum of the
* monomer concentrations (i.e., a "mask").
*
* \param wFields array of chemical potential fields.
* \param phiTot volume fraction of unit cell occupied by material
*/
void compute(DArray< RField<D> > const & wFields,
double phiTot = 1.0);
/**
* Compute stress contribution from this species.
*
* This function computes contributions from this species to the
* derivatives of free energy per monomer with respect to unit cell
* parameters and stores the values.
*/
void computeStress();
/**
* Get precomputed contribution to stress from this species.
*
* This function gets the precomputed value of the derivative of
* free energy per monomer with respect to unit cell parameter n,
* as computed by the most recent call to computeStress().
*
* \param n index of unit cell parameter
*/
double stress(int n) const;
// Inherited public functions
using Base::nBlock;
using Base::block;
using Base::ensemble;
using Base::solve;
using Base::length;
protected:
using ParamComposite::setClassName;
using Base::phi_;
using Base::mu_;
private:
/// Stress contribution from this polymer species
FArray<double, 6> stress_;
/// Pointer to associated UnitCell<D>
const UnitCell<D>* unitCellPtr_;
};
/// Get stress with respect to unit cell parameter n.
template <int D>
inline double Polymer<D>::stress(int n) const
{ return stress_[n]; }
#ifndef PSPC_POLYMER_TPP
// Supress implicit instantiation
extern template class Polymer<1>;
extern template class Polymer<2>;
extern template class Polymer<3>;
#endif
}
}
#endif
| 5,705
|
C++
|
.h
| 153
| 31.287582
| 74
| 0.672638
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,172
|
Propagator.h
|
dmorse_pscfpp/src/pspc/solvers/Propagator.h
|
#ifndef PSPC_PROPAGATOR_H
#define PSPC_PROPAGATOR_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/solvers/PropagatorTmpl.h> // base class template
#include <pspc/field/RField.h> // member template
#include <util/containers/DArray.h> // member template
#include <util/containers/FArray.h> // member template
namespace Pscf { template <int D> class Mesh; }
namespace Pscf {
namespace Pspc
{
template <int D> class Block;
using namespace Util;
/**
* MDE solver for one direction of one block.
*
* A fully initialized Propagator<D> has an association with a
* Block<D> that owns this propagator and its partner, and has an
* association with a Mesh<D> that describes a spatial grid, in
* addition to associations with partner and source Propagator<D>
* objects that are managed by the PropagatorTmpl base class template.
*
* The associated Block<D> stores information required to numerically
* solve the modified diffusion equation (MDE), including the contour
* step size ds and all parameters that depend on ds. These quantities
* are set and stored by the block because their values must be the
* same for the two propagators owned by each block (i.e., this
* propagator and its partner). The algorithm used by a propagator
* to solve the the MDE simply repeatedly calls the step() function
* of the associated block, because that function has access to all
* the parameters used in the numerical solution.
*
* \ingroup Pspc_Solver_Module
*/
template <int D>
class Propagator : public PropagatorTmpl< Propagator<D> >
{
public:
// Public typedefs
/**
* Generic field (function of position, defined on regular grid).
*/
typedef RField<D> Field;
/**
* Chemical potential field type (r-grid format)
*/
typedef RField<D> WField;
/**
* Monomer concentration field type (r-grid format)
*/
typedef RField<D> CField;
/**
* Propagator q-field type, i.e., q(r,s) at fixed s.
*/
typedef RField<D> QField;
// Member functions
/**
* Constructor.
*/
Propagator();
/**
* Destructor.
*/
~Propagator();
/**
* Associate this propagator with a unique block.
*
* \param block associated Block object.
*/
void setBlock(Block<D>& block);
/**
* Allocate memory used by this propagator.
*
* The parameter ns is the number of values of s at which q(r,s) is
* calculated, including the end values at the terminating vertices.
* See docs for the function ns(), which returns this value.
*
* The address of the associated Mesh<D> object is retained.
*
* An Exception is thrown if the propagator is already allocated.
*
* \param ns number of slices (including end points)
* \param mesh spatial discretization mesh
*/
void allocate(int ns, const Mesh<D>& mesh);
/**
* Reallocate memory used by this propagator.
*
* This function is used when the value of ns is changed after initial
* allocation. This occurs during parameter sweeps that change the
* block length. See the docs for the function ns() for the definition
* of ns.
*
* The spatial mesh is set by derefencing a pointer to the associated
* Mesh<D> object, which was set by a previous call to allocate.
*
* An Exception is thrown if the propagator has not been previously
* allocated, or if the parameter ns is equal to the current value.
*
* \param ns number of slices (including end points)
*/
void reallocate(int ns);
/**
* Solve the modified diffusion equation (MDE) for this block.
*
* This function computes an initial QField at the head of this
* block, and then solves the modified diffusion equation (MDE) to
* propagate the solution from the head to the tail. The initial
* QField at the head is computed by pointwise multiplication of
* the tail QFields of all source propagators. The MDE is solved
* by repeatedly calling the step() function of the associated
* Block<D> .
*/
void solve();
/**
* Solve the MDE for a specified initial condition.
*
* This function solves the modified diffusion equation (MDE) for
* this block with a specified initial condition, which is given by
* the function parameter "head". The MDE is solved by repeatedly
* calling the step() function of the associated Block<D>.
*
* \param head initial condition of QField at head of block
*/
void solve(QField const & head);
/**
* Compute and return partition function for the polymer.
*
* This function computes the partition function Q for the
* molecule as a spatial average of pointwise product of the
* initial/head Qfield for this propagator and the final/tail
* Qfield of its partner.
*
* \return value of Q (spatial average of q*q^{+} at head)
*/
double computeQ();
/**
* Return q-field at specified step.
*
* \param i step index, 0 <= i < ns
*/
const QField& q(int i) const;
/**
* Return q-field at beginning of the block (initial condition).
*/
const QField& head() const;
/**
* Return q-field at the end of the block.
*/
const QField& tail() const;
/**
* Get the associated Block object by reference.
*/
Block<D>& block();
/**
* Number of values of s (or slices), including head and tail.
*
* The value of ns is the number of values of s at which q(r,s) is
* calculated, including the end values at the terminating vertices
* (the head and tail). This is one more than the number of contour
* variable steps.
*/
int ns() const;
/**
* Has memory been allocated for this propagator?
*/
bool isAllocated() const;
// Inherited public members with non-dependent names
using PropagatorTmpl< Propagator<D> >::nSource;
using PropagatorTmpl< Propagator<D> >::source;
using PropagatorTmpl< Propagator<D> >::partner;
using PropagatorTmpl< Propagator<D> >::setIsSolved;
using PropagatorTmpl< Propagator<D> >::isSolved;
using PropagatorTmpl< Propagator<D> >::hasPartner;
protected:
/**
* Compute initial QField at head from tail QFields of sources.
*/
void computeHead();
private:
/// Array of statistical weight fields
DArray<QField> qFields_;
/// Workspace
QField work_;
/// Pointer to associated Block.
Block<D>* blockPtr_;
/// Pointer to associated Mesh
Mesh<D> const * meshPtr_;
/// Number of grid points = # of contour length steps + 1
int ns_;
/// Is this propagator allocated?
bool isAllocated_;
};
// Inline member functions
/*
* Return q-field at beginning of block.
*/
template <int D>
inline
typename Propagator<D>::QField const& Propagator<D>::head() const
{ return qFields_[0]; }
/*
* Return q-field at end of block, after solution.
*/
template <int D>
inline
typename Propagator<D>::QField const& Propagator<D>::tail() const
{ return qFields_[ns_-1]; }
/*
* Return q-field at specified step.
*/
template <int D>
inline
typename Propagator<D>::QField const& Propagator<D>::q(int i) const
{ return qFields_[i]; }
/*
* Get the associated Block object.
*/
template <int D>
inline
Block<D>& Propagator<D>::block()
{
assert(blockPtr_);
return *blockPtr_;
}
/*
* Get the number of counter grid points.
*/
template <int D>
inline int Propagator<D>::ns() const
{ return ns_; }
template <int D>
inline bool Propagator<D>::isAllocated() const
{ return isAllocated_; }
/*
* Associate this propagator with a unique block.
*/
template <int D>
inline void Propagator<D>::setBlock(Block<D>& block)
{ blockPtr_ = █ }
#ifndef PSPC_PROPAGATOR_TPP
extern template class Propagator<1>;
extern template class Propagator<2>;
extern template class Propagator<3>;
#endif
}
}
#endif
| 8,636
|
C++
|
.h
| 253
| 28.158103
| 75
| 0.648811
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,173
|
Block.h
|
dmorse_pscfpp/src/pspc/solvers/Block.h
|
#ifndef PSPC_BLOCK_H
#define PSPC_BLOCK_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Propagator.h" // base class argument
#include <pscf/solvers/BlockTmpl.h> // base class template
#include <pscf/mesh/Mesh.h> // member
#include <pscf/crystal/UnitCell.h> // member
#include <pspc/field/RField.h> // member
#include <pspc/field/RFieldDft.h> // member
#include <pspc/field/FFT.h> // member
#include <util/containers/FArray.h> // member template
#include <util/containers/DMatrix.h> // member template
namespace Pscf {
template <int D> class Mesh;
template <int D> class UnitCell;
}
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Block within a branched polymer.
*
* Derived from BlockTmpl< Propagator<D> >. A BlockTmpl< Propagator<D> >
* has two Propagator<D> members and is derived from BlockDescriptor.
*
* \ref user_param_block_sec "Parameter File Format"
* \ingroup Pspc_Solver_Module
*/
template <int D>
class Block : public BlockTmpl< Propagator<D> >
{
public:
/**
* Constructor.
*/
Block();
/**
* Destructor.
*/
~Block();
/**
* Initialize discretization and allocate required memory.
*
* This function chooses a value for the number ns of contour
* variable grid points for this block so as to yield a value
* for the the actual step size length/(ns-1) as close as possible
* to the input parameter ds (the desired step size) consistent
* with the requirements that ns be odd and ns > 1. These
* requirements allow use of Simpson's rule for integration with
* respect to the contour variable s.
*
* \param ds desired (optimal) value for contour length step
* \param mesh spatial discretization mesh
*/
void setDiscretization(double ds, const Mesh<D>& mesh);
/**
* Setup parameters that depend on the unit cell.
*
* This should be called once after every change in unit cell
* parameters. Doing so marks internal variables that depends on the
* unit cell parameters as being "dirty" or outdated. These internal
* variables are actually recomputed later, in the setupSolver
* function, which is called within Polymer<D>::compute function before
* solving the modified diffusion equation (MDE) for all propagators
* associated with the polymer, using a pointer to the unit cell that
* is set in this function.
*
* \param unitCell crystallographic unit cell, defines cell dimensions
*/
void setupUnitCell(const UnitCell<D>& unitCell);
/**
* Set or reset block length.
*
* \param newLength new block length
*/
void setLength(double newLength);
/**
* Set or reset monomer statistical segment length.
*
* \param kuhn new monomer statistical segment length.
*/
void setKuhn(double kuhn);
/**
* Set solver for this block.
*
* This should be called once after every change in w fields, the
* unit cell parameters, block length or kuhn length, before
* entering the loop used to solve the MDE for either propagator.
* This function is called by Polymer<D>::compute.
*
* \param w chemical potential field for this monomer type
*/
void setupSolver(RField<D> const & w);
/**
* Compute one step of solution of MDE, from step i to i+1.
*
* This function is called internally by the PropagatorTmpl solve
* function within a loop over steps. It is implemented in the
* Block class because the same private data structures are needed
* for the two propagators associated with a Block.
*
* \param q input slic of q, from step i
* \param qNew ouput slice of q, from step i+1
*/
void step(RField<D> const & q, RField<D>& qNew);
/**
* Compute concentration (volume fraction) for block by integration.
*
* This should be called after both associated propagators are known.
* Upon return, grid point r of array cField() contains the integal,
* int ds q(r,s)q^{*}(r,L-s) times the prefactor parameter, where
* q(r,s) is the solution obtained from propagator(0), q^{*}(r,s) is
* the solution of propagator(1), and s is a contour variable that
* is integrated over the domain 0 < s < length(), where length()
* is the block length. The "prefactor" parameter for a system with
* a constant total density should be set to prefactor = phi/(L q),
* where phi is the overall volume fraction for this molecular species,
* L is the total number of monomers in the polymer species, and q is
* the species partition function, i.e., the spatial average of q(r,L).
* This function is called by Polymer<D>::compute().
*
* \param prefactor constant multiplying integral over s
*/
void computeConcentration(double prefactor);
/**
* Compute stress contribution for this block.
*
* This function is called by Polymer<D>::computeStress. The parameter
* prefactor should be the same as that passed to the function
* computeConcentration.
*
* \param prefactor constant multiplying integral over s
*/
void computeStress(double prefactor);
/**
* Get associated spatial Mesh by const reference.
*/
Mesh<D> const & mesh() const;
/**
* Get contour length step size.
*/
double ds() const;
/**
* Get the number of contour length steps in this block.
*/
int ns() const;
/**
* Get derivative of free energy w/ respect to unit cell parameter n.
*
* This function returns a value computed by a previous call to the
* computeStress function.
*
* \param n index of unit cell parameter
*/
double stress(int n) const;
// Functions with non-dependent names from BlockTmpl< Propagator<D> >
using BlockTmpl< Propagator<D> >::setKuhn;
using BlockTmpl< Propagator<D> >::propagator;
using BlockTmpl< Propagator<D> >::cField;
using BlockTmpl< Propagator<D> >::length;
using BlockTmpl< Propagator<D> >::kuhn;
// Functions with non-dependent names from BlockDescriptor
using BlockDescriptor::setId;
using BlockDescriptor::setVertexIds;
using BlockDescriptor::setMonomerId;
using BlockDescriptor::setLength;
using BlockDescriptor::id;
using BlockDescriptor::monomerId;
using BlockDescriptor::vertexIds;
using BlockDescriptor::vertexId;
using BlockDescriptor::length;
private:
// Matrix to store derivatives of plane waves
DMatrix<double> dGsq_;
// Stress arising from this block
FSArray<double, 6> stress_;
// Fourier transform plan
FFT<D> fft_;
// Array of elements containing exp(-K^2 b^2 ds/6)
RField<D> expKsq_;
// Array of elements containing exp(-W[i] ds/2)
RField<D> expW_;
// Array of elements containing exp(-K^2 b^2 ds/(6*2))
RField<D> expKsq2_;
// Array of elements containing exp(-W[i] (ds/2)*0.5)
RField<D> expW2_;
// Work array for real-space field (step size ds)
RField<D> qr_;
// Work array for real-space field (step size ds/2)
RField<D> qr2_;
// Work array for wavevector space field (step size ds)
RFieldDft<D> qk_;
// Work array for wavevector space field (step size ds/2)
RFieldDft<D> qk2_;
// Pointer to associated Mesh<D> object
Mesh<D> const* meshPtr_;
// Pointer to associated UnitCell<D> object
UnitCell<D> const* unitCellPtr_;
// Dimensions of wavevector mesh in real-to-complex transform
IntVec<D> kMeshDimensions_;
// Contour length step size (actual step size for this block)
double ds_;
// Contour length step size (value input in param file)
double dsTarget_;
// Number of contour grid points = # of contour steps + 1
int ns_;
// Have arrays been allocated in setDiscretization ?
bool isAllocated_;
// Are expKsq_ arrays up to date ? (initialize false)
bool hasExpKsq_;
/**
* Access associated UnitCell<D> as reference.
*/
UnitCell<D> const & unitCell() const
{ return *unitCellPtr_; }
/**
* Compute dGsq_ matrix.
*/
void computedGsq();
/**
* Compute expKSq_ arrays.
*/
void computeExpKsq();
};
// Inline member functions
/// Get number of contour steps.
template <int D>
inline int Block<D>::ns() const
{ return ns_; }
/// Get number of contour steps.
template <int D>
inline double Block<D>::ds() const
{ return ds_; }
/// Stress with respect to unit cell parameter n.
template <int D>
inline double Block<D>::stress(int n) const
{ return stress_[n]; }
/// Get Mesh by reference.
template <int D>
inline Mesh<D> const & Block<D>::mesh() const
{
UTIL_ASSERT(meshPtr_);
return *meshPtr_;
}
#ifndef PSPC_BLOCK_TPP
// Suppresse implicit instantiation
extern template class Block<1>;
extern template class Block<2>;
extern template class Block<3>;
#endif
}
}
#endif
| 9,669
|
C++
|
.h
| 258
| 31.158915
| 77
| 0.64775
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,174
|
Mixture.h
|
dmorse_pscfpp/src/pspc/solvers/Mixture.h
|
#ifndef PSPC_MIXTURE_H
#define PSPC_MIXTURE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Polymer.h"
#include "Solvent.h"
#include <pscf/solvers/MixtureTmpl.h>
#include <pscf/inter/Interaction.h>
#include <pscf/chem/Monomer.h>
#include <util/containers/DArray.h>
#include <util/containers/FArray.h>
#include <iostream>
namespace Pscf {
template <int D> class Mesh;
}
namespace Pscf {
namespace Pspc
{
/**
* Solver for a mixture of polymers and solvents.
*
* A Mixture contains a list of Polymer and Solvent objects. Each such
* object can solve the single-molecule statistical mechanics problem
* for an ideal gas of the associated species in a set of specified
* chemical potential fields, and thereby compute concentrations and
* and single-molecule partition functions. A Mixture is thus both a
* a chemistry descriptor and an ideal-gas solver.
*
* The single-molecule partition functions and concentrations for a
* non-interacting mixture of polymer and solvent species are computed
* by invoking the Mixture::compute function. The Mixture::compute
* function takes an arrays of monomer chemical potential fields
* (w fields) as an input argument and an array of monomer concentration
* fields (c fields) as an output. The objects that store these fields
* are owned by the parent System.
*
* A Mixture is associated with a Mesh<D> object, which models a spatial
* discretization mesh, and a UnitCell<D> object, which describes the
* the periodic unit cell. The Mixture::setupUnitCell function sets up
* all parameters that depend on the unit cell, and must be called once
* once after every time the unit cell is initialized or modified,
* before the next call to Mixture::compute.
*
* \ref user_param_mixture_page "Parameter File Format"
* \ingroup Pspc_Solver_Module
*/
template <int D>
class Mixture : public MixtureTmpl< Polymer<D>, Solvent<D> >
{
public:
/**
* Constructor.
*/
Mixture();
/**
* Destructor.
*/
~Mixture();
/**
* Read all parameters and initialize.
*
* This function reads in a complete description of the structure of
* all species and the composition of the mixture, as well as the
* target contour length step size ds.
*
* \param in input parameter stream
*/
void readParameters(std::istream& in);
/**
* Create an association with the mesh and allocate memory.
*
* The Mesh<D> object must have already been initialized,
* e.g., by reading its parameters from a file, so that the
* mesh dimensions are known on entry.
*
* \param mesh associated Mesh<D> object (stores address).
*/
void setMesh(Mesh<D> const & mesh);
/**
* Set unit cell parameters used in solver.
*
* This function resets unit cell information in the solvers for
* every species in the system. It should be called once after
* every change in the unit cell.
*
* \param unitCell UnitCell<D> object that contains Bravais lattice.
*/
void setupUnitCell(const UnitCell<D>& unitCell);
/**
* Reset statistical segment length for one monomer type.
*
* This function resets the kuhn or statistical segment length value
* for a monomer type, and updates the associcated value in every
* block of that monomer type.
*
* \param monomerId monomer type id
* \param kuhn new value for the statistical segment length
*/
void setKuhn(int monomerId, double kuhn);
/**
* Compute partition functions and concentrations.
*
* This function calls the compute function of every molecular
* species, and then adds the resulting block concentration fields
* for blocks of the same monomer type to compute a total monomer
* concentration (or volume fraction) for each monomer type.
* Upon return, values are set for volume fraction and chemical
* potential (mu) members of each species, and for the
* concentration fields for each Block and Solvent. The total
* concentration for each monomer type is returned in the
* cFields output parameter. Monomer "concentrations" are returned
* in units of inverse steric volume per monomer in an incompressible
* mixture, and are thus also volume fractions.
*
* The arrays wFields and cFields must each have capacity nMonomer(),
* and contain fields that are indexed by monomer type index.
*
* The optional parameter phiTot is only relevant to problems such as
* thin films in which the material is excluded from part of the unit
* cell by imposing an inhomogeneous constrain on the sum of mononer
* concentrations, (i.e., a "mask").
*
* \param wFields array of chemical potential fields (input)
* \param cFields array of monomer concentration fields (output)
* \param phiTot volume fraction of unit cell occupied by material
*/
void compute(DArray< RField<D> > const & wFields,
DArray< RField<D> >& cFields,
double phiTot = 1.0);
/**
* Compute derivatives of free energy w/ respect to cell parameters.
*/
void computeStress();
/**
* Combine cFields for each block/solvent into one DArray, which
* is used in System.tpp to print a more detailed r-grid file using
* the command WRITE_C_BLOCK_RGRID.
*
* \param blockCFields empty but allocated DArray to store fields
*/
void createBlockCRGrid(DArray< RField<D> >& blockCFields) const;
/**
* Get derivative of free energy w/ respect to a unit cell parameter.
*
* Get the pre-computed derivative with respect to unit cell
* parameter number n of the free energy per monomer (i.e., of the
* product of the free energy density and the monomer reference
* volume). The returned value is precomputed by the computeStress()
* function.
*
* \param n index of unit cell parameter
*/
double stress(int n) const;
/**
* Is this mixture being treated in canonical ensemble?
*
* Returns true iff an closed ensemble is used for every polymer
* and solve species, by specifying a volume fraction phi rather
* than a chemical potential mu for every species.
*/
bool isCanonical();
// Inherited public member functions with non-dependent names
using MixtureTmpl< Polymer<D>, Solvent<D> >::nMonomer;
using MixtureTmpl< Polymer<D>, Solvent<D> >::nPolymer;
using MixtureTmpl< Polymer<D>, Solvent<D> >::nSolvent;
using MixtureTmpl< Polymer<D>, Solvent<D> >::nBlock;
using MixtureTmpl< Polymer<D>, Solvent<D> >::polymer;
using MixtureTmpl< Polymer<D>, Solvent<D> >::monomer;
using MixtureTmpl< Polymer<D>, Solvent<D> >::solvent;
protected:
// Inherited protected member functions with non-dependent names
using MixtureTmpl< Polymer<D>, Solvent<D> >::setClassName;
using ParamComposite::read;
using ParamComposite::readOptional;
private:
/// Optimal contour length step size.
double ds_;
/// Array to store total stress
FArray<double, 6> stress_;
/// Pointer to associated Mesh<D> object.
Mesh<D> const * meshPtr_;
/// Pointer to associated UnitCell<D>
UnitCell<D> const * unitCellPtr_;
/// Return associated domain by reference.
Mesh<D> const & mesh() const;
/// Has stress been computed for current w fields?
bool hasStress_;
};
// Inline member function
// Stress with respect to unit cell parameter n.
template <int D>
inline double Mixture<D>::stress(int n) const
{
UTIL_CHECK(hasStress_);
return stress_[n];
}
// Get Mesh<D> by constant reference (private).
template <int D>
inline Mesh<D> const & Mixture<D>::mesh() const
{
UTIL_ASSERT(meshPtr_);
return *meshPtr_;
}
#ifndef PSPC_MIXTURE_TPP
extern template class Mixture<1>;
extern template class Mixture<2>;
extern template class Mixture<3>;
#endif
} // namespace Pspc
} // namespace Pscf
#endif
| 8,533
|
C++
|
.h
| 215
| 33.627907
| 75
| 0.68044
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,175
|
Solvent.h
|
dmorse_pscfpp/src/pspc/solvers/Solvent.h
|
#ifndef PSPC_SOLVENT_H
#define PSPC_SOLVENT_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/chem/SolventDescriptor.h> // base class
#include <pspc/solvers/Propagator.h> // typedefs
namespace Pscf {
template <int D> class Mesh;
}
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Solver and descriptor for a solvent species.
*
* \ref user_param_solvent_sec "Parameter File Format"
* \ingroup Pspc_Solver_Module
*/
template <int D>
class Solvent : public SolventDescriptor
{
public:
/**
* Constructor.
*/
Solvent();
/**
* Destructor.
*/
~Solvent();
/**
* Set association with Mesh and allocate concentration field array.
*
* \param mesh associated Mesh<D> object
*/
void setDiscretization(Mesh<D> const & mesh);
/**
* Compute monomer concentration field, q and phi and/or mu.
*
* Computes monomer concentration field cField, partition function
* q, and either the solvent volume fraction phi or solvent chemical
* potential mu, depending on ensemble. The function takes the
* chemical potential field wField for the relevant monomer type as
* its only input argument.
*
* The optional parameter phiTot is only relevant to problems such
* as thin films in which the material is excluded from part of the
* unit cell by imposing an inhomogeneous constraint on the sum of
* monomer concentrations (i.e., a "mask").
*
* \param wField monomer chemical potential field of relevant type.
* \param phiTot volume fraction of unit cell occupied by material
*/
void compute(RField<D> const & wField, double phiTot = 1.0);
/**
* Get the monomer concentration field for this solvent.
*/
RField<D> const & cField() const;
// Inherited accessor functions
using Pscf::Species::phi;
using Pscf::Species::mu;
using Pscf::Species::q;
using Pscf::Species::ensemble;
using Pscf::SolventDescriptor::monomerId;
using Pscf::SolventDescriptor::size;
protected:
// Inherited protected data members
using Pscf::Species::phi_;
using Pscf::Species::mu_;
using Pscf::Species::q_;
using Pscf::Species::ensemble_;
using Pscf::SolventDescriptor::monomerId_;
using Pscf::SolventDescriptor::size_;
private:
/// Concentration field for this solvent
RField<D> cField_;
/// Pointer to associated mesh
Mesh<D> const * meshPtr_;
};
// Inline member function
/*
* Get monomer concentration field for this solvent.
*/
template <int D>
inline RField<D> const & Solvent<D>::cField() const
{ return cField_; }
#ifndef PSPC_SOLVENT_TPP
// Supress implicit instantiation
extern template class Solvent<1>;
extern template class Solvent<2>;
extern template class Solvent<3>;
#endif
}
}
#endif
| 3,175
|
C++
|
.h
| 99
| 26.505051
| 74
| 0.66853
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,176
|
SweepParameter.h
|
dmorse_pscfpp/src/pspc/sweep/SweepParameter.h
|
#ifndef PSPC_SWEEP_PARAMETER_H
#define PSPC_SWEEP_PARAMETER_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <iostream>
namespace Pscf {
namespace Pspc {
template <int D> class System;
/**
* Class for storing data about an individual sweep parameter.
*
* This class stores the information required to sweep a single
* parameter value of any of several types. The type of parameter
* is indicated in the public interface and parameter file format
* by a string identifier with any of several allowed values.
* Each parameter is also identified by one or two associated index
* values, denoted here by id(0) and id(1), that specify the index
* or indices for a subobject or array element with which the
* parameter is associated applied. Allowed string representations
* and meanings of parameter types are given below, along with the
* meaning of any associated index value or pair of values.
* To indicate the meaning of index values, we use mId to denote
* a monomer type index, pId to denote a polymer species index,
* bId to denote the index of a block within a polymer, sId to
* denote a solvent species index, lId to denote a lattice parameter
* index, and wId to denote a wall index:
* \code
* | Type | Meaning | id(0) | id(1)
* | ----------- | ---------------------------------- | ----- | -----
* | kuhn | monomer segment length | mId |
* | chi | Flory-Huggins parameter | mId | mId
* | block | block length | pId | bId
* | solvent | solvent size | sId |
* | phi_polymer | polymer volume fraction | pId |
* | mu_polymer | polymer chemical potential | pId |
* | phi_solvent | solvent volume fraction | sId |
* | mu_solvent | solvent chemical potential | sId |
* | cell_param | lattice parameter | lId |
* | chi_bottom | thin film wall/monomer interaction | mId |
* | chi_top | thin film wall/monomer interaction | mId |
* \endcode
* The two indices for a Flory-Huggins chi parameter refer to indices
* in the chi matrix maintained by Interaction. Changes to element
* chi(i, j) automatically also update chi(j, i) for i !\ j, thus
* maintaining the symmetry of the matrix.
*
* Each SweepParameter also has a "change" value that gives the
* intended difference between the final and initial value of the
* parameter over the course of a sweep, corresponding to a change
* sweep parameter s over the range [0,1]. The initial value of each
* parameter is obtained from a query of the state of the parent
* system at the beginning of a sweep, and thus does not need to
* be supplied as part of the text format for a SweepParameter.
*
* A SweepParameter<D> object is initialized by reading the parameter
* type, index or index and change value from a parameter file as a
* a single line. An overloaded >> operator is defined that allows
* a SweepParameter<D> object named "parameter" to be read from an
* istream named "in" using the syntax "in >> parameter".
*
* The text format for a parameter of a type that requires a single
* index id(0) is:
*
* type id(0) change
*
* where type indicates a type string, id(0) is an integer index value,
* and change is the a floating point value for the change in parameter
* value. The corresponding format for a parameter that requires two
* indices (e.g., block or chi) is instead: "type id(0) id(1) change".
*
* \ingroup Pspc_Sweep_Module
*/
template <int D>
class SweepParameter
{
public:
/**
* Default constructor.
*/
SweepParameter();
/**
* Constructor that stores a pointer to parent system.
*
* \param system parent system
*/
SweepParameter(System<D>& system);
/**
* Set the system associated with this object.
*
* Invoke this function on objects created with the default
* constructor to create an association with a parent system.
*
* \param system parent system
*/
void setSystem(System<D>& system)
{ systemPtr_ = &system;}
/**
* Store the pre-sweep value of the corresponding parameter.
*/
void getInitial();
/**
* Update the corresponding parameter value in the system.
*
* \param newVal new value for the parameter (input)
*/
void update(double newVal);
/**
* Return a string representation of the parameter type.
*/
std::string type() const;
/**
* Write the parameter type to an output stream.
*
* \param out output file stream
*/
void writeParamType(std::ostream& out) const;
/**
* Get a id for a sub-object or element to which this is applied.
*
* This function returns a value from the id_ array. Elements
* of this array store indices associating the parameter with
* a particular subobject or value. Different types of parameters
* require either 1 or 2 such identifiers. The number of required
* identifiers is denoted by private variable nID_.
*
*
*
* \param i array index to access
*/
int id(int i) const
{ return id_[i];}
/**
* Return the current system parameter value.
*/
double current()
{ return get_(); }
/**
* Return the initial system parameter value.
*/
double initial() const
{ return initial_; }
/**
* Return the total change planned for this parameter during sweep.
*/
double change() const
{ return change_; }
/**
* Serialize to or from an archive.
*
* \param ar Archive object
* \param version archive format version index
*/
template <class Archive>
void serialize(Archive ar, const unsigned int version);
private:
/// Enumeration of allowed parameter types.
enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
Chi_Bottom, Chi_Top, Null};
/// Type of parameter associated with an object of this class.
ParamType type_;
/// Number of identifiers needed for this parameter type.
int nID_;
/// Identifier indices.
DArray<int> id_;
/// Initial parameter value, retrieved from system at start of sweep.
double initial_;
/// Change in parameter
double change_;
/// Pointer to the parent system.
System<D>* systemPtr_;
/**
* Read type of parameter being swept, and set number of identifiers.
*
* \param in input stream from param file.
*/
void readParamType(std::istream& in);
/**
* Gets the current system parameter value.
*/
double get_();
/**
* Set the system parameter value.
*
* \param newVal new value for this parameter.
*/
void set_(double newVal);
/**
* Check if the system iterator is a thin film iterator.
*/
bool isFilmIterator() const;
// friends:
template <int U>
friend
std::istream& operator >> (std::istream&, SweepParameter<U>&);
template <int U>
friend
std::ostream&
operator << (std::ostream&, SweepParameter<U> const&);
};
/**
* Inserter for reading a SweepParameter from an istream.
*
* \param in input stream
* \param param SweepParameter<D> object to read
*/
template <int D>
std::istream& operator >> (std::istream& in,
SweepParameter<D>& param);
/**
* Extractor for writing a SweepParameter to ostream.
*
* \param out output stream
* \param param SweepParameter<D> object to write
*/
template <int D>
std::ostream& operator << (std::ostream& out,
SweepParameter<D> const & param);
}
}
#include "SweepParameter.tpp"
#endif
| 8,415
|
C++
|
.h
| 226
| 31.159292
| 75
| 0.624755
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,177
|
FieldState.h
|
dmorse_pscfpp/src/pspc/sweep/FieldState.h
|
#ifndef PSPC_FIELD_STATE_H
#define PSPC_FIELD_STATE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2021, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/crystal/UnitCell.h> // member
#include <pspc/field/FieldIo.h> // member
#include <util/containers/DArray.h> // member template
namespace Pscf {
namespace Pspc
{
using namespace Util;
template <int D> class System;
/**
* Record of a state of a System (fields + unit cell).
*
* - a UnitCell<D> object
* - An array of field objects of class FT
*
* The template parameter D is the dimension of space, while
* parameter FT is a field type.
*
* A FieldState can be used to store either chemical potential or
* concentration fields, along with an associated UnitCell<D>.
* Different choices for class FT can be used to store fields in
* symmetry-adapted basis function, r-grid or k-grid format.
*
* \ingroup Pspc_Sweep_Module
*/
template <int D, class FT>
class FieldState
{
public:
/// \name Construction and Destruction
///@{
/**
* Default constructor.
*/
FieldState();
/**
* Constructor, creates association with a System.
*
* Equivalent to default construction followed by setSystem(system).
*
* \param system associated parent System<D> object.
*/
FieldState(System<D>& system);
/**
* Destructor.
*/
~FieldState();
/**
* Set association with System, after default construction.
*
* \param system associated parent System<D> object.
*/
void setSystem(System<D>& system);
///@}
/// \name Accessors
///@{
/**
* Get array of all fields by const reference.
*
* The array capacity is equal to the number of monomer types.
*/
const DArray<FT>& fields() const;
/**
* Get array of all chemical potential fields (non-const reference).
*
* The array capacity is equal to the number of monomer types.
*/
DArray<FT>& fields();
/**
* Get a field for a single monomer type by const reference.
*
* \param monomerId integer monomer type index
*/
const FT& field(int monomerId) const;
/**
* Get field for a specific monomer type (non-const reference).
*
* \param monomerId integer monomer type index
*/
FT& field(int monomerId);
/**
* Get UnitCell (i.e., lattice type and parameters) by const reference.
*/
const UnitCell<D>& unitCell() const;
/**
* Get the UnitCell by non-const reference.
*/
UnitCell<D>& unitCell();
///@}
protected:
/**
* Has a system been set?
*/
bool hasSystem();
/**
* Get associated System by reference.
*/
System<D>& system();
private:
/**
* Array of fields for all monomer types.
*/
DArray<FT> fields_;
/**
* Crystallographic unit cell (crystal system and cell parameters).
*/
UnitCell<D> unitCell_;
/**
* Pointer to associated system.
*/
System<D>* systemPtr_;
};
// Public inline member functions
// Get an array of all fields (const reference)
template <int D, class FT>
inline
const DArray<FT>& FieldState<D,FT>::fields() const
{ return fields_; }
// Get an array of all fields (non-const reference)
template <int D, class FT>
inline
DArray<FT>& FieldState<D,FT>::fields()
{ return fields_; }
// Get field for monomer type id (const reference)
template <int D, class FT>
inline
const FT& FieldState<D,FT>::field(int id) const
{ return fields_[id]; }
// Get field for monomer type id (non-const reference)
template <int D, class FT>
inline FT& FieldState<D,FT>::field(int id)
{ return fields_[id]; }
// Get the internal Unitcell (const reference)
template <int D, class FT>
inline
const UnitCell<D>& FieldState<D,FT>::unitCell() const
{ return unitCell_; }
// Get the internal Unitcell (non-const reference)
template <int D, class FT>
inline UnitCell<D>& FieldState<D,FT>::unitCell()
{ return unitCell_; }
// Protected inline member functions
// Has the system been set?
template <int D, class FT>
inline bool FieldState<D,FT>::hasSystem()
{ return (systemPtr_ != 0); }
// Get the associated System<D> object.
template <int D, class FT>
inline System<D>& FieldState<D,FT>::system()
{
assert(systemPtr_ != 0);
return *systemPtr_;
}
#ifndef PSPC_FIELD_STATE_TPP
// Suppress implicit instantiation
extern template class FieldState< 1, DArray<double> >;
extern template class FieldState< 2, DArray<double> >;
extern template class FieldState< 3, DArray<double> >;
#endif
} // namespace Pspc
} // namespace Pscf
#endif
| 5,067
|
C++
|
.h
| 169
| 24.538462
| 76
| 0.631102
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,178
|
SweepFactory.h
|
dmorse_pscfpp/src/pspc/sweep/SweepFactory.h
|
#ifndef PSPC_SWEEP_FACTORY_H
#define PSPC_SWEEP_FACTORY_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <util/param/Factory.h>
#include "Sweep.h"
#include <string>
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Default Factory for subclasses of Sweep.
*
* \ingroup Pspc_Sweep_Module
*/
template <int D>
class SweepFactory : public Factory< Sweep<D> >
{
public:
/**
* Constructor.
*
* \param system parent System object
*/
SweepFactory(System<D>& system);
/**
* Method to create any Sweep subclass.
*
* \param className name of the Sweep subclass
* \return Sweep<D>* pointer to new instance of speciesName
*/
Sweep<D>* factory(std::string const & className) const;
using Factory< Sweep<D> >::trySubfactories;
private:
System<D>* systemPtr_;
};
#ifndef PSPC_SWEEP_FACTORY_TPP
// Suppress implicit instantiation
extern template class SweepFactory<1>;
extern template class SweepFactory<2>;
extern template class SweepFactory<3>;
#endif
}
}
#endif
| 1,274
|
C++
|
.h
| 49
| 21.632653
| 67
| 0.682684
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,179
|
LinearSweep.h
|
dmorse_pscfpp/src/pspc/sweep/LinearSweep.h
|
#ifndef PSPC_LINEAR_SWEEP_H
#define PSPC_LINEAR_SWEEP_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Sweep.h" // base class
#include "SweepParameter.h" // member
#include <util/global.h>
#include <iostream>
namespace Pscf {
namespace Pspc {
template <int D> class System;
using namespace Util;
/**
* A sweep in parameter space where one or more parameters change
* linearly with the sweep variable.
*
* \ref user_param_sweep_linear_sec "Parameter File Format"
* \ingroup Pspc_Sweep_Module
*/
template <int D>
class LinearSweep : public Sweep<D>
{
public:
/**
* Constructor.
* \param system parent System object
*/
LinearSweep(System<D>& system);
/**
* Read parameters from param file.
*
* \param in Input stream from param file.
*/
void readParameters(std::istream& in);
/**
* Setup operation at the beginning of a sweep. Gets initial
* values of individual parameters.
*/
void setup();
/**
* Set the state before an iteration. Called with each new iteration
* in SweepTempl::sweep()
*
* \param s path length coordinate, in [0,1]
*/
void setParameters(double s);
/**
* Output data to a running summary.
*
* \param out output file, open for writing
*/
void outputSummary(std::ostream& out);
protected:
using Sweep<D>::system;
using Sweep<D>::hasSystem;
private:
/// Number of parameters being swept.
int nParameter_;
/// Array of SweepParameter objects.
DArray< SweepParameter<D> > parameters_;
};
#ifndef PSPC_LINEAR_SWEEP_TPP
// Suppress implicit instantiation
extern template class LinearSweep<1>;
extern template class LinearSweep<2>;
extern template class LinearSweep<3>;
#endif
}
}
#endif
| 2,077
|
C++
|
.h
| 74
| 22.783784
| 74
| 0.651646
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,180
|
Sweep.h
|
dmorse_pscfpp/src/pspc/sweep/Sweep.h
|
#ifndef PSPC_SWEEP_H
#define PSPC_SWEEP_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/sweep/SweepTmpl.h> // base class template
#include <pspc/sweep/BasisFieldState.h> // base class template parameter
#include "SweepParameter.h" // parameter class
#include <util/global.h>
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Solve a sequence of problems along a line in parameter space.
*/
template <int D>
class Sweep : public SweepTmpl< BasisFieldState<D> >
{
public:
/**
* Default Constructor.
*/
Sweep();
/**
* Constructor, creates assocation with parent system.
*/
Sweep(System<D>& system);
/**
* Destructor.
*/
~Sweep();
/**
* Set association with parent System.
*/
void setSystem(System<D>& system);
/**
* Read parameters from param file.
*
* \param in Input stream from param file.
*/
virtual void readParameters(std::istream& in);
// Public members inherited from base class template SweepTmpl
using SweepTmpl< BasisFieldState<D> >::historyCapacity;
using SweepTmpl< BasisFieldState<D> >::historySize;
using SweepTmpl< BasisFieldState<D> >::nAccept;
using SweepTmpl< BasisFieldState<D> >::state;
using SweepTmpl< BasisFieldState<D> >::s;
using SweepTmpl< BasisFieldState<D> >::c;
protected:
/**
* Check allocation state of fields in one state, allocate if necessary.
*
* \param state object that represents a stored state of the system.
*/
virtual void checkAllocation(BasisFieldState<D>& state);
/**
* Setup operation at the beginning of a sweep.
*/
virtual void setup();
/**
* Set non-adjustable system parameters to new values.
*
* \param sNew contour variable value for new trial solution.
*/
virtual void setParameters(double sNew) = 0;
/**
* Create a guess for adjustable variables by continuation.
*
* \param sNew contour variable value for new trial solution.
*/
virtual void extrapolate(double sNew);
/**
* Call current iterator to solve SCFT problem.
*
* Return 0 for sucessful solution, 1 on failure to converge.
*/
virtual int solve(bool isContinuation);
/**
* Reset system to previous solution after iterature failure.
*
* The implementation of this function should reset the system state
* to correspond to that stored in state(0).
*/
virtual void reset();
/**
* Update state(0) and output data after successful convergence
*
* The implementation of this function should copy the current
* system state into state(0) and output any desired information
* about the current converged solution.
*/
virtual void getSolution();
/**
* Cleanup operation at the beginning of a sweep.
*/
virtual void cleanup();
/**
* Has an association with the parent System been set?
*/
bool hasSystem()
{ return (systemPtr_ != 0); }
/**
* Return the parent system by reference.
*/
System<D>& system()
{ return *systemPtr_; }
/// Whether to write real space concentration field files.
bool writeCRGrid_;
/// Whether to write concentration field files in basis format.
bool writeCBasis_;
/// Whether to write real space potential field files.
bool writeWRGrid_;
// Protected members inherited from base classes
using SweepTmpl< BasisFieldState<D> >::ns_;
using SweepTmpl< BasisFieldState<D> >::baseFileName_;
using SweepTmpl< BasisFieldState<D> >::initialize;
using SweepTmpl< BasisFieldState<D> >::setCoefficients;
using ParamComposite::readOptional;
private:
/// Trial state (produced by continuation in setGuess)
BasisFieldState<D> trial_;
/// Unit cell parameters for trial state
FSArray<double, 6> unitCellParameters_;
/// Log file for summary output
std::ofstream logFile_;
/// Pointer to parent system.
System<D>* systemPtr_;
/// Output data to several files after convergence
void outputSolution();
/// Output brief summary of thermodynamic properties
void outputSummary(std::ostream&);
};
} // namespace Pspc
} // namespace Pscf
#endif
| 4,661
|
C++
|
.h
| 138
| 27.449275
| 77
| 0.65166
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,181
|
BasisFieldState.h
|
dmorse_pscfpp/src/pspc/sweep/BasisFieldState.h
|
#ifndef PSPC_BASIS_FIELD_STATE_H
#define PSPC_BASIS_FIELD_STATE_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2021, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "FieldState.h"
#include <string>
namespace Pscf {
namespace Pspc
{
using namespace Util;
/**
* FieldState for fields in symmetry-adapted basis format.
*/
template <int D>
class BasisFieldState : public FieldState<D, DArray<double> >
{
public:
/**
* Default constructor.
*/
BasisFieldState();
/**
* Constructor, create association with a parent system.
*
* \param system associated parent system
*/
BasisFieldState(System<D>& system);
/**
* Destructor.
*/
~BasisFieldState();
/**
* Allocate all fields.
*
* Precondition: hasSystem() == true
*/
void allocate();
/**
* Read state from file.
*
* \param filename name of input w-field file in symmetry-adapted format.
*/
void read(const std::string & filename);
/**
* Write state to file.
*
* \param filename name of output file, in symmetry-adapated format.
*/
void write(const std::string & filename);
/**
* Copy the current state of the associated system.
*
* Copy the fields and the unit cell.
*/
void getSystemState();
/**
* Set the state of the associated system to this state.
*
* \param isFlexible update system unit cell iff isFlexible == true.
*/
void setSystemState(bool isFlexible);
// Inherited member functions
using FieldState<D, DArray<double> >::fields;
using FieldState<D, DArray<double> >::field;
using FieldState<D, DArray<double> >::unitCell;
using FieldState<D, DArray<double> >::system;
using FieldState<D, DArray<double> >::hasSystem;
using FieldState<D, DArray<double> >::setSystem;
};
#ifndef PSPC_BASIS_FIELD_STATE_TPP
// Suppress implicit instantiation
extern template class BasisFieldState<1>;
extern template class BasisFieldState<2>;
extern template class BasisFieldState<3>;
#endif
} // namespace Pspc
} // namespace Pscf
#endif
| 2,339
|
C++
|
.h
| 82
| 23
| 78
| 0.647743
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,182
|
IteratorTestComposite.h
|
dmorse_pscfpp/src/pspc/tests/iterator/IteratorTestComposite.h
|
#ifndef PSPC_TEST_ITERATOR_TEST_COMPOSITE_H
#define PSPC_TEST_ITERATOR_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
// include the headers for individual tests
#include "FilmIteratorTest.h"
TEST_COMPOSITE_BEGIN(IteratorTestComposite)
TEST_COMPOSITE_ADD_UNIT(FilmIteratorTest)
TEST_COMPOSITE_END
#endif
| 317
|
C++
|
.h
| 9
| 33.666667
| 43
| 0.848684
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,183
|
FilmIteratorTest.h
|
dmorse_pscfpp/src/pspc/tests/iterator/FilmIteratorTest.h
|
#ifndef PSPC_FILM_ITERATOR_TEST_H
#define PSPC_FILM_ITERATOR_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/iterator/FilmIterator.h>
#include <pspc/iterator/AmIterator.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/FieldIo.h>
#include <pspc/System.h>
#include <pscf/crystal/BFieldComparison.h>
#include <pscf/crystal/UnitCell.h>
#include <util/misc/Exception.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pspc;
class FilmIteratorTest : public UnitTest
{
public:
std::ofstream logFile_;
void setUp()
{ setVerbose(0); }
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
}
void testConstructor()
{
printMethod(TEST_FUNC);
System<3> system;
FilmIterator<3, AmIterator<3> > iterator(system);
}
void testReadParameters() // test FilmIterator::readParameters()
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestReadParameters.log");
// Set up system with some data
System<2> system;
FilmIteratorTest::setUpSystem(system, "in/film/system2D");
// Set up iterator from file
FilmIterator<2, AmIterator<2> > iterator(system);
FilmIteratorTest::setUpFilmIterator(iterator, "in/film/film2D");
// Check that everything was read in correctly
TEST_ASSERT(eq(iterator.normalVecId(),1));
TEST_ASSERT(eq(iterator.interfaceThickness(),0.2));
TEST_ASSERT(eq(iterator.wallThickness(),0.4));
TEST_ASSERT(eq(iterator.chiBottom(0),3.0));
TEST_ASSERT(eq(iterator.chiBottom(1),0.0));
TEST_ASSERT(eq(iterator.chiTop(0),0.0));
TEST_ASSERT(eq(iterator.chiTop(1),4.0));
TEST_ASSERT(iterator.isFlexible());
}
void testGenerateWallFields() // testFilmIterator::generateWallFields()
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestGenerateWallFields.log");
// Set up system with some data
System<1> system;
FilmIteratorTest::setUpSystem(system, "in/film/system1D");
// Set up iterator from file
FilmIterator<1, AmIterator<1> > iterator(system);
FilmIteratorTest::setUpFilmIterator(iterator, "in/film/film1D");
system.readWBasis("in/film/w_1D_ref.bf");
// Allocate mask and external field containers
system.mask().allocate(system.basis().nBasis(),
system.mesh().dimensions());
system.h().allocateRGrid(system.mesh().dimensions());
system.h().allocateBasis(system.basis().nBasis());
// Run the generateWallFields function
iterator.generateWallFields();
// Check that the homogeneous components of the mask
// and the blocks were adjusted correctly
TEST_ASSERT(eq(system.mask().phiTot(),8.0951532073e-01));
// output mask field files for reference
system.fieldIo().writeFieldBasis("out/mask_1D.bf", system.mask().basis(),
system.unitCell());
system.fieldIo().writeFieldRGrid("out/mask_1D.rf", system.mask().rgrid(),
system.unitCell());
// output external field for reference
system.fieldIo().writeFieldsBasis("out/h_1D.bf", system.h().basis(),
system.unitCell());
// Check that the mask field files were generated correctly by
// comparing them to the reference files in in/film
UnitCell<1> unitCell; // UnitCell object to pass into FieldIo functions
DArray<double> cFieldsCheck; // Copy of reference field
system.fieldIo().readFieldBasis("in/film/mask_1D_ref.bf",
cFieldsCheck, unitCell);
BFieldComparison bComparison(0); // object to compare fields
bComparison.compare(system.mask().basis(), cFieldsCheck);
if (verbose() > 0) {
std::cout << "\nMax error = " << bComparison.maxDiff() << "\n";
}
TEST_ASSERT(bComparison.maxDiff() < 1.0E-7);
RField<1> cRGridCheck; // Array to store reference field
system.fieldIo().readFieldRGrid("in/film/mask_1D_ref.rf",
cRGridCheck, unitCell);
RField<1> cRGridFromIterator;
cRGridFromIterator.allocate(system.domain().mesh().dimensions());
// Put iterator cField inside a DArray so it can be passed into
// convertBasisToRGrid
DArray<double> cFieldFromIterator;
cFieldFromIterator = system.mask().basis();
system.fieldIo().convertBasisToRGrid(cFieldFromIterator,
cRGridFromIterator);
RFieldComparison<1> rComparison; // object to compare fields
rComparison.compare(cRGridFromIterator, cRGridCheck);
if (verbose() > 0) {
std::cout << "\nMax error = " << rComparison.maxDiff() << "\n";
}
TEST_ASSERT(rComparison.maxDiff() < 1.0E-7);
}
void testCheckSpaceGroup1DA() // test FilmIterator::checkSpaceGroup
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckSpaceGroup1DA.log");
// Set up 1D system with a correct space group and check it
System<1> system1;
FilmIteratorTest::setUpSystem(system1, "in/film/system1D");
// Set unit cell parameter
FSArray<double, 6> parameters;
double parameter = 2.9;
parameters.append(parameter);
system1.setUnitCell(UnitCell<1>::Lamellar, parameters);
//system1.readWBasis("in/film/w_ref.bf");
FilmIterator<1, AmIterator<1> > iterator1(system1);
FilmIteratorTest::setUpFilmIterator(iterator1, "in/film/film1D");
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator1,false));
}
void testCheckSpaceGroup1DB() // test FilmIterator::checkSpaceGroup
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckSpaceGroup1DB.log");
// Set up 1D system with an incorrect space group and check it
System<1> system2;
FilmIteratorTest::setUpSystem(system2, "in/film/system_bad_1D");
FilmIterator<1, AmIterator<1> > iterator2(system2);
// Set unit cell parameter
FSArray<double, 6> parameters;
//double parameter = 2.2;
parameters.append(2.2);
system2.setUnitCell(UnitCell<1>::Lamellar, parameters);
FilmIteratorTest::setUpFilmIterator(iterator2, "in/film/film1D");
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator2,true));
}
void testCheckSpaceGroup2D() // test FilmIterator::checkSpaceGroup
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckSpaceGroup2D.log");
// Set up 2D system with an incorrect space group and check it
System<2> system3;
FilmIteratorTest::setUpSystem(system3, "in/film/system_bad_2D_2");
// Set unit cell parameter
FSArray<double, 6> parameters;
parameters.append(2.0);
parameters.append(2.0);
system3.setUnitCell(UnitCell<2>::Rectangular, parameters);
FilmIterator<2, AmIterator<2> > iterator3(system3);
FilmIteratorTest::setUpFilmIterator(iterator3, "in/film/film2D");
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator3,true));
}
void testCheckSpaceGroup3DA()
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckSpaceGroup3DA.log");
// Set up 3D system with a correct space group and check it
System<3> system4;
FilmIteratorTest::setUpSystem(system4, "in/film/system3D");
FilmIterator<3, AmIterator<3> > iterator4(system4);
FilmIteratorTest::setUpFilmIterator(iterator4, "in/film/film3D");
// Set unit cell parameter
FSArray<double, 6> parameters;
parameters.append(2.0);
parameters.append(4.2);
system4.setUnitCell(UnitCell<3>::Tetragonal, parameters);
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator4,false));
TEST_ASSERT(iterator4.isFlexible()); // check that isFlexible works
}
void testCheckSpaceGroup3DB()
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckSpaceGroup3DB.log");
// Set up 3D system with an incorrect space group and check it
System<3> system5;
FilmIteratorTest::setUpSystem(system5, "in/film/system_bad_3D_1");
FilmIterator<3, AmIterator<3> > iterator5(system5);
FilmIteratorTest::setUpFilmIterator(iterator5, "in/film/film3D");
// Set unit cell parameter
FSArray<double, 6> parameters;
parameters.append(2.0);
parameters.append(4.2);
system5.setUnitCell(UnitCell<3>::Tetragonal, parameters);
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator5,true));
// Set up another 3D system with an incorrect space group and check it
System<3> system6;
FilmIteratorTest::setUpSystem(system6, "in/film/system_bad_3D_2");
FilmIterator<3, AmIterator<3> > iterator6(system6);
FilmIteratorTest::setUpFilmIterator(iterator6, "in/film/film3D");
TEST_ASSERT(FilmIteratorTest::checkCheckSpaceGroup(iterator6,true));
}
void testCheckLatticeVectors() // test FilmIterator::checkLatticeVectors()
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestCheckLatticeVectors.log");
// Set up 2D system with incorrect lattice vectors and check it
System<2> system1;
FilmIteratorTest::setUpSystem(system1, "in/film/system_bad_2D_1");
// Set unit cell parameter
FSArray<double, 6> parameters;
parameters.append(2.0);
parameters.append(2.0);
parameters.append(1.0);
system1.setUnitCell(UnitCell<2>::Oblique, parameters);
FilmIterator<2, AmIterator<2> > iterator1(system1);
FilmIteratorTest::setUpFilmIterator(iterator1, "in/film/film2D");
try {
iterator1.checkLatticeVectors();
// If above does not throw an error, then it failed this test
TEST_ASSERT(1 == 2);
} catch (Exception& e) {
Log::file() << "EXCEPTION CAUGHT, expected behavior occurred"
<< std::endl;
}
// Set up 3D system with correct lattice vectors and check it
System<3> system2;
FilmIteratorTest::setUpSystem(system2, "in/film/system_bad_3D_1");
parameters.clear();
parameters.append(2.0);
parameters.append(4.2);
system2.setUnitCell(UnitCell<3>::Tetragonal, parameters);
FilmIterator<3, AmIterator<3> > iterator2(system2);
FilmIteratorTest::setUpFilmIterator(iterator2, "in/film/film3D");
iterator2.checkLatticeVectors(); // this should not throw an error
// Set up 3D system with incorrect lattice vectors and check it
System<3> system3;
FilmIteratorTest::setUpSystem(system3, "in/film/system_bad_3D_2");
parameters[1] = 2.0;
parameters.append(2.0);
parameters.append(1.0);
system3.setUnitCell(UnitCell<3>::Monoclinic, parameters);
FilmIterator<3, AmIterator<3> > iterator3(system3);
FilmIteratorTest::setUpFilmIterator(iterator3, "in/film/film3D");
try {
iterator3.checkLatticeVectors();
// If above doesn't throw an error, then it failed this test
TEST_ASSERT(1 == 2);
} catch (Exception& e) {
Log::file() << "EXCEPTION CAUGHT, expected behavior occurred"
<< std::endl;
}
}
void testFlexibleParams() // test FilmIterator::flexibleParams
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestFlexibleParams.log");
// Set up 1D system and make sure flexibleParams is empty
System<1> system1;
FilmIteratorTest::setUpSystem(system1, "in/film/system1D");
FilmIterator<1, AmIterator<1> > iterator1(system1);
FilmIteratorTest::setUpFilmIterator(iterator1, "in/film/film1D");
TEST_ASSERT(iterator1.nFlexibleParams() == 0);
// Set up 2D system and make sure flexibleParams is correct
System<2> system2;
FilmIteratorTest::setUpSystem(system2, "in/film/system2D");
FilmIterator<2, AmIterator<2> > iterator2(system2);
FilmIteratorTest::setUpFilmIterator(iterator2, "in/film/film2D");
TEST_ASSERT(iterator2.nFlexibleParams() == 1);
TEST_ASSERT(iterator2.flexibleParams()[0]);
// Set up 3D tetragonal system, validate flexibleParams
System<3> system3;
FilmIteratorTest::setUpSystem(system3, "in/film/system3D");
FilmIterator<3, AmIterator<3> > iterator3(system3);
FilmIteratorTest::setUpFilmIterator(iterator3, "in/film/film3D");
TEST_ASSERT(iterator3.nFlexibleParams() == 1);
TEST_ASSERT(iterator3.flexibleParams()[0]);
// Set up 3D monoclinic system (monoclinic), validate flexibleParams
System<3> system4;
FilmIteratorTest::setUpSystem(system4, "in/film/system_bad_3D_2");
FilmIterator<3, AmIterator<3> > iterator4(system4);
FilmIteratorTest::setUpFilmIterator(iterator4, "in/film/film2D");
// Using film2D here because it has normalVecId=1 which
// we want for this example
TEST_ASSERT(iterator4.nFlexibleParams() == 3);
TEST_ASSERT(iterator4.flexibleParams()[0]);
TEST_ASSERT(iterator4.flexibleParams()[2]);
TEST_ASSERT(iterator4.flexibleParams()[3]);
}
void testReadFlexibleParams() // test manual entry of flexibleParams
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestReadFlexibleParams.log");
// Set up system
System<2> system;
FilmIteratorTest::setUpSystem(system, "in/film/system_bad_2D_1");
// Check flexibleParams array
TEST_ASSERT(system.iterator().nFlexibleParams() == 2);
TEST_ASSERT(system.iterator().flexibleParams()[0]);
TEST_ASSERT(system.iterator().flexibleParams()[2]);
// Set up another system
System<3> system2;
FilmIteratorTest::setUpSystem(system2, "in/film/system_bad_3D_2");
// Check flexibleParams array
TEST_ASSERT(system2.iterator().nFlexibleParams() == 3);
TEST_ASSERT(system2.iterator().flexibleParams()[0]);
TEST_ASSERT(system2.iterator().flexibleParams()[2]);
TEST_ASSERT(system2.iterator().flexibleParams()[3]);
}
void testSolve1D() // test FilmIterator::solve
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestSolve1D.log");
// Set up system with some data
System<1> system;
FilmIteratorTest::setUpSystem(system, "in/film/system1D");
// Read initial guess
system.readWBasis("in/film/w_1D_in.bf");
// Set up iterator from file
FilmIterator<1, AmIterator<1> > iterator(system);
FilmIteratorTest::setUpFilmIterator(iterator, "in/film/film1D");
// Run the solve function
iterator.solve();
TEST_ASSERT(eq(system.mask().phiTot(), 8.0951532073e-01));
// Check converged field is correct by comparing to files in in/film
UnitCell<1> unitCell; // UnitCell object to pass to FieldIo functions
DArray< DArray<double> > wFieldsCheck; // Copy of reference field
system.fieldIo().readFieldsBasis("in/film/w_1D_ref.bf",
wFieldsCheck, unitCell);
BFieldComparison bComparison(0); // object to compare fields
bComparison.compare(system.w().basis(), wFieldsCheck);
if (verbose() > 0) {
std::cout << "\nMax error = " << bComparison.maxDiff() << "\n";
}
system.fieldIo().writeFieldsBasis("out/w_1D.bf", system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsRGrid("out/w_1D.rf", system.w().rgrid(),
system.unitCell());
TEST_ASSERT(bComparison.maxDiff() < 1.0E-5);
}
void testSolve2D() // test FilmIterator::solve
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestSolve2D.log");
// Set up system with some data
System<2> system;
FilmIteratorTest::setUpSystem(system, "in/film/system2D");
// Read initial guess
system.readWBasis("in/film/w_2D_in.bf");
// Solve
system.iterate();
TEST_ASSERT(eq(system.mask().phiTot(), 8.7096155661e-01));
// Check that lattice parameters are correct
TEST_ASSERT((system.unitCell().parameter(0) - 1.6418585139) < 1.0e-6);
TEST_ASSERT(eq(system.unitCell().parameter(1), 3.1));
// Check converged field is correct by comparing to reference
UnitCell<2> unitCell; // UnitCell object to pass to FieldIo functions
DArray< DArray<double> > wFieldsCheck; // Copy of reference field
system.fieldIo().readFieldsBasis("in/film/w_2D_ref.bf",
wFieldsCheck, unitCell);
BFieldComparison bComparison(0); // object to compare fields
bComparison.compare(system.w().basis(), wFieldsCheck);
system.writeWBasis("out/w_2D.bf");
double epsilon = 1.0E-5;
double diff = bComparison.maxDiff();
if (verbose() > 0 || diff > epsilon) {
std::cout << "\n";
std::cout << "diff = " << diff << "\n";
std::cout << "epsilon = " << epsilon << "\n";
}
TEST_ASSERT(diff < epsilon);
}
void testSweep() // test sweep along chiBottom and lattice parameter
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestSweep.log");
// Set up system
System<1> system;
FilmIteratorTest::setUpSystem(system, "in/film/system1D");
// Read initial guess
system.readWBasis("out/w_1D.bf");
// Run the sweep function
system.sweep();
// Check converged field is correct by comparing to reference
UnitCell<1> unitCell; // UnitCell object to pass to FieldIo functions
DArray< DArray<double> > wFieldsCheck; // Copy of reference field
system.fieldIo().readFieldsBasis("in/film/w_1D_ref_sweep.bf",
wFieldsCheck, unitCell);
BFieldComparison bComparison(0); // object to compare fields
bComparison.compare(system.w().basis(), wFieldsCheck);
double diff = bComparison.maxDiff();
double epsilon = 1.0E-5;
if (verbose() > 0 || diff > epsilon) {
std::cout << "\n";
std::cout << "diff = " << diff << "\n";
std::cout << "epsilon = " << epsilon << "\n";
}
TEST_ASSERT(diff < epsilon);
}
void testFreeEnergy() // test System::computeFreeEnergy with mask/h fields
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestFreeEnergy.log");
// Set up system
System<1> system;
FilmIteratorTest::setUpSystem(system, "in/film/system1D");
// Read a converged solution as initial guess
system.readWBasis("out/w_1D.bf");
// Set up iterator
FilmIterator<1, AmIterator<1> > iterator(system);
FilmIteratorTest::setUpFilmIterator(iterator, "in/film/film1D");
// Solve (should only take a few iterations)
iterator.solve();
// Compute free energy
system.computeFreeEnergy();
system.writeThermo(Log::file());
if (verbose() > 0) {
std::cout << "\nFree energy error = "
<< (system.fHelmholtz() - 3.87784944222) << "\n";
std::cout << "\nPressure error = "
<< (system.pressure() + 12.1117881919) << "\n";
}
TEST_ASSERT(system.fHelmholtz() - 3.87784944222 < 1e-6);
TEST_ASSERT(system.pressure() + 12.1117881919 < 1e-5);
}
void testMaskAndH() // test manual entry of mask and h fields
{
printMethod(TEST_FUNC);
openLogFile("out/filmTestMaskAndH.log");
// Set up system
System<1> system;
FilmIteratorTest::setUpSystem(system, "in/film/system1D_noFilm");
// Read the same initial guess as testSolve
system.readWBasis("in/film/w_1D_in.bf");
// Read in the mask and external fields from file
UnitCell<1> unitCell; // UnitCell object to pass to FieldIo functions
unitCell = system.unitCell();
system.mask().setFieldIo(system.fieldIo());
system.mask().allocate(system.basis().nBasis(),
system.mesh().dimensions());
system.mask().readBasis("out/mask_1D.bf", unitCell);
TEST_ASSERT(eq(system.mask().phiTot(), 8.0951532073e-01));
system.h().setFieldIo(system.fieldIo());
system.h().allocateBasis(system.basis().nBasis());
system.h().allocateRGrid(system.mesh().dimensions());
system.h().readBasis("out/h_1D.bf", unitCell);
// Run the solve function
system.iterate();
// Check converged field is correct by comparing to files in in/film
DArray< DArray<double> > wFieldsCheck; // Copy of reference field
system.fieldIo().readFieldsBasis("in/film/w_1D_ref.bf", wFieldsCheck, unitCell);
BFieldComparison bComparison(0); // object to compare fields
bComparison.compare(system.w().basis(), wFieldsCheck);
double diff = bComparison.maxDiff();
double epsilon = 1.0E-5;
if (verbose() > 0 || diff > epsilon) {
std::cout << "\n";
std::cout << "diff = " << diff << "\n";
std::cout << "epsilon = " << epsilon << "\n";
}
system.fieldIo().writeFieldsBasis("out/w_1D_2.bf", system.w().basis(),
system.unitCell());
TEST_ASSERT(diff < epsilon);
}
// Read parameter file to create a System object
template <int D>
void setUpSystem(System<D>& system, std::string fname)
{
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile(fname, in);
system.readParam(in);
in.close();
}
// Read parameter file section to create a FilmIterator object
template <int D>
void setUpFilmIterator(FilmIterator<D, AmIterator<D>>& iterator,
std::string fname)
{
std::ifstream in;
openInputFile(fname, in);
iterator.readParam(in);
in.close();
}
// Determine if we get expected result when running checkSpaceGroup.
// Function accepts a boolean indicating whether we expect it to throw
// an error or not, and returns a boolean indicating whether the
// function demonstrated the expected behavior.
template <int D>
bool checkCheckSpaceGroup(FilmIterator<D, AmIterator<D>>& iterator,
bool expectError)
{
bool pass = true;
if (expectError) {
try {
iterator.checkSpaceGroup();
// This is expected to fail. If it succeeds, the test fails.
pass = false;
} catch (Exception& e) {
Log::file() << "EXCEPTION CAUGHT, expected behavior occurred"
<< std::endl;
}
} else {
try {
iterator.checkSpaceGroup();
// This should succeed. If not, the test fails.
} catch (Exception& e) {
pass = false;
}
}
return pass;
}
};
TEST_BEGIN(FilmIteratorTest)
TEST_ADD(FilmIteratorTest, testConstructor)
TEST_ADD(FilmIteratorTest, testReadParameters)
TEST_ADD(FilmIteratorTest, testGenerateWallFields)
TEST_ADD(FilmIteratorTest, testCheckSpaceGroup1DA)
TEST_ADD(FilmIteratorTest, testCheckSpaceGroup1DB)
TEST_ADD(FilmIteratorTest, testCheckSpaceGroup2D)
TEST_ADD(FilmIteratorTest, testCheckSpaceGroup3DA)
TEST_ADD(FilmIteratorTest, testCheckSpaceGroup3DB)
TEST_ADD(FilmIteratorTest, testFlexibleParams)
TEST_ADD(FilmIteratorTest, testReadFlexibleParams)
TEST_ADD(FilmIteratorTest, testCheckLatticeVectors)
TEST_ADD(FilmIteratorTest, testSolve1D)
TEST_ADD(FilmIteratorTest, testSolve2D)
TEST_ADD(FilmIteratorTest, testSweep)
TEST_ADD(FilmIteratorTest, testFreeEnergy)
TEST_ADD(FilmIteratorTest, testMaskAndH)
TEST_END(FilmIteratorTest)
#endif
| 23,991
|
C++
|
.h
| 537
| 36.743017
| 86
| 0.661587
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,184
|
MixtureTest.h
|
dmorse_pscfpp/src/pspc/tests/solvers/MixtureTest.h
|
#ifndef PSPC_MIXTURE_TEST_H
#define PSPC_MIXTURE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/solvers/Mixture.h>
#include <pspc/solvers/Polymer.h>
#include <pspc/solvers/Block.h>
#include <pspc/solvers/Propagator.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/math/IntVec.h>
#include <util/math/Constants.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class MixtureTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testConstructor1D()
{
printMethod(TEST_FUNC);
Mixture<1> mixture;
}
void testReadParameters1D()
{
printMethod(TEST_FUNC);
Mixture<1> mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
in.close();
}
void testSolver1D()
{
printMethod(TEST_FUNC);
Mixture<1> mixture;
std::ifstream in;
openInputFile("in/Mixture", in);
mixture.readParam(in);
UnitCell<1> unitCell;
in >> unitCell;
IntVec<1> d;
in >> d;
in.close();
Mesh<1> mesh;
mesh.setDimensions(d);
mixture.setMesh(mesh);
mixture.setupUnitCell(unitCell);
#if 0
std::cout << "\n";
mixture.writeParam(std::cout);
std::cout << "unitCell " << unitCell << std::endl;
std::cout << "mesh " << mesh.dimensions() << std::endl;
#endif
int nMonomer = mixture.nMonomer();
DArray< RField<1> > wFields;
DArray< RField<1> > cFields;
wFields.allocate(nMonomer);
cFields.allocate(nMonomer);
double nx = (double)mesh.size();
for (int i = 0; i < nMonomer; ++i) {
wFields[i].allocate(nx);
cFields[i].allocate(nx);
}
double cs;
for (int i = 0; i < nx; ++i) {
//cs = cos(2.0*Constants::Pi*(double(i)+0.5)/nx);
//cs = cos(2.0*Constants::Pi*double(i)/double(nx-1));
cs = cos(2.0*Constants::Pi*double(i)/double(nx));
wFields[0][i] = 0.5 + cs;
wFields[1][i] = 0.5 - cs;
}
mixture.compute(wFields, cFields);
// Test if same Q is obtained from different methods
double Q = mixture.polymer(0).propagator(1, 0).computeQ();
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 1).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 0).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(1, 1).computeQ()));
#if 0
std::cout << "Propagator(0,0), Q = "
<< mixture.polymer(0).propagator(0, 0).computeQ() << "\n";
std::cout << "Propagator(1,0), Q = "
<< mixture.polymer(0).propagator(1, 0).computeQ() << "\n";
std::cout << "Propagator(1,1), Q = "
<< mixture.polymer(0).propagator(1, 1).computeQ() << "\n";
std::cout << "Propagator(0,1), Q = "
<< mixture.polymer(0).propagator(0, 1).computeQ() << "\n";
#endif
#if 0
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(cFields[0]);
double sum1 = domain.spatialAverage(cFields[1]);
std::cout << "Volume fraction of block 0 = " << sum0 << "\n";
std::cout << "Volume fraction of block 1 = " << sum1 << "\n";
#endif
}
void testSolver2D()
{
printMethod(TEST_FUNC);
Mixture<2> mixture;
std::ifstream in;
openInputFile("in/Mixture2d", in);
mixture.readParam(in);
UnitCell<2> unitCell;
in >> unitCell;
IntVec<2> d;
in >> d;
in.close();
Mesh<2> mesh;
mesh.setDimensions(d);
mixture.setMesh(mesh);
mixture.setupUnitCell(unitCell);
#if 0
std::cout << "\n";
mixture.writeParam(std::cout);
std::cout << "unitCell " << unitCell << std::endl;
std::cout << "mesh " << mesh.dimensions() << std::endl;
#endif
int nMonomer = mixture.nMonomer();
DArray< RField<2> > wFields;
DArray< RField<2> > cFields;
wFields.allocate(nMonomer);
cFields.allocate(nMonomer);
double nx = (double)mesh.size();
for (int i = 0; i < nMonomer; ++i) {
wFields[i].allocate(nx);
cFields[i].allocate(nx);
}
#if 0
double cs;
for (int i = 0; i < nx; ++i) {
//cs = cos(2.0*Constants::Pi*(double(i)+0.5)/nx);
//cs = cos(2.0*Constants::Pi*double(i)/double(nx-1));
cs = cos(2.0*Constants::Pi*double(i)/double(nx));
wFields[0][i] = 0.5 + cs;
wFields[1][i] = 0.5 - cs;
}
#endif
// Generate oscillatory wField
int dx = mesh.dimension(0);
int dy = mesh.dimension(1);
double fx = 2.0*Constants::Pi/double(dx);
double fy = 2.0*Constants::Pi/double(dy);
double cx, cy;
int k = 0;
for (int i = 0; i < dx; ++i) {
cx = cos(fx*double(i));
for (int j = 0; j < dy; ++j) {
cy = cos(fy*double(j));
wFields[0][k] = 0.5 + cx + cy;
wFields[1][k] = 0.5 - cx - cy;
++k;
}
}
TEST_ASSERT(k == nx);
mixture.compute(wFields, cFields);
// Test if same Q is obtained from different methods
double Q = mixture.polymer(0).propagator(1, 0).computeQ();
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 1).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 0).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(1, 1).computeQ()));
#if 0
std::cout << "Propagator(0,0), Q = "
<< mixture.polymer(0).propagator(0, 0).computeQ() << "\n";
std::cout << "Propagator(1,0), Q = "
<< mixture.polymer(0).propagator(1, 0).computeQ() << "\n";
std::cout << "Propagator(1,1), Q = "
<< mixture.polymer(0).propagator(1, 1).computeQ() << "\n";
std::cout << "Propagator(0,1), Q = "
<< mixture.polymer(0).propagator(0, 1).computeQ() << "\n";
#endif
#if 0
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(cFields[0]);
double sum1 = domain.spatialAverage(cFields[1]);
std::cout << "Volume fraction of block 0 = " << sum0 << "\n";
std::cout << "Volume fraction of block 1 = " << sum1 << "\n";
#endif
}
void testSolver2D_hex()
{
printMethod(TEST_FUNC);
Mixture<2> mixture;
std::ifstream in;
openInputFile("in/Mixture2d_hex", in);
mixture.readParam(in);
UnitCell<2> unitCell;
in >> unitCell;
IntVec<2> d;
in >> d;
in.close();
Mesh<2> mesh;
mesh.setDimensions(d);
mixture.setMesh(mesh);
mixture.setupUnitCell(unitCell);
#if 0
std::cout << "\n";
mixture.writeParam(std::cout);
std::cout << "unitCell " << unitCell << std::endl;
std::cout << "mesh " << mesh.dimensions() << std::endl;
#endif
int nMonomer = mixture.nMonomer();
DArray< RField<2> > wFields;
DArray< RField<2> > cFields;
wFields.allocate(nMonomer);
cFields.allocate(nMonomer);
double nx = (double)mesh.size();
for (int i = 0; i < nMonomer; ++i) {
wFields[i].allocate(nx);
cFields[i].allocate(nx);
}
// Generate oscillatory wField
int dx = mesh.dimension(0);
int dy = mesh.dimension(1);
double fx = 2.0*Constants::Pi/double(dx);
double fy = 2.0*Constants::Pi/double(dy);
double cx, cy;
int k = 0;
for (int i = 0; i < dx; ++i) {
cx = cos(fx*double(i));
for (int j = 0; j < dy; ++j) {
cy = cos(fy*double(j));
wFields[0][k] = 0.5 + cx + cy;
wFields[1][k] = 0.5 - cx - cy;
++k;
}
}
TEST_ASSERT(k == nx);
mixture.compute(wFields, cFields);
// Test if same Q is obtained from different methods
double Q = mixture.polymer(0).propagator(1, 0).computeQ();
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 1).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 0).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(1, 1).computeQ()));
#if 0
std::cout << "Propagator(0,0), Q = "
<< mixture.polymer(0).propagator(0, 0).computeQ() << "\n";
std::cout << "Propagator(1,0), Q = "
<< mixture.polymer(0).propagator(1, 0).computeQ() << "\n";
std::cout << "Propagator(1,1), Q = "
<< mixture.polymer(0).propagator(1, 1).computeQ() << "\n";
std::cout << "Propagator(0,1), Q = "
<< mixture.polymer(0).propagator(0, 1).computeQ() << "\n";
#endif
#if 0
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(cFields[0]);
double sum1 = domain.spatialAverage(cFields[1]);
std::cout << "Volume fraction of block 0 = " << sum0 << "\n";
std::cout << "Volume fraction of block 1 = " << sum1 << "\n";
#endif
}
void testSolver3D()
{
printMethod(TEST_FUNC);
Mixture<3> mixture;
std::ifstream in;
openInputFile("in/Mixture3d", in);
mixture.readParam(in);
UnitCell<3> unitCell;
in >> unitCell;
IntVec<3> d;
in >> d;
in.close();
Mesh<3> mesh;
mesh.setDimensions(d);
mixture.setMesh(mesh);
mixture.setupUnitCell(unitCell);
#if 0
std::cout << "\n";
mixture.writeParam(std::cout);
std::cout << "unitCell " << unitCell << std::endl;
std::cout << "mesh " << mesh.dimensions() << std::endl;
#endif
int nMonomer = mixture.nMonomer();
DArray< RField<3> > wFields;
DArray< RField<3> > cFields;
wFields.allocate(nMonomer);
cFields.allocate(nMonomer);
double nx = (double)mesh.size();
for (int i = 0; i < nMonomer; ++i) {
wFields[i].allocate(nx);
cFields[i].allocate(nx);
}
double cs;
for (int i = 0; i < nx; ++i) {
//cs = cos(2.0*Constants::Pi*(double(i)+0.5)/nx);
//cs = cos(2.0*Constants::Pi*double(i)/double(nx-1));
cs = cos(2.0*Constants::Pi*double(i)/double(nx));
wFields[0][i] = 0.5 + cs;
wFields[1][i] = 0.5 - cs;
}
mixture.compute(wFields, cFields);
// Test if same Q is obtained from different methods
double Q = mixture.polymer(0).propagator(1, 0).computeQ();
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 1).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(0, 0).computeQ()));
TEST_ASSERT(eq(Q, mixture.polymer(0).propagator(1, 1).computeQ()));
#if 0
std::cout << "Propagator(0,0), Q = "
<< mixture.polymer(0).propagator(0, 0).computeQ() << "\n";
std::cout << "Propagator(1,0), Q = "
<< mixture.polymer(0).propagator(1, 0).computeQ() << "\n";
std::cout << "Propagator(1,1), Q = "
<< mixture.polymer(0).propagator(1, 1).computeQ() << "\n";
std::cout << "Propagator(0,1), Q = "
<< mixture.polymer(0).propagator(0, 1).computeQ() << "\n";
#endif
#if 0
// Test spatial integral of block concentration
double sum0 = domain.spatialAverage(cFields[0]);
double sum1 = domain.spatialAverage(cFields[1]);
std::cout << "Volume fraction of block 0 = " << sum0 << "\n";
std::cout << "Volume fraction of block 1 = " << sum1 << "\n";
#endif
}
};
TEST_BEGIN(MixtureTest)
TEST_ADD(MixtureTest, testConstructor1D)
TEST_ADD(MixtureTest, testReadParameters1D)
TEST_ADD(MixtureTest, testSolver1D)
TEST_ADD(MixtureTest, testSolver2D)
TEST_ADD(MixtureTest, testSolver2D_hex)
TEST_ADD(MixtureTest, testSolver3D)
TEST_END(MixtureTest)
#endif
| 11,927
|
C++
|
.h
| 331
| 28.583082
| 74
| 0.564855
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,185
|
PolymerTest.h
|
dmorse_pscfpp/src/pspc/tests/solvers/PolymerTest.h
|
#ifndef PSPC_POLYMER_TEST_H
#define PSPC_POLYMER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class PolymerTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
};
#endif
| 294
|
C++
|
.h
| 16
| 16.4375
| 35
| 0.780669
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,186
|
SolverTestComposite.h
|
dmorse_pscfpp/src/pspc/tests/solvers/SolverTestComposite.h
|
#ifndef PSPC_TEST_SOLVER_TEST_COMPOSITE_H
#define PSPC_TEST_SOLVER_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "PropagatorTest.h"
#include "MixtureTest.h"
TEST_COMPOSITE_BEGIN(SolverTestComposite)
TEST_COMPOSITE_ADD_UNIT(PropagatorTest);
TEST_COMPOSITE_ADD_UNIT(MixtureTest);
TEST_COMPOSITE_END
#endif
| 326
|
C++
|
.h
| 10
| 31.2
| 41
| 0.842949
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,187
|
PropagatorTest.h
|
dmorse_pscfpp/src/pspc/tests/solvers/PropagatorTest.h
|
#ifndef PSPC_PROPAGATOR_TEST_H
#define PSPC_PROPAGATOR_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/solvers/Block.h>
#include <pscf/mesh/MeshIterator.h>
#include <pspc/solvers/Propagator.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/math/IntVec.h>
#include <util/math/Constants.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class PropagatorTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
template <int D>
void setupBlock(Block<D>& block)
{
block.setId(0);
double length = 2.0;
block.setLength(length);
block.setMonomerId(1);
double step = sqrt(6.0);
block.setKuhn(step);
return;
}
template <int D>
void setupMesh(Mesh<D>& mesh)
{
IntVec<D> d;
for (int i = 0; i < D; ++i) {
d[i] = 32;
}
mesh.setDimensions(d);
}
template <int D>
void setupUnitCell(UnitCell<D>& unitCell, std::string fname)
{
std::ifstream in;
openInputFile(fname, in);
in >> unitCell;
in.close();
}
void testConstructor1D()
{
printMethod(TEST_FUNC);
Block<1> block;
}
void testSetDiscretization1D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<1> block;
setupBlock<1>(block);
// Create and initialize mesh
Mesh<1> mesh;
setupMesh<1>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
TEST_ASSERT(eq(block.length(), 2.0));
TEST_ASSERT(eq(block.ds(), 0.02));
TEST_ASSERT(block.ns() == 101);
TEST_ASSERT(block.mesh().dimensions()[0] == 32);
}
void testSetDiscretization2D()
{
printMethod(TEST_FUNC);
//Create and initialize block
Block<2> block;
setupBlock<2>(block);
Mesh<2> mesh;
setupMesh<2>(mesh);
double ds = 0.26;
block.setDiscretization(ds, mesh);
TEST_ASSERT(eq(block.length(), 2.0));
TEST_ASSERT(eq(block.ds(), 0.25));
TEST_ASSERT(block.ns() == 9);
TEST_ASSERT(block.mesh().dimensions()[0] == 32);
TEST_ASSERT(block.mesh().dimensions()[1] == 32);
}
void testSetDiscretization3D()
{
printMethod(TEST_FUNC);
//Create and initialize block
Block<3> block;
setupBlock<3>(block);
Mesh<3> mesh;
setupMesh<3>(mesh);
double ds = 0.3;
block.setDiscretization(ds, mesh);
TEST_ASSERT(eq(block.length(), 2.0));
TEST_ASSERT(block.ns() == 7);
TEST_ASSERT(eq(block.ds(), 1.0/3.0));
TEST_ASSERT(block.mesh().dimensions()[0] == 32);
TEST_ASSERT(block.mesh().dimensions()[1] == 32);
TEST_ASSERT(block.mesh().dimensions()[2] == 32);
}
void testSetupSolver1D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<1> block;
setupBlock<1>(block);
// Create and initialize mesh
Mesh<1> mesh;
setupMesh<1>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<1> unitCell;
setupUnitCell<1>(unitCell, "in/Lamellar");
TEST_ASSERT(eq(unitCell.rBasis(0)[0], 4.0));
// Setup chemical potential field
RField<1> w;
w.allocate(mesh.dimensions());
TEST_ASSERT(w.capacity() == mesh.size());
for (int i=0; i < w.capacity(); ++i) {
w[i] = 1.0;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
}
void testSetupSolver2D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<2> block;
setupBlock<2>(block);
// Create and initialize mesh
Mesh<2> mesh;
setupMesh<2>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<2> unitCell;
setupUnitCell<2>(unitCell, "in/Rectangular");
TEST_ASSERT(eq(unitCell.rBasis(0)[0], 3.0));
TEST_ASSERT(eq(unitCell.rBasis(1)[1], 4.0));
// Setup chemical potential field
RField<2> w;
w.allocate(mesh.dimensions());
TEST_ASSERT(w.capacity() == mesh.size());
for (int i=0; i < w.capacity(); ++i) {
w[i] = 1.0;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
}
void testSetupSolver3D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<3> block;
setupBlock<3>(block);
// Create and initialize mesh
Mesh<3> mesh;
setupMesh<3>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<3> unitCell;
setupUnitCell<3>(unitCell, "in/Orthorhombic");
TEST_ASSERT(eq(unitCell.rBasis(0)[0], 3.0));
TEST_ASSERT(eq(unitCell.rBasis(1)[1], 4.0));
TEST_ASSERT(eq(unitCell.rBasis(2)[2], 5.0));
// Setup chemical potential field
RField<3> w;
w.allocate(mesh.dimensions());
TEST_ASSERT(w.capacity() == mesh.size());
for (int i=0; i < w.capacity(); ++i) {
w[i] = 1.0;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
}
void testSolver1D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<1> block;
setupBlock<1>(block);
// Create and initialize mesh
Mesh<1> mesh;
setupMesh<1>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<1> unitCell;
setupUnitCell<1>(unitCell, "in/Lamellar");
// Setup chemical potential field
RField<1> w;
w.allocate(mesh.dimensions());
int nx = mesh.size();
TEST_ASSERT(w.capacity() == nx);
double wc = 0.3;
for (int i=0; i < nx; ++i) {
w[i] = wc;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
// Test step
Propagator<1>::QField qin;
Propagator<1>::QField qout;
qin.allocate(mesh.dimensions());
qout.allocate(mesh.dimensions());
double twoPi = 2.0*Constants::Pi;
for (int i=0; i < nx; ++i) {
qin[i] = cos(twoPi*double(i)/double(nx));
}
block.step(qin, qout);
double a = 4.0;
double b = block.kuhn();
double Gb = twoPi*b/a;
double r = Gb*Gb/6.0;
ds = block.ds();
double expected = exp(-(wc + r)*ds);
for (int i = 0; i < nx; ++i) {
TEST_ASSERT(eq(qout[i], qin[i]*expected));
}
// Test propagator solve
block.propagator(0).solve();
for (int i = 0; i < nx; ++i) {
TEST_ASSERT(eq(block.propagator(0).head()[i],1.0));
}
expected = exp(-wc*block.length());
for (int i = 0; i < nx; ++i) {
TEST_ASSERT(eq(block.propagator(0).tail()[i], expected));
}
}
void testSolver2D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<2> block;
setupBlock<2>(block);
// Create and initialize mesh
Mesh<2> mesh;
setupMesh<2>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<2> unitCell;
setupUnitCell<2>(unitCell, "in/Rectangular");
TEST_ASSERT(eq(unitCell.rBasis(0)[0], 3.0));
TEST_ASSERT(eq(unitCell.rBasis(1)[1], 4.0));
// Setup chemical potential field
RField<2> w;
w.allocate(mesh.dimensions());
MeshIterator<2> iter(mesh.dimensions());
TEST_ASSERT(w.capacity() == mesh.size());
double wc = 0.3;
for (int i=0; i < w.capacity(); ++i) {
w[i] = wc;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
// Test step
Propagator<2>::QField qin;
Propagator<2>::QField qout;
qin.allocate(mesh.dimensions());
qout.allocate(mesh.dimensions());
double twoPi = 2.0*Constants::Pi;
for (iter.begin(); !iter.atEnd(); ++iter){
qin[iter.rank()] = cos(twoPi *
(double(iter.position(0))/double(mesh.dimension(0)) +
double(iter.position(1))/double(mesh.dimension(1)) ) );
}
block.step(qin, qout);
double b = block.kuhn();
double Gb;
double expected;
IntVec<2> temp;
temp[0] = 1;
temp[1] = 1;
ds = block.ds();
for (iter.begin(); !iter.atEnd(); ++iter){
Gb = unitCell.ksq(temp);
double factor = b;
double r = Gb*factor*factor/6.0;
expected = exp(-(wc + r)*ds);
TEST_ASSERT(eq(qout[iter.rank()],
qin[iter.rank()]*expected));
}
// Test propagator solve
block.propagator(0).solve();
for (iter.begin(); !iter.atEnd(); ++iter){
TEST_ASSERT(eq(block.propagator(0).head()[iter.rank()], 1.0));
}
expected = exp(-wc*block.length());
for (iter.begin(); !iter.atEnd(); ++iter){
TEST_ASSERT(eq(block.propagator(0).tail()[iter.rank()], expected));
}
}
void testSolver3D()
{
printMethod(TEST_FUNC);
// Create and initialize block
Block<3> block;
setupBlock<3>(block);
// Create and initialize mesh
Mesh<3> mesh;
setupMesh<3>(mesh);
double ds = 0.02;
block.setDiscretization(ds, mesh);
UnitCell<3> unitCell;
setupUnitCell<3>(unitCell, "in/Orthorhombic");
TEST_ASSERT(eq(unitCell.rBasis(0)[0], 3.0));
TEST_ASSERT(eq(unitCell.rBasis(1)[1], 4.0));
TEST_ASSERT(eq(unitCell.rBasis(2)[2], 5.0));
// Setup chemical potential field
RField<3> w;
w.allocate(mesh.dimensions());
MeshIterator<3> iter(mesh.dimensions());
TEST_ASSERT(w.capacity() == mesh.size());
double wc = 0.3;
for (int i=0; i < w.capacity(); ++i) {
w[i] = wc;
}
block.setupUnitCell(unitCell);
block.setupSolver(w);
// Test step
Propagator<3>::QField qin;
Propagator<3>::QField qout;
qin.allocate(mesh.dimensions());
qout.allocate(mesh.dimensions());
double twoPi = 2.0*Constants::Pi;
for (iter.begin(); !iter.atEnd(); ++iter){
qin[iter.rank()] = cos(twoPi *
(double(iter.position(0))/double(mesh.dimension(0)) +
double(iter.position(1))/double(mesh.dimension(1)) +
double(iter.position(2))/double(mesh.dimension(2)) ) );
}
block.step(qin, qout);
double b = block.kuhn();
double Gb;
double expected;
IntVec<3> temp;
temp[0] = 1;
temp[1] = 1;
temp[2] = 1;
ds = block.ds();
for (iter.begin(); !iter.atEnd(); ++iter){
Gb = unitCell.ksq(temp);
double factor = b;
double r = Gb*factor*factor/6.0;
expected = exp(-(wc + r)*ds);
TEST_ASSERT(eq(qout[iter.rank()],
qin[iter.rank()]*expected));
}
// Test propagator solve
block.propagator(0).solve();
for (iter.begin(); !iter.atEnd(); ++iter){
TEST_ASSERT(eq(block.propagator(0).head()[iter.rank()], 1.0));
}
expected = exp(-wc*block.length());
for (iter.begin(); !iter.atEnd(); ++iter){
TEST_ASSERT(eq(block.propagator(0).tail()[iter.rank()], expected));
}
}
};
TEST_BEGIN(PropagatorTest)
TEST_ADD(PropagatorTest, testConstructor1D)
TEST_ADD(PropagatorTest, testSetDiscretization1D)
TEST_ADD(PropagatorTest, testSetDiscretization2D)
TEST_ADD(PropagatorTest, testSetDiscretization3D)
TEST_ADD(PropagatorTest, testSetupSolver1D)
TEST_ADD(PropagatorTest, testSetupSolver3D)
TEST_ADD(PropagatorTest, testSolver1D)
TEST_ADD(PropagatorTest, testSolver2D)
TEST_ADD(PropagatorTest, testSolver3D)
TEST_END(PropagatorTest)
#endif
| 11,758
|
C++
|
.h
| 374
| 24.312834
| 80
| 0.587094
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,188
|
SweepTestComposite.h
|
dmorse_pscfpp/src/pspc/tests/sweep/SweepTestComposite.h
|
#ifndef PSPC_TEST_SWEEP_TEST_COMPOSITE_H
#define PSPC_TEST_SWEEP_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
// include the headers for individual tests
#include "BasisFieldStateTest.h"
#include "SweepTest.h"
TEST_COMPOSITE_BEGIN(SweepTestComposite)
TEST_COMPOSITE_ADD_UNIT(BasisFieldStateTest)
TEST_COMPOSITE_ADD_UNIT(SweepTest)
TEST_COMPOSITE_END
#endif
| 371
|
C++
|
.h
| 11
| 32.363636
| 44
| 0.845506
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,189
|
BasisFieldStateTest.h
|
dmorse_pscfpp/src/pspc/tests/sweep/BasisFieldStateTest.h
|
#ifndef PSPC_BASIS_FIELD_STATE_TEST_H
#define PSPC_BASIS_FIELD_STATE_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/System.h>
#include <pspc/sweep/BasisFieldState.h>
#include <pscf/crystal/BFieldComparison.h>
#include <util/tests/LogFileUnitTest.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class BasisFieldStateTest : public LogFileUnitTest
{
public:
void setUp()
{}
void testConstructor()
{
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs1(system);
BasisFieldState<3> bfs2;
}
void testRead()
{
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs(system);
BFieldComparison comparison;
// Setup system
BasisFieldStateTest::SetUpSystem(system);
TEST_ASSERT(system.domain().basis().isInitialized());
// Read in file one way
system.readWBasis("in/bcc/omega.ref");
// Read in file another way
bfs.read("in/bcc/omega.ref");
// Compare
comparison.compare(bfs.fields(), system.w().basis());
// Assert small difference
TEST_ASSERT(comparison.maxDiff() < 5.0e-7);
}
void testWrite()
{
// Write tested with a read/write/read/comparison procedure
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs1(system), bfs2(system);
BFieldComparison comparison;
// Setup system
BasisFieldStateTest::SetUpSystem(system);
// read, write, read
bfs1.read("in/bcc/omega.ref");
bfs1.write("out/testBasisFieldStateWrite.ref");
bfs2.read("out/testBasisFieldStateWrite.ref");
// compare
comparison.compare(bfs1.fields(),bfs2.fields());
// Assert small difference
TEST_ASSERT(comparison.maxDiff() < 5.0e-7);
}
void testGetSystemState()
{
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs(system);
BFieldComparison comparison;
// Setup system
BasisFieldStateTest::SetUpSystem(system);
// Read in state using system
system.readWBasis("in/bcc/omega.ref");
// get it using bfs
bfs.getSystemState();
// compare
comparison.compare(bfs.fields(),system.w().basis());
// Assert small difference
TEST_ASSERT(comparison.maxDiff() < 5.0e-7);
}
void testSetSystemState()
{
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs(system);
BFieldComparison comparison;
// Setup system
BasisFieldStateTest::SetUpSystem(system);
// Read in state using bfs
bfs.read("in/bcc/omega.ref");
// set system state
bfs.setSystemState(true);
// compare
comparison.compare(bfs.fields(),system.w().basis());
// Assert small difference
TEST_ASSERT(comparison.maxDiff() < 5.0e-7);
}
void testSetSystem()
{
printMethod(TEST_FUNC);
System<3> system;
BasisFieldState<3> bfs;
// Setup system
BasisFieldStateTest::SetUpSystem(system);
// Invoke setSystem
bfs.setSystem(system);
}
void SetUpSystem(System<3>& system)
{
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/bcc/param.flex", in);
system.readParam(in);
in.close();
FSArray<double, 6> parameters;
parameters.append(1.759);
system.setUnitCell(parameters);
}
};
TEST_BEGIN(BasisFieldStateTest)
TEST_ADD(BasisFieldStateTest, testConstructor)
TEST_ADD(BasisFieldStateTest, testRead)
TEST_ADD(BasisFieldStateTest, testWrite)
TEST_ADD(BasisFieldStateTest, testGetSystemState)
TEST_ADD(BasisFieldStateTest, testSetSystemState)
TEST_ADD(BasisFieldStateTest, testSetSystem)
TEST_END(BasisFieldStateTest)
#endif
| 3,914
|
C++
|
.h
| 126
| 25.436508
| 65
| 0.686264
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,190
|
SweepTest.h
|
dmorse_pscfpp/src/pspc/tests/sweep/SweepTest.h
|
#ifndef PSPC_SWEEP_TEST_H
#define PSPC_SWEEP_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/System.h>
#include <pspc/sweep/SweepFactory.h>
#include <pspc/sweep/LinearSweep.h>
#include <pscf/crystal/BFieldComparison.h>
#include <util/tests/LogFileUnitTest.h>
#include <util/format/Dbl.h>
#include <fstream>
#include <sstream>
using namespace Util;
using namespace Pscf;
using namespace Pspc;
class SweepTest : public LogFileUnitTest
{
public:
void setUp()
{ setVerbose(0); }
void testConstructors()
{
printMethod(TEST_FUNC);
System<3> system;
LinearSweep<3> ls(system);
SweepFactory<3> sf(system);
}
void testFactory()
{
printMethod(TEST_FUNC);
System<3> system;
SweepFactory<3> sf(system);
Sweep<3>* sweepPtr;
sweepPtr = sf.factory("LinearSweep");
TEST_ASSERT(sweepPtr != 0);
}
void testParameterRead()
{
printMethod(TEST_FUNC);
// Set up system with some data
System<1> system;
SweepTest::SetUpSystem(system, "in/block/param");
// Set up SweepParameter objects
DArray< SweepParameter<1> > ps;
ps.allocate(4);
for (int i = 0; i < 4; ++i) {
ps[i].setSystem(system);
}
// Open test input file
std::ifstream in;
// Read in data
openInputFile("in/param.test", in);
for (int i = 0; i < 4; ++i) {
in >> ps[i];
}
// Assert that it is read correctly
TEST_ASSERT(ps[0].type()=="block");
TEST_ASSERT(ps[0].id(0)==0);
TEST_ASSERT(ps[0].id(1)==0);
TEST_ASSERT(ps[0].change()==0.25);
TEST_ASSERT(ps[1].type()=="chi");
TEST_ASSERT(ps[1].id(0)==0);
TEST_ASSERT(ps[1].id(1)==1);
TEST_ASSERT(ps[1].change()==5.00);
TEST_ASSERT(ps[2].type()=="kuhn");
TEST_ASSERT(ps[2].id(0)==0);
TEST_ASSERT(ps[2].change()==0.1);
TEST_ASSERT(ps[3].type()=="phi_polymer");
TEST_ASSERT(ps[3].id(0)==0);
TEST_ASSERT(ps[3].change()==-0.01);
}
void testParameterGet()
{
printMethod(TEST_FUNC);
// Set up system
System<1> system;
SweepTest::SetUpSystem(system, "in/block/param");
// Set up SweepParameter objects
DArray< SweepParameter<1> > ps;
ps.allocate(4);
std::ifstream in;
openInputFile("in/param.test", in);
for (int i = 0; i < 4; ++i) {
ps[i].setSystem(system);
in >> ps[i];
}
DArray<double> sysval, paramval;
sysval.allocate(4);
paramval.allocate(4);
// Call get_ function to get value through parameter
for (int i = 0; i < 4; ++i) {
paramval[i] = ps[i].current();
}
// Manually check equality for each one
sysval[0] = system.mixture().polymer(0).block(0).length();
sysval[1] = system.interaction().chi(0,1);
sysval[2] = system.mixture().monomer(0).kuhn();
sysval[3] = system.mixture().polymer(0).phi();
for (int i = 0; i < 4; ++i) {
TEST_ASSERT(sysval[i] == paramval[i]);
}
}
void testParameterSet()
{
printMethod(TEST_FUNC);
// Set up system
System<1> system;
SweepTest::SetUpSystem(system, "in/block/param");
// Set up SweepParameter objects
DArray< SweepParameter<1> > ps;
ps.allocate(4);
std::ifstream in;
openInputFile("in/param.test", in);
for (int i = 0; i < 4; ++i) {
ps[i].setSystem(system);
in >> ps[i];
ps[i].getInitial();
}
DArray<double> sysval, paramval;
sysval.allocate(4);
paramval.allocate(4);
// Set for some arbitrary value of s in [0,1]
double s = 0.295586;
double newVal;
for (int i = 0; i < 4; ++i) {
newVal = ps[i].initial() + s*ps[i].change();
ps[i].update(newVal);
}
// Calculate expected value of parameter using s
for (int i = 0; i < 4; ++i) {
paramval[i] = ps[i].initial() + s*ps[i].change();
}
// Manually check equality for each one
sysval[0] = system.mixture().polymer(0).block(0).length();
sysval[1] = system.interaction().chi(0,1);
sysval[2] = system.mixture().monomer(0).kuhn();
sysval[3] = system.mixture().polymer(0).phi();
for (int i = 0; i < 4; ++i) {
TEST_ASSERT(sysval[i]==paramval[i]);
}
}
void testLinearSweepRead()
{
printMethod(TEST_FUNC);
// Set up system with Linear Sweep Object
System<1> system;
SweepTest::SetUpSystem(system, "in/block/param");
}
void testLinearSweepBlock()
{
printMethod(TEST_FUNC);
openLogFile("out/testLinearSweepBlock");
double maxDiff = testLinearSweepParam("block");
TEST_ASSERT(maxDiff < 5.0e-7);
}
void testLinearSweepChi()
{
printMethod(TEST_FUNC);
openLogFile("out/testLinearSweepChi");
double maxDiff = testLinearSweepParam("chi");
TEST_ASSERT(maxDiff < 5.0e-7);
}
void testLinearSweepKuhn()
{
printMethod(TEST_FUNC);
openLogFile("out/testLinearSweepKuhn");
double maxDiff = testLinearSweepParam("kuhn");
TEST_ASSERT(maxDiff < 5.0e-7);
}
void testLinearSweepPhi()
{
printMethod(TEST_FUNC);
openLogFile("out/testLinearSweepPhi");
double maxDiff = testLinearSweepParam("phi");
TEST_ASSERT(maxDiff < 5.0e-7);
}
void testLinearSweepSolvent()
{
printMethod(TEST_FUNC);
openLogFile("out/testLinearSweepSolvent");
double maxDiff = testLinearSweepParam("solvent");
TEST_ASSERT(maxDiff < 5.0e-7);
}
void SetUpSystem(System<1>& system, std::string fname)
{
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile(fname, in);
system.readParam(in);
in.close();
FSArray<double, 6> parameters;
parameters.append(1.3835);
system.setUnitCell(parameters);
}
double testLinearSweepParam(std::string paramname)
{
// Set up system with a LinearSweep object
System<1> system;
SweepTest::SetUpSystem(system, "in/" + paramname + "/param");
// Read expected w fields
DArray< BasisFieldState<1> > fieldsRef;
fieldsRef.allocate(5);
for (int i = 0; i < 5; ++i) {
fieldsRef[i].setSystem(system);
fieldsRef[i].read("in/sweepref/" + paramname + "/" + std::to_string(i) +"_w.bf");
}
// Read initial field guess and sweep
system.readWBasis("in/" + paramname + "/w.bf");
system.sweep();
// Check if sweep had to backtrack. It shouldn't need to.
std::ifstream f(std::string(filePrefix() + "out/" + paramname + "/5_w.bf").c_str());
if (f.good()) {
TEST_THROW("Sweep backtracked due to iteration count greater than maxItr.");
}
// Read outputted fields
DArray< BasisFieldState<1> > fieldsOut;
fieldsOut.allocate(5);
for (int i = 0; i < 5; ++i) {
fieldsOut[i].setSystem(system);
fieldsOut[i].read("out/" + paramname + "/" + std::to_string(i) +"_w.bf");
}
// Compare output
BFieldComparison comparison(1);
double maxDiff = 0.0;
for (int i = 0; i < 5; ++i) {
comparison.compare(fieldsRef[i].fields(), fieldsOut[i].fields());
if (comparison.maxDiff() > maxDiff) {
maxDiff = comparison.maxDiff();
}
}
//setVerbose(1);
if (verbose() > 0) {
Log::file() << std::endl;
Log::file() << "maxDiff = " << Dbl(maxDiff, 14, 6) << std::endl;
}
return maxDiff;
}
};
TEST_BEGIN(SweepTest)
TEST_ADD(SweepTest, testConstructors)
TEST_ADD(SweepTest, testFactory)
TEST_ADD(SweepTest, testParameterRead)
TEST_ADD(SweepTest, testParameterGet)
TEST_ADD(SweepTest, testParameterSet)
TEST_ADD(SweepTest, testLinearSweepRead)
TEST_ADD(SweepTest, testLinearSweepBlock)
TEST_ADD(SweepTest, testLinearSweepChi)
TEST_ADD(SweepTest, testLinearSweepKuhn)
TEST_ADD(SweepTest, testLinearSweepPhi)
TEST_ADD(SweepTest, testLinearSweepSolvent)
TEST_END(SweepTest)
#endif
| 8,230
|
C++
|
.h
| 253
| 26.094862
| 90
| 0.61159
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,191
|
SystemTest.h
|
dmorse_pscfpp/src/pspc/tests/system/SystemTest.h
|
#ifndef PSPC_SYSTEM_TEST_H
#define PSPC_SYSTEM_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/System.h>
#include <pspc/field/RFieldComparison.h>
#include <pscf/crystal/BFieldComparison.h>
#include <util/tests/LogFileUnitTest.h>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class SystemTest : public LogFileUnitTest
{
public:
void setUp()
{ setVerbose(0); }
void testConstructor1D()
{
printMethod(TEST_FUNC);
System<1> system;
}
void testReadParameters1D()
{
printMethod(TEST_FUNC);
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/lam/param.flex", in);
system.readParam(in);
in.close();
}
void testConversion1D_lam()
{
printMethod(TEST_FUNC);
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
openLogFile("out/testConversion1D_lam.log");
std::ifstream in;
openInputFile("in/diblock/lam/param.flex", in);
system.readParam(in);
in.close();
// Read w-fields (reference solution, solved by Fortran PSCF)
system.readWBasis("in/diblock/lam/omega.in");
// Copy w field components to wFields_check after reading
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Round trip conversion basis -> rgrid -> basis, read result
system.basisToRGrid("in/diblock/lam/omega.in",
"out/testConversion1D_lam_w.rf");
system.rGridToBasis("out/testConversion1D_lam_w.rf",
"out/testConversion1D_lam_w.bf");
system.readWBasis("out/testConversion1D_lam_w.bf");
// Compare result to original
BFieldComparison comparison1;
comparison1.compare(wFields_check, system.w().basis());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison1.maxDiff() << "\n";
}
TEST_ASSERT(comparison1.maxDiff() < 1.0E-10);
// Round trip conversion basis -> kgrid -> basis, read result
system.basisToKGrid("in/diblock/lam/omega.in",
"out/testConversion1D_lam_w.kf");
system.kGridToBasis("out/testConversion1D_lam_w.kf",
"out/testConversion1D_lam_w_2.bf");
system.readWBasis("out/testConversion1D_lam_w_2.bf");
// Compare result to original
BFieldComparison comparison2;
comparison2.compare(wFields_check, system.w().basis());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison2.maxDiff() << "\n";
}
TEST_ASSERT(comparison2.maxDiff() < 1.0E-10);
// Round trip conversion rgrid -> kgrid -> rgrid, read result
system.readWRGrid("out/testConversion1D_lam_w.rf");
DArray< RField<1> > wFieldsRGrid_check;
wFieldsRGrid_check = system.w().rgrid();
system.rGridToKGrid("out/testConversion1D_lam_w.rf",
"out/testConversion1D_lam_w_2.kf");
system.kGridToRGrid("out/testConversion1D_lam_w_2.kf",
"out/testConversion1D_lam_w_2.rf");
system.readWRGrid("out/testConversion1D_lam_w_2.rf");
// Compare result to original
RFieldComparison<1> comparison3;
comparison3.compare(wFieldsRGrid_check, system.w().rgrid());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison3.maxDiff() << "\n";
}
TEST_ASSERT(comparison3.maxDiff() < 1.0E-10);
}
void testConversion2D_hex()
{
printMethod(TEST_FUNC);
System<2> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
openLogFile("out/testConversion2D_hex.log");
// Read parameter file
std::ifstream in;
openInputFile("in/diblock/hex/param.flex", in);
system.readParam(in);
in.close();
// Read w fields
system.readWBasis("in/diblock/hex/omega.in");
// Store components in wFields_check for later comparison
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Round trip basis -> rgrid -> basis, read resulting wField
system.basisToRGrid("in/diblock/hex/omega.in",
"out/testConversion2D_hex_w.rf");
system.rGridToBasis("out/testConversion2D_hex_w.rf",
"out/testConversion2D_hex_w.bf");
system.readWBasis("out/testConversion2D_hex_w.bf");
// Check symmetry of rgrid representation
bool hasSymmetry
= system.checkRGridFieldSymmetry("out/testConversion2D_hex_w.rf");
TEST_ASSERT(hasSymmetry);
// Compare result to original
BFieldComparison comparison1;
comparison1.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison1.maxDiff() << "\n";
}
TEST_ASSERT(comparison1.maxDiff() < 1.0E-10);
// Round trip conversion basis -> kgrid -> basis, read result
system.basisToKGrid("in/diblock/hex/omega.in",
"out/testConversion2D_hex_w.kf");
system.kGridToBasis("out/testConversion2D_hex_w.kf",
"out/testConversion2D_hex_w_2.bf");
system.readWBasis("out/testConversion2D_hex_w_2.bf");
// Compare result to original
BFieldComparison comparison2;
comparison2.compare(wFields_check, system.w().basis());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison2.maxDiff() << "\n";
}
TEST_ASSERT(comparison2.maxDiff() < 1.0E-10);
// Round trip conversion rgrid -> kgrid -> rgrid, read result
system.readWRGrid("out/testConversion2D_hex_w.rf");
DArray< RField<2> > wFieldsRGrid_check;
wFieldsRGrid_check = system.w().rgrid();
system.rGridToKGrid("out/testConversion2D_hex_w.rf",
"out/testConversion2D_hex_w_2.kf");
system.kGridToRGrid("out/testConversion2D_hex_w_2.kf",
"out/testConversion2D_hex_w_2.rf");
system.readWRGrid("out/testConversion2D_hex_w_2.rf");
// Compare result to original
RFieldComparison<2> comparison3;
comparison3.compare(wFieldsRGrid_check, system.w().rgrid());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison3.maxDiff() << "\n";
}
TEST_ASSERT(comparison3.maxDiff() < 1.0E-10);
}
void testConversion3D_bcc()
{
printMethod(TEST_FUNC);
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
openLogFile("out/testConversion3D_bcc.log");
// Read parameter file
std::ifstream in;
openInputFile("in/diblock/bcc/param.flex", in);
system.readParam(in);
in.close();
// Read w fields in system.wFields
system.readWBasis("in/diblock/bcc/omega.in");
// Store components of field as input
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Complete round trip basis -> rgrid -> basis
system.basisToRGrid("in/diblock/bcc/omega.in",
"out/testConversion3D_bcc_w.rf");
system.rGridToBasis("out/testConversion3D_bcc_w.rf",
"out/testConversion3D_bcc_w.bf");
system.readWBasis("out/testConversion3D_bcc_w.bf");
// Check symmetry of rgrid representation
bool hasSymmetry
= system.checkRGridFieldSymmetry("out/testConversion3D_bcc_w.rf");
TEST_ASSERT(hasSymmetry);
// Compare result to original
BFieldComparison comparison1;
comparison1.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison1.maxDiff() << "\n";
}
TEST_ASSERT(comparison1.maxDiff() < 1.0E-10);
// Round trip conversion basis -> kgrid -> basis, read result
system.basisToKGrid("in/diblock/bcc/omega.in",
"out/testConversion3D_bcc_w.kf");
system.kGridToBasis("out/testConversion3D_bcc_w.kf",
"out/testConversion3D_bcc_w_2.bf");
system.readWBasis("out/testConversion3D_bcc_w_2.bf");
// Compare result to original
BFieldComparison comparison2;
comparison2.compare(wFields_check, system.w().basis());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison2.maxDiff() << "\n";
}
TEST_ASSERT(comparison2.maxDiff() < 1.0E-10);
// Round trip conversion rgrid -> kgrid -> rgrid, read result
system.readWRGrid("out/testConversion3D_bcc_w.rf");
DArray< RField<3> > wFieldsRGrid_check;
wFieldsRGrid_check = system.w().rgrid();
system.rGridToKGrid("out/testConversion3D_bcc_w.rf",
"out/testConversion3D_bcc_w_2.kf");
system.kGridToRGrid("out/testConversion3D_bcc_w_2.kf",
"out/testConversion3D_bcc_w_2.rf");
system.readWRGrid("out/testConversion3D_bcc_w_2.rf");
// Compare result to original
RFieldComparison<3> comparison3;
comparison3.compare(wFieldsRGrid_check, system.w().rgrid());
if (verbose()>0) {
std::cout << "\n";
std::cout << "Max error = " << comparison3.maxDiff() << "\n";
}
TEST_ASSERT(comparison3.maxDiff() < 1.0E-10);
}
void testCheckSymmetry3D_bcc()
{
printMethod(TEST_FUNC);
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
openLogFile("out/testSymmetry3D_bcc.log");
// Read system parameter file
std::ifstream in;
openInputFile("in/diblock/bcc/param.flex", in);
system.readParam(in);
in.close();
system.readWBasis("in/diblock/bcc/omega.in");
bool hasSymmetry = system.fieldIo().hasSymmetry(system.w().rgrid(0));
TEST_ASSERT(hasSymmetry);
// Copy the wFieldsRGrid to a temporary container
RField<3> field;
field.allocate(system.mesh().dimensions());
int meshSize = system.mesh().size();
for (int j = 0; j < meshSize; ++j) {
field[j] = system.w().rgrid(0)[j];
}
hasSymmetry = system.fieldIo().hasSymmetry(field);
TEST_ASSERT(hasSymmetry);
// Intentionally mess up the field, check that symmetry is destroyed
field[23] += 0.1;
hasSymmetry = system.fieldIo().hasSymmetry(field);
TEST_ASSERT(!hasSymmetry);
}
void testIterate1D_lam_rigid()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_rigid.log");
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/lam/param.rigid", in);
system.readParam(in);
in.close();
// Read w fields
system.readWBasis("in/diblock/lam/omega.ref");
// Make a copy of the original field
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Iterate and output solution
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_rigid_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_rigid_c.bf",
system.c().basis(),
system.unitCell());
// Compare solution to original fields
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
//setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-7);
// Check stress value
system.mixture().computeStress();
double stress = system.mixture().stress(0);
if (verbose() > 0) {
std::cout << "stress = " << stress << "\n";
}
TEST_ASSERT(std::abs(stress) < 1.0E-8);
}
void testIterate1D_lam_flex()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_flex.log");
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/lam/param.flex", in);
system.readParam(in);
in.close();
// Read input w-fields, iterate and output solution
system.readWBasis("in/diblock/lam/omega.in");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_flex_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_flex_c.bf",
system.c().basis(),
system.unitCell());
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
system.readWBasis("in/diblock/lam/omega.ref");
//wFields_check = system.w().basis();
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-7);
}
void testIterate1D_lam_soln()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_soln.log");
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/solution/lam/param", in);
system.readParam(in);
in.close();
system.readWBasis("in/solution/lam/w.bf");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Read input w-fields, iterate and output solution
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_soln_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_soln_c.bf",
system.c().basis(),
system.unitCell());
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 2.0E-6);
}
void testIterate1D_lam_open_soln()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_open_soln.log");
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/solution/lam_open/param", in);
system.readParam(in);
in.close();
// Read in comparison result
system.readWBasis("in/solution/lam_open/w.ref");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Read input w-fields, iterate and output solution
system.readWBasis("in/solution/lam_open/w.bf");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_open_soln_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_open_soln_c.bf",
system.c().basis(),
system.unitCell());
// Compare result
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
}
void testIterate1D_lam_open_blend()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_open_blend.log");
System<1> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/blend/lam/param", in);
system.readParam(in);
in.close();
// Read in comparison result
system.readWBasis("in/blend/lam/w.ref");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Read input w-fields, iterate and output solution
system.readWBasis("in/blend/lam/w.bf");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_open_blend_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate1D_lam_open_blend_c.bf",
system.c().basis(),
system.unitCell());
// Compare result
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-8);
}
void testIterate1D_lam_open_shift()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate1D_lam_open_shift.log");
System<1> system, systemShift;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
systemShift.fileMaster().setInputPrefix(filePrefix());
systemShift.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in, inShift;
openInputFile("in/solution/lam_open/param", in);
system.readParam(in);
openInputFile("in/solution/lam_open/param", inShift);
systemShift.readParam(inShift);
in.close();
// Read in comparison result
system.readWBasis("in/solution/lam_open/w.ref");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Read input w-fields, iterate and output solution
system.readWBasis("in/solution/lam_open/w.bf");
systemShift.readWBasis("in/solution/lam_open/w.bf");
// Apply shift to input fields.
double shift = 2;
DArray<DArray <double> > wFields_ = systemShift.w().basis();
for (int i = 0; i < systemShift.mixture().nMonomer(); ++i) {
wFields_[i][0] += shift;
}
systemShift.setWBasis(wFields_);
// Apply shift to polymer and solvent chemical potentials.
for (int i = 0; i < systemShift.mixture().nSolvent(); ++i) {
double L = systemShift.mixture().solvent(i).size();
double newMu = systemShift.mixture().solvent(i).mu() + L*shift;
systemShift.mixture().solvent(i).setMu(newMu);
}
for (int i = 0; i < systemShift.mixture().nPolymer(); ++i) {
double L = 0;
for (int j = 0; j < systemShift.mixture().polymer(i).nBlock(); ++j) {
L += systemShift.mixture().polymer(i).block(j).length();
}
double newMu = systemShift.mixture().polymer(i).mu() + L*shift;
systemShift.mixture().polymer(i).setMu(newMu);
}
// Iterate
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
int errorShift = systemShift.iterate();
if (errorShift) {
TEST_THROW("Shifted iterator failed to converge.");
}
// Verify concentration fields, thermo, and pressure
BFieldComparison comparison(1);
comparison.compare(system.c().basis(),systemShift.c().basis());
double fDiff, pDiff;
fDiff = std::abs(system.fHelmholtz() - systemShift.fHelmholtz());
pDiff = std::abs(system.pressure() - systemShift.pressure() + shift);
TEST_ASSERT(comparison.maxDiff() < 5.0E-8);
TEST_ASSERT(fDiff < 1E-6);
TEST_ASSERT(pDiff < 1E-6);
}
void testIterate2D_hex_rigid()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate2D_hex_rigid.log");
System<2> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/hex/param.rigid", in);
system.readParam(in);
in.close();
// Read reference solution
system.readWBasis("in/diblock/hex/omega.ref");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Iterate, output solution
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate2D_hex_rigid_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate2D_hex_rigid_c.bf",
system.c().basis(),
system.unitCell());
// Compare current solution to reference solution
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
// Maximum error of 2.608E-7 occurs for the first star
// Check stress
system.mixture().computeStress();
double stress = system.mixture().stress(0);
if (verbose() > 0) {
std::cout << "stress = " << stress << "\n";
}
TEST_ASSERT (std::abs(stress) < 1.0E-8);
}
void testIterate2D_hex_flex()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate2D_hex_flex.log");
System<2> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
// Read parameter file
std::ifstream in;
openInputFile("in/diblock/hex/param.flex", in);
system.readParam(in);
in.close();
// Read reference solution (produced by Fortran code)
system.readWBasis("in/diblock/hex/omega.ref");
// Save reference solution to wFields_check array
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
system.readWBasis("in/diblock/hex/omega.in");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate2D_hex_flex_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate2D_hex_flex_c.bf",
system.c().basis(),
system.unitCell());
// Compare solution to reference solution
BFieldComparison comparison(1);
// setVerbose(1);
comparison.compare(wFields_check, system.w().basis());
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
// Maximum difference of 2.58E-7 occurs for the first star
}
void testIterate3D_bcc_rigid()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate3D_bcc_rigid.log");
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/bcc/param.rigid", in);
system.readParam(in);
in.close();
// Read initial guess
system.readWBasis("in/diblock/bcc/omega.ref");
// Save copy of initial fields
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
// Iterate and output solution
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate3D_bcc_rigid_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate3D_bcc_rigid_c.bf",
system.c().basis(),
system.unitCell());
// Compare solution to reference solution
BFieldComparison comparison(1); // Constructor argument 1 skips star 0
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
// Maximum difference of 1.023E-7 occurs for the second star
// Test that stress is small
system.mixture().computeStress();
double stress = system.mixture().stress(0);
if (verbose() > 0) {
std::cout << "stress = " << stress << "\n";
}
TEST_ASSERT(std::abs(stress) < 1.0E-7);
}
void testIterate3D_bcc_flex()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate3D_bcc_flex.log");
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/bcc/param.flex", in);
system.readParam(in);
in.close();
system.readWBasis("in/diblock/bcc/omega.ref");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
system.readWBasis("in/diblock/bcc/omega.in");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate3D_bcc_flex_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate3D_bcc_flex_c.bf",
system.c().basis(),
system.unitCell());
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
// Maximum difference of 1.09288E-7 occurs for the second star
}
void testIterate3D_altGyr_flex()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate3D_altGyr_flex.log");
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
// Read parameter file
std::ifstream in;
openInputFile("in/triblock/altGyr/param", in);
system.readParam(in);
in.close();
// Input a converged solution from PSCF Fortran
system.readWBasis("in/triblock/altGyr/w.bf");
// Make copy of input fields for later comparison
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate3D_altGyr_flex_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsBasis("out/testIterate3D_altGyr_flex_c.bf",
system.c().basis(),
system.unitCell());
// Compare w fields
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-6);
// Compare Helmoltz free energies
double fHelmholtz = system.fHelmholtz();
double fHelmholtzRef = 3.9642295402; // from PSCF Fortran
double fDiff = fHelmholtz - fHelmholtzRef;
if (verbose() > 0) {
std::cout << "fHelmholtz diff = " << fDiff << "\n";
}
TEST_ASSERT(std::abs(fDiff) < 1.0E-7);
// Compare relaxed unit cell parameters
double cellParam = system.unitCell().parameter(0);
double cellParamRef = 2.2348701424; // from PSCF Fortran
double cellDiff = cellParam - cellParamRef;
if (verbose() > 0) {
std::cout << "Cell param diff = " << cellDiff << "\n";
}
TEST_ASSERT(std::abs(cellDiff) < 1.0E-7);
}
void testIterate3D_c15_1_flex()
{
printMethod(TEST_FUNC);
openLogFile("out/testIterate3D_c15_1_flex.log");
System<3> system;
system.fileMaster().setInputPrefix(filePrefix());
system.fileMaster().setOutputPrefix(filePrefix());
std::ifstream in;
openInputFile("in/diblock/c15_1/param.flex", in);
system.readParam(in);
in.close();
system.readWBasis("in/diblock/c15_1/w_ref.bf");
DArray< DArray<double> > wFields_check;
wFields_check = system.w().basis();
system.readWBasis("in/diblock/c15_1/w_in.bf");
int error = system.iterate();
if (error) {
TEST_THROW("Iterator failed to converge.");
}
system.fieldIo().writeFieldsBasis("out/testIterate3D_c15_1_flex_w.bf",
system.w().basis(),
system.unitCell());
system.fieldIo().writeFieldsRGrid("out/testIterate3D_c15_1_flex_w.rf",
system.c().rgrid(),
system.unitCell());
BFieldComparison comparison(1);
comparison.compare(wFields_check, system.w().basis());
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Max error = " << comparison.maxDiff() << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 5.0E-7);
// Maximum difference of 1.09288E-7 occurs for the second star
}
};
TEST_BEGIN(SystemTest)
TEST_ADD(SystemTest, testConstructor1D)
TEST_ADD(SystemTest, testReadParameters1D)
TEST_ADD(SystemTest, testConversion1D_lam)
TEST_ADD(SystemTest, testConversion2D_hex)
TEST_ADD(SystemTest, testConversion3D_bcc)
TEST_ADD(SystemTest, testCheckSymmetry3D_bcc)
TEST_ADD(SystemTest, testIterate1D_lam_rigid)
TEST_ADD(SystemTest, testIterate1D_lam_flex)
TEST_ADD(SystemTest, testIterate1D_lam_soln)
TEST_ADD(SystemTest, testIterate1D_lam_open_soln)
TEST_ADD(SystemTest, testIterate1D_lam_open_blend)
TEST_ADD(SystemTest, testIterate1D_lam_open_shift)
TEST_ADD(SystemTest, testIterate2D_hex_rigid)
TEST_ADD(SystemTest, testIterate2D_hex_flex)
TEST_ADD(SystemTest, testIterate3D_bcc_rigid)
TEST_ADD(SystemTest, testIterate3D_bcc_flex)
TEST_ADD(SystemTest, testIterate3D_altGyr_flex)
TEST_ADD(SystemTest, testIterate3D_c15_1_flex)
TEST_END(SystemTest)
#endif
| 32,742
|
C++
|
.h
| 778
| 32.6491
| 81
| 0.599428
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,192
|
FieldTestComposite.h
|
dmorse_pscfpp/src/pspc/tests/field/FieldTestComposite.h
|
#ifndef PSPC_FIELD_TEST_COMPOSITE_H
#define PSPC_FIELD_TEST_COMPOSITE_H
#include <test/CompositeTestRunner.h>
#include "FieldTest.h"
#include "RFieldTest.h"
#include "RFieldDftTest.h"
#include "FftTest.h"
#include "FieldComparisonTest.h"
#include "DomainTest.h"
#include "FieldIoTest.h"
#include "WFieldContainerTest.h"
#include "CFieldContainerTest.h"
#include "MaskTest.h"
TEST_COMPOSITE_BEGIN(FieldTestComposite)
TEST_COMPOSITE_ADD_UNIT(FieldTest);
TEST_COMPOSITE_ADD_UNIT(RFieldTest);
TEST_COMPOSITE_ADD_UNIT(RFieldDftTest);
TEST_COMPOSITE_ADD_UNIT(FftTest);
TEST_COMPOSITE_ADD_UNIT(FieldComparisonTest);
TEST_COMPOSITE_ADD_UNIT(DomainTest);
TEST_COMPOSITE_ADD_UNIT(FieldIoTest);
TEST_COMPOSITE_ADD_UNIT(WFieldContainerTest);
TEST_COMPOSITE_ADD_UNIT(CFieldContainerTest);
TEST_COMPOSITE_ADD_UNIT(MaskTest);
TEST_COMPOSITE_END
#endif
| 841
|
C++
|
.h
| 26
| 31.192308
| 45
| 0.833539
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,193
|
FFTWTest.h
|
dmorse_pscfpp/src/pspc/tests/field/FFTWTest.h
|
#ifndef PSPC_FFTW_TEST_H
#define PSPC_FFTW_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <util/containers/DArray.h>
#include <util/math/Constants.h>
#include <util/format/Dbl.h>
#include <fftw3.h>
#include <iostream>
#include <fstream>
using namespace Util;
//using namespace Pscf;
//using namespace Pspc;
class FFTWTest : public UnitTest
{
public:
void setUp()
{}
void tearDown()
{}
void testFFTW_1D() {
printMethod(TEST_FUNC);
printEndl();
DArray<double> in;
DArray<fftw_complex> out;
int n = 10;
in.allocate(n);
out.allocate(n/2+1);
unsigned int flags = FFTW_ESTIMATE;
double x;
double twoPi = 2.0*Constants::Pi;
for (int i = 0; i < n; ++i) {
x = twoPi*float(i)/float(n);
in[i] = cos(x);
std::cout << Dbl(in[i]);
}
std::cout << std::endl;
//std::cout << "Entering forward transform plan creation" << std::endl;
fftw_plan plan_f = fftw_plan_dft_r2c_1d(n, &in[0], &out[0], flags);
//std::cout << "Finished forward plan creation" << std::endl;
fftw_execute(plan_f);
//std::cout << "Finished forward transform" << std::endl;
fftw_plan plan_r = fftw_plan_dft_c2r_1d(n, &out[0], &in[0], flags);
//std::cout << "Finished inverse plan creation" << std::endl;
fftw_execute(plan_r);
//std::cout << "Finished inverse transform" << std::endl;
double factor = 1.0/double(n);
for (int i = 0; i < n/2 + 1; ++i) {
out[i][0] *= factor;
out[i][1] *= factor;
//std::cout << out[i][0] << " " << out[i][1] << std::endl;
}
for (int i = 0; i < n; ++i) {
std::cout << Dbl(in[i]);
}
std::cout << std::endl;
}
};
TEST_BEGIN(FFTWTest)
TEST_ADD(FFTWTest, testFFTW_1D)
TEST_END(FFTWTest)
#endif
| 1,883
|
C++
|
.h
| 62
| 24.806452
| 77
| 0.581564
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,194
|
FieldComparisonTest.h
|
dmorse_pscfpp/src/pspc/tests/field/FieldComparisonTest.h
|
#ifndef PSPC_FIELD_COMPARISON_TEST_H
#define PSPC_FIELD_COMPARISON_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/KFieldComparison.h>
#include <util/format/Dbl.h>
using namespace Util;
using namespace Pscf::Pspc;
class FieldComparisonTest : public UnitTest
{
public:
void setUp()
{ setVerbose(0); }
void tearDown()
{}
void testRFieldComparison_1D()
{
printMethod(TEST_FUNC);
RField<1> rf_0, rf_1;
int n = 10;
IntVec<1> dimensions;
dimensions[0] = n;
rf_0.allocate(dimensions);
rf_1.allocate(dimensions);
int size = rf_0.capacity();
TEST_ASSERT(size == n);
for (int i = 0; i < n; ++i) {
rf_0[i] = 2.0;
rf_1[i] = 2.001;
}
RFieldComparison<1> comparison;
comparison.compare(rf_0, rf_1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "MaxDiff = "
<< Dbl(comparison.maxDiff(), 20, 12) << "\n";
std::cout << "RmsDiff = "
<< Dbl(comparison.rmsDiff(), 20, 12) << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 0.0011);
TEST_ASSERT(comparison.maxDiff() > 0.0009);
TEST_ASSERT(comparison.rmsDiff() < 0.0011);
TEST_ASSERT(comparison.rmsDiff() > 0.0009);
}
void testRFieldComparison_2D()
{
printMethod(TEST_FUNC);
RField<2> rf_0, rf_1;
int m = 5;
int n = 10;
IntVec<2> dimensions;
dimensions[0] = m;
dimensions[1] = n;
rf_0.allocate(dimensions);
rf_1.allocate(dimensions);
int size = rf_0.capacity();
TEST_ASSERT(size == m*n);
for (int i = 0; i < size; ++i) {
rf_0[i] = 2.0;
rf_1[i] = 2.001;
}
RFieldComparison<2> comparison;
comparison.compare(rf_0, rf_1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "MaxDiff = "
<< Dbl(comparison.maxDiff(), 20, 12) << "\n";
std::cout << "RmsDiff = "
<< Dbl(comparison.rmsDiff(), 20, 12) << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 0.0011);
TEST_ASSERT(comparison.maxDiff() > 0.0009);
TEST_ASSERT(comparison.rmsDiff() < 0.0011);
TEST_ASSERT(comparison.rmsDiff() > 0.0009);
}
};
TEST_BEGIN(FieldComparisonTest)
TEST_ADD(FieldComparisonTest, testRFieldComparison_1D)
TEST_ADD(FieldComparisonTest, testRFieldComparison_2D)
TEST_END(FieldComparisonTest)
#endif
| 2,605
|
C++
|
.h
| 84
| 24.547619
| 64
| 0.586262
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,195
|
WFieldContainerTest.h
|
dmorse_pscfpp/src/pspc/tests/field/WFieldContainerTest.h
|
#ifndef PSPC_W_FIELD_CONTAINER_TEST_H
#define PSPC_W_FIELD_CONTAINER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/WFieldContainer.h>
#include <pspc/field/Domain.h>
#include <pspc/field/FieldIo.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pscf/crystal/BFieldComparison.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/mesh/MeshIterator.h>
#include <util/containers/DArray.h>
#include <util/misc/FileMaster.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class WFieldContainerTest : public UnitTest
{
std::ofstream logFile_;
FileMaster fileMaster_;
int nMonomer_;
public:
void setUp()
{
setVerbose(0);
nMonomer_ = 2;
openLogFile("out/wFieldContainerTestLogFile");
}
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
}
// Open and read parameter header to initialize Domain<D> system.
template <int D>
void readParam(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readParam(in);
in.close();
}
// Open and read file header to initialize Domain<D> system.
template <int D>
void readHeader(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readRGridFieldHeader(in, nMonomer_);
in.close();
}
// Allocate an array of fields in symmetry adapated format.
void allocateFields(int nMonomer, int nBasis,
DArray< DArray<double> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(nBasis);
}
}
// Allocate an array of r-grid fields
template <int D>
void allocateFields(int nMonomer, IntVec<D> dimensions,
DArray< RField<D> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(dimensions);
}
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsBasis(in, fields, domain.unitCell());
in.close();
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< RField<D> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsRGrid(in, fields, domain.unitCell());
in.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsBasis(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RField<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsRGrid(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RFieldDft<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsKGrid(out, fields, domain.unitCell());
out.close();
}
void testAllocate_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedRGrid());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
}
void testSetBasis_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
//std::cout << "\n domain.basis().nBasis() = "
// << domain.basis().nBasis() << "\n";
DArray< DArray<double> > bf;
allocateFields(nMonomer_, domain.basis().nBasis(), bf);
TEST_ASSERT(bf.capacity() == nMonomer_);
readFields("in/w_bcc.bf", domain, bf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedRGrid());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
fields.setBasis(bf);
TEST_ASSERT(fields.hasData());
TEST_ASSERT(fields.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf, fields.basis());
//std::cout << comparison.maxDiff() << std::endl;
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
domain.fieldIo().convertRGridToBasis(fields.rgrid(), bf_1);
comparison.compare(bf, fields.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testSetRGrid_1_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< RField<3> > rf;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
readFields("in/w_bcc.rf", domain, rf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedRGrid());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
fields.setRGrid(rf);
TEST_ASSERT(fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
RFieldComparison<3> comparison;
comparison.compare(rf, fields.rgrid());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testSetRGrid_2_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf;
allocateFields(nMonomer_, domain.basis().nBasis(), bf);
TEST_ASSERT(bf.capacity() == nMonomer_);
readFields("in/w_bcc.bf", domain, bf);
DArray< RField<3> > rf;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
domain.fieldIo().convertBasisToRGrid(bf, rf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedRGrid());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
bool isSymmetric = true;
fields.setRGrid(rf, isSymmetric);
TEST_ASSERT(fields.hasData());
TEST_ASSERT(fields.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf, fields.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testReadBasis_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf;
allocateFields(nMonomer_, domain.basis().nBasis(), bf);
TEST_ASSERT(bf.capacity() == nMonomer_);
readFields("in/w_bcc.bf", domain, bf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
std::ifstream in;
openInputFile("in/w_bcc.bf", in);
fields.readBasis(in, domain.unitCell());
TEST_ASSERT(fields.hasData());
TEST_ASSERT(fields.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf, fields.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
domain.fieldIo().convertRGridToBasis(fields.rgrid(), bf_1);
comparison.compare(bf, fields.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testReadRGrid_1_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< RField<3> > rf;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
readFields("in/w_bcc.rf", domain, rf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
std::ifstream in;
openInputFile("in/w_bcc.rf", in);
fields.readRGrid(in, domain.unitCell());
TEST_ASSERT(fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
RFieldComparison<3> comparison;
comparison.compare(rf, fields.rgrid());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testReadRGrid_2_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf;
allocateFields(nMonomer_, domain.basis().nBasis(), bf);
TEST_ASSERT(bf.capacity() == nMonomer_);
readFields("in/w_bcc.bf", domain, bf);
DArray< RField<3> > rf;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
domain.fieldIo().convertBasisToRGrid(bf, rf);
WFieldContainer<3> fields;
fields.setFieldIo(domain.fieldIo());
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(!fields.hasData());
TEST_ASSERT(!fields.isSymmetric());
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
std::ifstream in;
openInputFile("in/w_bcc.rf", in);
bool isSymmetric = true;
fields.readRGrid(in, domain.unitCell(), isSymmetric);
TEST_ASSERT(fields.hasData());
TEST_ASSERT(fields.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf, fields.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
};
TEST_BEGIN(WFieldContainerTest)
TEST_ADD(WFieldContainerTest, testAllocate_bcc)
TEST_ADD(WFieldContainerTest, testSetBasis_bcc)
TEST_ADD(WFieldContainerTest, testSetRGrid_1_bcc)
TEST_ADD(WFieldContainerTest, testSetRGrid_2_bcc)
TEST_ADD(WFieldContainerTest, testReadBasis_bcc)
TEST_ADD(WFieldContainerTest, testReadRGrid_1_bcc)
TEST_ADD(WFieldContainerTest, testReadRGrid_2_bcc)
TEST_END(WFieldContainerTest)
#endif
| 12,719
|
C++
|
.h
| 344
| 30.366279
| 72
| 0.648383
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,196
|
FieldTest.h
|
dmorse_pscfpp/src/pspc/tests/field/FieldTest.h
|
#ifndef PSPC_FIELD_TEST_H
#define PSPC_FIELD_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/Field.h>
#include <util/archives/MemoryOArchive.h>
#include <util/archives/MemoryIArchive.h>
#include <util/archives/MemoryCounter.h>
#include <util/archives/BinaryFileOArchive.h>
#include <util/archives/BinaryFileIArchive.h>
using namespace Util;
using namespace Pscf::Pspc;
class FieldTest : public UnitTest
{
private:
const static int capacity = 3;
public:
void setUp()
{ }
void tearDown() {}
void testConstructor();
void testAllocate();
void testSubscript();
void testSerialize1Memory();
void testSerialize2Memory();
void testSerialize1File();
void testSerialize2File();
};
void FieldTest::testConstructor()
{
printMethod(TEST_FUNC);
{
Field<double> v;
TEST_ASSERT(v.capacity() == 0 );
TEST_ASSERT(!v.isAllocated() );
}
}
void FieldTest::testAllocate()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == capacity );
TEST_ASSERT(v.isAllocated());
}
}
void FieldTest::testSubscript()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0 ;
}
TEST_ASSERT(v[0] == 10.0);
TEST_ASSERT(v[2] == 30.0);
}
}
void FieldTest::testSerialize1Memory()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int size = memorySize(v);
int i1 = 13;
int i2;
MemoryOArchive oArchive;
oArchive.allocate(size + 12);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
oArchive << i1;
// Show that v is unchanged by packing
TEST_ASSERT(v[1]==20.0);
TEST_ASSERT(v.capacity() == 3);
Field<double> u;
u.allocate(3);
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
// Load into u and i2
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Release
iArchive.release();
TEST_ASSERT(!iArchive.isAllocated());
TEST_ASSERT(iArchive.begin() == 0);
TEST_ASSERT(iArchive.cursor() == 0);
TEST_ASSERT(iArchive.end() == 0);
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size + sizeof(int));
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
iArchive = oArchive;
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void FieldTest::testSerialize2Memory()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int size = memorySize(v);
MemoryOArchive oArchive;
oArchive.allocate(size);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == capacity);
Field<double> u;
// Note: We do not allocate Field<double> u in this test.
// This is the main difference from testSerialize1Memory()
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
iArchive >> u;
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(u.capacity() == 3);
}
}
void FieldTest::testSerialize1File()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1]==20.0);
TEST_ASSERT(v.capacity() == 3);
Field<double> u;
u.allocate(3);
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void FieldTest::testSerialize2File()
{
printMethod(TEST_FUNC);
{
Field<double> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == 3);
Field<double> u;
// u.allocate(3); ->
// Note: We do not allocate first. This is the difference
// from the previous test
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
TEST_BEGIN(FieldTest)
TEST_ADD(FieldTest, testConstructor)
TEST_ADD(FieldTest, testAllocate)
TEST_ADD(FieldTest, testSubscript)
TEST_ADD(FieldTest, testSerialize1Memory)
TEST_ADD(FieldTest, testSerialize2Memory)
TEST_ADD(FieldTest, testSerialize1File)
TEST_ADD(FieldTest, testSerialize2File)
TEST_END(FieldTest)
#endif
| 7,589
|
C++
|
.h
| 253
| 23.596838
| 78
| 0.60042
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,197
|
FftTest.h
|
dmorse_pscfpp/src/pspc/tests/field/FftTest.h
|
#ifndef PSPC_FFT_TEST_H
#define PSPC_FFT_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/FFT.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pspc/field/RFieldComparison.h>
#include <util/math/Constants.h>
#include <util/format/Dbl.h>
using namespace Util;
using namespace Pscf::Pspc;
class FftTest : public UnitTest
{
public:
void setUp() {}
void tearDown() {}
void testConstructor();
void testTransform1D();
void testTransform2D();
void testTransform3D();
};
void FftTest::testConstructor()
{
printMethod(TEST_FUNC);
{
FFT<1> v;
//TEST_ASSERT(v.capacity() == 0 );
//TEST_ASSERT(!v.isAllocated() );
}
}
void FftTest::testTransform1D() {
printMethod(TEST_FUNC);
//printEndl();
int n = 10;
IntVec<1> d;
d[0] = n;
FFT<1> v;
v.setup(d);
RField<1> in;
in.allocate(d);
TEST_ASSERT(in.capacity() == n);
// Initialize input data
double x;
double twoPi = 2.0*Constants::Pi;
for (int i = 0; i < n; ++i) {
x = twoPi*float(i)/float(n);
in[i] = cos(x);
}
// Transform in -> out
RFieldDft<1> out;
out.allocate(d);
v.forwardTransform(in, out);
#if 0
// Save a copy of out (to check if input was overwritten)
RFieldDft<1> outCopy(out);
TEST_ASSERT(out.capacity() == outCopy.capacity());
#endif
// Inverse transform out -> inCopy
RField<1> inCopy;
inCopy.allocate(d);
v.inverseTransform(out, inCopy);
for (int i = 0; i < n; ++i) {
TEST_ASSERT(eq(in[i], inCopy[i]));
}
#if 0
// Test if input of inverse transform was overwritten
for (int i = 0; i < out.capacity(); ++i) {
TEST_ASSERT(eq(out[i][0], outCopy[i][0]));
TEST_ASSERT(eq(out[i][1], outCopy[i][1]));
}
#endif
}
void FftTest::testTransform2D()
{
printMethod(TEST_FUNC);
//printEndl();
int n1 = 3;
int n2 = 3;
IntVec<2> d;
d[0] = n1;
d[1] = n2;
FFT<2> v;
v.setup(d);
RField<2> in;
in.allocate(d);
int rank = 0;
double x, y, cx, sy;
double twoPi = 2.0*Constants::Pi;
for (int i = 0; i < n1; i++) {
x = twoPi*float(i)/float(n1);
cx = cos(x);
for (int j = 0; j < n2; j++) {
y = twoPi*float(j)/float(n2);
sy = sin(y);
rank = j + (i * n2);
in[rank] = 0.5 + 0.2*cx + 0.6*cx*cx - 0.1*sy + 0.3*cx*sy;
}
}
// Forward transform in -> out
RFieldDft<2> out;
out.allocate(d);
TEST_ASSERT(eq(in.capacity() / in.meshDimensions()[1],
out.capacity() / (out.meshDimensions()[1]/2 + 1)));
v.forwardTransform(in, out);
#if 1
// Save a copy of out
RFieldDft<2> outCopy(out);
TEST_ASSERT(out.capacity() == outCopy.capacity());
for (int i = 0; i < out.capacity(); ++i) {
TEST_ASSERT(eq(out[i][0], outCopy[i][0]));
TEST_ASSERT(eq(out[i][1], outCopy[i][1]));
}
#endif
// Inverse transform out -> inCopy
RField<2> inCopy;
inCopy.allocate(d);
v.inverseTransform(out, inCopy);
// Check if in == inCopy
for (int i = 0; i < n1; i++) {
for (int j = 0; j < n2; j++) {
rank = j + (i * n2);
TEST_ASSERT(eq(in[rank], inCopy[rank]));
}
}
#if 0
// Check if out was not modified my inverseTransform
for (int i = 0; i < out.capacity(); ++i) {
TEST_ASSERT(eq(out[i][0], outCopy[i][0]));
TEST_ASSERT(eq(out[i][1], outCopy[i][1]));
}
#endif
}
void FftTest::testTransform3D() {
printMethod(TEST_FUNC);
//printEndl();
int n1 = 3;
int n2 = 3;
int n3 = 3;
IntVec<3> d;
d[0] = n1;
d[1] = n2;
d[2] = n3;
FFT<3> v;
v.setup(d);
RField<3> in;
RFieldDft<3> out;
in.allocate(d);
out.allocate(d);
TEST_ASSERT(eq(in.capacity() / in.meshDimensions()[2],
out.capacity() / (out.meshDimensions()[2]/2 + 1)));
int rank = 0;
for (int i = 0; i < n1; i++) {
for (int j = 0; j < n2; j++) {
for (int k = 0; k < n3; k++){
rank = k + ((j + (i * n2)) * n3);
in[rank] = 1.0 + double(rank)/double(in.capacity());
}
}
}
v.forwardTransform(in, out);
RField<3> inCopy;
inCopy.allocate(d);
v.inverseTransform(out, inCopy);
for (int i = 0; i < n1; i++) {
for (int j = 0; j < n2; j++) {
for (int k = 0; k < n3; k++){
rank = k + ((j + (i * n1)) * n3);
TEST_ASSERT(eq(in[rank], inCopy[rank]));
}
}
}
RFieldComparison<3> comparison;
comparison.compare(in, inCopy);
//std::cout << std::endl;
//std::cout << "maxDiff = "
// << Dbl(comparison.maxDiff(), 20, 13)
// << std::endl;
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
}
TEST_BEGIN(FftTest)
TEST_ADD(FftTest, testConstructor)
TEST_ADD(FftTest, testTransform1D)
TEST_ADD(FftTest, testTransform2D)
TEST_ADD(FftTest, testTransform3D)
TEST_END(FftTest)
#endif
| 4,958
|
C++
|
.h
| 187
| 21.754011
| 69
| 0.569042
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,198
|
MaskTest.h
|
dmorse_pscfpp/src/pspc/tests/field/MaskTest.h
|
#ifndef PSPC_MASK_TEST_H
#define PSPC_MASK_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/Mask.h>
#include <pspc/field/Domain.h>
#include <pspc/field/FieldIo.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pscf/crystal/BFieldComparison.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/mesh/MeshIterator.h>
#include <util/containers/DArray.h>
#include <util/misc/FileMaster.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class MaskTest : public UnitTest
{
std::ofstream logFile_;
FileMaster fileMaster_;
int nMonomer_;
public:
void setUp()
{
setVerbose(0);
nMonomer_ = 2;
openLogFile("out/maskTestLogFile");
}
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
}
// Open and read parameter header to initialize Domain<D> system.
template <int D>
void readParam(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readParam(in);
in.close();
}
// Open and read file header to initialize Domain<D> system.
template <int D>
void readHeader(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readRGridFieldHeader(in, nMonomer_);
in.close();
}
// Allocate an array of fields in symmetry adapated format.
void allocateFields(int nMonomer, int nBasis,
DArray< DArray<double> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(nBasis);
}
}
// Allocate an array of r-grid fields
template <int D>
void allocateFields(int nMonomer, IntVec<D> dimensions,
DArray< RField<D> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(dimensions);
}
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsBasis(in, fields, domain.unitCell());
in.close();
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< RField<D> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsRGrid(in, fields, domain.unitCell());
in.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsBasis(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RField<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsRGrid(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RFieldDft<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsKGrid(out, fields, domain.unitCell());
out.close();
}
void testSetBasis()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< DArray<double> > bf;
allocateFields(nMonomer_, nBasis, bf);
readFields("in/mask.bf", domain, bf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
mask.setBasis(bf[0]);
TEST_ASSERT(mask.hasData());
TEST_ASSERT(mask.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf[0], mask.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
DArray<double> bf_1;
bf_1.allocate(nBasis);
domain.fieldIo().convertRGridToBasis(mask.rgrid(), bf_1);
comparison.compare(bf_1, mask.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testSetRGrid_1()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< RField<1> > rf;
allocateFields(nMonomer_, dimensions, rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
readFields("in/mask.rf", domain, rf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
mask.setRGrid(rf[0]);
TEST_ASSERT(mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
RFieldComparison<1> comparison;
comparison.compare(rf[0], mask.rgrid());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testSetRGrid_2()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< DArray<double> > bf;
allocateFields(nMonomer_, nBasis, bf);
TEST_ASSERT(bf.capacity() == nMonomer_);
readFields("in/mask.bf", domain, bf);
RField<1> rf;
rf.allocate(dimensions);
domain.fieldIo().convertBasisToRGrid(bf[0], rf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
bool isSymmetric = true;
mask.setRGrid(rf, isSymmetric);
TEST_ASSERT(mask.hasData());
TEST_ASSERT(mask.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf[0], mask.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testReadBasis()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< DArray<double> > bf;
allocateFields(nMonomer_, nBasis, bf);
readFields("in/mask.bf", domain, bf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
std::ifstream in;
openInputFile("in/mask.bf", in);
mask.readBasis(in, domain.unitCell());
TEST_ASSERT(mask.hasData());
TEST_ASSERT(mask.isSymmetric());
BFieldComparison comparison;
comparison.compare(bf[0], mask.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
DArray<double> bf_1;
bf_1.allocate(nBasis);
domain.fieldIo().convertRGridToBasis(mask.rgrid(), bf_1);
comparison.compare(bf_1, mask.basis());
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testReadRGrid_1()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< RField<1> > rf;
allocateFields(nMonomer_, dimensions, rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
readFields("in/mask.rf", domain, rf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
std::ifstream in;
openInputFile("in/mask.rf", in);
mask.readRGrid(in, domain.unitCell());
TEST_ASSERT(mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
RFieldComparison<1> comparison;
comparison.compare(rf[0], mask.rgrid());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testReadRGrid_2()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
DArray< RField<1> > rf;
allocateFields(nMonomer_, dimensions, rf);
TEST_ASSERT(rf.capacity() == nMonomer_);
readFields("in/mask.rf", domain, rf);
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
std::ifstream in;
openInputFile("in/mask.rf", in);
mask.readRGrid(in, domain.unitCell(), true);
TEST_ASSERT(mask.hasData());
TEST_ASSERT(mask.isSymmetric());
RFieldComparison<1> comparison;
comparison.compare(rf[0], mask.rgrid());
TEST_ASSERT(comparison.maxDiff() < 1.0E-8);
}
void testPhiTot()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/mask.rf", domain);
int nBasis = domain.basis().nBasis();
IntVec<1> dimensions = domain.mesh().dimensions();
// Create empty mask object, check phiTot
Mask<1> mask;
mask.setFieldIo(domain.fieldIo());
mask.allocate(nBasis, dimensions);
TEST_ASSERT(mask.isAllocated());
TEST_ASSERT(!mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
TEST_ASSERT(eq(mask.phiTot(), 1.0));
// Read unsymmetrized r-grid, check phiTot
std::ifstream in;
openInputFile("in/mask.rf", in);
mask.readRGrid(in, domain.unitCell());
TEST_ASSERT(mask.hasData());
TEST_ASSERT(!mask.isSymmetric());
TEST_ASSERT(eq(mask.phiTot(), 8.9461021637e-01));
// Read basis, check phiTot
std::ifstream in2;
openInputFile("in/mask.bf", in2);
mask.readBasis(in2, domain.unitCell());
TEST_ASSERT(mask.hasData());
TEST_ASSERT(mask.isSymmetric());
TEST_ASSERT(eq(mask.phiTot(), mask.basis()[0]));
TEST_ASSERT(eq(mask.phiTot(), 8.9461021637e-01));
}
};
TEST_BEGIN(MaskTest)
TEST_ADD(MaskTest, testSetBasis)
TEST_ADD(MaskTest, testSetRGrid_1)
TEST_ADD(MaskTest, testSetRGrid_2)
TEST_ADD(MaskTest, testReadBasis)
TEST_ADD(MaskTest, testReadRGrid_1)
TEST_ADD(MaskTest, testReadRGrid_2)
TEST_ADD(MaskTest, testPhiTot)
TEST_END(MaskTest)
#endif
| 11,437
|
C++
|
.h
| 339
| 27.474926
| 72
| 0.644269
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,199
|
RFieldTest.h
|
dmorse_pscfpp/src/pspc/tests/field/RFieldTest.h
|
#ifndef PSPC_R_FIELD_TEST_H
#define PSPC_R_FIELD_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RField.h>
#include <util/archives/MemoryOArchive.h>
#include <util/archives/MemoryIArchive.h>
#include <util/archives/MemoryCounter.h>
#include <util/archives/BinaryFileOArchive.h>
#include <util/archives/BinaryFileIArchive.h>
using namespace Util;
using namespace Pscf::Pspc;
class RFieldTest : public UnitTest
{
private:
const static int capacity = 3;
typedef double Data;
public:
void setUp()
{ }
void tearDown() {}
void testConstructor();
void testAllocate();
void testAllocate3();
void testSubscript();
void testCopyConstructor();
void testAssignment();
void testSerialize1Memory();
void testSerialize2Memory();
void testSerialize1File();
void testSerialize2File();
};
void RFieldTest::testConstructor()
{
printMethod(TEST_FUNC);
{
RField<3> v;
TEST_ASSERT(v.capacity() == 0 );
TEST_ASSERT(!v.isAllocated() );
}
}
void RFieldTest::testAllocate()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == capacity );
TEST_ASSERT(v.isAllocated());
}
}
void RFieldTest::testAllocate3()
{
printMethod(TEST_FUNC);
{
IntVec<3> d;
d[0] = 2;
d[1] = 3;
d[2] = 4;
RField<3> v;
v.allocate(d);
TEST_ASSERT(v.capacity() == 24);
TEST_ASSERT(v.isAllocated());
TEST_ASSERT(v.meshDimensions() == d);
}
}
void RFieldTest::testSubscript()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0 ;
}
TEST_ASSERT(v[0] == 10.0);
TEST_ASSERT(v[2] == 30.0);
}
}
void RFieldTest::testCopyConstructor()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == 3 );
TEST_ASSERT(v.isAllocated() );
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
RField<3> u(v);
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
TEST_ASSERT(v[0] == 10.0);
TEST_ASSERT(v[2] == 30.0);
TEST_ASSERT(u[0] == 10.0);
TEST_ASSERT(u[2] == 30.0);
}
}
void RFieldTest::testAssignment()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == 3 );
TEST_ASSERT(v.isAllocated() );
RField<3> u;
u.allocate(3);
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
u = v;
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
TEST_ASSERT(v[0] == 10.0);
TEST_ASSERT(v[2] == 30.0);
TEST_ASSERT(u[0] == 10.0);
TEST_ASSERT(u[2] == 30.0);
}
}
void RFieldTest::testSerialize1Memory()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int size = memorySize(v);
int i1 = 13;
int i2;
MemoryOArchive oArchive;
oArchive.allocate(size + 12);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
oArchive << i1;
// Show that v is unchanged by packing
TEST_ASSERT(v[1]==20.0);
TEST_ASSERT(v.capacity() == 3);
RField<3> u;
u.allocate(3);
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
// Load into u and i2
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Release
iArchive.release();
TEST_ASSERT(!iArchive.isAllocated());
TEST_ASSERT(iArchive.begin() == 0);
TEST_ASSERT(iArchive.cursor() == 0);
TEST_ASSERT(iArchive.end() == 0);
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size + sizeof(int));
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
iArchive = oArchive;
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldTest::testSerialize2Memory()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int size = memorySize(v);
MemoryOArchive oArchive;
oArchive.allocate(size);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == capacity);
RField<3> u;
// Note: We do not allocate RField u in this test.
// This is the main difference from testSerialize1Memory()
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
iArchive >> u;
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldTest::testSerialize1File()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1]==20.0);
TEST_ASSERT(v.capacity() == 3);
RField<3> u;
u.allocate(3);
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldTest::testSerialize2File()
{
printMethod(TEST_FUNC);
{
RField<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i] = (i+1)*10.0;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == 3);
RField<3> u;
// u.allocate(3); ->
// Note: We do not allocate first. This is the difference
// from the previous test
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
TEST_BEGIN(RFieldTest)
TEST_ADD(RFieldTest, testConstructor)
TEST_ADD(RFieldTest, testAllocate)
TEST_ADD(RFieldTest, testAllocate3)
TEST_ADD(RFieldTest, testSubscript)
TEST_ADD(RFieldTest, testCopyConstructor)
TEST_ADD(RFieldTest, testAssignment)
TEST_ADD(RFieldTest, testSerialize1Memory)
TEST_ADD(RFieldTest, testSerialize2Memory)
TEST_ADD(RFieldTest, testSerialize1File)
TEST_ADD(RFieldTest, testSerialize2File)
TEST_END(RFieldTest)
#endif
| 9,323
|
C++
|
.h
| 321
| 22.716511
| 78
| 0.590914
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,200
|
CFieldContainerTest.h
|
dmorse_pscfpp/src/pspc/tests/field/CFieldContainerTest.h
|
#ifndef PSPC_C_FIELD_CONTAINER_TEST_H
#define PSPC_C_FIELD_CONTAINER_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/CFieldContainer.h>
#include <pspc/field/Domain.h>
#include <pspc/field/FieldIo.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pscf/crystal/BFieldComparison.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/mesh/MeshIterator.h>
#include <util/containers/DArray.h>
#include <util/misc/FileMaster.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class CFieldContainerTest : public UnitTest
{
std::ofstream logFile_;
FileMaster fileMaster_;
int nMonomer_;
public:
void setUp()
{
setVerbose(0);
nMonomer_ = 2;
}
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
}
// Open and read parameter header to initialize Domain<D> system.
template <int D>
void readParam(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readParam(in);
in.close();
}
// Open and read file header to initialize Domain<D> system.
template <int D>
void readHeader(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readRGridFieldHeader(in, nMonomer_);
in.close();
}
// Allocate an array of fields in symmetry adapated format.
void allocateFields(int nMonomer, int nBasis,
DArray< DArray<double> > & fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(nBasis);
}
}
// Allocate an array of r-grid fields
template <int D>
void allocateFields(int nMonomer, IntVec<D> const & dimensions,
DArray< RField<D> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(dimensions);
}
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsBasis(in, fields, domain.unitCell());
in.close();
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< RField<D> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsRGrid(in, fields, domain.unitCell());
in.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsBasis(out, fields, domain.unitCell());
out.close();
}
void testAllocate()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
CFieldContainer<3> fields;
fields.allocate(nMonomer_, domain.basis().nBasis(),
domain.mesh().dimensions());
TEST_ASSERT(fields.isAllocatedRGrid());
TEST_ASSERT(fields.isAllocatedBasis());
TEST_ASSERT(fields.rgrid().capacity() == nMonomer_);
TEST_ASSERT(fields.basis().capacity() == nMonomer_);
}
};
TEST_BEGIN(CFieldContainerTest)
TEST_ADD(CFieldContainerTest, testAllocate)
TEST_END(CFieldContainerTest)
#endif
| 3,857
|
C++
|
.h
| 128
| 24.632813
| 72
| 0.658293
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,201
|
FieldIoTest.h
|
dmorse_pscfpp/src/pspc/tests/field/FieldIoTest.h
|
#ifndef PSPC_FIELD_IO_TEST_H
#define PSPC_FIELD_IO_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RFieldComparison.h>
#include <pspc/field/KFieldComparison.h>
#include <pspc/field/Domain.h>
#include <pspc/field/FieldIo.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pspc/field/FFT.h>
#include <pscf/crystal/BFieldComparison.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <pscf/mesh/MeshIterator.h>
#include <util/containers/DArray.h>
#include <util/misc/FileMaster.h>
#include <util/format/Dbl.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class FieldIoTest : public UnitTest
{
std::ofstream logFile_;
FileMaster fileMaster_;
int nMonomer_;
public:
void setUp()
{
setVerbose(0);
nMonomer_ = 2;
openLogFile("out/fieldIoTestLogFile");
}
void tearDown()
{
if (logFile_.is_open()) {
logFile_.close();
}
}
void openLogFile(char const * filename)
{
openOutputFile(filename, logFile_);
Log::setFile(logFile_);
}
/*
* Open and read parameter header to initialize Domain<D> system.
*/
template <int D>
void readParam(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readParam(in);
in.close();
}
/*
* Open and read file header to initialize Domain<D> system.
*/
template <int D>
void readHeader(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readRGridFieldHeader(in, nMonomer_);
in.close();
}
// Allocate an array of fields in symmetry adapated format
void allocateFields(int nMonomer, int nStar,
DArray< DArray<double> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(nStar);
}
}
// Allocate an array of r-grid fields
template <int D>
void allocateFields(int nMonomer, IntVec<D> dimensions,
DArray< RField<D> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(dimensions);
}
}
// Allocate an array of k-grid fields
template <int D>
void allocateFields(int nMonomer, IntVec<D> dimensions,
DArray< RFieldDft<D> >& fields)
{
fields.allocate(nMonomer);
for (int i = 0; i < nMonomer; ++i) {
fields[i].allocate(dimensions);
}
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsBasis(in, fields, domain.unitCell());
in.close();
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< RField<D> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsRGrid(in, fields, domain.unitCell());
in.close();
}
template <int D>
void readFields(std::string filename, Domain<D>& domain,
DArray< RFieldDft<D> >& fields)
{
std::ifstream in;
openInputFile(filename, in);
domain.fieldIo().readFieldsKGrid(in, fields, domain.unitCell());
in.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< DArray<double> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsBasis(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RField<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsRGrid(out, fields, domain.unitCell());
out.close();
}
template <int D>
void writeFields(std::string filename, Domain<D>& domain,
DArray< RFieldDft<D> > const & fields)
{
std::ofstream out;
openOutputFile(filename, out);
domain.fieldIo().writeFieldsKGrid(out, fields, domain.unitCell());
out.close();
}
void testReadHeader()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
TEST_ASSERT(domain.mesh().dimension(0) == 32);
TEST_ASSERT(domain.mesh().dimension(1) == 32);
TEST_ASSERT(domain.mesh().dimension(2) == 32);
TEST_ASSERT(domain.unitCell().lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.basis().nBasis() == 489);
//TEST_ASSERT(nMonomer_ == 2);
if (verbose() > 0) {
std::cout << "\n";
std::cout << "Cell = " << domain.unitCell() << "\n";
std::cout << "Ngrid = " << domain.mesh().dimensions() << "\n";
if (verbose() > 1) {
domain.basis().outputStars(std::cout);
}
}
DArray< DArray<double> > fb;
allocateFields(nMonomer_, domain.basis().nBasis(), fb);
DArray< RField<3> > fr;
allocateFields(nMonomer_, domain.mesh().dimensions(), fr);
DArray< RFieldDft<3> > fk;
allocateFields(nMonomer_, domain.mesh().dimensions(), fk);
}
void testBasisIo_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
std::ifstream in;
openInputFile("in/w_bcc.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_0, domain.unitCell());
in.close();
std::ofstream out;
openOutputFile("out/w_bcc.bf", out);
domain.fieldIo().writeFieldsBasis(out, bf_0, domain.unitCell());
out.close();
openInputFile("out/w_bcc.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_1, domain.unitCell());
in.close();
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(),21,13) << std::endl;
std::cout << Dbl(comparison.rmsDiff(),21,13) << std::endl;
}
}
void testBasisIo_c15_1()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/c_c15_1.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
std::ifstream in;
openInputFile("in/w_c15_1.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_0, domain.unitCell());
in.close();
std::ofstream out;
openOutputFile("out/w_c15_1.bf", out);
domain.fieldIo().writeFieldsBasis(out, bf_0, domain.unitCell());
out.close();
openInputFile("out/w_c15_1.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_1, domain.unitCell());
in.close();
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(),21,13) << std::endl;
std::cout << Dbl(comparison.rmsDiff(),21,13) << std::endl;
}
}
void testBasisIo_altG()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_altG.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
std::ifstream in;
openInputFile("in/w_altG.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_0, domain.unitCell());
in.close();
std::ofstream out;
openOutputFile("out/w_altG.bf", out);
domain.fieldIo().writeFieldsBasis(out, bf_0, domain.unitCell());
out.close();
openInputFile("out/w_altG.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_1, domain.unitCell());
in.close();
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(),21,13) << std::endl;
std::cout << Dbl(comparison.rmsDiff(),21,13) << std::endl;
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
}
void testBasisIo_altG_fort()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_altG.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
std::ifstream in;
openInputFile("in/w_altG_fort.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_0, domain.unitCell());
in.close();
std::ofstream out;
openOutputFile("out/w_altG_fort.bf", out);
domain.fieldIo().writeFieldsBasis(out, bf_0, domain.unitCell());
out.close();
openInputFile("out/w_altG_fort.bf", in);
domain.fieldIo().readFieldsBasis(in, bf_1, domain.unitCell());
in.close();
#if 0
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(),21,13) << std::endl;
std::cout << Dbl(comparison.rmsDiff(),21,13) << std::endl;
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
#endif
}
void testRGridIo_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< RField<3> > rf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf_0);
DArray< RField<3> > rf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf_1);
readFields("in/w_bcc.rf", domain, rf_0);
writeFields("out/w_bcc.rf", domain, rf_0);
readFields("out/w_bcc.rf", domain, rf_1);
RFieldComparison<3> comparison;
comparison.compare(rf_0, rf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
}
void testConvertBasisKGridBasis_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
readFields("in/w_bcc.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
domain.fieldIo().convertKGridToBasis(kf_0, bf_1);
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
}
void testConvertBasisRGridBasis_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RField<3> > rf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf_0);
readFields("in/w_bcc.bf", domain, bf_0);
domain.fieldIo().convertBasisToRGrid(bf_0, rf_0);
domain.fieldIo().convertRGridToBasis(rf_0, bf_1);
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
}
void testConvertBasisKGridBasis_altG()
{
printMethod(TEST_FUNC);
nMonomer_ = 3;
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_altG.rf", domain);
std::ofstream out;
openOutputFile("out/stars_altG", out);
domain.basis().outputStars(out);
out.close();
#if 1
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
readFields("in/w_altG.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
domain.fieldIo().convertKGridToBasis(kf_0, bf_1);
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
#endif
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testConvertBasisKGridBasis_c15_1()
{
printMethod(TEST_FUNC);
nMonomer_ = 2;
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/c_c15_1.rf", domain);
#if 0
std::ofstream out;
openOutputFile("out/waves_c15_1", out);
domain.basis().outputWaves(out);
out.close();
#endif
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
readFields("in/w_c15_1.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
domain.fieldIo().convertKGridToBasis(kf_0, bf_1);
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
// setVerbose(1);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
void testKGridIo_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
DArray< RFieldDft<3> > kf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_1);
readFields("in/w_bcc.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
writeFields("out/w_bcc.kf", domain, kf_0);
readFields("out/w_bcc.kf", domain, kf_1);
KFieldComparison<3> comparison;
comparison.compare(kf_0, kf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-11);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
}
void testKGridIo_altG()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_altG.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
DArray< RFieldDft<3> > kf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_1);
readFields("in/w_altG.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
writeFields("out/w_altG.kf", domain, kf_0);
readFields("out/w_altG.kf", domain, kf_1);
KFieldComparison<3> comparison;
comparison.compare(kf_0, kf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-11);
if (verbose() > 0) {
std::cout << "\n";
std::cout << Dbl(comparison.maxDiff(),21,13) << "\n";
std::cout << Dbl(comparison.rmsDiff(),21,13) << "\n";
}
}
void testKGridIo_lam()
{
printMethod(TEST_FUNC);
Domain<1> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_lam.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< RFieldDft<1> > kf_0, kf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_1);
readFields("in/w_lam.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
writeFields("out/w_lam.kf", domain, kf_0);
readFields("out/w_lam.kf", domain, kf_1);
KFieldComparison<1> comparison;
comparison.compare(kf_0, kf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-12);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(), 21, 13) << "\n";
std::cout << Dbl(comparison.rmsDiff(), 21, 13) << "\n";
}
}
void testConvertBasisKGridRGridKGrid_bcc()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
DArray< RFieldDft<3> > kf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_1);
DArray< RFieldDft<3> > kf_2;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_2);
DArray< RField<3> > rf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf_0);
readFields("in/w_bcc.bf", domain, bf_0);
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
kf_2 = kf_0;
domain.fieldIo().convertKGridToRGrid(kf_0, rf_0);
#if 0
// Demonstrate that input kf_0 is modified by above (it is)
KFieldComparison<3> check;
check.compare(kf_2, kf_0);
std::cout << std::endl;
std::cout << Dbl(check.maxDiff(), 21, 13) << "\n";
std::cout << Dbl(check.rmsDiff(), 21, 13) << "\n";
#endif
domain.fieldIo().convertRGridToKGrid(rf_0, kf_1);
KFieldComparison<3> comparison;
comparison.compare(kf_2, kf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(comparison.maxDiff(), 21, 13) << "\n";
std::cout << Dbl(comparison.rmsDiff(), 21, 13) << "\n";
}
}
void testConvertBasisKGridRGridKGrid_c15_1()
{
printMethod(TEST_FUNC);
// Read header
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/c_c15_1.rf", domain);
// Allocate required fields
DArray< DArray<double> > bf_0;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_0);
DArray< DArray<double> > bf_1;
allocateFields(nMonomer_, domain.basis().nBasis(), bf_1);
DArray< RFieldDft<3> > kf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_0);
DArray< RFieldDft<3> > kf_1;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_1);
DArray< RFieldDft<3> > kf_2;
allocateFields(nMonomer_, domain.mesh().dimensions(), kf_2);
DArray< RField<3> > rf_0;
allocateFields(nMonomer_, domain.mesh().dimensions(), rf_0);
// Read fields in basis format
readFields("in/w_c15_1.bf", domain, bf_0);
// Convert basis -> kgrid -> rgrid -> kgrid -> basis
domain.fieldIo().convertBasisToKGrid(bf_0, kf_0);
kf_2 = kf_0;
domain.fieldIo().convertKGridToRGrid(kf_0, rf_0);
#if 0
// Demonstrate that input kf_0 is modified by above (it is)
KFieldComparison<3> check;
check.compare(kf_2, kf_0);
std::cout << std::endl;
std::cout << Dbl(check.maxDiff(), 21, 13) << "\n";
std::cout << Dbl(check.rmsDiff(), 21, 13) << "\n";
#endif
domain.fieldIo().convertRGridToKGrid(rf_0, kf_1);
KFieldComparison<3> Bcomparison;
Bcomparison.compare(kf_2, kf_1);
TEST_ASSERT(Bcomparison.maxDiff() < 1.0E-10);
if (verbose() > 0) {
std::cout << std::endl;
std::cout << Dbl(Bcomparison.maxDiff(), 21, 13) << "\n";
std::cout << Dbl(Bcomparison.rmsDiff(), 21, 13) << "\n";
}
domain.fieldIo().convertKGridToBasis(kf_1, bf_1);
BFieldComparison comparison;
comparison.compare(bf_0, bf_1);
TEST_ASSERT(comparison.maxDiff() < 1.0E-10);
}
};
TEST_BEGIN(FieldIoTest)
TEST_ADD(FieldIoTest, testReadHeader)
TEST_ADD(FieldIoTest, testBasisIo_bcc)
TEST_ADD(FieldIoTest, testBasisIo_c15_1)
TEST_ADD(FieldIoTest, testBasisIo_altG)
TEST_ADD(FieldIoTest, testBasisIo_altG_fort)
TEST_ADD(FieldIoTest, testRGridIo_bcc)
TEST_ADD(FieldIoTest, testConvertBasisKGridBasis_bcc)
TEST_ADD(FieldIoTest, testConvertBasisRGridBasis_bcc)
TEST_ADD(FieldIoTest, testConvertBasisKGridBasis_altG)
TEST_ADD(FieldIoTest, testConvertBasisKGridBasis_c15_1)
TEST_ADD(FieldIoTest, testKGridIo_bcc)
TEST_ADD(FieldIoTest, testKGridIo_altG)
TEST_ADD(FieldIoTest, testKGridIo_lam)
TEST_ADD(FieldIoTest, testConvertBasisKGridRGridKGrid_bcc)
TEST_ADD(FieldIoTest, testConvertBasisKGridRGridKGrid_c15_1)
TEST_END(FieldIoTest)
#endif
| 22,819
|
C++
|
.h
| 615
| 30.302439
| 72
| 0.616477
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,202
|
RFieldDftTest.h
|
dmorse_pscfpp/src/pspc/tests/field/RFieldDftTest.h
|
#ifndef PSPC_R_FIELD_DFT_TEST_H
#define PSPC_R_FIELD_DFT_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/RFieldDft.h>
#include <util/archives/MemoryOArchive.h>
#include <util/archives/MemoryIArchive.h>
#include <util/archives/MemoryCounter.h>
#include <util/archives/BinaryFileOArchive.h>
#include <util/archives/BinaryFileIArchive.h>
using namespace Util;
using namespace Pscf::Pspc;
class RFieldDftTest : public UnitTest
{
private:
const static int capacity = 3;
typedef double Data;
public:
void setUp()
{ }
void tearDown() {}
void testConstructor();
void testAllocate();
void testAllocate1();
void testAllocate3();
void testSubscript();
void testAssignment();
void testCopyConst();
//void testSerialize1Memory();
//void testSerialize2Memory();
//void testSerialize1File();
//void testSerialize2File();
};
void RFieldDftTest::testConstructor()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
TEST_ASSERT(v.capacity() == 0 );
TEST_ASSERT(!v.isAllocated() );
}
}
void RFieldDftTest::testAllocate()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == capacity );
TEST_ASSERT(v.isAllocated());
}
}
void RFieldDftTest::testAllocate1()
{
printMethod(TEST_FUNC);
{
IntVec<1> d;
d[0] = 3;
RFieldDft<1> v;
v.allocate(d);
TEST_ASSERT(v.capacity() == 2);
TEST_ASSERT(v.isAllocated());
TEST_ASSERT(d == v.meshDimensions());
}
}
void RFieldDftTest::testAllocate3()
{
printMethod(TEST_FUNC);
{
IntVec<3> d;
d[0] = 2;
d[1] = 3;
d[2] = 4;
RFieldDft<3> v;
v.allocate(d);
TEST_ASSERT(v.capacity() == 18);
TEST_ASSERT(v.isAllocated());
TEST_ASSERT(d == v.meshDimensions());
}
}
void RFieldDftTest::testSubscript()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
TEST_ASSERT(v[0][0] == 10.0);
TEST_ASSERT(v[0][1] == 10.1);
TEST_ASSERT(v[1][0] == 20.0);
TEST_ASSERT(v[1][1] == 20.1);
TEST_ASSERT(v[2][0] == 30.0);
TEST_ASSERT(v[2][1] == 30.1);
}
}
void RFieldDftTest::testCopyConst()
{
printMethod(TEST_FUNC);
{
IntVec<3> d;
d[0] = 3;
d[1] = 3;
d[2] = 2;
RFieldDft<3> v;
v.allocate(d);
TEST_ASSERT(v.capacity() == 18);
TEST_ASSERT(v.isAllocated());
for(int i = 0; i < v.capacity(); i++)
{
v[i][0] = (i + 1) * 10.0;
v[i][1] = (i + 1) * 10.0 + 0.1;
}
RFieldDft<3> u(v);
TEST_ASSERT(u.isAllocated());
TEST_ASSERT(u.capacity() == v.capacity());
for(int i = 0; i < v.capacity(); i++)
{
TEST_ASSERT(u[i][0] == v[i][0]);
TEST_ASSERT(u[i][1] == v[i][1]);
}
}
}
void RFieldDftTest::testAssignment()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(capacity);
TEST_ASSERT(v.capacity() == 3);
TEST_ASSERT(v.isAllocated() );
RFieldDft<3> u;
u.allocate(3);
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
u = v;
TEST_ASSERT(u.capacity() == 3 );
TEST_ASSERT(u.isAllocated() );
TEST_ASSERT(v[0][0] == 10.0);
TEST_ASSERT(v[0][1] == 10.1);
TEST_ASSERT(v[1][0] == 20.0);
TEST_ASSERT(v[1][1] == 20.1);
TEST_ASSERT(u[0][0] == 10.0);
TEST_ASSERT(u[0][1] == 10.1);
TEST_ASSERT(u[1][0] == 20.0);
TEST_ASSERT(u[1][1] == 20.1);
TEST_ASSERT(u[2][0] == 30.0);
TEST_ASSERT(u[2][1] == 30.1);
}
}
#if 0
void RFieldDftTest::testSerialize1Memory()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
int size = memorySize(v);
int i1 = 13;
int i2;
MemoryOArchive oArchive;
oArchive.allocate(size + 12);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
oArchive << i1;
// Show that v is unchanged by packing
TEST_ASSERT(v[1][0]==20.0);
TEST_ASSERT(v[1][1]==20.0);
TEST_ASSERT(v.capacity() == 3);
RFieldDft<3> u;
u.allocate(3);
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
// Load into u and i2
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Release
iArchive.release();
TEST_ASSERT(!iArchive.isAllocated());
TEST_ASSERT(iArchive.begin() == 0);
TEST_ASSERT(iArchive.cursor() == 0);
TEST_ASSERT(iArchive.end() == 0);
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size + sizeof(int));
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i][0] = 0.0;
u[i][1] = 0.0;
}
i2 = 0;
// Reload into u and i2
iArchive = oArchive;
iArchive >> u;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
iArchive >> i2;
TEST_ASSERT(iArchive.cursor() == iArchive.end());
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.end() == oArchive.cursor());
TEST_ASSERT(u[0][0] == 10.0);
TEST_ASSERT(u[0][1] == 10.1);
TEST_ASSERT(u[1][0] == 20.0);
TEST_ASSERT(u[1][1] == 20.1);
TEST_ASSERT(u[2][0] == 30.0);
TEST_ASSERT(u[2][1] == 30.1);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldDftTest::testSerialize2Memory()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(capacity);
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
int size = memorySize(v);
MemoryOArchive oArchive;
oArchive.allocate(size);
oArchive << v;
TEST_ASSERT(oArchive.cursor() == oArchive.begin() + size);
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == capacity);
RFieldDft<3> u;
// Note: We do not allocate RFieldDft<3> u in this test.
// This is the main difference from testSerialize1Memory()
MemoryIArchive iArchive;
iArchive = oArchive;
TEST_ASSERT(iArchive.begin() == oArchive.begin());
TEST_ASSERT(iArchive.cursor() == iArchive.begin());
iArchive >> u;
TEST_ASSERT(iArchive.cursor() == iArchive.begin() + size);
TEST_ASSERT(u[0][0] == 10.0);
TEST_ASSERT(u[0][1] == 10.1);
TEST_ASSERT(u[1][0] == 20.0);
TEST_ASSERT(u[1][1] == 20.1);
TEST_ASSERT(u[2][0] == 30.0);
TEST_ASSERT(u[2][1] == 30.1);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldDftTest::testSerialize1File()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1]==20.0);
TEST_ASSERT(v.capacity() == 3);
RFieldDft<3> u;
u.allocate(3);
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(u[1] == 20.0);
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
void RFieldDftTest::testSerialize2File()
{
printMethod(TEST_FUNC);
{
RFieldDft<3> v;
v.allocate(3);
for (int i=0; i < capacity; i++ ) {
v[i][0] = (i+1)*10.0 ;
v[i][1] = (i+1)*10.0 + 0.1;
}
int i1 = 13;
int i2;
BinaryFileOArchive oArchive;
openOutputFile("out/binary", oArchive.file());
oArchive << v;
oArchive << i1;
oArchive.file().close();
// Show that v is unchanged by packing
TEST_ASSERT(v[1] == 20.0);
TEST_ASSERT(v.capacity() == 3);
RFieldDft<3> u;
// u.allocate(3); ->
// Note: We do not allocate first. This is the difference
// from the previous test
BinaryFileIArchive iArchive;
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
iArchive.file().close();
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
// Clear values of u and i2
for (int i=0; i < capacity; i++ ) {
u[i] = 0.0;
}
i2 = 0;
// Reload into u and i2
openInputFile("out/binary", iArchive.file());
iArchive >> u;
iArchive >> i2;
TEST_ASSERT(eq(u[1], 20.0));
TEST_ASSERT(i2 == 13);
TEST_ASSERT(u.capacity() == 3);
}
}
#endif
TEST_BEGIN(RFieldDftTest)
TEST_ADD(RFieldDftTest, testConstructor)
TEST_ADD(RFieldDftTest, testAllocate)
TEST_ADD(RFieldDftTest, testAllocate1)
TEST_ADD(RFieldDftTest, testAllocate3)
TEST_ADD(RFieldDftTest, testSubscript)
TEST_ADD(RFieldDftTest, testAssignment)
TEST_ADD(RFieldDftTest, testCopyConst)
//TEST_ADD(RFieldDftTest, testSerialize1Memory)
//TEST_ADD(RFieldDftTest, testSerialize2Memory)
//TEST_ADD(RFieldDftTest, testSerialize1File)
//TEST_ADD(RFieldDftTest, testSerialize2File)
TEST_END(RFieldDftTest)
#endif
| 10,913
|
C++
|
.h
| 371
| 23.061995
| 78
| 0.571692
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,203
|
DomainTest.h
|
dmorse_pscfpp/src/pspc/tests/field/DomainTest.h
|
#ifndef PSPC_DOMAIN_TEST_H
#define PSPC_DOMAIN_TEST_H
#include <test/UnitTest.h>
#include <test/UnitTestRunner.h>
#include <pspc/field/Domain.h>
#include <pspc/field/FieldIo.h>
#include <pspc/field/RField.h>
#include <pspc/field/RFieldDft.h>
#include <pspc/field/FFT.h>
#include <pscf/crystal/Basis.h>
#include <pscf/crystal/UnitCell.h>
#include <pscf/mesh/Mesh.h>
#include <util/tests/LogFileUnitTest.h>
#include <util/containers/DArray.h>
#include <util/misc/FileMaster.h>
#include <iostream>
#include <fstream>
using namespace Util;
using namespace Pscf;
using namespace Pscf::Pspc;
class DomainTest : public LogFileUnitTest
{
FileMaster fileMaster_;
int nMonomer_;
public:
void setUp()
{
setVerbose(0);
}
/*
* Open and read file header to initialize Domain<D> system.
*/
template <int D>
void readHeader(std::string filename, Domain<D>& domain)
{
std::ifstream in;
openInputFile(filename, in);
domain.readRGridFieldHeader(in, nMonomer_);
in.close();
}
#if 0
void testReadParam()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
std::ifstream in;
openInputFile("in/Domain_old.prm", in);
domain.readParam(in);
in.close();
TEST_ASSERT(domain.mesh().dimension(0) == 32);
TEST_ASSERT(domain.mesh().dimension(1) == 32);
TEST_ASSERT(domain.mesh().dimension(2) == 32);
TEST_ASSERT(domain.unitCell().lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.basis().nBasis() == 489);
}
#endif
void testReadParamHeader()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
// Read parameter file
std::ifstream in;
openInputFile("in/Domain.prm", in);
domain.readParam(in);
in.close();
TEST_ASSERT(domain.mesh().dimension(0) == 32);
TEST_ASSERT(domain.mesh().dimension(1) == 32);
TEST_ASSERT(domain.mesh().dimension(2) == 32);
TEST_ASSERT(domain.lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.unitCell().lattice() == domain.lattice());
TEST_ASSERT(domain.group().size() == 96);
TEST_ASSERT(domain.basis().nBasis() == 0);
// Read header and construct basis
openInputFile("in/w_bcc.rf", in);
domain.fieldIo().readFieldHeader(in, nMonomer_, domain.unitCell());
in.close();
TEST_ASSERT(domain.unitCell().lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.group().size() > 1);
TEST_ASSERT(domain.basis().nBasis() == 489);
}
void testReadHeader()
{
printMethod(TEST_FUNC);
Domain<3> domain;
domain.setFileMaster(fileMaster_);
readHeader("in/w_bcc.rf", domain);
TEST_ASSERT(domain.mesh().dimension(0) == 32);
TEST_ASSERT(domain.mesh().dimension(1) == 32);
TEST_ASSERT(domain.mesh().dimension(2) == 32);
TEST_ASSERT(domain.unitCell().lattice() == UnitCell<3>::Cubic);
TEST_ASSERT(domain.basis().nBasis() == 489);
TEST_ASSERT(nMonomer_ == 2);
if (verbose() > 0) {
// openLogFile("out/DomainTestReadHeader.log");
Log::file() << "\n";
Log::file() << "Cell = " << domain.unitCell() << "\n";
Log::file() << "Ngrid = " << domain.mesh().dimensions() << "\n";
if (verbose() > 1) {
domain.basis().outputStars(Log::file());
}
}
}
};
TEST_BEGIN(DomainTest)
//TEST_ADD(DomainTest, testReadParam)
TEST_ADD(DomainTest, testReadParamHeader)
TEST_ADD(DomainTest, testReadHeader)
TEST_END(DomainTest)
#endif
| 3,669
|
C++
|
.h
| 112
| 27.473214
| 73
| 0.643991
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,204
|
RField.h
|
dmorse_pscfpp/src/pspc/field/RField.h
|
#ifndef PSPC_R_FIELD_H
#define PSPC_R_FIELD_H
/*
* PSCF Package
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "Field.h"
#include <pscf/math/IntVec.h>
#include <util/global.h>
namespace Pscf {
namespace Pspc
{
using namespace Util;
using namespace Pscf;
/**
* Field of real double precision values on an FFT mesh.
*
* \ingroup Pspc_Field_Module
*/
template <int D>
class RField : public Field<double>
{
public:
/**
* Default constructor.
*/
RField();
/**
* Copy constructor.
*
* Allocates new memory and copies all elements by value.
*
*\param other the RField to be copied.
*/
RField(const RField& other);
/**
* Destructor.
*
* Deletes underlying C array, if allocated previously.
*/
virtual ~RField();
/**
* Assignment operator.
*
* If this Field is not allocated, allocates and copies all elements.
*
* If this and the other Field are both allocated, the capacities must
* be exactly equal. If so, this method copies all elements.
*
* \param other the RHS RField
*/
RField& operator = (const RField& other);
using Field<double>::allocate;
/**
* Allocate the underlying C array for an FFT grid.
*
* \throw Exception if the RField is already allocated.
*
* \param meshDimensions vector of numbers of grid points per direction
*/
void allocate(const IntVec<D>& meshDimensions);
/**
* Return mesh dimensions by constant reference.
*/
const IntVec<D>& meshDimensions() const;
/**
* Serialize a Field to/from an Archive.
*
* \param ar archive
* \param version archive version id
*/
template <class Archive>
void serialize(Archive& ar, const unsigned int version);
private:
// Vector containing number of grid points in each direction.
IntVec<D> meshDimensions_;
};
/*
* Return mesh dimensions by constant reference.
*/
template <int D>
inline const IntVec<D>& RField<D>::meshDimensions() const
{ return meshDimensions_; }
/*
* Serialize a Field to/from an Archive.
*/
template <int D>
template <class Archive>
void RField<D>::serialize(Archive& ar, const unsigned int version)
{
Field<double>::serialize(ar, version);
ar & meshDimensions_;
}
#ifndef PSPC_R_FIELD_TPP
extern template class RField<1>;
extern template class RField<2>;
extern template class RField<3>;
#endif
}
}
#endif
| 2,733
|
C++
|
.h
| 103
| 21.223301
| 76
| 0.639709
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,205
|
BFieldComparison.h
|
dmorse_pscfpp/src/pspc/field/BFieldComparison.h
|
#ifndef PSPC_B_FIELD_COMPARISON_H
#define PSPC_B_FIELD_COMPARISON_H
/*
* PSCF - Polymer Self-Consistent Field Theory
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include <pscf/math/FieldComparison.h>
#include <util/containers/DArray.h>
namespace Pscf {
namespace Pspc {
using namespace Util;
/**
* Comparator for fields in symmetry-adapted basis format.
*
* \ingroup Pspc_Field_Module
*/
class BFieldComparison : public FieldComparison< DArray<double> >
{
public:
/**
* Constructor.
*
* The basis function with index 0 in a symmetry adapted basis is always
* a spatially homogeneous function, i.e., a constant. In some situations,
* we may be interested in determining whether two fields are equivalent
* to within a constant.
*
* Set begin = 0 to include the coefficient of the first basis function
* in the comparison, thus determining how close to fields are to being
* strictly equal.
*
* Set begin = 1 to exclude the coefficient of the first basis function,
* thus comparing only deviatoric parts of the fields.
*
* \param begin index of first element to include in comparison.
*/
BFieldComparison(int begin = 0);
};
} // namespace Pspc
} // namespace Pscf
#endif
| 1,415
|
C++
|
.h
| 43
| 28.395349
| 79
| 0.70066
|
dmorse/pscfpp
| 30
| 20
| 8
|
GPL-3.0
|
9/20/2024, 10:44:10 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.