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,534,906
|
MeshIterator.cpp
|
dmorse_pscfpp/src/pscf/mesh/MeshIterator.cpp
|
/*
* 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 "MeshIterator.tpp"
namespace Pscf
{
template class MeshIterator<1>;
template class MeshIterator<2>;
template class MeshIterator<3>;
}
| 342
|
C++
|
.cpp
| 13
| 24.384615
| 67
| 0.776758
|
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,534,907
|
Monomer.cpp
|
dmorse_pscfpp/src/pscf/chem/Monomer.cpp
|
/*
* 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 "Monomer.h"
namespace Pscf
{
Monomer::Monomer()
: id_(-1),
kuhn_(0.0)
{}
void Monomer::setId(int id)
{ id_ = id; }
/*
* Extract a Monomer from an istream.
*/
std::istream& operator >> (std::istream& in, Monomer& monomer)
{
// in >> monomer.id_;
in >> monomer.kuhn_;
return in;
}
/*
* Output a Monomer to an ostream, without line breaks.
*/
std::ostream& operator << (std::ostream& out, const Monomer& monomer)
{
// out << monomer.id_;
out.setf(std::ios::scientific);
out.width(15);
out.precision(8);
out << monomer.kuhn_;
return out;
}
}
| 862
|
C++
|
.cpp
| 37
| 18.864865
| 73
| 0.606135
|
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,534,908
|
PolymerType.cpp
|
dmorse_pscfpp/src/pscf/chem/PolymerType.cpp
|
/*
* 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 "PolymerType.h"
#include <util/global.h>
#include <string>
namespace Pscf
{
using namespace Util;
/*
* Input stream extractor for a PolymerType enumeration.
*/
std::istream& operator >> (std::istream& in, PolymerType::Enum& type)
{
std::string buffer;
in >> buffer;
if (buffer == "Branched" || buffer == "branched") {
type = PolymerType::Branched;
} else
if (buffer == "Linear" || buffer == "linear") {
type = PolymerType::Linear;
} else {
std::string msg = "Unknown input PolymerType value string: ";
msg += buffer;
UTIL_THROW(msg.c_str());
}
return in;
}
/*
* Input stream extractor for a PolymerType enumeration.
*/
std::ostream& operator << (std::ostream& out, PolymerType::Enum& type)
{
if (type == PolymerType::Branched) {
out << "branched";
} else
if (type == PolymerType::Linear) {
out << "linear";
} else {
// This should never happen
UTIL_THROW("Error writing a PolymerType value");
}
return out;
}
}
| 1,321
|
C++
|
.cpp
| 48
| 22.0625
| 73
| 0.605367
|
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,534,909
|
BlockDescriptor.cpp
|
dmorse_pscfpp/src/pscf/chem/BlockDescriptor.cpp
|
/*
* 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 "BlockDescriptor.h"
namespace Pscf
{
/*
* Constructor.
*/
BlockDescriptor::BlockDescriptor()
: id_(-1),
monomerId_(-1),
length_(-1.0),
vertexIds_(),
polymerType_(PolymerType::Branched)
{
// Initialize vertex ids to null value -1.
vertexIds_[0] = -1;
vertexIds_[1] = -1;
}
/*
* Destructor (virtual)
*/
BlockDescriptor::~BlockDescriptor()
{}
/*
* Set the id for this block.
*/
void BlockDescriptor::setId(int id)
{ id_ = id; }
/*
* Set indices of associated vertices.
*/
void BlockDescriptor::setVertexIds(int vertexId0, int vertexId1)
{
vertexIds_[0] = vertexId0;
vertexIds_[1] = vertexId1;
}
/*
* Set the monomer id.
*/
void BlockDescriptor::setMonomerId(int monomerId)
{ monomerId_ = monomerId; }
/*
* Set the length of this block.
*/
void BlockDescriptor::setLength(double length)
{ length_ = length; }
/*
* Set the type of the polymer containing this block.
*/
void BlockDescriptor::setPolymerType(PolymerType::Enum type)
{ polymerType_ = type; }
/*
* Extract a BlockDescriptor from an istream.
*/
std::istream& operator >> (std::istream& in, BlockDescriptor& block)
{
in >> block.monomerId_;
in >> block.length_;
if (block.polymerType_ == PolymerType::Branched) {
in >> block.vertexIds_[0];
in >> block.vertexIds_[1];
}
return in;
}
/*
* Output a BlockDescriptor to an ostream, without line breaks.
*/
std::ostream& operator << (std::ostream& out,
BlockDescriptor const & block)
{
out << " " << block.monomerId_;
out << " ";
out.setf(std::ios::scientific);
out.width(20);
out.precision(12);
out << block.length_;
if (block.polymerType_ == PolymerType::Branched) {
out << " " << block.vertexIds_[0];
out << " " << block.vertexIds_[1];
}
return out;
}
}
| 2,230
|
C++
|
.cpp
| 88
| 20.147727
| 71
| 0.599061
|
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,534,910
|
Species.cpp
|
dmorse_pscfpp/src/pscf/chem/Species.cpp
|
/*
* 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 "Species.h"
namespace Pscf
{
using namespace Util;
Species::Species()
: ensemble_(Species::Closed)
{}
/*
* Extract a Species::Ensemble from an istream as a string.
*/
std::istream& operator >> (std::istream& in, Species::Ensemble& policy)
{
std::string buffer;
in >> buffer;
if (buffer == "Closed" || buffer == "closed") {
policy = Species::Closed;
} else
if (buffer == "Open" || buffer == "open") {
policy = Species::Open;
} else {
UTIL_THROW("Invalid Species::Ensemble string in operator >>");
}
return in;
}
/*
* Insert a Species::Ensemble to an ostream as a string.
*/
std::ostream& operator<<(std::ostream& out, Species::Ensemble policy)
{
if (policy == Species::Closed) {
out << "Closed";
} else
if (policy == Species::Open) {
out << "Open";
} else
if (policy == Species::Unknown) {
out << "Unknown";
} else {
std::cout << "Invalid Species::Ensemble value on input" << std::endl;
UTIL_THROW("Unrecognized value for Species::Ensemble");
}
return out;
}
} // namespace Pscf
| 1,411
|
C++
|
.cpp
| 50
| 22.48
| 78
| 0.589193
|
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,534,911
|
SolventDescriptor.cpp
|
dmorse_pscfpp/src/pscf/chem/SolventDescriptor.cpp
|
#ifndef PSCF_SOLVENT_DESCRIPTOR_TPP
#define PSCF_SOLVENT_DESCRIPTOR_TPP
/*
* 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 "SolventDescriptor.h"
namespace Pscf {
/*
* Constructor
*/
SolventDescriptor::SolventDescriptor()
{ setClassName("SolventDescriptor"); }
/*
* Destructor
*/
SolventDescriptor::~SolventDescriptor()
{}
/*
* Read contents of parameter file block
*/
void SolventDescriptor::readParameters(std::istream& in)
{
read<int>(in, "monomerId", monomerId_);
read<double>(in, "size", size_);
// Read phi or mu (but not both)
bool hasPhi = readOptional(in, "phi", phi_).isActive();
if (hasPhi) {
ensemble_ = Species::Closed;
} else {
ensemble_ = Species::Open;
read(in, "mu", mu_);
}
}
/*
* Rest phi to a new value, if closed ensemble.
*/
void SolventDescriptor::setPhi(double phi)
{
UTIL_CHECK(ensemble() == Species::Closed);
UTIL_CHECK(phi >= 0.0);
UTIL_CHECK(phi <= 1.0);
phi_ = phi;
}
/*
* Rest mu to a new value, if open ensemble.
*/
void SolventDescriptor::setMu(double mu)
{
UTIL_CHECK(ensemble() == Species::Open);
mu_ = mu;
}
/*
* Set the id for this solvent.
*/
void SolventDescriptor::setMonomerId(int monomerId)
{ monomerId_ = monomerId; }
/*
* Set the id for this solvent.
*/
void SolventDescriptor::setSize(double size)
{ size_ = size; }
}
#endif
| 1,660
|
C++
|
.cpp
| 66
| 20.454545
| 67
| 0.628481
|
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,534,912
|
Vertex.cpp
|
dmorse_pscfpp/src/pscf/chem/Vertex.cpp
|
/*
* 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 "Vertex.h"
#include "BlockDescriptor.h"
#include <util/global.h>
namespace Pscf
{
/*
* Constructor.
*/
Vertex::Vertex()
: inPropagatorIds_(),
outPropagatorIds_(),
id_(-1)
{}
/*
* Destructor.
*/
Vertex::~Vertex()
{}
/*
* Set integer id.
*/
void Vertex::setId(int id)
{ id_ = id; }
/*
* Add this block to the list.
*/
void Vertex::addBlock(const BlockDescriptor& block)
{
// Preconditions
if (id_ < 0) {
UTIL_THROW("Negative vertex id");
}
if (block.id() < 0) {
UTIL_THROW("Negative block id");
}
if (block.vertexId(0) < 0) {
UTIL_THROW("Error: Negative block vertexId 0");
}
if (block.vertexId(1) < 0) {
UTIL_THROW("Error: Negative block vertexId 1");
}
if (block.vertexId(0) == block.vertexId(1)) {
UTIL_THROW("Error: Equal vertex indices in block");
}
Pair<int> propagatorId;
propagatorId[0] = block.id();
if (block.vertexId(0) == id_) {
propagatorId[1] = 0;
outPropagatorIds_.append(propagatorId);
propagatorId[1] = 1;
inPropagatorIds_.append(propagatorId);
} else
if (block.vertexId(1) == id_) {
propagatorId[1] = 1;
outPropagatorIds_.append(propagatorId);
propagatorId[1] = 0;
inPropagatorIds_.append(propagatorId);
} else {
UTIL_THROW("Neither block vertex id matches this vertex");
}
}
}
| 1,715
|
C++
|
.cpp
| 68
| 19.455882
| 67
| 0.58547
|
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,534,913
|
SymmetryGroup.cpp
|
dmorse_pscfpp/src/pscf/crystal/SymmetryGroup.cpp
|
/*
* 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 <pscf/crystal/SymmetryGroup.tpp>
#include <pscf/crystal/SpaceSymmetry.tpp>
namespace Pscf
{
template class SymmetryGroup< SpaceSymmetry<1> >;
template class SymmetryGroup< SpaceSymmetry<2> >;
template class SymmetryGroup< SpaceSymmetry<3> >;
}
| 476
|
C++
|
.cpp
| 14
| 32.071429
| 68
| 0.792576
|
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,534,914
|
SpaceGroup.cpp
|
dmorse_pscfpp/src/pscf/crystal/SpaceGroup.cpp
|
/*
* 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 <pscf/crystal/SpaceGroup.tpp>
namespace Pscf
{
template class SpaceGroup<1>;
template class SpaceGroup<2>;
template class SpaceGroup<3>;
template void readGroup(std::string, SpaceGroup<1>& );
template void readGroup(std::string, SpaceGroup<2>& );
template void readGroup(std::string, SpaceGroup<3>& );
template void writeGroup(std::string, SpaceGroup<1> const&);
template void writeGroup(std::string, SpaceGroup<2> const&);
template void writeGroup(std::string, SpaceGroup<3> const&);
}
| 739
|
C++
|
.cpp
| 19
| 36.157895
| 68
| 0.759104
|
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,534,915
|
UnitCell2.cpp
|
dmorse_pscfpp/src/pscf/crystal/UnitCell2.cpp
|
/*
* 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 "UnitCell.h"
#include <util/math/Constants.h>
namespace Pscf
{
using namespace Util;
/*
* Constructor.
*/
UnitCell<2>::UnitCell()
: lattice_(Null)
{}
/*
* Read the lattice system and set nParameter.
*/
void UnitCell<2>::setNParameter()
{
UTIL_CHECK(lattice_ != UnitCell<2>::Null);
if (lattice_ == UnitCell<2>::Square) {
nParameter_ = 1;
} else
if (lattice_ == UnitCell<2>::Hexagonal) {
nParameter_ = 1;
} else
if (lattice_ == UnitCell<2>::Rectangular) {
nParameter_ = 2;
} else
if (lattice_ == UnitCell<2>::Rhombic) {
nParameter_ = 2;
} else
if (lattice_ == UnitCell<2>::Oblique) {
nParameter_ = 3;
} else {
UTIL_THROW("Invalid lattice system value");
}
}
/*
* Set the Bravais and reciprocal lattice vectors.
*/
void UnitCell<2>::setBasis()
{
UTIL_CHECK(lattice_ != UnitCell<2>::Null);
UTIL_CHECK(nParameter_ > 0);
double twoPi = 2.0*Constants::Pi;
int i;
if (lattice_ == UnitCell<2>::Square) {
UTIL_CHECK(nParameter_ == 1);
for (i=0; i < 2; ++i) {
rBasis_[i][i] = parameters_[0];
kBasis_[i][i] = twoPi/parameters_[0];
drBasis_[0](i,i) = 1.0;
}
} else
if (lattice_ == UnitCell<2>::Rectangular) {
UTIL_CHECK(nParameter_ == 2);
for (i=0; i < 2; ++i) {
rBasis_[i][i] = parameters_[i];
kBasis_[i][i] = twoPi/parameters_[i];
drBasis_[i](i,i) = 1.0;
}
} else
if (lattice_ == UnitCell<2>::Hexagonal) {
UTIL_CHECK(nParameter_ == 1);
double a = parameters_[0];
double rt3 = sqrt(3.0);
rBasis_[0][0] = a;
rBasis_[0][1] = 0.0;
rBasis_[1][0] = -0.5*a;
rBasis_[1][1] = 0.5*rt3*a;
drBasis_[0](0, 0) = 1.0;
drBasis_[0](0, 1) = 0.0;
drBasis_[0](1, 0) = -0.5;
drBasis_[0](1, 1) = 0.5*rt3;
kBasis_[0][0] = twoPi/a;
kBasis_[0][1] = twoPi/(rt3*a);
kBasis_[1][0] = 0.0;
kBasis_[1][1] = twoPi/(0.5*rt3*a);
} else
if (lattice_ == UnitCell<2>::Rhombic) {
UTIL_CHECK(nParameter_ == 2);
double a = parameters_[0];
double gamma = parameters_[1];
// gamma is the angle between the two Bravais basis vectors
double cg = cos(gamma);
double sg = sin(gamma);
rBasis_[0][0] = a;
rBasis_[0][1] = 0.0;
rBasis_[1][0] = cg*a;
rBasis_[1][1] = sg*a;
drBasis_[0](0, 0) = 1.0;
drBasis_[0](0, 1) = 0.0;
drBasis_[0](1, 0) = cg;
drBasis_[0](1, 1) = sg;
drBasis_[1](1, 0) = -sg*a;
drBasis_[1](1, 1) = cg*a;
kBasis_[0][0] = twoPi/a;
kBasis_[0][1] = -twoPi*cg/(sg*a);
kBasis_[1][0] = 0.0;
kBasis_[1][1] = twoPi/(a*sg);
} else
if (lattice_ == UnitCell<2>::Oblique) {
UTIL_CHECK(nParameter_ == 3);
double a = parameters_[0];
double b = parameters_[1];
double gamma = parameters_[2];
// gamma is the angle between the two Bravais basis vectors
double cg = cos(gamma);
double sg = sin(gamma);
rBasis_[0][0] = a;
rBasis_[0][1] = 0.0;
rBasis_[1][0] = cg*b;
rBasis_[1][1] = sg*b;
drBasis_[0](0, 0) = 1.0;
drBasis_[0](0, 1) = 0.0;
drBasis_[1](1, 0) = cg;
drBasis_[1](1, 1) = sg;
drBasis_[1](1, 0) = -sg*b;
drBasis_[1](1, 1) = cg*b;
kBasis_[0][0] = twoPi/a;
kBasis_[0][1] = -twoPi*cg/(sg*a);
kBasis_[1][0] = 0.0;
kBasis_[1][1] = twoPi/(b*sg);
} else {
UTIL_THROW("Unimplemented 2D lattice type");
}
}
/*
* Extract a UnitCell<2>::LatticeSystem from an istream as a string.
*/
std::istream& operator >> (std::istream& in,
UnitCell<2>::LatticeSystem& lattice)
{
std::string buffer;
in >> buffer;
if (buffer == "Square" || buffer == "square") {
lattice = UnitCell<2>::Square;
} else
if (buffer == "Rectangular" || buffer == "rectangular") {
lattice = UnitCell<2>::Rectangular;
} else
if (buffer == "Rhombic" || buffer == "rhombic") {
lattice = UnitCell<2>::Rhombic;
} else
if (buffer == "Hexagonal" || buffer == "hexagonal") {
lattice = UnitCell<2>::Hexagonal;
} else
if (buffer == "Oblique" || buffer == "oblique") {
lattice = UnitCell<2>::Oblique;
} else {
UTIL_THROW("Invalid UnitCell<2>::LatticeSystem value input");
}
return in;
}
/*
* Insert a UnitCell<2>::LatticeSystem to an ostream as a string.
*/
std::ostream& operator << (std::ostream& out,
UnitCell<2>::LatticeSystem lattice)
{
if (lattice == UnitCell<2>::Square) {
out << "square";
} else
if (lattice == UnitCell<2>::Rectangular) {
out << "rectangular";
} else
if (lattice == UnitCell<2>::Rhombic) {
out << "rhombic";
} else
if (lattice == UnitCell<2>::Hexagonal) {
out << "hexagonal";
} else
if (lattice == UnitCell<2>::Oblique) {
out << "oblique";
} else
if (lattice == UnitCell<2>::Null) {
out << "Null";
} else {
UTIL_THROW("This should never happen");
}
return out;
}
/*
* Assignment operator.
*/
UnitCell<2>& UnitCell<2>::operator = (const UnitCell<2>& other)
{
isInitialized_ = false;
lattice_ = other.lattice_;
setNParameter();
UTIL_CHECK(nParameter_ == other.nParameter_);
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = other.parameters_[i];
}
setLattice();
return *this;
}
/*
* Set state of the unit cell (lattice system and parameters)
*/
void UnitCell<2>::set(UnitCell<2>::LatticeSystem lattice)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
}
/*
* Set state of the unit cell (lattice system and parameters)
*/
void UnitCell<2>::set(UnitCell<2>::LatticeSystem lattice,
FSArray<double, 6> const & parameters)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = parameters[i];
}
setLattice();
}
}
| 6,855
|
C++
|
.cpp
| 225
| 22.573333
| 70
| 0.509721
|
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,534,916
|
shiftToMinimum.cpp
|
dmorse_pscfpp/src/pscf/crystal/shiftToMinimum.cpp
|
/*
* 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 "shiftToMinimum.h"
#include <util/global.h>
namespace Pscf
{
using namespace Util;
template <>
IntVec<1> shiftToMinimum(IntVec<1>& v, IntVec<1> d, UnitCell<1> const & cell)
{
IntVec<1> u;
if (v[0] > d[0]/2) {
u[0] = v[0] - d[0];
} else
if (v[0] < -(d[0]/2) ) {
u[0] = v[0] + d[0];
} else {
u[0] = v[0];
}
UTIL_ASSERT(abs(u[0]) <= d[0]/2);
return u;
}
template <>
IntVec<2> shiftToMinimum(IntVec<2>& v, IntVec<2> d, UnitCell<2> const & cell)
{
// Initialize minimum to input value
const double epsilon = 1.0E-6;
double Gsq = cell.ksq(v);
double Gsq_min_lo = Gsq - epsilon;
double Gsq_min_hi = Gsq + epsilon;
// Loop over neighboring images
IntVec<2> r = v; // Minimum image of v
IntVec<2> u; // Vector used in loop
int s0, s1;
const int q = 2;
for (s0 = -q; s0 < q+1; ++s0) {
u[0] = v[0] + s0*d[0];
for (s1 = -q; s1 < q+1; ++s1) {
u[1] = v[1] + s1*d[1];
Gsq = cell.ksq(u);
if (Gsq < Gsq_min_hi) {
if ((Gsq < Gsq_min_lo) || (r < u)) {
Gsq_min_lo = Gsq - epsilon;
Gsq_min_hi = Gsq + epsilon;
r = u;
}
}
}
}
return r;
}
template <>
IntVec<3> shiftToMinimum(IntVec<3>& v, IntVec<3> d, UnitCell<3> const & cell)
{
// Initialize minimum to input value
const double epsilon = 1.0E-6;
double Gsq = cell.ksq(v);
double Gsq_min_lo = Gsq - epsilon;
double Gsq_min_hi = Gsq + epsilon;
// Loop over neighboring images
IntVec<3> r = v; // Minimum image
IntVec<3> u; // Vector used in loop
int s0, s1, s2;
const int q = 2;
for (s0 = -q; s0 < q + 1; ++s0) {
u[0] = v[0] + s0*d[0];
for (s1 = -q; s1 < q + 1; ++s1) {
u[1] = v[1] + s1*d[1];
for (s2 = -q; s2 < q + 1; ++s2) {
u[2] = v[2] + s2*d[2];
Gsq = cell.ksq(u);
if (Gsq < Gsq_min_hi) {
if ((Gsq < Gsq_min_lo) || (r < u)) {
Gsq_min_lo = Gsq - epsilon;
Gsq_min_hi = Gsq + epsilon;
r = u;
}
}
}
}
}
return r;
}
}
| 2,680
|
C++
|
.cpp
| 88
| 21.897727
| 80
| 0.445606
|
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,534,917
|
SpaceSymmetry.cpp
|
dmorse_pscfpp/src/pscf/crystal/SpaceSymmetry.cpp
|
/*
* 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 "SpaceSymmetry.tpp"
namespace Pscf
{
using namespace Util;
// Explicit specializations D = 1
template<>
int SpaceSymmetry<1>::determinant() const
{ return R_(0, 0); }
template<>
SpaceSymmetry<1>::Rotation SpaceSymmetry<1>::inverseRotation() const
{
// Compute and check the determinant
int det = R_(0,0);
if (1 != det*det) {
std::cout << "Determinant (1D symmetry) =" << det << std::endl;
UTIL_THROW("Invalid SpaceSymmetry<1>: |det| != 1");
}
// Compute the inverse matrix
SpaceSymmetry<1>::Rotation A;
A(0,0) = R_(0,0);
return A;
}
// Explicit specializations D = 2
template<>
int SpaceSymmetry<2>::determinant() const
{ return (R_(0,0)*R(1,1) - R(0,1)*R(1,0)); }
template<>
SpaceSymmetry<2>::Rotation SpaceSymmetry<2>::inverseRotation() const
{
// Compute and check the determinant
int det = determinant();
if (1 != det*det) {
UTIL_THROW("Invalid SpaceSymmetry<2>: |det| != 1");
}
// Compute the inverse matrix
SpaceSymmetry<2>::Rotation A;
A(0,0) = R_(1,1)/det;
A(1,1) = R_(0,0)/det;
A(0,1) = -R_(0,1)/det;
A(1,0) = -R_(1,0)/det;
return A;
}
// Explicit specializations D = 3
template<>
int SpaceSymmetry<3>::determinant() const
{
int det = 0;
det += R_(0,0)*(R(1,1)*R(2,2) - R(1,2)*R(2,1));
det += R_(0,1)*(R(1,2)*R(2,0) - R(1,0)*R(2,2));
det += R_(0,2)*(R(1,0)*R(2,1) - R(1,1)*R(2,0));
return det;
}
template<>
SpaceSymmetry<3>::Rotation SpaceSymmetry<3>::inverseRotation() const
{
// Compute and check the determinant
int det = determinant();
if (1 != det*det) {
UTIL_THROW("Invalid SpaceSymmetry<3>: |det| != 1");
}
// Compute the inverse matrix
SpaceSymmetry<3>::Rotation A;
A(0,0) = (R_(1,1)*R(2,2) - R(1,2)*R(2,1))/det;
A(1,0) = (R_(1,2)*R(2,0) - R(1,0)*R(2,2))/det;
A(2,0) = (R_(1,0)*R(2,1) - R(1,1)*R(2,0))/det;
A(0,1) = (R_(2,1)*R(0,2) - R(2,2)*R(0,1))/det;
A(1,1) = (R_(2,2)*R(0,0) - R(2,0)*R(0,2))/det;
A(2,1) = (R_(2,0)*R(0,1) - R(2,1)*R(0,0))/det;
A(0,2) = (R_(0,1)*R(1,2) - R(0,2)*R(1,1))/det;
A(1,2) = (R_(0,2)*R(1,0) - R(0,0)*R(1,2))/det;
A(2,2) = (R_(0,0)*R(1,1) - R(0,1)*R(1,0))/det;
return A;
}
// Explicit instantiation of required class instances
template class SpaceSymmetry<1>;
template class SpaceSymmetry<2>;
template class SpaceSymmetry<3>;
}
| 2,777
|
C++
|
.cpp
| 84
| 27.214286
| 72
| 0.552711
|
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,534,918
|
BFieldComparison.cpp
|
dmorse_pscfpp/src/pscf/crystal/BFieldComparison.cpp
|
/*
* 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 "BFieldComparison.h"
namespace Pscf {
// Constructor
BFieldComparison::BFieldComparison(int begin)
: FieldComparison< DArray<double> > (begin)
{};
}
| 362
|
C++
|
.cpp
| 13
| 25.538462
| 67
| 0.756522
|
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,534,919
|
groupFile.cpp
|
dmorse_pscfpp/src/pscf/crystal/groupFile.cpp
|
/*
* 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 "groupFile.h"
#include <pscf/paths.h>
#include <util/global.h>
// Macros to generated quoted path to data directory, DAT_DIR
#define XSTR(s) STR(s)
#define STR(s) # s
#define DAT_DIR_STRING XSTR(PSCF_DATA_DIR)
//#define DAT_DIR_STRING XSTR(DAT_DIR)
namespace Pscf {
using namespace Util;
/*
* Generates the file name from a group name.
*/
std::string makeGroupFileName(int D, std::string groupName)
{
std::string filename = DAT_DIR_STRING ;
filename += "groups/";
if (D==1) {
filename += "1/";
} else
if (D==2) {
filename += "2/";
} else
if (D==3) {
filename += "3/";
} else {
UTIL_THROW("Invalid dimension of space");
}
filename += groupName;
return filename;
}
} // namespace Pscf
| 1,009
|
C++
|
.cpp
| 38
| 22.131579
| 67
| 0.633161
|
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,534,920
|
Basis.cpp
|
dmorse_pscfpp/src/pscf/crystal/Basis.cpp
|
/*
* 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 "Basis.tpp"
namespace Pscf {
template class Basis<1>;
template class Basis<2>;
template class Basis<3>;
}
| 315
|
C++
|
.cpp
| 12
| 24.166667
| 67
| 0.755853
|
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,534,921
|
UnitCell1.cpp
|
dmorse_pscfpp/src/pscf/crystal/UnitCell1.cpp
|
/*
* 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 "UnitCell.h"
#include <util/math/Constants.h>
namespace Pscf
{
using namespace Util;
/*
* Constructor.
*/
UnitCell<1>::UnitCell()
: lattice_(Null)
{}
/*
* Set nParameter based on the lattice system.
*/
void UnitCell<1>::setNParameter()
{
UTIL_CHECK(lattice_ != UnitCell<1>::Null);
if (lattice_ == UnitCell<1>::Lamellar) {
nParameter_ = 1;
} else {
UTIL_THROW("Invalid lattice system value");
}
}
/*
* Set the Bravais and reciprocal lattice parameters.
*/
void UnitCell<1>::setBasis()
{
UTIL_CHECK(lattice_ != UnitCell<1>::Null);
UTIL_CHECK(nParameter_ == 1);
rBasis_[0][0] = parameters_[0];
kBasis_[0][0] = 2.0*Constants::Pi/parameters_[0];
drBasis_[0](0,0) = 1.0;
}
/*
* Extract a UnitCell<1>::LatticeSystem from an istream as a string.
*/
std::istream& operator >> (std::istream& in,
UnitCell<1>::LatticeSystem& lattice)
{
std::string buffer;
in >> buffer;
if (buffer == "Lamellar" || buffer == "lamellar") {
lattice = UnitCell<1>::Lamellar;
} else {
UTIL_THROW("Invalid UnitCell<1>::LatticeSystem value input");
}
return in;
}
/*
* Insert a UnitCell<1>::LatticeSystem to an ostream as a string.
*/
std::ostream& operator << (std::ostream& out,
UnitCell<1>::LatticeSystem lattice)
{
if (lattice == UnitCell<1>::Lamellar) {
out << "lamellar";
} else
if (lattice == UnitCell<1>::Null) {
out << "Null";
} else {
UTIL_THROW("Invalid value of UnitCell<1>::Lamellar");
}
return out;
}
/*
* Assignment operator.
*/
UnitCell<1>& UnitCell<1>::operator = (const UnitCell<1>& other)
{
isInitialized_ = false;
lattice_ = other.lattice_;
setNParameter();
UTIL_CHECK(nParameter_ == other.nParameter_);
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = other.parameters_[i];
}
setLattice();
return *this;
}
/*
* Set the lattice system, but not unit cell parameters.
*/
void UnitCell<1>::set(UnitCell<1>::LatticeSystem lattice)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
}
/*
* Set state of the unit cell (lattice system and parameters).
*/
void UnitCell<1>::set(UnitCell<1>::LatticeSystem lattice,
FSArray<double, 6> const & parameters)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = parameters[i];
}
setLattice();
}
}
| 2,965
|
C++
|
.cpp
| 110
| 20.836364
| 70
| 0.57691
|
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,534,922
|
UnitCell3.cpp
|
dmorse_pscfpp/src/pscf/crystal/UnitCell3.cpp
|
/*
* 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 "UnitCell.h"
#include <util/math/Constants.h>
namespace Pscf
{
using namespace Util;
/*
* Constructor.
*/
UnitCell<3>::UnitCell()
: lattice_(Null)
{}
/*
* Read the lattice system and set nParameter.
*/
void UnitCell<3>::setNParameter()
{
UTIL_CHECK(lattice_ != UnitCell<3>::Null);
if (lattice_ == UnitCell<3>::Cubic) {
nParameter_ = 1;
} else
if (lattice_ == UnitCell<3>::Tetragonal) {
nParameter_ = 2;
} else
if (lattice_ == UnitCell<3>::Orthorhombic) {
nParameter_ = 3;
} else
if (lattice_ == UnitCell<3>::Monoclinic) {
nParameter_ = 4;
} else
if (lattice_ == UnitCell<3>::Triclinic) {
nParameter_ = 6;
} else
if (lattice_ == UnitCell<3>::Rhombohedral) {
nParameter_ = 2;
} else
if (lattice_ == UnitCell<3>::Hexagonal) {
nParameter_ = 2;
} else {
UTIL_THROW("Invalid value");
}
}
/*
* Set Bravais and reciprocal lattice parameters, and drBasis.
*
* Function UnitCellBase::initializeToZero() must be called before
* setBasis() to initialize all elements of vectors and tensors to
* zero. Only nonzero elements need to be set here.
*/
void UnitCell<3>::setBasis()
{
UTIL_CHECK(lattice_ != UnitCell<3>::Null);
UTIL_CHECK(nParameter_ > 0);
// Set elements for specific lattice types
double twoPi = 2.0*Constants::Pi;
int i;
if (lattice_ == UnitCell<3>::Cubic) {
UTIL_CHECK(nParameter_ == 1);
for (i=0; i < 3; ++i) {
rBasis_[i][i] = parameters_[0];
kBasis_[i][i] = twoPi/parameters_[0];
drBasis_[0](i,i) = 1.0;
}
} else
if (lattice_ == UnitCell<3>::Tetragonal) {
UTIL_CHECK(nParameter_ == 2);
rBasis_[0][0] = parameters_[0];
rBasis_[1][1] = parameters_[0];
rBasis_[2][2] = parameters_[1];
drBasis_[0](0,0) = 1.0;
drBasis_[0](1,1) = 1.0;
drBasis_[1](2,2) = 1.0;
kBasis_[0][0] = twoPi/parameters_[0];
kBasis_[1][1] = kBasis_[0][0];
kBasis_[2][2] = twoPi/parameters_[1];
}else
if (lattice_ == UnitCell<3>::Orthorhombic) {
UTIL_CHECK(nParameter_ == 3);
for (i=0; i < 3; ++i) {
rBasis_[i][i] = parameters_[i];
drBasis_[i](i,i) = 1.0;
kBasis_[i][i] = twoPi/parameters_[i];
}
} else
if (lattice_ == UnitCell<3>::Hexagonal) {
UTIL_CHECK(nParameter_ == 2);
double a = parameters_[0];
double c = parameters_[1];
double rt3 = sqrt(3.0);
rBasis_[0][0] = a;
rBasis_[1][0] = -0.5*a;
rBasis_[1][1] = 0.5*rt3*a;
rBasis_[2][2] = c;
drBasis_[0](0, 0) = 1.0;
drBasis_[0](1, 0) = -0.5;
drBasis_[0](1, 1) = 0.5*rt3;
drBasis_[1](2, 2) = 1.0;
kBasis_[0][0] = twoPi/a;
kBasis_[0][1] = twoPi/(rt3*a);
kBasis_[1][0] = 0.0;
kBasis_[1][1] = twoPi/(0.5*rt3*a);
kBasis_[2][2] = twoPi/(c);
} else
if (lattice_ == UnitCell<3>::Rhombohedral) {
UTIL_CHECK(nParameter_ == 2);
// Set parameters
double a, beta, theta;
a = parameters_[0]; // magnitude of Bravais basis vectors
beta = parameters_[1]; // angle between basis vectors
theta = acos( sqrt( (2.0*cos(beta) + 1.0)/3.0 ) );
// theta is the angle of all basis vectors from the z axis
/*
* Bravais lattice vectora a_i with i=0, 1, or 2 have form:
*
* a_i = a * (z * cos(theta) + u_i * sin(theta) )
*
* where z denotes a unit vector parallel to the z axis, and
* the u_i are three unit vectors in the x-y separated by
* angles of 2 pi /3 (or 120 degrees), for which u_0 is
* parallel to the x axis. Note that u_i . u_j = -1/2 for any
* i not equal to j.
*
* The angle between any two such Bravais basis vectors is easily
* computed from the dot product, a_i . a_j for unequal i and j.
* This gives:
*
* cos beta = cos^2(theta) - 0.5 sin^2 (theta)
* = (3cos^{2}(theta) - 1)/2
*
* The angle theta is computed above by solving this equation
* for theta as a function of the input parameter beta.
*
* The corresponding reciprocal lattice vectors have the form
*
* b_i = (2*pi/3*a)( z/cos(theta) + 2 * u_i / sin(theta) )
*
* It is straightforward to confirm that these reciprocal
* vectors satisfy the condition a_i . b_j = 2 pi delta_{ij}
*/
// Trig function values
double cosT = cos(theta);
double sinT = sin(theta);
double sqrt3 = sqrt(3.0);
double sinPi3 = 0.5*sqrt3;
double cosPi3 = 0.5;
// Bravais basis vectors
rBasis_[0][0] = sinT * a;
rBasis_[0][2] = cosT * a;
rBasis_[1][0] = -cosPi3 * sinT * a;
rBasis_[1][1] = sinPi3 * sinT * a;
rBasis_[1][2] = cosT * a;
rBasis_[2][0] = -cosPi3 * sinT * a;
rBasis_[2][1] = -sinPi3 * sinT * a;
rBasis_[2][2] = cosT * a;
// Reciprocal lattice basis vectors
kBasis_[0][0] = 2.0 * twoPi /( 3.0 * sinT * a);
kBasis_[0][2] = twoPi /( 3.0 * cosT * a);
kBasis_[1][0] = -2.0 * cosPi3 * twoPi /( 3.0 * sinT * a);
kBasis_[1][1] = 2.0 * sinPi3 * twoPi /( 3.0 * sinT * a);
kBasis_[1][2] = twoPi /( 3.0 * cosT * a);
kBasis_[2][0] = -2.0 * cosPi3 * twoPi /( 3.0 * sinT * a);
kBasis_[2][1] = -2.0 * sinPi3 * twoPi /( 3.0 * sinT * a);
kBasis_[2][2] = twoPi /( 3.0 * cosT * a);
// Derivatives with respect to length a
drBasis_[0](0,0) = sinT;
drBasis_[0](0,2) = cosT;
drBasis_[0](1,0) = -cosPi3 * sinT;
drBasis_[0](1,1) = sinPi3 * sinT;
drBasis_[0](1,2) = cosT;
drBasis_[0](2,0) = -cosPi3 * sinT;
drBasis_[0](2,1) = -sinPi3* sinT;
drBasis_[0](2,2) = cosT;
// Define alpha = d(theta)/d(beta)
double alpha = -sin(beta)/(3.0*cosT*sinT);
// Derivatives with respect to beta
drBasis_[1](0,0) = cosT * alpha * a;
drBasis_[1](0,2) = -sinT * alpha * a;
drBasis_[1](1,0) = -cosPi3 * cosT * alpha * a;
drBasis_[1](1,1) = sinPi3 * cosT * alpha * a;
drBasis_[1](1,2) = -sinT * alpha * a;
drBasis_[1](2,0) = -cosPi3 * cosT * alpha * a;
drBasis_[1](2,1) = -sinPi3* cosT * alpha * a;
drBasis_[1](2,2) = -sinT * alpha * a;
} else
if (lattice_ == UnitCell<3>::Monoclinic) {
UTIL_CHECK(nParameter_ == 4);
/*
* Description: Bravais basis vectors A, B, and C
* A (vector 0) is along x axis
* B (vector 1) is along y axis
* C (vector 2) is in the x-z plane, an angle beta from A/x
* B is the unique axis (perpendicular to A and C)
* Angle beta is stored in radians.
*/
// Parameters
double a = parameters_[0]; // length of A
double b = parameters_[1]; // length of B
double c = parameters_[2]; // length of C
double beta = parameters_[3]; // angle between C and A/x
double cb = cos(beta);
double sb = sin(beta);
// Nonzero components of basis vectors
// For rBasis_[i][j], i:basis vector, j:Cartesian component
rBasis_[0][0] = a;
rBasis_[1][1] = b;
rBasis_[2][0] = c*cb;
rBasis_[2][2] = c*sb;
// Nonzero derivatives of basis vectors with respect to parameters
// For drBasis_[k](i,j), k:parameter, i:basis vector, j:Cartesian
drBasis_[0](0,0) = 1.0;
drBasis_[1](1,1) = 1.0;
drBasis_[2](2,0) = cb;
drBasis_[2](2,2) = sb;
drBasis_[3](2,0) = c*sb;
drBasis_[3](2,2) = -c*cb;
// Reciprocal lattice vectors
kBasis_[0][0] = twoPi/a;
kBasis_[0][2] = -twoPi*cb/(a*sb);
kBasis_[1][1] = twoPi / b;
kBasis_[2][2] = twoPi/(c*sb);
} else
if (lattice_ == UnitCell<3>::Triclinic) {
UTIL_CHECK(nParameter_ == 6);
/*
* Description: Bravais basis vectors A, B, and C
* A (vector 0) is along x axis
* B (vector 1) is in the x-y plane, an angle gamma from x axis
* C (vector 2) is tilted by an angle theta from z axis
* phi is the angle beween c-z an x-z (or a-z) planes
* All three angles are stored in radians
*/
double a = parameters_[0]; // length of A
double b = parameters_[1]; // length of B
double c = parameters_[2]; // length of C
double phi = parameters_[3]; // angle between c-z and a-z planes
double theta = parameters_[4]; // angle between c and z axis
double gamma = parameters_[5]; // angle between a and b
// sine and cosine of all angles
double cosPhi = cos(phi);
double sinPhi = sin(phi);
double cosTheta = cos(theta);
double sinTheta = sin(theta);
double cosGamma = cos(gamma);
double sinGamma = sin(gamma);
// Nonzero components of Bravais basis vectors
rBasis_[0][0] = a;
rBasis_[1][0] = b * cosGamma;
rBasis_[1][1] = b * sinGamma;
rBasis_[2][0] = c * sinTheta * cosPhi;
rBasis_[2][1] = c * sinTheta * sinPhi;
rBasis_[2][2] = c * cosTheta;
// Nonzero derivatives of basis vectors with respect to parameters
drBasis_[0](0,0) = 1.0;
drBasis_[1](1,0) = cosGamma;
drBasis_[1](1,1) = sinGamma;
drBasis_[2](2,0) = sinTheta * cosPhi;
drBasis_[2](2,1) = sinTheta * sinPhi;
drBasis_[2](2,2) = cosTheta;
drBasis_[3](2,0) = -c * sinTheta * sinPhi;
drBasis_[3](2,1) = c * sinTheta * cosPhi;
drBasis_[4](2,0) = c * cosTheta * cosPhi;
drBasis_[4](2,1) = c * cosTheta * sinPhi;
drBasis_[4](2,2) = -c * sinTheta;
drBasis_[5](1,0) = -b * sinGamma;
drBasis_[5](1,1) = b * cosGamma;
// Reciprocal lattice vectors
kBasis_[0][0] = twoPi / a;
kBasis_[0][1] = -twoPi * cosGamma / (a * sinGamma);
kBasis_[0][2] = sinTheta * (cosGamma * sinPhi - sinGamma * cosPhi);
kBasis_[0][2] = twoPi * kBasis_[0][2] / (a * sinGamma * cosTheta);
kBasis_[1][1] = twoPi/(b*sinGamma);
kBasis_[1][2] = -twoPi*sinPhi*sinTheta/(b*cosTheta*sinGamma);
kBasis_[2][2] = twoPi/(c*cosTheta);
} else {
UTIL_THROW("Unimplemented 3D lattice type");
}
}
/*
* Extract a UnitCell<3>::LatticeSystem from an istream as a string.
*/
std::istream& operator >> (std::istream& in,
UnitCell<3>::LatticeSystem& lattice)
{
std::string buffer;
in >> buffer;
if (buffer == "Cubic" || buffer == "cubic") {
lattice = UnitCell<3>::Cubic;
} else
if (buffer == "Tetragonal" || buffer == "tetragonal") {
lattice = UnitCell<3>::Tetragonal;
} else
if (buffer == "Orthorhombic" || buffer == "orthorhombic") {
lattice = UnitCell<3>::Orthorhombic;
} else
if (buffer == "Monoclinic" || buffer == "monoclinic") {
lattice = UnitCell<3>::Monoclinic;
} else
if (buffer == "Triclinic" || buffer == "triclinic") {
lattice = UnitCell<3>::Triclinic;
} else
if (buffer == "Rhombohedral" || buffer == "rhombohedral") {
lattice = UnitCell<3>::Rhombohedral;
} else
if (buffer == "Hexagonal" || buffer == "hexagonal") {
lattice = UnitCell<3>::Hexagonal;
} else {
UTIL_THROW("Invalid UnitCell<3>::LatticeSystem value input");
}
return in;
}
/*
* Insert a UnitCell<3>::LatticeSystem to an ostream as a string.
*/
std::ostream& operator << (std::ostream& out,
UnitCell<3>::LatticeSystem lattice)
{
if (lattice == UnitCell<3>::Cubic) {
out << "cubic";
} else
if (lattice == UnitCell<3>::Tetragonal) {
out << "tetragonal";
} else
if (lattice == UnitCell<3>::Orthorhombic) {
out << "orthorhombic";
} else
if (lattice == UnitCell<3>::Monoclinic) {
out << "monoclinic";
} else
if (lattice == UnitCell<3>::Triclinic) {
out << "triclinic";
} else
if (lattice == UnitCell<3>::Rhombohedral) {
out << "rhombohedral";
} else
if (lattice == UnitCell<3>::Hexagonal) {
out << "hexagonal";
} else
if (lattice == UnitCell<3>::Null) {
out << "Null";
} else {
UTIL_THROW("This should never happen");
}
return out;
}
/*
* Assignment operator.
*/
UnitCell<3>& UnitCell<3>::operator = (UnitCell<3> const & other)
{
isInitialized_ = false;
lattice_ = other.lattice_;
setNParameter();
UTIL_CHECK(nParameter_ == other.nParameter_);
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = other.parameters_[i];
}
setLattice();
return *this;
}
/*
* Set lattice system of the unit cell (but not the parameters).
*/
void UnitCell<3>::set(UnitCell<3>::LatticeSystem lattice)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
}
/*
* Set state of the unit cell.
*/
void UnitCell<3>::set(UnitCell<3>::LatticeSystem lattice,
FSArray<double, 6> const & parameters)
{
isInitialized_ = false;
lattice_ = lattice;
setNParameter();
for (int i = 0; i < nParameter_; ++i) {
parameters_[i] = parameters[i];
}
setLattice();
}
}
| 14,337
|
C++
|
.cpp
| 388
| 28.332474
| 76
| 0.521479
|
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,534,923
|
Molecule.cpp
|
dmorse_pscfpp/src/pscf/homogeneous/Molecule.cpp
|
/*
* 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 "Molecule.h"
namespace Pscf{
/*
* Constructor.
*/
Homogeneous::Molecule::Molecule()
: clumps_(),
nClump_(0),
size_(0.0),
hasSize_(false)
{ setClassName("Molecule"); }
/*
* Destructor.
*/
Homogeneous::Molecule::~Molecule()
{}
/*
* Read chemical composition from file.
*/
void Homogeneous::Molecule::readParameters(std::istream& in)
{
UTIL_ASSERT(clumps_.capacity() == 0);
read<int>(in, "nClump", nClump_);
// Allocate all arrays
clumps_.allocate(nClump_);
readDArray<Homogeneous::Clump>(in, "clumps", clumps_, nClump_);
computeSize();
}
/*
* Allocate memory for specified number of clumps.
*/
void Homogeneous::Molecule::setNClump(int nClump)
{
UTIL_ASSERT(clumps_.capacity() == 0);
nClump_ = nClump;
clumps_.allocate(nClump_);
}
/*
* Compute molecular size, by adding all clump sizes.
*/
void Homogeneous::Molecule::computeSize()
{
UTIL_ASSERT(clumps_.capacity() > 0);
UTIL_ASSERT(clumps_.capacity() == nClump_);
size_ = 0.0;
for (int clumpId = 0; clumpId < nClump_; ++clumpId) {
size_ += clumps_[clumpId].size();
}
hasSize_ = true;
}
}
| 1,457
|
C++
|
.cpp
| 57
| 20.649123
| 69
| 0.617605
|
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,534,924
|
Mixture.cpp
|
dmorse_pscfpp/src/pscf/homogeneous/Mixture.cpp
|
/*
* PSCF - Molecule 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 "Mixture.h"
#include <pscf/inter/Interaction.h>
#include <pscf/math/LuSolver.h>
#include <cmath>
namespace Pscf {
namespace Homogeneous {
using namespace Util;
/*
* Constructor.
*/
Mixture::Mixture()
: ParamComposite(),
molecules_(),
mu_(),
phi_(),
c_(),
w_(),
residual_(),
dX_(),
dWdC_(),
dWdPhi_(),
jacobian_(),
phiOld_(),
fHelmholtz_(0.0),
pressure_(0.0),
solverPtr_(0),
nMolecule_(0),
nMonomer_(0),
hasComposition_(false)
{ setClassName("Mixture"); }
/*
* Destructor.
*/
Mixture::~Mixture()
{}
/*
* Read all parameters and initialize.
*/
void Mixture::readParameters(std::istream& in)
{
// Precondition
UTIL_ASSERT(molecules_.capacity() == 0);
read<int>(in, "nMonomer", nMonomer_);
c_.allocate(nMonomer_);
w_.allocate(nMonomer_);
read<int>(in, "nMolecule", nMolecule_);
molecules_.allocate(nMolecule_);
mu_.allocate(nMolecule_);
phi_.allocate(nMolecule_);
for (int i = 0; i < nMolecule_; ++i) {
readParamComposite(in, molecules_[i]);
}
validate();
}
void Mixture::setNMolecule(int nMolecule)
{
UTIL_ASSERT(molecules_.capacity() == 0);
nMolecule_ = nMolecule;
molecules_.allocate(nMolecule_);
mu_.allocate(nMolecule_);
phi_.allocate(nMolecule_);
}
void Mixture::setNMonomer(int nMonomer)
{
UTIL_ASSERT(nMonomer_ == 0);
nMonomer_ = nMonomer;
c_.allocate(nMonomer_);
w_.allocate(nMonomer_);
}
/*
* Set molecular and monomer volume fractions.
*/
void Mixture::setComposition(DArray<double> const & phi)
{
validate();
UTIL_ASSERT(phi.capacity() == nMolecule_);
// Set molecular volume fractions
double sum = 0;
for (int i = 0; i < nMolecule_ - 1; ++i) {
UTIL_CHECK(phi[i] >= 0.0);
UTIL_CHECK(phi[i] <= 1.0);
phi_[i] = phi[i];
sum += phi[i];
}
UTIL_CHECK(sum <= 1.0);
phi_[nMolecule_ -1] = 1.0 - sum;
computeC();
hasComposition_ = true;
}
void Mixture::computeC()
{
// Initialize monomer fractions to zero
int k;
for (k = 0; k < nMonomer_; ++k) {
c_[k] = 0.0;
}
// Compute monomer volume fractions
double concentration;
int i, j;
for (i = 0; i < nMolecule_; ++i) {
Molecule& mol = molecules_[i];
concentration = phi_[i]/mol.size();
for (j = 0; j < molecules_[i].nClump(); ++j) {
k = mol.clump(j).monomerId();
c_[k] += concentration*mol.clump(j).size();
}
}
// Check and normalize monomer volume fractions
double sum = 0.0;
for (k = 0; k < nMonomer_; ++k) {
UTIL_CHECK(c_[k] >= 0.0);
UTIL_CHECK(c_[k] <= 1.0);
sum += c_[k];
}
UTIL_CHECK(sum > 0.9999);
UTIL_CHECK(sum < 1.0001);
for (k = 0; k < nMonomer_; ++k) {
c_[k] /= sum;
}
}
/*
* Compute thermodynamic properties.
*/
void Mixture::computeMu(Interaction const & interaction,
double xi)
{
UTIL_CHECK(interaction.nMonomer() == nMonomer_);
UTIL_CHECK(hasComposition_);
// Compute monomer excess chemical potentials
interaction.computeW(c_, w_);
int m; // molecule index
int c; // clump index
int t; // monomer type index
double mu, size;
for (m = 0; m < nMolecule_; ++m) {
Molecule& mol = molecules_[m];
mu = log( phi_[m] );
mu += xi*mol.size();
for (c = 0; c < mol.nClump(); ++c) {
t = mol.clump(c).monomerId();
size = mol.clump(c).size();
mu += size*w_[t];
}
mu_[m] = mu;
}
}
/*
* Compute composition from chemical potentials.
*/
void Mixture::computePhi(Interaction const & interaction,
DArray<double> const & mu,
DArray<double> const & phi,
double& xi)
{
UTIL_ASSERT(interaction.nMonomer() == nMonomer_);
// Allocate residual and jacobian on first use.
if (residual_.capacity() == 0) {
residual_.allocate(nMonomer_);
dX_.allocate(nMolecule_);
dWdC_.allocate(nMonomer_, nMonomer_);
dWdPhi_.allocate(nMonomer_, nMolecule_);
jacobian_.allocate(nMolecule_, nMolecule_);
phiOld_.allocate(nMolecule_);
solverPtr_ = new LuSolver();
solverPtr_->allocate(nMolecule_);
}
// Compute initial state
setComposition(phi);
computeMu(interaction, xi);
adjustXi(mu, xi);
// Compute initial residual
double error;
double epsilon = 1.0E-10;
computeResidual(mu, error);
#if 0
std::cout << "mu[0] =" << mu[0] << std::endl;
std::cout << "mu[1] =" << mu[1] << std::endl;
std::cout << "mu_[0] =" << mu_[0] << std::endl;
std::cout << "mu_[1] =" << mu_[1] << std::endl;
std::cout << "residual[0] =" << residual_[0] << std::endl;
std::cout << "residual[1] =" << residual_[1] << std::endl;
std::cout << "error =" << error << std::endl;
#endif
if (error < epsilon) return;
double s1; // clump size
double v1; // molecule size
double f1; // clump fraction
int m1, m2; // molecule type indices
int c1; // clump index
int t1, t2; // monomer type indices
for (int it = 0; it < 50; ++it) {
// Compute matrix of derivative dWdC (C = monomer fraction)
interaction.computeDwDc(c_, dWdC_);
// Compute matrix derivative dWdPhi (Phi = molecule fraction)
for (t1 = 0; t1 < nMonomer_; ++t1) {
for (m1 = 0; m1 < nMolecule_; ++m1) {
dWdPhi_(t1, m1) = 0.0;
}
}
for (m1 = 0; m1 < nMolecule_; ++m1) {
v1 = molecule(m1).size();
for (c1 = 0; c1 < molecule(m1).nClump(); ++c1) {
t1 = molecule(m1).clump(c1).monomerId();
s1 = molecule(m1).clump(c1).size();
f1 = s1/v1;
for (t2 = 0; t2 < nMonomer_; ++t2) {
dWdPhi_(t2, m1) += dWdC_(t2, t1)*f1;
}
}
}
// Compute matrix d(mu)/d(Phi), stored in jacobian_
for (m1 = 0; m1 < nMolecule_; ++m1) {
for (m2 = 0; m2 < nMolecule_; ++m2) {
jacobian_(m1, m2) = 0.0;
}
jacobian_(m1, m1) = 1.0/phi_[m1];
}
for (m1 = 0; m1 < nMolecule_; ++m1) {
v1 = molecule(m1).size();
for (c1 = 0; c1 < molecule(m1).nClump(); ++c1) {
t1 = molecule(m1).clump(c1).monomerId();
s1 = molecule(m1).clump(c1).size();
for (m2 = 0; m2 < nMolecule_; ++m2) {
jacobian_(m1, m2) += s1*dWdPhi_(t1, m2);
}
}
}
// Impose incompressibility
int mLast = nMolecule_ - 1;
for (m1 = 0; m1 < nMolecule_; ++m1) {
for (m2 = 0; m2 < nMolecule_ - 1; ++m2) {
jacobian_(m1, m2) -= jacobian_(m1, mLast);
}
// Derivative of mu_[m1] with respect to xi
jacobian_(m1, mLast) = molecule(m1).size();
}
// Newton Raphson update of phi and xi fields
solverPtr_->computeLU(jacobian_);
solverPtr_->solve(residual_, dX_);
// Store old value of phi
for (m1 = 0; m1 < nMolecule_; ++m1) {
phiOld_[m1] = phi_[m1];
}
// Apply update
bool inRange = false;
for (int j = 0; j < 5; ++j) {
// Update volume fractions
double sum = 0.0;
for (m1 = 0; m1 < nMolecule_ - 1; ++m1) {
phi_[m1] = phiOld_[m1] - dX_[m1];
sum += phi_[m1];
}
phi_[mLast] = 1.0 - sum;
// Check if all volume fractions are in [0,1]
inRange = true;
for (m1 = 0; m1 < nMolecule_; ++m1) {
if (phi_[m1] < 0.0) inRange = false;
if (phi_[m1] > 1.0) inRange = false;
}
// Exit loop or reduce increment
if (inRange) {
break;
} else {
for (m1 = 0; m1 < nMolecule_; ++m1) {
dX_[m1] *= 0.5;
}
}
}
if (inRange) {
xi = xi - dX_[mLast];
} else {
UTIL_THROW("Volume fractions remain out of range");
}
// Compute residual
computeC();
computeMu(interaction, xi);
adjustXi(mu, xi);
computeResidual(mu, error);
#if 0
std::cout << "mu[0] =" << mu[0] << std::endl;
std::cout << "mu[1] =" << mu[1] << std::endl;
std::cout << "mu_[0] =" << mu_[0] << std::endl;
std::cout << "mu_[1] =" << mu_[1] << std::endl;
std::cout << "residual[0] =" << residual_[0] << std::endl;
std::cout << "residual[1] =" << residual_[1] << std::endl;
std::cout << "error =" << error << std::endl;
#endif
if (error < epsilon) return;
}
UTIL_THROW("Failed to converge");
}
void Mixture::adjustXi(DArray<double> const & mu, double& xi)
{
double dxi = 0.0;
double sum = 0.0;
for (int i=0; i < nMolecule_; ++i) {
dxi += mu[i] - mu_[i];
sum += molecules_[i].size();
}
dxi = dxi/sum;
for (int i=0; i < nMolecule_; ++i) {
mu_[i] += dxi*molecules_[i].size();
}
xi += dxi;
}
void Mixture::computeResidual(DArray<double> const & mu, double& error)
{
error = 0.0;
for (int i = 0; i < nMonomer_; ++i) {
residual_[i] = mu_[i] - mu[i];
if (std::abs(residual_[i]) > error) {
error = std::abs(residual_[i]);
}
}
}
/*
* Compute Helmoltz free energy and pressure
*/
void Mixture::computeFreeEnergy(Interaction const & interaction)
{
fHelmholtz_ = 0.0;
// Compute ideal gas contributions to fHelhmoltz_
double size;
for (int i = 0; i < nMolecule_; ++i) {
size = molecules_[i].size();
fHelmholtz_ += phi_[i]*( log(phi_[i]) - 1.0 )/size;
}
// Add average interaction free energy density per monomer
fHelmholtz_ += interaction.fHelmholtz(c_);
// Compute pressure
pressure_ = -fHelmholtz_;
for (int i = 0; i < nMolecule_; ++i) {
size = molecules_[i].size();
pressure_ += phi_[i]*mu_[i]/size;
}
}
/*
* Check validity after completing initialization.
*/
void Mixture::validate() const
{
UTIL_ASSERT(nMolecule_ > 0);
UTIL_ASSERT(nMonomer_ > 0);
for (int i = 0; i < nMolecule_; ++i) {
Molecule const & mol = molecules_[i];
UTIL_ASSERT(mol.nClump() > 0);
for (int j = 0; j < mol.nClump(); ++j) {
UTIL_ASSERT(mol.clump(j).monomerId() < nMonomer_);
}
}
}
} // namespace Homogeneous
} // namespace Pscf
| 11,494
|
C++
|
.cpp
| 359
| 23.448468
| 74
| 0.498601
|
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,534,925
|
Clump.cpp
|
dmorse_pscfpp/src/pscf/homogeneous/Clump.cpp
|
/*
* 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 "Clump.h"
namespace Pscf {
namespace Homogeneous {
/*
* Constructor.
*/
Clump::Clump()
: monomerId_(-1),
size_(0.0)
{}
/*
* Set the monomer id.
*/
void Clump::setMonomerId(int monomerId)
{ monomerId_ = monomerId; }
/*
* Set the size of this block.
*/
void Clump::setSize(double size)
{ size_ = size; }
/*
* Extract a Clump from an istream.
*/
std::istream& operator>>(std::istream& in, Clump &block)
{
in >> block.monomerId_;
in >> block.size_;
return in;
}
/*
* Output a Clump to an ostream, without line breaks.
*/
std::ostream& operator<<(std::ostream& out, const Clump &block)
{
out << " " << block.monomerId_;
out << " ";
out.setf(std::ios::scientific);
out.width(16);
out.precision(8);
out << block.size_;
return out;
}
}
}
| 1,108
|
C++
|
.cpp
| 50
| 17.6
| 67
| 0.594621
|
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,534,926
|
Interaction.cpp
|
dmorse_pscfpp/src/pscf/inter/Interaction.cpp
|
/*
* 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 "Interaction.h"
#include <pscf/math/LuSolver.h>
namespace Pscf {
using namespace Util;
/*
* Constructor.
*/
Interaction::Interaction()
: nMonomer_(0)
{ setClassName("Interaction"); }
/*
* Destructor.
*/
Interaction::~Interaction()
{}
/*
* Set the number of monomer types.
*/
void Interaction::setNMonomer(int nMonomer)
{
UTIL_CHECK(nMonomer_ == 0);
UTIL_CHECK(nMonomer > 0);
nMonomer_ = nMonomer;
chi_.allocate(nMonomer, nMonomer);
chiInverse_.allocate(nMonomer, nMonomer);
}
/*
* Read chi matrix from file.
*/
void Interaction::readParameters(std::istream& in)
{
UTIL_CHECK(nMonomer() > 0);
readDSymmMatrix(in, "chi", chi_, nMonomer());
// Compute relevant AM iterator quantities.
updateMembers();
}
void Interaction::updateMembers()
{
UTIL_CHECK(chi_.isAllocated());
UTIL_CHECK(chiInverse_.isAllocated());
if (nMonomer() == 2) {
double det = chi_(0,0)*chi_(1, 1) - chi_(0,1)*chi_(1,0);
double norm = chi_(0,0)*chi_(0, 0) + chi_(1,1)*chi_(1,1)
+ 2.0*chi_(0,1)*chi_(1,0);
if (fabs(det/norm) < 1.0E-8) {
UTIL_THROW("Singular chi matrix");
}
chiInverse_(0,1) = -chi_(0,1)/det;
chiInverse_(1,0) = -chi_(1,0)/det;
chiInverse_(1,1) = chi_(0,0)/det;
chiInverse_(0,0) = chi_(1,1)/det;
} else {
LuSolver solver;
solver.allocate(nMonomer());
solver.computeLU(chi_);
solver.inverse(chiInverse_);
}
}
void Interaction::setChi(int i, int j, double chi)
{
chi_(i,j) = chi;
if (i != j) {
chi_(j,i) = chi;
}
// Compute relevant AM iterator quantities.
updateMembers();
}
/*
* Compute and return excess Helmholtz free energy per monomer.
*/
double Interaction::fHelmholtz(Array<double> const & c) const
{
int i, j;
double sum = 0.0;
for (i = 0; i < nMonomer(); ++i) {
for (j = 0; j < nMonomer(); ++j) {
sum += chi_(i, j)* c[i]*c[j];
}
}
return 0.5*sum;
}
/*
* Compute chemical potential from monomer concentrations
*/
void
Interaction::computeW(Array<double> const & c,
Array<double>& w) const
{
int i, j;
for (i = 0; i < nMonomer(); ++i) {
w[i] = 0.0;
for (j = 0; j < nMonomer(); ++j) {
w[i] += chi_(i, j)* c[j];
}
}
}
/*
* Compute concentrations and xi from chemical potentials.
*/
void
Interaction::computeC(Array<double> const & w,
Array<double>& c, double& xi)
const
{
double sum1 = 0.0;
double sum2 = 0.0;
int i, j;
for (i = 0; i < nMonomer(); ++i) {
for (j = 0; j < nMonomer(); ++j) {
sum1 += chiInverse_(i, j)*w[j];
sum2 += chiInverse_(i, j);
}
}
xi = (sum1 - 1.0)/sum2;
for (i = 0; i < nMonomer(); ++i) {
c[i] = 0;
for (j = 0; j < nMonomer(); ++j) {
c[i] += chiInverse_(i, j)*( w[j] - xi );
}
}
}
/*
* Compute Langrange multiplier from chemical potentials.
*/
void
Interaction::computeXi(Array<double> const & w, double& xi)
const
{
double sum1 = 0.0;
double sum2 = 0.0;
int i, j;
for (i = 0; i < nMonomer(); ++i) {
for (j = 0; j < nMonomer(); ++j) {
sum1 += chiInverse_(i, j)*w[j];
sum2 += chiInverse_(i, j);
}
}
xi = (sum1 - 1.0)/sum2;
}
/*
* Return dWdC = chi matrix.
*/
void
Interaction::computeDwDc(Array<double> const & c,
Matrix<double>& dWdC) const
{
int i, j;
for (i = 0; i < nMonomer(); ++i) {
for (j = 0; j < nMonomer(); ++j) {
dWdC(i, j) = chi_(i, j);
}
}
}
} // namespace Pscf
| 4,231
|
C++
|
.cpp
| 160
| 19.50625
| 67
| 0.508763
|
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,534,927
|
Field.cpp
|
dmorse_pscfpp/src/pscf/math/Field.cpp
|
/*
* 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 "Field.h"
#include <util/global.h>
namespace Pscf {
template class Field<double>;
}
| 288
|
C++
|
.cpp
| 11
| 24.454545
| 67
| 0.765568
|
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,534,928
|
IntVec.cpp
|
dmorse_pscfpp/src/pscf/math/IntVec.cpp
|
/*
* 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 "IntVec.h"
#include <util/global.h>
namespace Pscf
{
template class IntVec<1>;
template class IntVec<2>;
template class IntVec<3>;
}
| 343
|
C++
|
.cpp
| 14
| 22.5
| 67
| 0.756923
|
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,534,929
|
TridiagonalSolver.cpp
|
dmorse_pscfpp/src/pscf/math/TridiagonalSolver.cpp
|
/*
* 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 <string>
#include <iostream>
#include "TridiagonalSolver.h"
namespace Pscf
{
/*
* Constructor.
*/
TridiagonalSolver::TridiagonalSolver()
{}
/*
* Destructor.
*/
TridiagonalSolver::~TridiagonalSolver()
{}
/*
* Allocate memory.
*/
void TridiagonalSolver::allocate(int n)
{
d_.allocate(n);
u_.allocate(n-1);
l_.allocate(n-1);
y_.allocate(n);
n_ = n;
}
/*
* Compute the LU decomposition of a symmetric matrix for later use.
*/
void TridiagonalSolver::computeLU(const DArray<double>& d,
const DArray<double>& u)
{
// Copy to local arrays
for (int i = 0; i < n_ - 1; ++i) {
d_[i] = d[i];
u_[i] = u[i];
l_[i] = u[i];
}
d_[n_ - 1] = d[n_ - 1];
gaussElimination();
}
/*
* Compute the LU decomposition of a symmetric matrix for later use.
*/
void TridiagonalSolver::computeLU(const DArray<double>& d,
const DArray<double>& u,
const DArray<double>& l)
{
// Copy to local arrays
for (int i = 0; i < n_ - 1; ++i) {
d_[i] = d[i];
u_[i] = u[i];
l_[i] = l[i];
}
d_[n_ - 1] = d[n_ - 1];
gaussElimination();
}
void TridiagonalSolver::gaussElimination()
{
// Gauss elimination
double q;
for (int i = 0; i < n_ - 1; ++i) {
q = l_[i]/d_[i];
d_[i+1] -= q*u_[i];
l_[i] = q;
}
#if 0
std::cout << "\n";
for (int i=0; i < n_; ++i) {
std::cout << " " << d_[i];
}
std::cout << "\n";
for (int i=0; i < n_ - 1; ++i) {
std::cout << " " << u_[i];
}
std::cout << "\n";
for (int i=0; i < n_ - 1; ++i) {
std::cout << " " << l_[i];
}
std::cout << "\n";
#endif
}
/*
* Compute matrix product Ab = x for x, given known vector b.
*/
void TridiagonalSolver::multiply(const DArray<double>& b, DArray<double>& x)
{
// Compute Ub = y
for (int i = 0; i < n_ - 1; ++i) {
y_[i] = d_[i]*b[i] + u_[i]*b[i+1];
}
y_[n_ - 1] = d_[n_ - 1]*b[n_ - 1];
// Compute Ly = x
x[0] = y_[0];
for (int i = 1; i < n_; ++i) {
x[i] = y_[i] + l_[i-1]*y_[i-1];
}
}
/*
* Solve Ax = b for x, given known b.
*/
void TridiagonalSolver::solve(const DArray<double>& b, DArray<double>& x)
{
// Solve Ly = b by forward substitution.
y_[0] = b[0];
for (int i = 1; i < n_; ++i) {
y_[i] = b[i] - l_[i-1]*y_[i-1];
}
// Solve Ux = y by back substitution.
x[n_ - 1] = y_[n_ - 1]/d_[n_ - 1];
for (int i = n_ - 2; i >= 0; --i) {
x[i] = (y_[i] - u_[i]*x[i+1])/d_[i];
}
}
}
| 3,083
|
C++
|
.cpp
| 121
| 18.710744
| 79
| 0.452292
|
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,534,930
|
LuSolver.cpp
|
dmorse_pscfpp/src/pscf/math/LuSolver.cpp
|
/*
* 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 "LuSolver.h"
#include <gsl/gsl_linalg.h>
namespace Pscf
{
LuSolver::LuSolver()
: luPtr_(0),
permPtr_(0),
n_(0)
{
// Initialize gs_vector b_
b_.size = 0;
b_.stride = 1;
b_.data = 0;
b_.block = 0;
b_.owner = 0;
// Initialize gsl_vector x_
x_.size = 0;
x_.stride = 1;
x_.data = 0;
x_.block = 0;
x_.owner = 0;
}
LuSolver::~LuSolver()
{
if (n_ > 0) {
if (luPtr_) gsl_matrix_free(luPtr_);
if (gMatInverse_) gsl_matrix_free(gMatInverse_);
if (permPtr_) gsl_permutation_free(permPtr_);
}
}
/*
* Allocate memory and set n.
*/
void LuSolver::allocate(int n)
{
UTIL_CHECK(n > 0);
UTIL_CHECK(n_ == 0);
UTIL_CHECK(luPtr_ == 0);
UTIL_CHECK(permPtr_ == 0);
luPtr_ = gsl_matrix_alloc(n, n);
gMatInverse_ = gsl_matrix_alloc(n, n);
permPtr_ = gsl_permutation_alloc(n);
b_.size = n;
x_.size = n;
n_ = n;
}
/*
* Compute the LU decomposition for later use.
*/
void LuSolver::computeLU(const Matrix<double>& A)
{
UTIL_CHECK(n_ > 0);
UTIL_CHECK(A.capacity1() == n_);
UTIL_CHECK(A.capacity2() == n_);
int i, j;
int k = 0;
for (i = 0; i < n_; ++i) {
for (j = 0; j < n_; ++j) {
luPtr_->data[k] = A(i,j);
++k;
}
}
gsl_linalg_LU_decomp(luPtr_, permPtr_, &signum_);
}
/*
* Solve Ax = b.
*/
void LuSolver::solve(Array<double>& b, Array<double>& x)
{
UTIL_CHECK(n_ > 0);
UTIL_CHECK(b.capacity() == n_);
UTIL_CHECK(x.capacity() == n_);
// Associate gsl_vectors b_ and x_ with Arrays b and x
b_.data = b.cArray();
x_.data = x.cArray();
// Solve system of equations
gsl_linalg_LU_solve(luPtr_, permPtr_, &b_, &x_);
// Destroy temporary associations
b_.data = 0;
x_.data = 0;
}
/*
* Find inverse
*/
void LuSolver::inverse(Matrix<double>& inv)
{
UTIL_CHECK(n_ > 0);
gMatInverse_->data = inv.cArray();
gsl_linalg_LU_invert(luPtr_, permPtr_, gMatInverse_);
}
}
| 2,402
|
C++
|
.cpp
| 97
| 18.804124
| 67
| 0.527766
|
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,534,931
|
SystemAccess.cpp
|
dmorse_pscfpp/src/fd1d/SystemAccess.cpp
|
/*
* 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 "SystemAccess.h" // header
namespace Pscf {
namespace Fd1d {
using namespace Util;
/*
* Default constructor.
*/
SystemAccess::SystemAccess()
: systemPtr_(0)
{}
/*
* Constructor.
*/
SystemAccess::SystemAccess(System& system)
: systemPtr_(&system)
{}
/**
* Destructor.
*/
SystemAccess::~SystemAccess()
{}
/*
* Set the system pointer.
*/
void SystemAccess::setSystem(System& system)
{ systemPtr_ = &system; }
} // namespace Fd1d
} // namespace Pscf
| 745
|
C++
|
.cpp
| 34
| 18.588235
| 67
| 0.648649
|
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,534,932
|
System.cpp
|
dmorse_pscfpp/src/fd1d/System.cpp
|
/*
* 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"
#include <fd1d/iterator/Iterator.h>
#include <fd1d/iterator/IteratorFactory.h>
#include <fd1d/sweep/Sweep.h>
#include <fd1d/sweep/SweepFactory.h>
#include <fd1d/iterator/NrIterator.h>
#include <fd1d/misc/HomogeneousComparison.h>
#include <fd1d/misc/FieldIo.h>
#include <pscf/inter/Interaction.h>
#include <pscf/inter/Interaction.h>
#include <pscf/homogeneous/Clump.h>
#include <util/format/Str.h>
#include <util/format/Int.h>
#include <util/format/Dbl.h>
#include <util/param/BracketPolicy.h>
#include <util/misc/ioUtil.h>
#include <string>
#include <unistd.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/*
* Constructor.
*/
System::System()
: mixture_(),
domain_(),
fileMaster_(),
fieldIo_(),
homogeneous_(),
interactionPtr_(0),
iteratorPtr_(0),
iteratorFactoryPtr_(0),
sweepPtr_(0),
sweepFactoryPtr_(0),
wFields_(),
cFields_(),
f_(),
c_(),
fHelmholtz_(0.0),
fIdeal_(0.0),
fInter_(0.0),
pressure_(0.0),
hasMixture_(0),
hasDomain_(0),
hasFields_(0),
hasSweep_(0)
{
setClassName("System");
fieldIo_.associate(domain_, fileMaster_);
interactionPtr_ = new Interaction();
iteratorFactoryPtr_ = new IteratorFactory(*this);
sweepFactoryPtr_ = new SweepFactory(*this);
BracketPolicy::set(BracketPolicy::Optional);
}
/*
* Destructor.
*/
System::~System()
{
if (interactionPtr_) {
delete interactionPtr_;
}
if (iteratorPtr_) {
delete iteratorPtr_;
}
if (iteratorFactoryPtr_) {
delete iteratorFactoryPtr_;
}
if (sweepPtr_) {
delete sweepPtr_;
}
if (sweepFactoryPtr_) {
delete sweepFactoryPtr_;
}
}
/*
* Process command line options.
*/
void System::setOptions(int argc, char **argv)
{
bool eflag = false; // echo
bool pFlag = false; // param file
bool cFlag = false; // command file
bool iFlag = false; // input prefix
bool oFlag = false; // output prefix
char* pArg = 0;
char* cArg = 0;
char* iArg = 0;
char* oArg = 0;
// Read program arguments
int c;
opterr = 0;
while ((c = getopt(argc, argv, "er:p:c:i:o:f")) != -1) {
switch (c) {
case 'e':
eflag = true;
break;
case 'p': // parameter file
pFlag = true;
pArg = optarg;
break;
case 'c': // command file
cFlag = true;
cArg = optarg;
break;
case 'i': // input prefix
iFlag = true;
iArg = optarg;
break;
case 'o': // output prefix
oFlag = true;
oArg = optarg;
break;
case '?':
Log::file() << "Unknown option -" << optopt << std::endl;
UTIL_THROW("Invalid command line option");
}
}
// Set flag to echo parameters as they are read.
if (eflag) {
Util::ParamComponent::setEcho(true);
}
// If option -p, set parameter file name
if (pFlag) {
fileMaster().setParamFileName(std::string(pArg));
}
// If option -c, set command file name
if (cFlag) {
fileMaster().setCommandFileName(std::string(cArg));
}
// If option -i, set path prefix for input files
if (iFlag) {
fileMaster().setInputPrefix(std::string(iArg));
}
// If option -o, set path prefix for output files
if (oFlag) {
fileMaster().setOutputPrefix(std::string(oArg));
}
}
/*
* Read parameters and initialize.
*/
void System::readParameters(std::istream& in)
{
readParamComposite(in, mixture());
hasMixture_ = true;
// Initialize homogeneous object
int nm = mixture().nMonomer();
int np = mixture().nPolymer();
int ns = mixture().nSolvent();
homogeneous_.setNMolecule(np+ns);
homogeneous_.setNMonomer(nm);
initHomogeneous();
interaction().setNMonomer(mixture().nMonomer());
readParamComposite(in, interaction());
readParamComposite(in, domain());
hasDomain_ = true;
allocateFields();
// Instantiate and initialize an Iterator
std::string className;
bool isEnd;
iteratorPtr_ = iteratorFactoryPtr_->readObject(in, *this,
className, isEnd);
if (!iteratorPtr_) {
std::string msg = "Unrecognized Iterator subclass name ";
msg += className;
UTIL_THROW(msg.c_str());
}
// Optionally instantiate and initialize a Sweep object
sweepPtr_ =
sweepFactoryPtr_->readObjectOptional(in, *this, className, isEnd);
if (sweepPtr_) {
hasSweep_ = true;
sweepPtr_->setSystem(*this);
} else {
hasSweep_ = false;
}
}
/*
* Read default parameter file.
*/
void System::readParam(std::istream& in)
{
readBegin(in, className().c_str());
readParameters(in);
readEnd(in);
}
/*
* Read default parameter file.
*/
void System::readParam()
{ readParam(fileMaster().paramFile()); }
/*
* Write parameter file, omitting the sweep block.
*/
void System::writeParamNoSweep(std::ostream& out) const
{
out << "System{" << std::endl;
mixture_.writeParam(out);
interactionPtr_->writeParam(out);
domain_.writeParam(out);
iteratorPtr_->writeParam(out);
out << "}" << std::endl;
}
/*
* Allocate memory for fields.
*/
void System::allocateFields()
{
// Preconditions
UTIL_CHECK(hasMixture_);
UTIL_CHECK(hasDomain_);
// Allocate memory in mixture
mixture().setDomain(domain());
// Allocate wFields and cFields
int nMonomer = mixture().nMonomer();
wFields_.allocate(nMonomer);
cFields_.allocate(nMonomer);
int nx = domain().nx();
for (int i = 0; i < nMonomer; ++i) {
wField(i).allocate(nx);
cField(i).allocate(nx);
}
hasFields_ = true;
}
/*
* Read and execute commands from a specified command file.
*/
void System::readCommands(std::istream &in)
{
UTIL_CHECK(hasMixture_);
UTIL_CHECK(hasDomain_);
std::string command;
std::string filename;
std::istream& inBuffer = in;
bool readNext = true;
while (readNext) {
inBuffer >> command;
if (inBuffer.eof()) {
break;
} else {
Log::file() << command;
}
if (command == "FINISH") {
Log::file() << std::endl;
readNext = false;
} else
if (command == "READ_W") {
readEcho(inBuffer, filename);
fieldIo_.readFields(wFields(), filename);
} else
if (command == "COMPUTE") {
// Solve the modified diffusion equation, without iteration
Log::file() << std::endl;
compute();
} else
if (command == "ITERATE") {
// Attempt iteratively solve a single SCFT problem
bool isContinuation = false;
int fail = iterate(isContinuation);
if (fail) {
readNext = false;
}
} else
if (command == "SWEEP") {
// Attempt to solve a sequence of SCFT problems along a line
// through parameter space.
sweep();
} else
if (command == "WRITE_PARAM") {
readEcho(inBuffer, filename);
std::ofstream file;
fileMaster().openOutputFile(filename, file);
writeParam(file);
file.close();
} else
if (command == "WRITE_THERMO") {
readEcho(inBuffer, filename);
std::ofstream file;
fileMaster().openOutputFile(filename, file, std::ios_base::app);
writeThermo(file);
file.close();
} else
if (command == "COMPARE_HOMOGENEOUS") {
int mode;
inBuffer >> mode;
Log::file() << std::endl;
Log::file() << "mode = " << mode << std::endl;
HomogeneousComparison comparison(*this);
comparison.compute(mode);
comparison.output(mode, Log::file());
} else
if (command == "WRITE_W") {
readEcho(inBuffer, filename);
fieldIo_.writeFields(wFields(), filename);
} else
if (command == "WRITE_C") {
readEcho(inBuffer, filename);
fieldIo_.writeFields(cFields(), filename);
} else
if (command == "WRITE_BLOCK_C") {
readEcho(inBuffer, filename);
fieldIo_.writeBlockCFields(mixture_, filename);
} else
if (command == "WRITE_Q_SLICE") {
int polymerId, blockId, directionId, segmentId;
readEcho(inBuffer, filename);
inBuffer >> polymerId;
inBuffer >> blockId;
inBuffer >> directionId;
inBuffer >> segmentId;
Log::file() << Str("polymer ID ", 21) << polymerId << "\n"
<< Str("block ID ", 21) << blockId << "\n"
<< Str("direction ID ", 21) << directionId << "\n"
<< Str("segment ID ", 21) << segmentId << std::endl;
writeQSlice(filename, polymerId, blockId, directionId,
segmentId);
} else
if (command == "WRITE_Q_TAIL") {
readEcho(inBuffer, filename);
int polymerId, blockId, directionId;
inBuffer >> polymerId;
inBuffer >> blockId;
inBuffer >> directionId;
Log::file() << Str("polymer ID ", 21) << polymerId << "\n"
<< Str("block ID ", 21) << blockId << "\n"
<< Str("direction ID ", 21) << directionId << "\n";
writeQTail(filename, polymerId, blockId, directionId);
} else
if (command == "WRITE_Q_VERTEX") {
int polymerId, vertexId;
inBuffer >> polymerId;
Log::file() << std::endl;
Log::file() << "polymerId = "
<< Int(polymerId, 5) << std::endl;
inBuffer >> vertexId;
Log::file() << "vertexId = "
<< Int(vertexId, 5) << std::endl;
inBuffer >> filename;
Log::file() << "outfile = "
<< Str(filename, 20) << std::endl;
fieldIo_.writeVertexQ(mixture_, polymerId, vertexId, filename);
} else
if (command == "WRITE_Q") {
readEcho(inBuffer, filename);
int polymerId, blockId, directionId;
inBuffer >> polymerId;
inBuffer >> blockId;
inBuffer >> directionId;
Log::file() << Str("polymer ID ", 21) << polymerId << "\n"
<< Str("block ID ", 21) << blockId << "\n"
<< Str("direction ID ", 21) << directionId << "\n";
writeQ(filename, polymerId, blockId, directionId);
} else
if (command == "WRITE_Q_ALL") {
readEcho(inBuffer, filename);
writeQAll(filename);
} else
if (command == "REMESH_W") {
int nx;
inBuffer >> nx;
Log::file() << std::endl;
Log::file() << "nx = " << Int(nx, 20) << std::endl;
inBuffer >> filename;
Log::file() << "outfile = " << Str(filename, 20) << std::endl;
fieldIo_.remesh(wFields(), nx, filename);
} else
if (command == "EXTEND_W") {
int m;
inBuffer >> m;
Log::file() << std::endl;
Log::file() << "m = " << Int(m, 20) << std::endl;
inBuffer >> filename;
Log::file() << "outfile = " << Str(filename, 20) << std::endl;
fieldIo_.extend(wFields(), m, filename);
} else {
Log::file() << " Error: Unknown command "
<< command << std::endl;
readNext = false;
}
}
}
/*
* Read and execute commands from the default command file.
*/
void System::readCommands()
{
if (fileMaster().commandFileName().empty()) {
UTIL_THROW("Empty command file name");
}
readCommands(fileMaster().commandFile());
}
/*
* Read a string (e.g., a filename) and echo to the log file.
*/
void System::readEcho(std::istream& in, std::string& string) const
{
in >> string;
Log::file() << " " << Str(string, 20) << std::endl;
}
// Primary SCFT Computations
/*
* Solve MDE for current w-fields, without iteration.
*/
void System::compute()
{
//UTIL_CHECK(hasWFields_);
// Solve the modified diffusion equation (without iteration)
mixture_.compute(wFields(), cFields_);
//hasCFields_ = true;
}
/*
* Iteratively solve a SCFT problem for specified parameters.
*/
int System::iterate(bool isContinuation)
{
// UTIL_CHECK(hasWFields_);
// hasCFields_ = false;
Log::file() << std::endl;
// Call iterator (return 0 for convergence, 1 for failure)
int error = iterator().solve(isContinuation);
//hasCFields_ = true;
// If converged, compute related properties
if (!error) {
computeFreeEnergy();
writeThermo(Log::file());
}
return error;
}
/*
* Perform sweep along a line in parameter space.
*/
void System::sweep()
{
//UTIL_CHECK(hasWFields_);
UTIL_CHECK(sweepPtr_);
Log::file() << std::endl;
Log::file() << std::endl;
sweepPtr_->sweep();
}
// Thermodynamic properties
/*
* Compute Helmholtz free energy and pressure
*/
void System::computeFreeEnergy()
{
fHelmholtz_ = 0.0;
int np = mixture().nPolymer();
int ns = mixture().nSolvent();
int nm = mixture().nMonomer();
double phi, mu;
// Polymeric ideal gas contributions to fHelhmoltz_
if (np > 0) {
Polymer* polymerPtr;
double length;
for (int i = 0; i < np; ++i) {
polymerPtr = &mixture().polymer(i);
phi = polymerPtr->phi();
mu = polymerPtr->mu();
// Recall: mu = ln(phi/q)
length = polymerPtr->length();
if (phi > 1E-08) {
fHelmholtz_ += phi*( mu - 1.0 )/length;
}
}
}
// Solvent ideal gas contributions to fHelhmoltz_
if (ns > 0) {
Solvent* solventPtr;
double size;
for (int i = 0; i < ns; ++i) {
solventPtr = &mixture().solvent(i);
phi = solventPtr->phi();
mu = solventPtr->mu();
// Recall: mu = ln(phi/q)
size = solventPtr->size();
if (phi > 1E-08) {
fHelmholtz_ += phi*( mu - 1.0 )/size;
}
}
}
// Apply Legendre transform subtraction
for (int i = 0; i < nm; ++i) {
fHelmholtz_ -=
domain().innerProduct(wFields_[i], cFields_[i]);
}
fIdeal_ = fHelmholtz_;
// Add average interaction free energy density per monomer
int nx = domain().nx();
if (!f_.isAllocated()) f_.allocate(nx);
if (!c_.isAllocated()) c_.allocate(nm);
int j;
for (int i = 0; i < nx; ++i) {
// Store c_[j] = local concentration of species j
for (j = 0; j < nm; ++j) {
c_[j] = cFields_[j][i];
}
// Compute f_[i] = excess free eenrgy at grid point i
f_[i] = interaction().fHelmholtz(c_);
}
fHelmholtz_ += domain().spatialAverage(f_);
fInter_ = fHelmholtz_ - fIdeal_;
// Compute pressure
pressure_ = -fHelmholtz_;
if (np > 0) {
double length;
Polymer* polymerPtr;
for (int i = 0; i < np; ++i) {
polymerPtr = & mixture().polymer(i);
phi = polymerPtr->phi();
mu = polymerPtr->mu();
length = polymerPtr->length();
if (phi > 1E-08) {
pressure_ += phi*mu/length;
}
}
}
if (ns > 0) {
double size;
Solvent* solventPtr;
for (int i = 0; i < ns; ++i) {
solventPtr = & mixture().solvent(i);
phi = solventPtr->phi();
mu = solventPtr->mu();
size = solventPtr->size();
if (phi > 1E-08) {
pressure_ += phi*mu/size;
}
}
}
}
void System::initHomogeneous()
{
// Set number of molecular species and monomers
int nm = mixture().nMonomer();
int np = mixture().nPolymer();
int ns = mixture().nSolvent();
UTIL_CHECK(homogeneous_.nMolecule() == np + ns);
UTIL_CHECK(homogeneous_.nMonomer() == nm);
// Allocate c_ work array, if necessary
if (c_.isAllocated()) {
UTIL_CHECK(c_.capacity() == nm);
} else {
c_.allocate(nm);
}
int i; // molecule index
int j; // monomer index
int k; // block or clump index
int nb; // number of blocks
int nc; // number of clumps
// Loop over polymer molecule species
if (np > 0) {
for (i = 0; i < np; ++i) {
// Initial array of clump sizes
for (j = 0; j < nm; ++j) {
c_[j] = 0.0;
}
// Compute clump sizes for all monomer types.
nb = mixture().polymer(i).nBlock();
for (k = 0; k < nb; ++k) {
Block& block = mixture().polymer(i).block(k);
j = block.monomerId();
c_[j] += block.length();
}
// Count the number of clumps of nonzero size
nc = 0;
for (j = 0; j < nm; ++j) {
if (c_[j] > 1.0E-8) {
++nc;
}
}
homogeneous_.molecule(i).setNClump(nc);
// Set clump properties for this Homogeneous::Molecule
k = 0; // Clump index
for (j = 0; j < nm; ++j) {
if (c_[j] > 1.0E-8) {
homogeneous_.molecule(i).clump(k).setMonomerId(j);
homogeneous_.molecule(i).clump(k).setSize(c_[j]);
++k;
}
}
homogeneous_.molecule(i).computeSize();
}
}
// Add solvent contributions
if (np > 0) {
double size;
int monomerId;
for (int is = 0; is < ns; ++is) {
i = is + np;
monomerId = mixture().solvent(is).monomerId();
size = mixture().solvent(is).size();
homogeneous_.molecule(i).setNClump(1);
homogeneous_.molecule(i).clump(0).setMonomerId(monomerId);
homogeneous_.molecule(i).clump(0).setSize(size);
homogeneous_.molecule(i).computeSize();
}
}
}
void System::writeThermo(std::ostream& out)
{
out << std::endl;
out << "fHelmholtz " << Dbl(fHelmholtz(), 18, 11) << std::endl;
out << "pressure " << Dbl(pressure(), 18, 11) << std::endl;
out << std::endl;
out << "fIdeal " << Dbl(fIdeal_, 18, 11) << std::endl;
out << "fInter " << Dbl(fInter_, 18, 11) << std::endl;
out << std::endl;
// Polymers
int np = mixture().nPolymer();
if (np > 0) {
out << "polymers:" << std::endl;
out << " "
<< " phi "
<< " mu "
<< std::endl;
for (int i = 0; i < np; ++i) {
out << Int(i, 5)
<< " " << Dbl(mixture().polymer(i).phi(),18, 11)
<< " " << Dbl(mixture().polymer(i).mu(), 18, 11)
<< std::endl;
}
out << std::endl;
}
// Solvents
int ns = mixture().nSolvent();
if (ns > 0) {
out << "solvents:" << std::endl;
out << " "
<< " phi "
<< " mu "
<< std::endl;
for (int i = 0; i < ns; ++i) {
out << Int(i, 5)
<< " " << Dbl(mixture().solvent(i).phi(),18, 11)
<< " " << Dbl(mixture().solvent(i).mu(), 18, 11)
<< std::endl;
}
out << std::endl;
}
}
// Output operations (correspond to command file commands)
/*
* Write w-fields in symmetry-adapted basis format.
*/
void System::writeW(std::string const & filename)
{
//UTIL_CHECK(hasWFields_);
fieldIo_.writeFields(wFields(), filename);
}
/*
* Write all concentration fields in symmetry-adapted basis format.
*/
void System::writeC(std::string const & filename)
{
//UTIL_CHECK(hasCFields_);
fieldIo_.writeFields(cFields(), filename);
}
/*
* Write all concentration fields in real space (r-grid) format, for
* each block (or solvent) individually rather than for each species.
*/
void System::writeBlockC(std::string const & filename)
{
//UTIL_CHECK(hasCFields_);
fieldIo_.writeBlockCFields(mixture_, filename);
}
/*
* Write the last time slice of the propagator in r-grid format.
*/
void System::writeQSlice(const std::string & filename,
int polymerId, int blockId,
int directionId, int segmentId)
const
{
UTIL_CHECK(polymerId >= 0);
UTIL_CHECK(polymerId < mixture_.nPolymer());
Polymer const& polymer = mixture_.polymer(polymerId);
UTIL_CHECK(blockId >= 0);
UTIL_CHECK(blockId < polymer.nBlock());
UTIL_CHECK(directionId >= 0);
UTIL_CHECK(directionId <= 1);
Propagator const &
propagator = polymer.propagator(blockId, directionId);
Field const& field = propagator.q(segmentId);
fieldIo_.writeField(field, filename);
}
/*
* Write the last time slice of the propagator in r-grid format.
*/
void System::writeQTail(const std::string & filename,
int polymerId, int blockId, int directionId)
const
{
UTIL_CHECK(polymerId >= 0);
UTIL_CHECK(polymerId < mixture_.nPolymer());
Polymer const& polymer = mixture_.polymer(polymerId);
UTIL_CHECK(blockId >= 0);
UTIL_CHECK(blockId < polymer.nBlock());
UTIL_CHECK(directionId >= 0);
UTIL_CHECK(directionId <= 1);
Field const&
field = polymer.propagator(blockId, directionId).tail();
fieldIo_.writeField(field, filename);
}
/*
* Write the propagator for a block and direction.
*/
void System::writeQ(const std::string & filename,
int polymerId, int blockId, int directionId)
const
{
UTIL_CHECK(polymerId >= 0);
UTIL_CHECK(polymerId < mixture_.nPolymer());
Polymer const& polymer = mixture_.polymer(polymerId);
UTIL_CHECK(blockId >= 0);
UTIL_CHECK(blockId < polymer.nBlock());
UTIL_CHECK(directionId >= 0);
UTIL_CHECK(directionId <= 1);
Propagator const& propagator
= polymer.propagator(blockId, directionId);
int nslice = propagator.ns();
// Open file
std::ofstream file;
fileMaster_.openOutputFile(filename, file);
// Write header
file << "ngrid" << std::endl
<< " " << domain_.nx() << std::endl
<< "nslice" << std::endl
<< " " << nslice << std::endl;
// Write data
bool hasHeader = false;
for (int i = 0; i < nslice; ++i) {
file << "slice " << i << std::endl;
Field const& field = propagator.q(i);
fieldIo_.writeField(field, file, hasHeader);
}
file.close();
}
/*
* Write propagators for all blocks of all polymers to files.
*/
void System::writeQAll(std::string const & basename)
{
std::string filename;
int np, nb, ip, ib, id;
np = mixture_.nPolymer();
for (ip = 0; ip < np; ++ip) {
nb = mixture_.polymer(ip).nBlock();
for (ib = 0; ib < nb; ++ib) {
for (id = 0; id < 2; ++id) {
filename = basename;
filename += "_";
filename += toString(ip);
filename += "_";
filename += toString(ib);
filename += "_";
filename += toString(id);
//filename += ".q";
writeQ(filename, ip, ib, id);
}
}
}
}
} // namespace Fd1d
} // namespace Pscf
| 25,344
|
C++
|
.cpp
| 774
| 23.593023
| 77
| 0.516777
|
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,534,933
|
pscf_fd.cpp
|
dmorse_pscfpp/src/fd1d/pscf_fd.cpp
|
/*
* 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/System.h>
int main(int argc, char **argv)
{
Pscf::Fd1d::System system;
// Process command line options
system.setOptions(argc, argv);
// Read parameters from default parameter file
system.readParam();
// Read command script to run system
system.readCommands();
return 0;
}
| 505
|
C++
|
.cpp
| 18
| 25.388889
| 67
| 0.740125
|
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,534,934
|
IteratorFactory.cpp
|
dmorse_pscfpp/src/fd1d/iterator/IteratorFactory.cpp
|
#include "IteratorFactory.h"
// Subclasses of Iterator
#include "NrIterator.h"
#include "AmIterator.h"
#include "BinaryRelaxIterator.h"
namespace Pscf {
namespace Fd1d {
using namespace Util;
/*
* Constructor
*/
IteratorFactory::IteratorFactory(System& system)
: sysPtr_(&system)
{}
/*
* Return a pointer to a instance of Iterator subclass className.
*/
Iterator* IteratorFactory::factory(const std::string &className) const
{
Iterator* ptr = 0;
// Try subfactories first
ptr = trySubfactories(className);
if (ptr) return ptr;
// Try to match classname
if (className == "Iterator" || className == "AmIterator") {
ptr = new AmIterator(*sysPtr_);
} else if (className == "NrIterator") {
ptr = new NrIterator(*sysPtr_);
} else if (className == "BinaryRelaxIterator") {
ptr = new BinaryRelaxIterator(*sysPtr_);
}
return ptr;
}
}
}
| 969
|
C++
|
.cpp
| 35
| 22.628571
| 73
| 0.647186
|
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,534,935
|
BinaryRelaxIterator.cpp
|
dmorse_pscfpp/src/fd1d/iterator/BinaryRelaxIterator.cpp
|
/*
* 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 "BinaryRelaxIterator.h"
#include <fd1d/System.h>
#include <pscf/inter/Interaction.h>
#include <util/misc/Log.h>
#include <util/misc/Timer.h>
#include <math.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
// Constructor
BinaryRelaxIterator::BinaryRelaxIterator(System& system)
: Iterator(system),
epsilon_(0.0),
lambdaPlus_(0.0),
lambdaMinus_(0.0),
maxItr_(200),
isAllocated_(false),
isCanonical_(true)
{ setClassName("BinaryRelaxIterator"); }
// Destructor
BinaryRelaxIterator::~BinaryRelaxIterator()
{}
// Read parameter file block and allocate memory
void BinaryRelaxIterator::readParameters(std::istream& in)
{
UTIL_CHECK(domain().nx() > 0);
read(in, "epsilon", epsilon_);
read(in, "maxIter", maxItr_);
read(in, "lambdaPlus", lambdaPlus_);
read(in, "lambdaMinus", lambdaMinus_);
allocate();
}
// Allocate required memory (called by readParameters)
void BinaryRelaxIterator::allocate()
{
if (isAllocated_) return;
int nm = mixture().nMonomer(); // number of monomer types
UTIL_CHECK(nm == 2);
int nx = domain().nx(); // number of grid points
UTIL_CHECK(nx > 0);
cArray_.allocate(nm);
wArray_.allocate(nm);
dW_.allocate(nm);
dWNew_.allocate(nm);
wFieldsNew_.allocate(nm);
cFieldsNew_.allocate(nm);
for (int i = 0; i < nm; ++i) {
wFieldsNew_[i].allocate(nx);
cFieldsNew_[i].allocate(nx);
dW_[i].allocate(nx);
dWNew_[i].allocate(nx);
}
isAllocated_ = true;
}
void BinaryRelaxIterator::computeDW(Array<WField> const & wOld,
Array<CField> const & cFields,
Array<WField> & dW,
double & dWNorm)
{
double dWm, dWp, c0, c1, w0, w1, wm;
double dWmNorm = 0.0;
double dWpNorm = 0.0;
double chi = system().interaction().chi(0,1);
int nx = domain().nx(); // number of grid points
//For AB diblok
for (int i = 0; i < nx; ++i) {
c0 = cFields[0][i];
c1 = cFields[1][i];
w0 = wOld[0][i];
w1 = wOld[1][i];
wm = w1 - w0;
dWp = c1 + c0 - 1.0;
dWm = 0.5*( c0 - c1 - wm/chi);
dWpNorm += dWp*dWp;
dWmNorm += dWm*dWm;
dWp *= lambdaPlus_;
dWm *= lambdaMinus_;
dW[0][i] = dWp - dWm;
dW[1][i] = dWp + dWm;
}
dWNorm = (dWpNorm + dWmNorm)/double(nx);
dWNorm = sqrt(dWNorm);
}
void BinaryRelaxIterator::updateWFields(Array<WField> const & wOld,
Array<WField> const & dW,
Array<WField> & wNew)
{
int nm = mixture().nMonomer(); // number of monomer types
UTIL_CHECK(nm == 2);
int nx = domain().nx(); // number of grid points
int i; // monomer index
int j; // grid point index
double w0, w1;
// Add dW
for (j = 0; j < nx; j++){
w0 = wOld[0][j];
w1 = wOld[1][j];
wNew[0][j] = w0 + dW[0][j];
wNew[1][j] = w1 + dW[1][j];
}
// If canonical, shift such that last element is exactly zero
if (isCanonical_) {
double shift = wNew[nm-1][nx-1];
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wNew[i][j] -= shift;
}
}
}
}
int BinaryRelaxIterator::solve(bool isContinuation)
{
//Declare Timer
Timer timerTotal;
int nm = mixture().nMonomer(); // number of monomer types
UTIL_CHECK(nm == 2);
int np = mixture().nPolymer(); // number of polymer species
int nx = domain().nx(); // number of grid points
// Start overall timer
timerTotal.start();
// Determine if isCanonical (iff all species ensembles are closed)
isCanonical_ = true;
Species::Ensemble ensemble;
for (int i = 0; i < np; ++i) {
ensemble = mixture().polymer(i).ensemble();
if (ensemble == Species::Unknown) {
UTIL_THROW("Unknown species ensemble");
}
if (ensemble == Species::Open) {
isCanonical_ = false;
}
}
// If isCanonical, shift so that last element is zero.
// Note: This is one of the residuals in this case.
if (isCanonical_) {
double shift = wFields()[nm-1][nx-1];
int i, j;
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wFields()[i][j] -= shift;
}
}
}
// Compute initial dWNorm.
mixture().compute(system().wFields(), system().cFields());
computeDW(system().wFields(), system().cFields(), dW_, dWNorm_);
// Iterative loop
int i, j, k;
for (i = 0; i < maxItr_; ++i) {
Log::file() << "iteration " << i
<< " , error = " << dWNorm_
<< std::endl;
if (dWNorm_ < epsilon_) {
// Stop timers
timerTotal.stop();
Log::file() << "The epsilon is " << epsilon_<< std::endl;
Log::file() << "Converged" << std::endl;
system().computeFreeEnergy();
// Success
Log::file() << "\n\n";
// Output timing resultsl;
Log::file() << "Total time: "
<< timerTotal.time() << " s " << std::endl;
Log::file() << "Average time cost of each iteration: "
<< timerTotal.time()/i << " s " << std::endl;
Log::file() << "\n\n";
return 0;
}
// Try full Fd relaxation update
updateWFields(system().wFields(), dW_, wFieldsNew_);
mixture().compute(wFieldsNew_, cFieldsNew_);
computeDW(wFieldsNew_, cFieldsNew_, dWNew_, dWNormNew_);
// Decrease increment if necessary
j = 0;
while (dWNormNew_ > dWNorm_ && j < 3) {
//double dWNormDecrease_;
Log::file() << " error = "
<< dWNormNew_ << ", decreasing increment" << std::endl;
lambdaPlus_ *= 0.5;
lambdaMinus_ *= 0.5;
//Print lambdaPlus_ and lambdaMinus_
Log::file() << " lambdaPlus = "
<< lambdaPlus_ << std::endl;
Log::file() << " lambdaMinus = "
<< lambdaMinus_<< std::endl;
computeDW(system().wFields(),system().cFields(), dWNew_,
dWNormNew_);
updateWFields(system().wFields(), dWNew_, wFieldsNew_);
mixture().compute(wFieldsNew_, cFieldsNew_);
++j;
}
// Accept or reject update
if (dWNormNew_ < dWNorm_) {
// Update system fields
for (j = 0; j < nm; ++j) {
for (k = 0; k < nx; ++k) {
system().wField(j)[k] = wFieldsNew_[j][k];
system().cField(j)[k] = cFieldsNew_[j][k];
dW_[j][k] = dWNew_[j][k];
}
dWNorm_ = dWNormNew_;
}
} else {
Log::file() << "Iteration failed, norm = "
<< dWNormNew_ << std::endl;
break;
}
}
// Failure
return 1;
}
} // namespace Fd1d
} // namespace Pscf
| 7,847
|
C++
|
.cpp
| 220
| 25.677273
| 79
| 0.496603
|
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,534,936
|
NrIterator.cpp
|
dmorse_pscfpp/src/fd1d/iterator/NrIterator.cpp
|
/*
* 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 "NrIterator.h"
#include <fd1d/System.h>
#include <pscf/inter/Interaction.h>
#include <util/misc/Log.h>
#include <math.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
NrIterator::NrIterator()
: Iterator(),
epsilon_(0.0),
maxItr_(0),
isAllocated_(false),
newJacobian_(false),
needsJacobian_(true),
isCanonical_(true)
{ setClassName("NrIterator"); }
NrIterator::NrIterator(System& system)
: Iterator(system),
epsilon_(0.0),
maxItr_(0),
isAllocated_(false),
newJacobian_(false),
needsJacobian_(true),
isCanonical_(true)
{ setClassName("NrIterator"); }
NrIterator::~NrIterator()
{}
void NrIterator::readParameters(std::istream& in)
{
maxItr_ = 400;
read(in, "epsilon", epsilon_);
readOptional(in, "maxItr", maxItr_);
setup();
}
void NrIterator::setup()
{
int nm = system().mixture().nMonomer(); // number of monomer types
int nx = domain().nx(); // number of grid points
UTIL_CHECK(nm > 0);
UTIL_CHECK(nx > 0);
int nr = nm*nx; // number of residual components
if (isAllocated_) {
UTIL_CHECK(cArray_.capacity() == nm);
UTIL_CHECK(residual_.capacity() == nr);
} else {
cArray_.allocate(nm);
wArray_.allocate(nm);
residual_.allocate(nr);
jacobian_.allocate(nr, nr);
residualNew_.allocate(nr);
dOmega_.allocate(nr);
wFieldsNew_.allocate(nm);
cFieldsNew_.allocate(nm);
for (int i = 0; i < nm; ++i) {
wFieldsNew_[i].allocate(nx);
cFieldsNew_[i].allocate(nx);
}
solver_.allocate(nr);
isAllocated_ = true;
}
}
void NrIterator::computeResidual(Array<WField> const & wFields,
Array<CField> const & cFields,
Array<double>& residual)
{
int nm = system().mixture().nMonomer(); // number of monomer types
int nx = domain().nx(); // number of grid points
int i; // grid point index
int j; // monomer indices
int ir; // residual index
// Loop over grid points
for (i = 0; i < nx; ++i) {
// Copy volume fractions at grid point i to cArray_
for (j = 0; j < nm; ++j) {
cArray_[j] = cFields[j][i];
}
// Compute w fields, without Langrange multiplier, from c fields
system().interaction().computeW(cArray_, wArray_);
// Initial residual = wPredicted(from above) - actual w
for (j = 0; j < nm; ++j) {
ir = j*nx + i;
residual[ir] = wArray_[j] - wFields[j][i];
}
// Residuals j = 1, ..., nm-1 are differences from component j=0
for (j = 1; j < nm; ++j) {
ir = j*nx + i;
residual[ir] = residual[ir] - residual[i];
}
// Residual for component j=0 then imposes incompressiblity
residual[i] = -1.0;
for (j = 0; j < nm; ++j) {
residual[i] += cArray_[j];
}
}
/*
* Note: In canonical ensemble, the spatial integral of the
* incompressiblity residual is guaranteed to be zero, as a result of how
* volume fractions are computed in SCFT. One of the nx incompressibility
* constraints is thus redundant. To avoid this redundancy, replace the
* incompressibility residual at the last grid point by a residual that
* requires the w field for the last monomer type at the last grid point
* to equal zero.
*/
if (isCanonical_) {
residual[nx-1] = wFields[nm-1][nx-1];
}
}
/*
* Compute Jacobian matrix numerically, by evaluating finite differences.
*/
void NrIterator::computeJacobian()
{
int nm = system().mixture().nMonomer(); // number of monomer types
int nx = domain().nx(); // number of grid points
int i; // monomer index
int j; // grid point index
// Copy system().wFields to wFieldsNew.
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
UTIL_CHECK(nx == wFieldsNew_[i].capacity());
UTIL_CHECK(nx == system().wField(i).capacity());
wFieldsNew_[i][j] = system().wField(i)[j];
}
}
// Compute jacobian, column by column
double delta = 0.001;
int nr = nm*nx; // number of residual elements
int jr; // jacobian row index
int jc = 0; // jacobian column index
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wFieldsNew_[i][j] += delta;
system().mixture().compute(wFieldsNew_, cFieldsNew_);
computeResidual(wFieldsNew_, cFieldsNew_, residualNew_);
for (jr = 0; jr < nr; ++jr) {
jacobian_(jr, jc) =
(residualNew_[jr] - residual_[jr])/delta;
}
wFieldsNew_[i][j] = system().wField(i)[j];
++jc;
}
}
// Decompose Jacobian matrix
solver_.computeLU(jacobian_);
}
void NrIterator::incrementWFields(Array<WField> const & wOld,
Array<double> const & dW,
Array<WField> & wNew)
{
int nm = system().mixture().nMonomer(); // number of monomers types
int nx = domain().nx(); // number of grid points
int i; // monomer index
int j; // grid point index
int k = 0; // residual element index
// Add dW
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wNew[i][j] = wOld[i][j] - dW[k];
++k;
}
}
// If canonical, shift such that last element is exactly zero
if (isCanonical_) {
double shift = wNew[nm-1][nx-1];
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wNew[i][j] -= shift;
}
}
}
}
double NrIterator::residualNorm(Array<double> const & residual) const
{
int nm = system().mixture().nMonomer(); // number of monomer types
int nx = domain().nx(); // number of grid points
int nr = nm*nx; // number of residual components
double value, norm;
norm = 0.0;
for (int ir = 0; ir < nr; ++ir) {
value = fabs(residual[ir]);
if (value > norm) {
norm = value;
}
}
return norm;
}
int NrIterator::solve(bool isContinuation)
{
int nm = system().mixture().nMonomer(); // number of monomer types
int np = system().mixture().nPolymer(); // number of polymer species
int nx = domain().nx(); // number of grid points
int nr = nm*nx; // number of residual elements
// Determine if isCanonical (iff all species ensembles are closed)
isCanonical_ = true;
Species::Ensemble ensemble;
for (int i = 0; i < np; ++i) {
ensemble = system().mixture().polymer(i).ensemble();
if (ensemble == Species::Unknown) {
UTIL_THROW("Unknown species ensemble");
}
if (ensemble == Species::Open) {
isCanonical_ = false;
}
}
// If isCanonical, shift so that last element is zero.
// Note: This is one of the residuals in this case.
if (isCanonical_) {
double shift = wFields()[nm-1][nx-1];
int i, j;
for (i = 0; i < nm; ++i) {
for (j = 0; j < nx; ++j) {
wFields()[i][j] -= shift;
}
}
}
// Compute initial residual vector and norm
system().mixture().compute(system().wFields(), system().cFields());
computeResidual(system().wFields(), system().cFields(), residual_);
double norm = residualNorm(residual_);
// Set Jacobian status
newJacobian_ = false;
if (!isContinuation) {
needsJacobian_ = true;
}
// Iterative loop
double normNew;
int i, j, k;
for (i = 0; i < maxItr_; ++i) {
Log::file() << "iteration " << i
<< " , error = " << norm
<< std::endl;
if (norm < epsilon_) {
Log::file() << "Converged" << std::endl;
system().computeFreeEnergy();
// Success
return 0;
}
if (needsJacobian_) {
Log::file() << "Computing jacobian" << std::endl;;
computeJacobian();
newJacobian_ = true;
needsJacobian_ = false;
}
// Compute Newton-Raphson increment dOmega_
solver_.solve(residual_, dOmega_);
// Try full Newton-Raphson update
incrementWFields(system().wFields(), dOmega_, wFieldsNew_);
system().mixture().compute(wFieldsNew_, cFieldsNew_);
computeResidual(wFieldsNew_, cFieldsNew_, residualNew_);
normNew = residualNorm(residualNew_);
// Decrease increment if necessary
j = 0;
while (normNew > norm && j < 3) {
Log::file() << " decreasing increment, error = "
<< normNew << std::endl;
needsJacobian_ = true;
for (k = 0; k < nr; ++k) {
dOmega_[k] *= 0.66666666;
}
incrementWFields(system().wFields(), dOmega_, wFieldsNew_);
system().mixture().compute(wFieldsNew_, cFieldsNew_);
computeResidual(wFieldsNew_, cFieldsNew_, residualNew_);
normNew = residualNorm(residualNew_);
++j;
}
// If necessary, try reversing direction
if (normNew > norm) {
Log::file() << " reversing increment, norm = "
<< normNew << std::endl;
needsJacobian_ = true;
for (k = 0; k < nr; ++k) {
dOmega_[k] *= -1.000;
}
incrementWFields(system().wFields(), dOmega_, wFieldsNew_);
system().mixture().compute(wFieldsNew_, cFieldsNew_);
computeResidual(wFieldsNew_, cFieldsNew_, residualNew_);
normNew = residualNorm(residualNew_);
}
// Accept or reject update
if (normNew < norm) {
// Update system fields and residual vector
for (j = 0; j < nm; ++j) {
for (k = 0; k < nx; ++k) {
system().wField(j)[k] = wFieldsNew_[j][k];
system().cField(j)[k] = cFieldsNew_[j][k];
}
}
for (j = 0; j < nr; ++j) {
residual_[j] = residualNew_[j];
}
newJacobian_ = false;
if (!needsJacobian_) {
if (normNew/norm > 0.5) {
needsJacobian_ = true;
}
}
norm = normNew;
} else {
Log::file() << "Iteration failed, norm = "
<< normNew << std::endl;
if (newJacobian_) {
return 1;
Log::file() << "Unrecoverable failure " << std::endl;
} else {
Log::file() << "Try rebuilding Jacobian" << std::endl;
needsJacobian_ = true;
}
}
}
// Failure
return 1;
}
} // namespace Fd1d
} // namespace Pscf
| 11,879
|
C++
|
.cpp
| 322
| 27.257764
| 78
| 0.505516
|
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,534,937
|
AmIterator.cpp
|
dmorse_pscfpp/src/fd1d/iterator/AmIterator.cpp
|
/*
* 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 "AmIterator.h"
#include <fd1d/System.h>
#include <pscf/inter/Interaction.h>
#include <pscf/iterator/NanException.h>
#include <util/global.h>
namespace Pscf {
namespace Fd1d{
using namespace Util;
// Constructor
AmIterator::AmIterator(System& system)
: Iterator(system),
interaction_()
{ setClassName("AmIterator"); }
// Destructor
AmIterator::~AmIterator()
{}
// Read parameters from file
void AmIterator::readParameters(std::istream& in)
{
// Call parent class readParameters and readErrorType functions
AmIteratorTmpl<Iterator, DArray<double> >::readParameters(in);
AmIteratorTmpl<Iterator, DArray<double> >::readErrorType(in);
const int nMonomer = system().mixture().nMonomer();
interaction_.setNMonomer(nMonomer);
}
// Setup before entering iteration loop
void AmIterator::setup(bool isContinuation)
{
AmIteratorTmpl<Iterator, DArray<double> >::setup(isContinuation);
interaction_.update(system().interaction());
}
// Assign one vector to another: a = b
void AmIterator::setEqual(DArray<double>& a, DArray<double> const & b)
{ a = b; }
// Compute and return inner product of two vectors
double AmIterator::dotProduct(DArray<double> const & a,
DArray<double> const & b)
{
const int n = a.capacity();
UTIL_CHECK(n == b.capacity());
double product = 0.0;
for (int i = 0; i < n; i++) {
// if either value is NaN, throw NanException
if (std::isnan(a[i]) || std::isnan(b[i])) {
throw NanException("AmIterator::dotProduct",__FILE__,__LINE__,0);
}
product += a[i] * b[i];
}
return product;
}
// Compute and return maximum element of residual vector.
double AmIterator::maxAbs(DArray<double> const & hist)
{
const int n = hist.capacity();
double maxRes = 0.0;
double value;
for (int i = 0; i < n; i++) {
value = hist[i];
if (std::isnan(value)) { // if value is NaN, throw NanException
throw NanException("AmIterator::dotProduct",__FILE__,__LINE__,0);
}
if (fabs(value) > maxRes)
maxRes = fabs(value);
}
return maxRes;
}
// Update basis
void AmIterator::updateBasis(RingBuffer<DArray<double> > & basis,
RingBuffer<DArray<double> > const & hists)
{
// Make sure at least two histories are stored
UTIL_CHECK(hists.size() >= 2);
const int n = hists[0].capacity();
DArray<double> newbasis;
newbasis.allocate(n);
// Basis vector is different of last to vectors
for (int i = 0; i < n; i++) {
newbasis[i] = hists[0][i] - hists[1][i];
}
basis.append(newbasis);
}
// Add linear combination of basis vector to current trial state
void AmIterator::addHistories(DArray<double>& trial,
RingBuffer< DArray<double> > const& basis,
DArray<double> coeffs,
int nHist)
{
int n = trial.capacity();
for (int i = 0; i < nHist; i++) {
for (int j = 0; j < n; j++) {
trial[j] += coeffs[i] * -1 * basis[i][j];
}
}
}
void AmIterator::addPredictedError(DArray<double>& fieldTrial,
DArray<double> const & resTrial,
double lambda)
{
int n = fieldTrial.capacity();
for (int i = 0; i < n; i++) {
fieldTrial[i] += lambda * resTrial[i];
}
}
bool AmIterator::hasInitialGuess()
{
// Fd1d::System doesn't hav a hasFields() function
return true;
}
// Compute and return the number of elements in a field vector
int AmIterator::nElements()
{
const int nm = system().mixture().nMonomer(); // # of monomers
const int nx = domain().nx(); // # of grid points
return nm*nx;
}
// Get the current fields from the system as a 1D array
void AmIterator::getCurrent(DArray<double>& curr)
{
const int nm = system().mixture().nMonomer(); // # of monomers
const int nx = domain().nx(); // # of grid points
const DArray< DArray<double> > * currSys = &system().wFields();
// Straighten out fields into linear arrays
for (int i = 0; i < nm; i++) {
for (int k = 0; k < nx; k++) {
curr[i*nx+k] = (*currSys)[i][k];
}
}
}
// Solve the MDEs for the current system w fields
void AmIterator::evaluate()
{
mixture().compute(system().wFields(), system().cFields());
}
// Check whether Canonical ensemble
bool AmIterator::isCanonical()
{
Species::Ensemble ensemble;
// Check ensemble of all polymers
for (int i = 0; i < mixture().nPolymer(); ++i) {
ensemble = mixture().polymer(i).ensemble();
if (ensemble == Species::Open) {
return false;
}
if (ensemble == Species::Unknown) {
UTIL_THROW("Unknown species ensemble");
}
}
// Check ensemble of all solvents
for (int i = 0; i < mixture().nSolvent(); ++i) {
ensemble = mixture().solvent(i).ensemble();
if (ensemble == Species::Open) {
return false;
}
if (ensemble == Species::Unknown) {
UTIL_THROW("Unknown species ensemble");
}
}
// Return true if no species had an open ensemble
return true;
}
// Compute the residual for the current system state
void AmIterator::getResidual(DArray<double>& resid)
{
const int nm = system().mixture().nMonomer();
const int nx = domain().nx();
const int nr = nm*nx;
// Initialize residuals
const double shift = -1.0/interaction_.sumChiInverse();
for (int i = 0 ; i < nr; ++i) {
resid[i] = shift;
}
// Compute SCF residual vector elements
double chi, p;
int i, j, k;
for (i = 0; i < nm; ++i) {
for (j = 0; j < nm; ++j) {
DArray<double>& cField = system().cField(j);
DArray<double>& wField = system().wField(j);
chi = interaction_.chi(i,j);
p = interaction_.p(i,j);
for (k = 0; k < nx; ++k) {
int idx = i*nx + k;
resid[idx] += chi*cField[k] - p*wField[k];
}
}
}
}
// Update the current system field coordinates
void AmIterator::update(DArray<double>& newGuess)
{
const int nm = mixture().nMonomer(); // # of monomers
const int nx = domain().nx(); // # of grid points
// Set current w fields in system
// If canonical, shift to as to set last element to zero
const double shift = newGuess[nm*nx - 1];
for (int i = 0; i < nm; i++) {
DArray<double>& wField = system().wField(i);
if (isCanonical()) {
for (int k = 0; k < nx; k++) {
wField[k] = newGuess[i*nx + k] - shift;
}
} else {
for (int k = 0; k < nx; k++) {
wField[k] = newGuess[i*nx + k];
}
}
}
}
void AmIterator::outputToLog()
{}
}
}
| 7,537
|
C++
|
.cpp
| 218
| 26.701835
| 77
| 0.559934
|
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,534,938
|
Iterator.cpp
|
dmorse_pscfpp/src/fd1d/iterator/Iterator.cpp
|
/*
* 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/System.h>
#include <fd1d/domain/Domain.h>
#include <fd1d/solvers/Mixture.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
Iterator::Iterator()
{ setClassName("Iterator"); }
Iterator::Iterator(System& system)
: SystemAccess(system)
{ setClassName("Iterator"); }
Iterator::~Iterator()
{}
} // namespace Fd1d
} // namespace Pscf
| 594
|
C++
|
.cpp
| 23
| 23.434783
| 67
| 0.73227
|
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,534,939
|
Block.cpp
|
dmorse_pscfpp/src/fd1d/solvers/Block.cpp
|
/*
* 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 <fd1d/domain/Domain.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/*
* Constructor.
*/
Block::Block()
: domainPtr_(0),
ds_(0.0),
dsTarget_(0.0),
ns_(0)
{
propagator(0).setBlock(*this);
propagator(1).setBlock(*this);
}
/*
* Destructor.
*/
Block::~Block()
{}
void Block::setDiscretization(Domain const & domain, double ds)
{
UTIL_CHECK(length() > 0);
UTIL_CHECK(domain.nx() > 1);
UTIL_CHECK(ds > 0.0);
// Set association to spatial domain
domainPtr_ = &domain;
// Set contour length discretization
dsTarget_ = ds;
ns_ = floor(length()/dsTarget_ + 0.5) + 1;
if (ns_%2 == 0) {
ns_ += 1;
}
ds_ = length()/double(ns_ - 1);
// Allocate all required memory
int nx = domain.nx();
dA_.allocate(nx);
dB_.allocate(nx);
uA_.allocate(nx - 1);
uB_.allocate(nx - 1);
lA_.allocate(nx - 1);
lB_.allocate(nx - 1);
v_.allocate(nx);
solver_.allocate(nx);
propagator(0).allocate(ns_, nx);
propagator(1).allocate(ns_, nx);
cField().allocate(nx);
}
void Block::setLength(double newLength)
{
BlockDescriptor::setLength(newLength);
if (dsTarget_ > 0) { // if setDiscretization has already been called
// Reset contour length discretization
UTIL_CHECK(ns_ > 0);
int oldNs = ns_;
ns_ = floor(length()/dsTarget_ + 0.5) + 1;
if (ns_%2 == 0) {
ns_ += 1;
}
ds_ = length()/double(ns_ - 1);
if (oldNs != ns_) {
// If propagators are already allocated and ns_ has changed,
// reallocate memory for solutions to MDE
propagator(0).reallocate(ns_);
propagator(1).reallocate(ns_);
}
}
}
/*
* Setup the contour length step algorithm.
*
* This implementation uses the Crank-Nicholson algorithm for stepping
* the modified diffusion equation. One step of this algorithm, which
* is implemented by the step() function, solves a matrix equation of
* the form
*
* A q(i) = B q(i-1)
*
* where A and B are domain().nx() x domain().nx() symmetric tridiagonal
* matrices given by
*
* A = 1 + 0.5*ds_*H
* B = 1 - 0.5*ds_*H
*
* in which ds_ is the contour step and
*
* H = -(b^2/6)d^2/dx^2 + w
*
* is a finite difference representation of the "Hamiltonian"
* operator, in which b = kuhn() is the statistical segment length.
*
* This function sets up arrays containing diagonal and off-diagonal
* elements of the matrices A and B, and computes the LU
* decomposition of matrix A. Arrays of domain().nx() diagonal elements
* of A and B are denoted by dA_ and dB_, respectively, while arrays of
* domain().nx() - 1 upper and lower off-diagonal elements of A and B
* are denoted by uA_, lA_, uB_, and lB_, respectively
*/
void Block::setupSolver(DArray<double> const& w)
{
// Preconditions
UTIL_CHECK(domainPtr_);
int nx = domain().nx();
UTIL_CHECK(nx > 0);
UTIL_CHECK(dA_.capacity() == nx);
UTIL_CHECK(uA_.capacity() == nx - 1);
UTIL_CHECK(lA_.capacity() == nx - 1);
UTIL_CHECK(dB_.capacity() == nx);
UTIL_CHECK(uB_.capacity() == nx - 1);
UTIL_CHECK(lB_.capacity() == nx - 1);
UTIL_CHECK(ns_ > 0);
UTIL_CHECK(propagator(0).isAllocated());
UTIL_CHECK(propagator(1).isAllocated());
// Set step size (in case block length has changed)
ds_ = length()/double(ns_ - 1);
// Chemical potential terms in matrix A
double halfDs = 0.5*ds_;
for (int i = 0; i < nx; ++i) {
dA_[i] = halfDs*w[i];
}
// Second derivative terms in matrix A
double dx = domain().dx();
double db = kuhn()/dx;
double c1 = halfDs*db*db/6.0;
double c2 = 2.0*c1;
GeometryMode mode = domain().mode();
if (mode == Planar) {
dA_[0] += c2;
uA_[0] = -c2;
for (int i = 1; i < nx - 1; ++i) {
dA_[i] += c2;
uA_[i] = -c1;
lA_[i-1] = -c1;
}
dA_[nx - 1] += c2;
lA_[nx - 2] = -c2;
} else {
double xMin = domain().xMin();
double xMax = domain().xMax();
double halfDx = 0.5*dx;
double x, rp, rm;
bool isShell = domain().isShell();
// First row: x = xMin
if (isShell) {
rp = 1.0 + halfDx/xMin;
if (mode == Spherical) {
rp *= rp;
}
} else {
if (mode == Spherical) {
rp = 3.0;
} else
if (mode == Cylindrical) {
rp = 2.0;
} else {
UTIL_THROW("Invalid GeometryMode");
}
}
rp *= c1;
dA_[0] += 2.0*rp;
uA_[0] = -2.0*rp;
// Interior rows
for (int i = 1; i < nx - 1; ++i) {
x = xMin + dx*i;
rm = 1.0 - halfDx/x;
rp = 1.0 + halfDx/x;
if (mode == Spherical) {
rm *= rm;
rp *= rp;
}
rm *= c1;
rp *= c1;
dA_[i] += rm + rp;
uA_[i] = -rp;
lA_[i-1] = -rm;
}
// Last row: x = xMax
rm = 1.0 - halfDx/xMax;
if (mode == Spherical) {
rm *= rm;
}
rm *= c1;
dA_[nx-1] += 2.0*rm;
lA_[nx-2] = -2.0*rm;
}
// Construct matrix B - 1
for (int i = 0; i < nx; ++i) {
dB_[i] = -dA_[i];
}
for (int i = 0; i < nx - 1; ++i) {
uB_[i] = -uA_[i];
}
for (int i = 0; i < nx - 1; ++i) {
lB_[i] = -lA_[i];
}
// Add diagonal identity terms to matrices A and B
for (int i = 0; i < nx; ++i) {
dA_[i] += 1.0;
dB_[i] += 1.0;
}
// Compute the LU decomposition of matrix A
solver_.computeLU(dA_, uA_, lA_);
}
/*
* Integrate to calculate monomer concentration for this block
*/
void Block::computeConcentration(double prefactor)
{
// Preconditions
UTIL_CHECK(domain().nx() > 0);
UTIL_CHECK(ns_ > 0);
UTIL_CHECK(ds_ > 0);
UTIL_CHECK(dA_.capacity() == domain().nx());
UTIL_CHECK(dB_.capacity() == domain().nx());
UTIL_CHECK(uA_.capacity() == domain().nx() -1);
UTIL_CHECK(uB_.capacity() == domain().nx() -1);
UTIL_CHECK(propagator(0).isAllocated());
UTIL_CHECK(propagator(1).isAllocated());
UTIL_CHECK(cField().capacity() == domain().nx())
// Initialize cField to zero at all points
int i;
int nx = domain().nx();
for (i = 0; i < nx; ++i) {
cField()[i] = 0.0;
}
Propagator const & p0 = propagator(0);
Propagator const & p1 = propagator(1);
// Evaluate unnormalized integral with respect to s
// Uses trapezoidal rule for integration
for (i = 0; i < nx; ++i) {
cField()[i] += 0.5*p0.q(0)[i]*p1.q(ns_ - 1)[i];
}
for (int j = 1; j < ns_ - 1; ++j) {
for (i = 0; i < nx; ++i) {
cField()[i] += p0.q(j)[i]*p1.q(ns_ - 1 - j)[i];
}
}
for (i = 0; i < nx; ++i) {
cField()[i] += 0.5*p0.q(ns_ - 1)[i]*p1.q(0)[i];
}
// Normalize
prefactor *= ds_;
for (i = 0; i < nx; ++i) {
cField()[i] *= prefactor;
}
}
/*
* Propagate solution by one step.
*
* This function implements one step of the Crank-Nicholson algorithm.
* To do so, it solves A q(i+1) = B q(i), where A and B are constant
* matrices defined in the documentation of the setupStep() function.
*/
void Block::step(DArray<double> const & q, DArray<double>& qNew)
{
int nx = domain().nx();
v_[0] = dB_[0]*q[0] + uB_[0]*q[1];
for (int i = 1; i < nx - 1; ++i) {
v_[i] = dB_[i]*q[i] + lB_[i-1]*q[i-1] + uB_[i]*q[i+1];
}
v_[nx - 1] = dB_[nx-1]*q[nx-1] + lB_[nx-2]*q[nx-2];
solver_.solve(v_, qNew);
}
}
}
| 8,437
|
C++
|
.cpp
| 274
| 23.255474
| 75
| 0.50166
|
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,534,940
|
Mixture.cpp
|
dmorse_pscfpp/src/fd1d/solvers/Mixture.cpp
|
/*
* 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 "Mixture.h"
#include <fd1d/domain/Domain.h>
#include <cmath>
namespace Pscf {
namespace Fd1d
{
Mixture::Mixture()
: ds_(-1.0),
domainPtr_(0)
{ setClassName("Mixture"); }
Mixture::~Mixture()
{}
void Mixture::readParameters(std::istream& in)
{
MixtureTmpl<Polymer, Solvent>::readParameters(in);
// Read optimal contour step size
read(in, "ds", ds_);
UTIL_CHECK(nMonomer() > 0);
UTIL_CHECK(nPolymer()+ nSolvent() > 0);
UTIL_CHECK(ds_ > 0);
}
void Mixture::setDomain(Domain const& domain)
{
UTIL_CHECK(nMonomer() > 0);
UTIL_CHECK(nPolymer()+ nSolvent() > 0);
UTIL_CHECK(ds_ > 0);
domainPtr_ = &domain;
// Process polymers - set discretization for all blocks
if (nPolymer() > 0) {
int i, j;
for (i = 0; i < nPolymer(); ++i) {
for (j = 0; j < polymer(i).nBlock(); ++j) {
polymer(i).block(j).setDiscretization(domain, ds_);
}
}
}
// Process solvents - set discretization for all solvents
if (nSolvent() > 0) {
for (int i = 0; i < nSolvent(); ++i) {
solvent(i).setDiscretization(domain);
}
}
}
/*
* Reset statistical segment length for one monomer type.
*/
void Mixture::setKuhn(int monomerId, double kuhn)
{
// Set new Kuhn length for relevant Monomer object
monomer(monomerId).setKuhn(kuhn);
// Update kuhn length for all blocks of this monomer type
for (int i = 0; i < nPolymer(); ++i) {
for (int j = 0; j < polymer(i).nBlock(); ++j) {
if (monomerId == polymer(i).block(j).monomerId()) {
polymer(i).block(j).setKuhn(kuhn);
}
}
}
}
/*
* Compute concentrations (but not total free energy).
*/
void Mixture::compute(DArray<Mixture::WField> const & wFields,
DArray<Mixture::CField>& cFields)
{
UTIL_CHECK(domainPtr_);
UTIL_CHECK(domain().nx() > 0);
UTIL_CHECK(nMonomer() > 0);
UTIL_CHECK(nPolymer() + nSolvent() > 0);
UTIL_CHECK(wFields.capacity() == nMonomer());
UTIL_CHECK(cFields.capacity() == nMonomer());
int nx = domain().nx();
int nm = nMonomer();
int i, j, k;
// Clear all monomer concentration fields
for (i = 0; i < nm; ++i) {
UTIL_CHECK(cFields[i].capacity() == nx);
UTIL_CHECK(wFields[i].capacity() == nx);
for (j = 0; j < nx; ++j) {
cFields[i][j] = 0.0;
}
}
// Process polymer species
if (nPolymer() > 0) {
for (i = 0; i < nPolymer(); ++i) {
// Solve MDE for all blocks in polymer
polymer(i).compute(wFields);
// Accumulate monomer concentrations
for (j = 0; j < polymer(i).nBlock(); ++j) {
int monomerId = polymer(i).block(j).monomerId();
UTIL_CHECK(monomerId >= 0);
UTIL_CHECK(monomerId < nm);
CField& monomerField = cFields[monomerId];
CField const & blockField = polymer(i).block(j).cField();
for (k = 0; k < nx; ++k) {
monomerField[k] += blockField[k];
}
}
}
}
// Process solvent species
if (nSolvent() > 0) {
for (i = 0; i < nSolvent(); ++i) {
int monomerId = solvent(i).monomerId();
UTIL_CHECK(monomerId >= 0);
UTIL_CHECK(monomerId < nm);
// Compute solvent concentration and q
solvent(i).compute(wFields[monomerId]);
// Add to monomer concentrations
CField& monomerField = cFields[monomerId];
CField const & solventField = solvent(i).cField();
for (k = 0; k < nx; ++k) {
monomerField[k] += solventField[k];
}
}
}
}
} // namespace Fd1d
} // namespace Pscf
| 4,189
|
C++
|
.cpp
| 125
| 25.12
| 72
| 0.539053
|
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,534,941
|
Propagator.cpp
|
dmorse_pscfpp/src/fd1d/solvers/Propagator.cpp
|
/*
* 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"
#include "Block.h"
#include <fd1d/domain/Domain.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/*
* Constructor.
*/
Propagator::Propagator()
: blockPtr_(0),
ns_(0),
nx_(0),
isAllocated_(false)
{}
/*
* Destructor.
*/
Propagator::~Propagator()
{}
/*
* Allocate memory used by this propagator.
*/
void Propagator::allocate(int ns, int nx)
{
ns_ = ns;
nx_ = nx;
qFields_.allocate(ns);
for (int i = 0; i < ns; ++i) {
qFields_[i].allocate(nx);
}
isAllocated_ = true;
}
/*
* Reallocate memory used by this propagator using new ns value.
*/
void Propagator::reallocate(int ns)
{
UTIL_CHECK(isAllocated_);
UTIL_CHECK(ns_ != ns);
ns_ = ns;
// Deallocate memory previously used by this propagator.
// NOTE: DArray::deallocate() calls "delete [] ptr", where ptr is a
// pointer to the underlying C array. This will call the destructor
// for each element in the underlying C array, freeing all memory
// that was allocated to the objects stored in the DArray.
qFields_.deallocate();
// Allocate memory in qFields_ using new value of ns
qFields_.allocate(ns);
for (int i = 0; i < ns; ++i) {
qFields_[i].allocate(nx_);
}
}
bool Propagator::isAllocated() const
{ return isAllocated_; }
/*
* Compute initial head QField from final tail QFields of sources.
*/
void Propagator::computeHead()
{
// Reference to head of this propagator
QField& qh = qFields_[0];
// Initialize qh field to 1.0 at all grid points
int ix;
for (ix = 0; ix < nx_; ++ix) {
qh[ix] = 1.0;
}
// Pointwise multiply tail QFields of all sources
for (int is = 0; is < nSource(); ++is) {
if (!source(is).isSolved()) {
UTIL_THROW("Source not solved in computeHead");
}
QField const& qt = source(is).tail();
for (ix = 0; ix < nx_; ++ix) {
qh[ix] *= qt[ix];
}
}
}
/*
* Solve the modified diffusion equation for this block.
*/
void Propagator::solve()
{
computeHead();
for (int iStep = 0; iStep < ns_ - 1; ++iStep) {
block().step(qFields_[iStep], qFields_[iStep + 1]);
}
setIsSolved(true);
}
/*
* Solve the modified diffusion equation with specified initial field.
*/
void Propagator::solve(const Propagator::QField& head)
{
// Initialize initial (head) field
QField& qh = qFields_[0];
for (int i = 0; i < nx_; ++i) {
qh[i] = head[i];
}
// Setup solver and solve
for (int iStep = 0; iStep < ns_ - 1; ++iStep) {
block().step(qFields_[iStep], qFields_[iStep + 1]);
}
setIsSolved(true);
}
/*
* Integrate to calculate monomer concentration for this block
*/
double Propagator::computeQ()
{
if (!isSolved()) {
UTIL_THROW("Propagator is not solved.");
}
if (!hasPartner()) {
UTIL_THROW("Propagator has no partner set.");
}
if (!partner().isSolved()) {
UTIL_THROW("Partner propagator is not solved");
}
QField const& qh = head();
QField const& qt = partner().tail();
return block().domain().innerProduct(qh, qt);
}
}
}
| 3,618
|
C++
|
.cpp
| 132
| 21.583333
| 74
| 0.58165
|
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,534,942
|
Polymer.cpp
|
dmorse_pscfpp/src/fd1d/solvers/Polymer.cpp
|
/*
* 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"
namespace Pscf {
namespace Fd1d
{
Polymer::Polymer()
{ setClassName("Polymer"); }
Polymer::~Polymer()
{}
void Polymer::setPhi(double phi)
{
UTIL_CHECK(ensemble() == Species::Closed);
UTIL_CHECK(phi >= 0.0);
UTIL_CHECK(phi <= 1.0);
phi_ = phi;
}
void Polymer::setMu(double mu)
{
UTIL_CHECK(ensemble() == Species::Open);
mu_ = mu;
}
/*
* Compute solution to MDE and concentrations.
*/
void Polymer::compute(DArray<Block::WField> const & wFields)
{
// Setup solvers for all blocks
int monomerId;
for (int j = 0; j < nBlock(); ++j) {
monomerId = block(j).monomerId();
block(j).setupSolver(wFields[monomerId]);
}
solve();
}
}
}
| 987
|
C++
|
.cpp
| 41
| 19.292683
| 67
| 0.612179
|
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,534,943
|
Solvent.cpp
|
dmorse_pscfpp/src/fd1d/solvers/Solvent.cpp
|
#ifndef FD1D_SOLVENT_TPP
#define FD1D_SOLVENT_TPP
/*
* 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 "Solvent.h"
#include <fd1d/domain/Domain.h>
namespace Pscf {
namespace Fd1d {
Solvent::Solvent()
: SolventDescriptor()
{ setClassName("Solvent"); }
Solvent::~Solvent()
{}
/*
* Set association with Domain and allocate concentration field.
*/
void Solvent::setDiscretization(Domain const & domain)
{
domainPtr_ = &domain;
int nx = domain.nx();
if (nx > 0) {
cField_.allocate(nx);
}
}
/*
* Compute concentration, q, phi or mu.
*/
void Solvent::compute(WField const & wField)
{
UTIL_CHECK(cField_.isAllocated());
// Evaluate unnormalized concentration, Boltzmann weight
int nx = domain().nx();
double s = size();
for (int i = 0; i < nx; ++i) {
cField_[i] = exp(-s*wField[i]);
}
// Compute spatial average q_
q_ = domain().spatialAverage(cField_);
// Compute mu_ or phi_ and prefactor
double prefactor;
if (ensemble_ == Species::Closed) {
prefactor = phi_/q_;
mu_ = log(prefactor);
} else {
prefactor = exp(mu_);
phi_ = prefactor*q_;
}
// Normalize concentration
for (int i = 0; i < nx; ++i) {
cField_[i] *= prefactor;
}
}
}
}
#endif
| 1,536
|
C++
|
.cpp
| 59
| 20.627119
| 67
| 0.59863
|
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,534,944
|
LinearSweep.cpp
|
dmorse_pscfpp/src/fd1d/sweep/LinearSweep.cpp
|
/*
* 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 "LinearSweep.h"
#include <fd1d/System.h>
#include <cstdio>
namespace Pscf {
namespace Fd1d {
using namespace Util;
LinearSweep::LinearSweep(System& system)
: Sweep(system)
{}
void LinearSweep::readParameters(std::istream& in)
{
// Call the base class's readParameters function.
Sweep::readParameters(in);
// Read in the number of sweep parameters and allocate.
read(in, "nParameter", nParameter_);
parameters_.allocate(nParameter_);
// Read in array of SweepParameters, calling << for each
readDArray< SweepParameter >(in, "parameters",
parameters_, nParameter_);
// Verify net zero change in volume fractions if being swept
double sum = 0.0;
for (int i = 0; i < nParameter_; ++i) {
if (parameters_[i].type() == "phi_polymer"
|| parameters_[i].type() == "phi_solvent")
{
sum += parameters_[i].change();
}
}
UTIL_CHECK(sum > -0.000001);
UTIL_CHECK(sum < 0.000001);
}
void LinearSweep::setup()
{
// Call base class's setup function
Sweep::setup();
// Set system pointer and initial value for each parameter object
for (int i = 0; i < nParameter_; ++i) {
parameters_[i].setSystem(system());
parameters_[i].getInitial();
}
}
void LinearSweep::setParameters(double s)
{
// Update the system parameter values
double newVal;
for (int i = 0; i < nParameter_; ++i) {
newVal = parameters_[i].initial() + s*parameters_[i].change();
parameters_[i].update(newVal);
}
}
void LinearSweep::outputSummary(std::ostream& out)
{}
}
}
| 1,945
|
C++
|
.cpp
| 60
| 25.833333
| 71
| 0.617917
|
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,534,945
|
SweepParameter.cpp
|
dmorse_pscfpp/src/fd1d/sweep/SweepParameter.cpp
|
/*
* 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/sweep/SweepParameter.h>
#include <fd1d/solvers/Block.h>
#include <fd1d/solvers/Mixture.h>
#include <fd1d/solvers/Polymer.h>
#include <fd1d/System.h>
#include <pscf/inter/Interaction.h>
#include <util/containers/FSArray.h>
#include <util/global.h>
#include <algorithm>
#include <iomanip>
namespace Pscf {
namespace Fd1d {
using namespace Util;
/*
* Default constructor.
*/
SweepParameter::SweepParameter()
: type_(SweepParameter::Null),
nID_(0),
id_(),
initial_(0.0),
change_(0.0),
systemPtr_(0)
{}
/*
* Constructor, creates association with system.
*/
SweepParameter::SweepParameter(System& system)
: type_(SweepParameter::Null),
nID_(0),
id_(),
initial_(0.0),
change_(0.0),
systemPtr_(&system)
{}
/*
* Read type, set nId and allocate id_ array.
*/
void SweepParameter::readParamType(std::istream& in)
{
std::string buffer;
in >> buffer;
std::transform(buffer.begin(), buffer.end(),
buffer.begin(), ::tolower);
if (buffer == "block" || buffer == "block_length") {
type_ = Block;
nID_ = 2; // polymer and block identifiers
} else if (buffer == "chi") {
type_ = Chi;
nID_ = 2; // two monomer type identifiers
} else if (buffer == "kuhn") {
type_ = Kuhn;
nID_ = 1; // monomer type identifier
} else if (buffer == "phi_polymer") {
type_ = Phi_Polymer;
nID_ = 1; //species identifier.
} else if (buffer == "phi_solvent") {
type_ = Phi_Solvent;
nID_ = 1; //species identifier.
} else if (buffer == "mu_polymer") {
type_ = Mu_Polymer;
nID_ = 1; //species identifier.
} else if (buffer == "mu_solvent") {
type_ = Mu_Solvent;
nID_ = 1; //species identifier.
} else if (buffer == "solvent" || buffer == "solvent_size") {
type_ = Solvent;
nID_ = 1; //species identifier.
} else if (buffer == "cell_param") {
type_ = Cell_Param;
nID_ = 1; //lattice parameter identifier.
} else {
UTIL_THROW("Invalid SweepParameter::ParamType value");
}
if (id_.isAllocated()) id_.deallocate();
id_.allocate(nID_);
}
/*
* Write type enum value
*/
void SweepParameter::writeParamType(std::ostream& out) const
{
out << type();
}
/*
* Get the current value from the parent system.
*/
void SweepParameter::getInitial()
{
initial_ = get_();
}
/*
* Set a new value in the parent system.
*/
void SweepParameter::update(double newVal)
{
set_(newVal);
}
/*
* Get string representation of type enum value.
*/
std::string SweepParameter::type() const
{
if (type_ == Block) {
return "block";
} else if (type_ == Chi) {
return "chi";
} else if (type_ == Kuhn) {
return "kuhn";
} else if (type_ == Phi_Polymer) {
return "phi_polymer";
} else if (type_ == Phi_Solvent) {
return "phi_solvent";
} else if (type_ == Mu_Polymer) {
return "mu_polymer";
} else if (type_ == Mu_Solvent) {
return "mu_solvent";
} else if (type_ == Solvent) {
return "solvent_size";
} else {
UTIL_THROW("Invalid type_ in accessor SweepParameter::type().");
}
}
double SweepParameter::get_()
{
if (type_ == Block) {
return systemPtr_->mixture().polymer(id(0)).block(id(1)).length();
} else if (type_ == Chi) {
return systemPtr_->interaction().chi(id(0), id(1));
} else if (type_ == Kuhn) {
return systemPtr_->mixture().monomer(id(0)).kuhn();
} else if (type_ == Phi_Polymer) {
return systemPtr_->mixture().polymer(id(0)).phi();
} else if (type_ == Phi_Solvent) {
return systemPtr_->mixture().solvent(id(0)).phi();
} else if (type_ == Mu_Polymer) {
return systemPtr_->mixture().polymer(id(0)).mu();
} else if (type_ == Mu_Solvent) {
return systemPtr_->mixture().solvent(id(0)).mu();
} else if (type_ == Solvent) {
return systemPtr_->mixture().solvent(id(0)).size();
} else {
UTIL_THROW("Invalid type_ in SweepParameter::get_.");
}
}
void SweepParameter::set_(double newVal)
{
if (type_ == Block) {
systemPtr_->mixture().polymer(id(0)).block(id(1)).setLength(newVal);
} else if (type_ == Chi) {
systemPtr_->interaction().setChi(id(0), id(1), newVal);
} else if (type_ == Kuhn) {
systemPtr_->mixture().setKuhn(id(0), newVal);
} else if (type_ == Phi_Polymer) {
systemPtr_->mixture().polymer(id(0)).setPhi(newVal);
} else if (type_ == Phi_Solvent) {
systemPtr_->mixture().solvent(id(0)).setPhi(newVal);
} else if (type_ == Mu_Polymer) {
systemPtr_->mixture().polymer(id(0)).setMu(newVal);
} else if (type_ == Mu_Solvent) {
systemPtr_->mixture().solvent(id(0)).setMu(newVal);
} else if (type_ == Solvent) {
systemPtr_->mixture().solvent(id(0)).setSize(newVal);
} else {
UTIL_THROW("Invalid type_ in SweepParameter::set_.");
}
}
// Definitions of operators, with no explicit instantiations.
/**
* Inserter for reading a SweepParameter from an istream.
*
* \param in input stream
* \param param SweepParameter object to read
*/
std::istream& operator >> (std::istream& in,
SweepParameter& param)
{
// Read the parameter type.
param.readParamType(in);
// Read the identifiers associated with this parameter type.
for (int i = 0; i < param.nID_; ++i) {
in >> param.id_[i];
}
// Read in the range in the parameter to sweep over
in >> param.change_;
return in;
}
/**
* Extractor for writing a SweepParameter to ostream.
*
* \param out output stream
* \param param SweepParameter object to write
*/
std::ostream& operator << (std::ostream& out,
SweepParameter const & param)
{
param.writeParamType(out);
out << " ";
for (int i = 0; i < param.nID_; ++i) {
out << param.id(i);
out << " ";
}
out << param.change_;
return out;
}
}
}
| 6,647
|
C++
|
.cpp
| 213
| 24.600939
| 77
| 0.56479
|
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,534,946
|
Sweep.cpp
|
dmorse_pscfpp/src/fd1d/sweep/Sweep.cpp
|
/*
* 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"
//#include <pscf/sweep/SweepTmpl.h>
#include <fd1d/System.h>
#include <fd1d/domain/Domain.h>
#include <fd1d/solvers/Mixture.h>
#include <fd1d/iterator/Iterator.h>
#include <util/misc/ioUtil.h>
#include <util/format/Int.h>
#include <util/format/Dbl.h>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
// Define maximum number of stored states = order of continuation + 1
#define FD1D_HISTORY_CAPACITY 3
/*
* Constructor.
*/
Sweep::Sweep(System& system)
: Base(FD1D_HISTORY_CAPACITY),
SystemAccess(system),
homogeneousMode_(-1),
comparison_(system),
fieldIo_()
{
setClassName("Sweep");
fieldIo_.associate(system.domain(), system.fileMaster());
}
/*
* Destructor.
*/
Sweep::~Sweep()
{}
/*
* Read parameters.
*/
void Sweep::readParameters(std::istream& in)
{
Base::readParameters(in);
homogeneousMode_ = -1; // default value
readOptional<int>(in, "homogeneousMode", homogeneousMode_);
}
/*
* Check allocation of a state, allocate if necessary.
*/
void Sweep::checkAllocation(Sweep::State& state)
{
int nm = mixture().nMonomer();
int nx = domain().nx();
UTIL_CHECK(nm > 0);
UTIL_CHECK(nx > 0);
if (state.isAllocated()) {
UTIL_CHECK(state.capacity() == nm);
} else {
state.allocate(nm);
}
for (int j = 0; j < nm; ++j) {
if (state[j].isAllocated()) {
UTIL_CHECK(state[j].capacity() == nx);
} else {
state[j].allocate(nx);
}
}
};
/*
* Setup operation at beginning sweep.
*
* Must call initializeHistory.
*/
void Sweep::setup()
{
// Initialize history
initialize();
// Open log summary file
std::string fileName = baseFileName_;
fileName += "log";
fileMaster().openOutputFile(fileName, logFile_);
};
/*
* Set non-adjustable system parameters to new values.
*
* \param s path length coordinate, in range [0,1]
*/
void Sweep::setParameters(double s)
{
UTIL_THROW("Called un-implemented Fd1d::Sweep::setParameters");
};
/*
* Create guess for adjustable variables by polynomial extrapolation.
*/
void Sweep::extrapolate(double sNew)
{
int nm = mixture().nMonomer();
int nx = domain().nx();
UTIL_CHECK(nm > 0);
UTIL_CHECK(nx > 0);
if (historySize() > 1) {
// Compute an array of coefficients for polynomial extrapolation
setCoefficients(sNew);
// Set System::wField to a linear combination of previous values
// Note: wField(i) is accessed through SystemAccess base class.
double coeff;
int i, j, k;
for (i = 0; i < nm; ++i) {
coeff = c(0);
for (j = 0; j < nx; ++j) {
wField(i)[j] = coeff*state(0)[i][j];
}
for (k = 1; k < historySize(); ++k) {
coeff = c(k);
for (j = 0; j < nx; ++j) {
wField(i)[j] += coeff*state(k)[i][j];
}
}
}
}
};
/**
* Call current iterator to solve SCFT problem.
*
* Return 0 for sucessful solution, 1 on failure to converge.
*/
int Sweep::solve(bool isContinuation)
{ return system().iterate(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).
*/
void Sweep::reset()
{ assignFields(wFields(), state(0)); };
/**
* 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.
*/
void Sweep::getSolution()
{
// Assign current wFields to state(0)
assignFields(state(0), wFields());
if (homogeneousMode_ >= 0) {
comparison_.compute(homogeneousMode_);
}
// Output solution
int i = nAccept() - 1;
std::string fileName = baseFileName_;
fileName += toString(i);
outputSolution(fileName);
// Output brief summary to log file
outputSummary(logFile_);
};
void Sweep::outputSolution(std::string const & fileName)
{
std::ofstream out;
std::string outFileName;
// Write parameter file, with thermodynamic properties at end
outFileName = fileName;
outFileName += ".stt";
fileMaster().openOutputFile(outFileName, out);
system().writeParam(out);
out << std::endl;
system().writeThermo(out);
if (homogeneousMode_ >= 0) {
comparison_.output(homogeneousMode_, out);
}
out.close();
// Write concentration fields
outFileName = fileName;
outFileName += ".c";
fieldIo_.writeFields(cFields(), outFileName);
// Write chemical potential fields
outFileName = fileName;
outFileName += ".w";
fieldIo_.writeFields(wFields(), outFileName);
}
void Sweep::outputSummary(std::ostream& out)
{
int i = nAccept() - 1;
double sNew = s(0);
out << Int(i,5) << Dbl(sNew)
<< Dbl(system().fHelmholtz(),16)
<< Dbl(system().pressure(),16);
#if 0
if (homogeneousMode_ != -1) {
if (homogeneousMode_ == 0) {
double dF = system().fHelmholtz()
- system().homogeneous().fHelmholtz();
out << Dbl(dF, 16);
} else {
double dP = system().pressure()
- system().homogeneous().pressure();
double dOmega = -1.0*dP*domain().volume();
out << Dbl(dOmega, 16);
}
}
#endif
out << std::endl;
}
void Sweep::cleanup()
{ logFile_.close(); }
void Sweep::assignFields(DArray<System::Field>& lhs,
DArray<System::Field> const & rhs) const
{
int nm = mixture().nMonomer();
int nx = domain().nx();
UTIL_CHECK(lhs.capacity() == nm);
UTIL_CHECK(rhs.capacity() == nm);
int i, j;
for (i = 0; i < nm; ++i) {
UTIL_CHECK(rhs[i].isAllocated());
UTIL_CHECK(rhs[i].capacity() == nx);
UTIL_CHECK(lhs[i].isAllocated());
UTIL_CHECK(lhs[i].capacity() == nx);
for (j = 0; j < nx; ++j) {
lhs[i][j] = rhs[i][j];
}
}
}
} // namespace Fd1d
} // namespace Pscf
| 6,812
|
C++
|
.cpp
| 229
| 23.043668
| 73
| 0.579719
|
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,534,947
|
SweepFactory.cpp
|
dmorse_pscfpp/src/fd1d/sweep/SweepFactory.cpp
|
/*
* 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 "SweepFactory.h"
// Subclasses of Sweep
#include "LinearSweep.h"
namespace Pscf {
namespace Fd1d {
using namespace Util;
SweepFactory::SweepFactory(System& system)
: systemPtr_(&system)
{}
/*
* Return a pointer to a instance of Sweep subclass speciesName.
*/
Sweep* SweepFactory::factory(const std::string &className) const
{
Sweep *ptr = 0;
// First if name is known by any subfactories
ptr = trySubfactories(className);
if (ptr) return ptr;
// Explicit class names
if (className == "Sweep" || className == "LinearSweep") {
ptr = new LinearSweep(*systemPtr_);
}
return ptr;
}
}
}
| 885
|
C++
|
.cpp
| 32
| 23.28125
| 67
| 0.67497
|
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,534,948
|
HomogeneousComparison.cpp
|
dmorse_pscfpp/src/fd1d/misc/HomogeneousComparison.cpp
|
/*
* 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 "HomogeneousComparison.h"
#include <pscf/inter/Interaction.h>
#include <pscf/homogeneous/Clump.h>
#include <util/format/Str.h>
#include <util/format/Int.h>
#include <util/format/Dbl.h>
#include <string>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/*
* Default constructor.
*/
HomogeneousComparison::HomogeneousComparison()
: SystemAccess()
{}
/*
* Constructor.
*/
HomogeneousComparison::HomogeneousComparison(System& system)
: SystemAccess(system)
{}
/*
* Destructor.
*/
HomogeneousComparison::~HomogeneousComparison()
{}
/*
* Compute properties of a homogeneous reference system.
*
* mode == 0 : Composition equals spatial average composition
* mode == 1: Chemical potential equal to that of system,
* composition guess given at last grid point.
* mode == 2: Chemical potential equal to that of system,
* composition guess given at first grid point.
*/
void HomogeneousComparison::compute(int mode)
{
int np = mixture().nPolymer();
int ns = mixture().nSolvent();
if (!p_.isAllocated()) {
p_.allocate(np+ns);
}
UTIL_CHECK(p_.capacity() == homogeneous().nMolecule());
if (mode == 0) {
for (int i = 0; i < np; ++i) {
p_[i] = mixture().polymer(i).phi();
}
homogeneous().setComposition(p_);
double xi = 0.0;
homogeneous().computeMu(interaction(), xi);
} else
if (mode == 1 || mode == 2) {
if (!m_.isAllocated()) {
m_.allocate(np+ns);
}
UTIL_CHECK(m_.capacity() == homogeneous().nMolecule());
for (int i = 0; i < np; ++i) {
m_[i] = mixture().polymer(i).mu();
}
int ix; // Grid index from which we obtain guess of composition
if (mode == 1) {
ix = domain().nx() - 1;
} else
if (mode == 2) {
ix = 0;
}
// Compute array p_
// Define: p_[i] = volume fraction of all blocks of polymer i
for (int i = 0; i < np; ++i) {
p_[i] = 0.0;
int nb = mixture().polymer(i).nBlock();
for (int j = 0; j < nb; ++j) {
p_[i] += mixture().polymer(i).block(j).cField()[ix];
}
}
double xi = 0.0;
homogeneous().computePhi(interaction(), m_, p_, xi);
} else {
UTIL_THROW("Unknown mode in computeHomogeneous");
}
// Compute Helmholtz free energy and pressure
homogeneous().computeFreeEnergy(interaction());
}
/*
* Output properties of homogeneous system and free energy difference.
*
* Mode 0: Outputs fHomo (Helmholtz) and difference df
* Mode 1 or 2: Outputs Helhmoltz, pressure and difference dp
*/
void HomogeneousComparison::output(int mode, std::ostream& out)
{
if (mode == 0) {
// Output free energies
double fHomo = homogeneous().fHelmholtz();
double df = system().fHelmholtz() - fHomo;
out << std::endl;
out << "f (homo) = " << Dbl(fHomo, 18, 11)
<< " [per monomer volume]" << std::endl;
out << "delta f = " << Dbl(df, 18, 11)
<< " [per monomer volume]" << std::endl;
// Output species-specific properties
out << std::endl;
out << "Species:" << std::endl;
out << " i"
<< " mu(homo) "
<< " phi(homo) "
<< std::endl;
for (int i = 0; i < homogeneous().nMolecule(); ++i) {
out << Int(i,5)
<< " " << Dbl(homogeneous().mu(i), 18, 11)
<< " " << Dbl(homogeneous().phi(i), 18, 11)
<< std::endl;
}
out << std::endl;
} else
if (mode == 1 || mode == 2) {
// Output free energies
double fHomo = homogeneous().fHelmholtz();
double pHomo = homogeneous().pressure();
double pEx = system().pressure() - pHomo;
double fEx = system().fHelmholtz() - fHomo;
double V = domain().volume()/mixture().vMonomer();
double PhiExTot = -1.0*pEx*V;
double fExTot = fEx*V;
out << std::endl;
out << "f (homo) = " << Dbl(fHomo, 18, 11)
<< " [per monomer volume]" << std::endl;
out << "p (homo) = " << Dbl(pHomo, 18, 11)
<< " [per monomer volume]" << std::endl;
out << "delta f = " << Dbl(fEx, 18, 11)
<< " [per monomer volume]" << std::endl;
out << "delta p = " << Dbl(pEx, 18, 11)
<< " [per monomer volume]" << std::endl;
out << "Phi (ex) = " << Dbl(PhiExTot, 18, 11)
<< " [total]" << std::endl;
out << "F (ex) = " << Dbl(fExTot, 18, 11)
<< " [total]" << std::endl;
out << "V(tot)/v = " << Dbl(V, 18, 11) << std::endl;
// Output species specific properties
double dV;
out << std::endl;
out << "Species:" << std::endl;
out << " i"
<< " mu "
<< " phi(homo) "
<< " delta V "
<< std::endl;
for (int i = 0; i < homogeneous().nMolecule(); ++i) {
dV = mixture().polymer(i).phi() - homogeneous().phi(i);
dV *= V;
out << Int(i,5)
<< " " << Dbl(homogeneous().mu(i), 18, 11)
<< " " << Dbl(homogeneous().phi(i), 18, 11)
<< " " << Dbl(dV, 18, 11)
<< std::endl;
}
out << std::endl;
}
}
} // namespace Fd1d
} // namespace Pscf
| 6,153
|
C++
|
.cpp
| 169
| 26.87574
| 75
| 0.481115
|
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,534,949
|
FieldIo.cpp
|
dmorse_pscfpp/src/fd1d/misc/FieldIo.cpp
|
/*
* 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 "FieldIo.h"
#include <fd1d/domain/Domain.h>
#include <fd1d/solvers/Mixture.h>
#include <fd1d/solvers/Polymer.h>
#include <pscf/chem/Vertex.h>
#include <pscf/homogeneous/Clump.h>
//#include <pscf/inter/Interaction.h>
#include <util/misc/FileMaster.h>
#include <util/format/Str.h>
#include <util/format/Int.h>
#include <util/format/Dbl.h>
#include <string>
namespace Pscf {
namespace Fd1d
{
using namespace Util;
/*
* Constructor.
*/
FieldIo::FieldIo()
{}
/*
* Destructor.
*/
FieldIo::~FieldIo()
{}
void FieldIo::associate(Domain const & domain,
FileMaster const & fileMaster)
{
domainPtr_ = &domain;
fileMasterPtr_ = &fileMaster;
}
void FieldIo::readFields(DArray<Field> & fields,
std::string const & filename)
{
std::ifstream in;
fileMaster().openInputFile(filename, in);
readFields(fields, in);
in.close();
}
void FieldIo::readFields(DArray<Field>& fields, std::istream& in)
{
// Read grid dimensions
std::string label;
in >> label;
UTIL_CHECK(label == "nx");
int nx;
in >> nx;
UTIL_CHECK(nx > 0);
UTIL_CHECK(nx == domain().nx());
in >> label;
UTIL_CHECK (label == "nm");
int nm;
in >> nm;
UTIL_CHECK(nm > 0);
// Check dimensions of fields array
UTIL_CHECK(nm == fields.capacity());
for (int i = 0; i < nm; ++i) {
UTIL_CHECK(nx == fields[i].capacity());
}
// Read fields
int i, j, idum;
for (i = 0; i < nx; ++i) {
in >> idum;
UTIL_CHECK(idum == i);
for (j = 0; j < nm; ++j) {
in >> fields[j][i];
}
}
}
void FieldIo::writeField(Field const & field,
std::string const & filename, bool writeHeader) const
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
writeField(field, out, writeHeader);
out.close();
}
void FieldIo::writeField(Field const & field, std::ostream& out, bool writeHeader) const
{
int nx = field.capacity();
UTIL_CHECK(nx == domain().nx());
if (writeHeader){
out << "nx " << nx << std::endl;
}
// Write fields
int i;
for (i = 0; i < nx; ++i) {
out << " " << Dbl(field[i], 18, 11);
out << std::endl;
}
}
void FieldIo::writeFields(DArray<Field> const & fields,
std::string const & filename, bool writeHeader)
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
writeFields(fields, out, writeHeader);
out.close();
}
void FieldIo::writeFields(DArray<Field> const & fields, std::ostream& out, bool writeHeader)
{
int nm = fields.capacity();
UTIL_CHECK(nm > 0);
int nx = fields[0].capacity();
UTIL_CHECK(nx == domain().nx());
if (nm > 1) {
for (int i = 0; i < nm; ++i) {
UTIL_CHECK(nx == fields[i].capacity());
}
}
if (writeHeader){
out << "nx " << nx << std::endl;
out << "nm " << nm << std::endl;
}
// Write fields
int i, j;
for (i = 0; i < nx; ++i) {
out << Int(i, 5);
for (j = 0; j < nm; ++j) {
out << " " << Dbl(fields[j][i], 18, 11);
}
out << std::endl;
}
}
void FieldIo::writeBlockCFields(Mixture const & mixture,
std::string const & filename)
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
writeBlockCFields(mixture, out);
out.close();
}
/*
* Write the concentrations associated with all blocks.
*/
void FieldIo::writeBlockCFields(Mixture const & mixture, std::ostream& out)
{
int nx = domain().nx(); // number grid points
int np = mixture.nPolymer(); // number of polymer species
int nb_tot = mixture.nBlock(); // number of blocks in all polymers
int ns = mixture.nSolvent(); // number of solvents
out << "nx " << nx << std::endl;
out << "n_block " << nb_tot << std::endl;
out << "n_solvent " << ns << std::endl;
int nb; // number of blocks per polymer
int i, j, k, l; // loop indices
double c;
for (i = 0; i < nx; ++i) {
out << Int(i, 5);
for (j = 0; j < np; ++j) {
nb = mixture.polymer(j).nBlock();
for (k = 0; k < nb; ++k) {
c = mixture.polymer(j).block(k).cField()[i];
out << " " << Dbl(c, 15, 8);
}
}
for (l = 0; l < ns; ++l) {
c = mixture.solvent(l).cField()[i];
out << " " << Dbl(c, 15, 8);
}
out << std::endl;
}
}
/*
* Write incoming q fields for a specified vertex.
*/
void FieldIo::writeVertexQ(Mixture const & mixture,
int polymerId, int vertexId,
std::string const & filename)
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
writeVertexQ(mixture, polymerId, vertexId, out);
out.close();
}
/*
* Write incoming q fields for a specified vertex.
*/
void FieldIo::writeVertexQ(Mixture const & mixture,
int polymerId, int vertexId,
std::ostream& out)
{
UTIL_CHECK(polymerId >= 0);
UTIL_CHECK(polymerId < mixture.nPolymer());
Polymer const & polymer = mixture.polymer(polymerId);
UTIL_CHECK(vertexId >= 0);
UTIL_CHECK(vertexId <= polymer.nBlock());
Vertex const & vertex = polymer.vertex(vertexId);
int nb = vertex.size(); // number of attached blocks
int nx = domain().nx(); // number grid points
Pair<int> pId;
int bId;
int dId;
int i, j;
double c, product;
for (i = 0; i < nx; ++i) {
out << Int(i, 5);
product = 1.0;
for (j = 0; j < nb; ++j) {
pId = vertex.inPropagatorId(j);
bId = pId[0]; // blockId
UTIL_CHECK(bId >= 0);
dId = pId[1]; // directionId
UTIL_CHECK(dId >= 0);
UTIL_CHECK(dId <= 1);
c = polymer.propagator(bId, dId).tail()[i];
out << " " << Dbl(c, 15, 8);
product *= c;
}
out << " " << Dbl(product, 15, 8) << std::endl;
}
}
/*
* Interpolate fields onto new mesh, write result to output file
*/
void FieldIo::remesh(DArray<Field> const & fields, int nx,
std::string const & filename)
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
remesh(fields, nx, out);
out.close();
}
/*
* Interpolate fields onto new mesh, write result to outputstream
*/
void
FieldIo::remesh(DArray<Field> const & fields, int nx, std::ostream& out)
{
// Query and check dimensions of fields array
int nm = fields.capacity();
UTIL_CHECK(nm > 0);
for (int i = 0; i < nm; ++i) {
UTIL_CHECK(fields[i].capacity() == domain().nx());
}
// Output new grid dimensions
out << "nx " << nx << std::endl;
out << "nm " << nm << std::endl;
// Output first grid point
int i, j;
i = 0;
out << Int(i, 5);
for (j = 0; j < nm; ++j) {
out << " " << Dbl(fields[j][i]);
}
out << std::endl;
// Spacing for new grid
double dx = (domain().xMax() - domain().xMin())/double(nx-1);
// Variables used for interpolation
double y; // Grid coordinate in old grid
double fu; // fractional part of y
double fl; // 1.0 - fl
double w; // interpolated field value
int yi; // Truncated integer part of y
// Loop over intermediate points
for (i = 1; i < nx -1; ++i) {
y = dx*double(i)/domain().dx();
yi = y;
UTIL_CHECK(yi >= 0);
UTIL_CHECK(yi + 1 < domain().nx());
fu = y - double(yi);
fl = 1.0 - fu;
out << Int(i, 5);
for (j = 0; j < nm; ++j) {
w = fl*fields[j][yi] + fu*fields[j][yi+1];
out << " " << Dbl(w);
}
out << std::endl;
}
// Output last grid point
out << Int(nx - 1, 5);
i = domain().nx() - 1;
for (j = 0; j < nm; ++j) {
out << " " << Dbl(fields[j][i]);
}
out << std::endl;
}
void
FieldIo::extend(DArray<Field> const & fields, int m,
std::string const & filename)
{
std::ofstream out;
fileMaster().openOutputFile(filename, out);
extend(fields, m, out);
out.close();
}
/*
* Interpolate fields onto new mesh.
*/
void
FieldIo::extend(DArray<Field> const & fields, int m, std::ostream& out)
{
// Query and check dimensions of fields array
int nm = fields.capacity();
UTIL_CHECK(nm > 0);
int nx = fields[0].capacity();
UTIL_CHECK(nx == domain().nx());
if (nm > 1) {
for (int i = 0; i < nm; ++i) {
UTIL_CHECK(nx == fields[i].capacity());
}
}
// Output new grid dimensions
out << "nx " << nx + m << std::endl;
out << "nm " << nm << std::endl;
// Loop over existing points;
int i, j;
for (i = 0; i < nx; ++i) {
out << Int(i, 5);
for (j = 0; j < nm; ++j) {
out << " " << Dbl(fields[j][i]);
}
out << std::endl;
}
// Add m new points, assign each the last value
for (i = nx; i < nx + m; ++i) {
out << Int(i, 5);
for (j = 0; j < nm; ++j) {
out << " " << Dbl(fields[j][nx-1]);
}
out << std::endl;
}
}
} // namespace Fd1d
} // namespace Pscf
| 10,349
|
C++
|
.cpp
| 332
| 23.415663
| 95
| 0.500402
|
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,534,950
|
GeometryMode.cpp
|
dmorse_pscfpp/src/fd1d/domain/GeometryMode.cpp
|
/*
* 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> // uses UTIL_THROW
#include "GeometryMode.h" // class header
namespace Pscf{
namespace Fd1d
{
using namespace Util;
/*
* Extract a GeometryMode from an istream as a string.
*/
std::istream& operator>>(std::istream& in, GeometryMode& mode)
{
std::string buffer;
in >> buffer;
if (buffer == "Planar" || buffer == "planar") {
mode = Planar;
} else
if (buffer == "Cylindrical" || buffer == "cylindrical") {
mode = Cylindrical;
} else
if (buffer == "Spherical" || buffer == "spherical") {
mode = Spherical;
} else {
UTIL_THROW("Invalid GeometryMode value input");
}
return in;
}
/*
* Insert a GeometryMode to an ostream as a string.
*/
std::ostream& operator<<(std::ostream& out, GeometryMode mode)
{
if (mode == Planar) {
out << "planar";
} else
if (mode == Cylindrical) {
out << "cylindrical";
} else
if (mode == Spherical) {
out << "spherical";
} else {
UTIL_THROW("This should never happen");
}
return out;
}
}
}
| 1,368
|
C++
|
.cpp
| 52
| 20.75
| 67
| 0.584545
|
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,534,951
|
Domain.cpp
|
dmorse_pscfpp/src/fd1d/domain/Domain.cpp
|
/*
* 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 "Domain.h"
#include <util/math/Constants.h>
namespace Pscf {
namespace Fd1d
{
Domain::Domain()
: xMin_(0.0),
xMax_(0.0),
dx_(0.0),
volume_(0.0),
nx_(0),
mode_(Planar),
isShell_(false)
{ setClassName("Domain"); }
Domain::~Domain()
{}
void Domain::readParameters(std::istream& in)
{
mode_ = Planar;
isShell_ = false;
xMin_ = 0.0;
read(in, "mode", mode_);
if (mode_ == Planar) {
readOptional(in, "xMin", xMin_);
} else {
isShell_ = readOptional(in, "xMin", xMin_).isActive();
if (isShell_) {
UTIL_CHECK(xMin_ > 0.0);
}
}
read(in, "xMax", xMax_);
read(in, "nx", nx_);
dx_ = (xMax_ - xMin_)/double(nx_ - 1);
computeVolume();
}
void Domain::setPlanarParameters(double xMin, double xMax, int nx)
{
mode_ = Planar;
isShell_ = false;
xMin_ = xMin;
xMax_ = xMax;
nx_ = nx;
dx_ = (xMax_ - xMin_)/double(nx_ - 1);
computeVolume();
}
void Domain::setShellParameters(GeometryMode mode,
double xMin, double xMax, int nx)
{
mode_ = mode;
isShell_ = true;
xMin_ = xMin;
xMax_ = xMax;
nx_ = nx;
dx_ = (xMax_ - xMin_)/double(nx_ - 1);
computeVolume();
}
void Domain::setCylinderParameters(double xMax, int nx)
{
mode_ = Cylindrical;
isShell_ = false;
xMin_ = 0.0;
xMax_ = xMax;
nx_ = nx;
dx_ = xMax_/double(nx_ - 1);
computeVolume();
}
void Domain::setSphereParameters(double xMax, int nx)
{
mode_ = Spherical;
isShell_ = false;
xMin_ = 0.0;
xMax_ = xMax;
nx_ = nx;
dx_ = xMax_/double(nx_ - 1);
computeVolume();
}
void Domain::computeVolume()
{
if (mode_ == Planar) {
volume_ = xMax_ - xMin_;
} else
if (mode_ == Cylindrical) {
volume_ = xMax_*xMax_;
if (isShell_) {
volume_ -= xMin_*xMin_;
}
volume_ *= Constants::Pi;
} else
if (mode_ == Spherical) {
volume_ = xMax_*xMax_*xMax_;
if (isShell_) {
volume_ -= xMin_*xMin_*xMin_;
}
volume_ *= Constants::Pi*(4.0/3.0);
} else {
UTIL_THROW("Invalid geometry mode");
}
}
/*
* Compute spatial average of a field.
*/
double Domain::spatialAverage(Field const & f) const
{
UTIL_CHECK(nx_ > 1);
UTIL_CHECK(dx_ > 0.0);
UTIL_CHECK(xMax_ - xMin_ >= dx_);
UTIL_CHECK(nx_ == f.capacity());
double sum = 0.0;
double norm = 0.0;
if (mode_ == Planar) {
sum += 0.5*f[0];
for (int i = 1; i < nx_ - 1; ++i) {
sum += f[i];
}
sum += 0.5*f[nx_ - 1];
norm = double(nx_ - 1);
} else
if (mode_ == Cylindrical) {
double x0 = xMin_/dx_;
// First value
if (isShell_) {
sum += 0.5*x0*f[0];
norm += 0.5*x0;
} else {
sum += f[0]/8.0;
norm += 1.0/8.0;
}
// Interior values
double x;
for (int i = 1; i < nx_ - 1; ++i) {
x = x0 + double(i);
sum += x*f[i];
norm += x;
}
// Last value
x = x0 + double(nx_-1);
sum += 0.5*x*f[nx_-1];
norm += 0.5*x;
} else
if (mode_ == Spherical) {
double x0 = xMin_/dx_;
// First value
if (isShell_) {
sum += 0.5*x0*x0*f[0];
norm += 0.5*x0*x0;
} else {
sum += f[0]/24.0;
norm += 1.0/24.0;
}
// Interior values
double x;
for (int i = 1; i < nx_ - 1; ++i) {
x = x0 + double(i);
sum += x*x*f[i];
norm += x*x;
}
// Last value
x = x0 + double(nx_-1);
sum += 0.5*x*x*f[nx_-1];
norm += 0.5*x*x;
} else {
UTIL_THROW("Invalid geometry mode");
}
return sum/norm;
}
/*
* Compute inner product of two real fields.
*/
double Domain::innerProduct(Field const & f, Field const & g) const
{
// Preconditions
UTIL_CHECK(nx_ > 1);
UTIL_CHECK(nx_ == f.capacity());
UTIL_CHECK(nx_ == g.capacity());
if (!work_.isAllocated()) {
work_.allocate(nx_);
} else {
UTIL_ASSERT(nx_ == work_.capacity());
}
// Compute average of f(x)*g(x)
for (int i = 0; i < nx_; ++i) {
work_[i] = f[i]*g[i];
}
return spatialAverage(work_);
}
}
}
| 4,922
|
C++
|
.cpp
| 193
| 17.782383
| 70
| 0.464468
|
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,534,952
|
pscf_pc3.cpp
|
dmorse_pscfpp/src/pspc/pscf_pc3.cpp
|
/*
* 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 <pspc/System.h>
int main(int argc, char **argv)
{
Pscf::Pspc::System<3> system;
// Process command line options
system.setOptions(argc, argv);
// Read parameters from default parameter file
system.readParam();
// Read command script to run system
system.readCommands();
return 0;
}
| 508
|
C++
|
.cpp
| 18
| 25.555556
| 67
| 0.737603
|
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,534,953
|
pscf_pc1.cpp
|
dmorse_pscfpp/src/pspc/pscf_pc1.cpp
|
/*
* 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 <pspc/System.h>
int main(int argc, char **argv)
{
Pscf::Pspc::System<1> system;
// Process command line options
system.setOptions(argc, argv);
// Read parameters from default parameter file
system.readParam();
// Read command script to run system
system.readCommands();
return 0;
}
| 508
|
C++
|
.cpp
| 18
| 25.555556
| 67
| 0.737603
|
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,534,954
|
System.cpp
|
dmorse_pscfpp/src/pspc/System.cpp
|
/*
* 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.tpp"
namespace Pscf {
namespace Pspc
{
template class System<1>;
template class System<2>;
template class System<3>;
} // namespace Pspc
} // namespace Pscf
| 374
|
C++
|
.cpp
| 15
| 23.066667
| 67
| 0.757746
|
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,534,955
|
pscf_pc2.cpp
|
dmorse_pscfpp/src/pspc/pscf_pc2.cpp
|
/*
* 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 <pspc/System.h>
int main(int argc, char **argv)
{
Pscf::Pspc::System<2> system;
// Process command line options
system.setOptions(argc, argv);
// Read parameters from default parameter file
system.readParam();
// Read command script to run system
system.readCommands();
return 0;
}
| 508
|
C++
|
.cpp
| 18
| 25.555556
| 67
| 0.737603
|
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,534,956
|
IteratorFactory.cpp
|
dmorse_pscfpp/src/pspc/iterator/IteratorFactory.cpp
|
/*
* 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 "IteratorFactory.tpp"
namespace Pscf {
namespace Pspc {
template class IteratorFactory<1>;
template class IteratorFactory<2>;
template class IteratorFactory<3>;
}
}
| 372
|
C++
|
.cpp
| 14
| 24.785714
| 67
| 0.783708
|
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,534,957
|
FilmIterator.cpp
|
dmorse_pscfpp/src/pspc/iterator/FilmIterator.cpp
|
/*
* 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 "FilmIterator.tpp"
#include "AmIterator.tpp"
namespace Pscf {
namespace Pspc {
template class FilmIterator<1, AmIterator<1> >;
template class FilmIterator<2, AmIterator<2> >;
template class FilmIterator<3, AmIterator<3> >;
}
}
| 437
|
C++
|
.cpp
| 15
| 27.2
| 67
| 0.76555
|
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,534,958
|
AmIterator.cpp
|
dmorse_pscfpp/src/pspc/iterator/AmIterator.cpp
|
/*
* 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 "AmIterator.tpp"
namespace Pscf {
namespace Pspc {
template class AmIterator<1>;
template class AmIterator<2>;
template class AmIterator<3>;
}
}
| 354
|
C++
|
.cpp
| 14
| 23.357143
| 67
| 0.770833
|
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,534,959
|
Block.cpp
|
dmorse_pscfpp/src/pspc/solvers/Block.cpp
|
/*
* 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.tpp"
namespace Pscf {
namespace Pspc {
template class Block<1>;
template class Block<2>;
template class Block<3>;
}
}
| 335
|
C++
|
.cpp
| 14
| 21.928571
| 67
| 0.753943
|
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,534,960
|
Mixture.cpp
|
dmorse_pscfpp/src/pspc/solvers/Mixture.cpp
|
/*
* PSCF - Mixture 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 "Mixture.tpp"
namespace Pscf {
namespace Pspc {
template class Mixture<1>;
template class Mixture<2>;
template class Mixture<3>;
}
}
| 343
|
C++
|
.cpp
| 14
| 22.5
| 67
| 0.76
|
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,534,961
|
Propagator.cpp
|
dmorse_pscfpp/src/pspc/solvers/Propagator.cpp
|
/*
* 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.tpp"
namespace Pscf {
namespace Pspc {
template class Propagator<1>;
template class Propagator<2>;
template class Propagator<3>;
}
}
| 355
|
C++
|
.cpp
| 14
| 23.357143
| 67
| 0.768546
|
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,534,962
|
Polymer.cpp
|
dmorse_pscfpp/src/pspc/solvers/Polymer.cpp
|
/*
* 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.tpp"
namespace Pscf {
namespace Pspc {
template class Polymer<1>;
template class Polymer<2>;
template class Polymer<3>;
}
}
| 343
|
C++
|
.cpp
| 14
| 22.5
| 67
| 0.76
|
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,534,963
|
Solvent.cpp
|
dmorse_pscfpp/src/pspc/solvers/Solvent.cpp
|
/*
* 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 "Solvent.tpp"
namespace Pscf {
namespace Pspc {
template class Solvent<1>;
template class Solvent<2>;
template class Solvent<3>;
}
}
| 343
|
C++
|
.cpp
| 14
| 22.5
| 67
| 0.76
|
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,534,964
|
LinearSweep.cpp
|
dmorse_pscfpp/src/pspc/sweep/LinearSweep.cpp
|
/*
* 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 "LinearSweep.tpp"
namespace Pscf {
namespace Pspc
{
template class LinearSweep<1>;
template class LinearSweep<2>;
template class LinearSweep<3>;
} // namespace Pspc
} // namespace Pscf
| 412
|
C++
|
.cpp
| 15
| 24.4
| 67
| 0.735369
|
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,534,965
|
FieldState.cpp
|
dmorse_pscfpp/src/pspc/sweep/FieldState.cpp
|
/*
* 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 "FieldState.tpp"
namespace Pscf {
namespace Pspc
{
template class FieldState< 1, DArray<double> >;
template class FieldState< 2, DArray<double> >;
template class FieldState< 3, DArray<double> >;
} // namespace Pspc
} // namespace Pscf
| 462
|
C++
|
.cpp
| 15
| 27.733333
| 67
| 0.724605
|
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,534,966
|
Sweep.cpp
|
dmorse_pscfpp/src/pspc/sweep/Sweep.cpp
|
/*
* 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.tpp"
namespace Pscf {
namespace Pspc
{
template class Sweep<1>;
template class Sweep<2>;
template class Sweep<3>;
} // namespace Pspc
} // namespace Pscf
| 370
|
C++
|
.cpp
| 15
| 22.8
| 67
| 0.754986
|
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,534,967
|
SweepFactory.cpp
|
dmorse_pscfpp/src/pspc/sweep/SweepFactory.cpp
|
/*
* 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 "SweepFactory.tpp"
namespace Pscf {
namespace Pspc
{
template class SweepFactory<1>;
template class SweepFactory<2>;
template class SweepFactory<3>;
} // namespace Pspc
} // namespace Pscf
| 416
|
C++
|
.cpp
| 15
| 24.666667
| 67
| 0.738035
|
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,534,968
|
BasisFieldState.cpp
|
dmorse_pscfpp/src/pspc/sweep/BasisFieldState.cpp
|
/*
* 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 "BasisFieldState.tpp"
namespace Pscf {
namespace Pspc
{
template class BasisFieldState<1>;
template class BasisFieldState<2>;
template class BasisFieldState<3>;
} // namespace Pspc
} // namespace Pscf
| 410
|
C++
|
.cpp
| 15
| 25.466667
| 67
| 0.780051
|
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,534,969
|
Mask.cpp
|
dmorse_pscfpp/src/pspc/field/Mask.cpp
|
/*
* 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 "Mask.tpp"
namespace Pscf {
namespace Pspc
{
template class Mask<1>;
template class Mask<2>;
template class Mask<3>;
} // namespace Pspc
} // namespace Pscf
| 366
|
C++
|
.cpp
| 15
| 22.533333
| 67
| 0.752161
|
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,534,970
|
CFieldContainer.cpp
|
dmorse_pscfpp/src/pspc/field/CFieldContainer.cpp
|
/*
* 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 "CFieldContainer.tpp"
namespace Pscf {
namespace Pspc
{
template class CFieldContainer<1>;
template class CFieldContainer<2>;
template class CFieldContainer<3>;
} // namespace Pspc
} // namespace Pscf
| 410
|
C++
|
.cpp
| 15
| 25.466667
| 67
| 0.780051
|
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,534,971
|
KFieldComparison.cpp
|
dmorse_pscfpp/src/pspc/field/KFieldComparison.cpp
|
/*
* 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 "KFieldComparison.tpp"
namespace Pscf {
namespace Pspc {
template class KFieldComparison<1>;
template class KFieldComparison<2>;
template class KFieldComparison<3>;
} // namespace Pscf::Pspc
} // namespace Pscf
| 420
|
C++
|
.cpp
| 14
| 28.071429
| 67
| 0.778607
|
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,534,972
|
FFT.cpp
|
dmorse_pscfpp/src/pspc/field/FFT.cpp
|
/*
* PSCF Package
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "FFT.tpp"
namespace Pscf {
namespace Pspc {
using namespace Util;
// Explicit class instantiations
template class FFT<1>;
template class FFT<2>;
template class FFT<3>;
// Planning functions, explicit specializations.
template<>
void FFT<1>::makePlans(RField<1>& rField, RFieldDft<1>& kField)
{
unsigned int flags = FFTW_ESTIMATE;
fPlan_ = fftw_plan_dft_r2c_1d(rSize_, &rField[0], &kField[0], flags);
iPlan_ = fftw_plan_dft_c2r_1d(rSize_, &kField[0], &rField[0], flags);
}
template <>
void FFT<2>::makePlans(RField<2>& rField, RFieldDft<2>& kField)
{
unsigned int flags = FFTW_ESTIMATE;
fPlan_ = fftw_plan_dft_r2c_2d(meshDimensions_[0], meshDimensions_[1],
&rField[0], &kField[0], flags);
iPlan_ = fftw_plan_dft_c2r_2d(meshDimensions_[0], meshDimensions_[1],
&kField[0], &rField[0], flags);
}
template <>
void FFT<3>::makePlans(RField<3>& rField, RFieldDft<3>& kField)
{
unsigned int flags = FFTW_ESTIMATE;
fPlan_ = fftw_plan_dft_r2c_3d(meshDimensions_[0], meshDimensions_[1],
meshDimensions_[2], &rField[0], &kField[0],
flags);
iPlan_ = fftw_plan_dft_c2r_3d(meshDimensions_[0], meshDimensions_[1],
meshDimensions_[2], &kField[0], &rField[0],
flags);
}
}
}
| 1,650
|
C++
|
.cpp
| 44
| 29.022727
| 79
| 0.587461
|
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,534,973
|
RFieldDft.cpp
|
dmorse_pscfpp/src/pspc/field/RFieldDft.cpp
|
/*
* PSCF Package
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "RFieldDft.tpp"
namespace Pscf {
namespace Pspc
{
template class RFieldDft<1>;
template class RFieldDft<2>;
template class RFieldDft<3>;
}
}
| 320
|
C++
|
.cpp
| 15
| 19.4
| 67
| 0.76412
|
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,534,974
|
BFieldComparison.cpp
|
dmorse_pscfpp/src/pspc/field/BFieldComparison.cpp
|
/*
* 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 "BFieldComparison.h"
namespace Pscf {
namespace Pspc {
// Constructor
BFieldComparison::BFieldComparison(int begin)
: FieldComparison< DArray<double> > (begin)
{};
}
}
| 381
|
C++
|
.cpp
| 15
| 23.266667
| 67
| 0.756906
|
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,534,975
|
RFieldComparison.cpp
|
dmorse_pscfpp/src/pspc/field/RFieldComparison.cpp
|
#define PSPC_R_FIELD_COMPARISON_CPP
/*
* 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 "RFieldComparison.h"
namespace Pscf {
namespace Pspc
{
template class RFieldComparison<1>;
template class RFieldComparison<2>;
template class RFieldComparison<3>;
} // namespace Pscf::Pspc
} // namespace Pscf
| 455
|
C++
|
.cpp
| 16
| 26.5625
| 67
| 0.78341
|
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,534,976
|
RField.cpp
|
dmorse_pscfpp/src/pspc/field/RField.cpp
|
/*
* PSCF Package
*
* Copyright 2016 - 2022, The Regents of the University of Minnesota
* Distributed under the terms of the GNU General Public License.
*/
#include "RField.tpp"
namespace Pscf {
namespace Pspc
{
template class RField<1>;
template class RField<2>;
template class RField<3>;
}
}
| 308
|
C++
|
.cpp
| 15
| 18.6
| 67
| 0.754325
|
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,534,977
|
Domain.cpp
|
dmorse_pscfpp/src/pspc/field/Domain.cpp
|
/*
* 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 "Domain.tpp"
namespace Pscf {
namespace Pspc
{
template class Domain<1>;
template class Domain<2>;
template class Domain<3>;
} // namespace Pspc
} // namespace Pscf
| 374
|
C++
|
.cpp
| 15
| 23.066667
| 67
| 0.757746
|
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,534,978
|
WFieldContainer.cpp
|
dmorse_pscfpp/src/pspc/field/WFieldContainer.cpp
|
/*
* 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 "WFieldContainer.tpp"
namespace Pscf {
namespace Pspc
{
template class WFieldContainer<1>;
template class WFieldContainer<2>;
template class WFieldContainer<3>;
} // namespace Pspc
} // namespace Pscf
| 410
|
C++
|
.cpp
| 15
| 25.466667
| 67
| 0.780051
|
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,534,979
|
FieldIo.cpp
|
dmorse_pscfpp/src/pspc/field/FieldIo.cpp
|
/*
* 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 "FieldIo.tpp"
namespace Pscf {
namespace Pspc
{
template class FieldIo<1>;
template class FieldIo<2>;
template class FieldIo<3>;
} // namespace Pscf::Pspc
} // namespace Pscf
| 384
|
C++
|
.cpp
| 15
| 23.733333
| 67
| 0.758904
|
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,534,980
|
Test.cc
|
dmorse_pscfpp/docs/notes/draft/cyln/tests/misc/Test.cc
|
/*
* This program runs all unit tests in the pssp/tests/fftw directory.
*/
#include <util/global.h>
#include "DomainTest.h"
//#include "FieldTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
TEST_RUNNER(DomainTest) runner;
//MiscTestComposite runner;
#if 0
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
#endif
runner.run();
}
| 496
|
C++
|
.cc
| 22
| 19.5
| 68
| 0.682303
|
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,534,981
|
Test.cc
|
dmorse_pscfpp/docs/notes/draft/cyln/tests/field/Test.cc
|
/*
* This program runs all unit tests in the pssp/tests/fftw directory.
*/
#include <util/global.h>
//#include "RFieldTest.h"
#include "FieldTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
//TEST_RUNNER(RMeshFieldTest) runner;
FieldTestComposite runner;
#if 0
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
#endif
runner.run();
}
| 501
|
C++
|
.cc
| 22
| 19.727273
| 68
| 0.685654
|
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,534,982
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests directory.
*/
#include <test/CompositeTestRunner.h>
#include "math/MathTestComposite.h"
#include "chem/ChemTestComposite.h"
#include "solvers/SolversTestComposite.h"
#include "inter/InterTestComposite.h"
#include "homogeneous/HomogeneousTestComposite.h"
#include "mesh/MeshTestComposite.h"
#include "crystal/CrystalTestComposite.h"
#include <util/param/BracketPolicy.h>
#include <util/global.h>
TEST_COMPOSITE_BEGIN(PscfNsTestComposite)
addChild(new MathTestComposite, "math/");
addChild(new ChemTestComposite, "chem/");
addChild(new SolversTestComposite, "solvers/");
addChild(new InterTestComposite, "inter/");
addChild(new HomogeneousTestComposite, "homogeneous/");
addChild(new MeshTestComposite, "mesh/");
addChild(new CrystalTestComposite, "crystal/");
TEST_COMPOSITE_END
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
BracketPolicy::set(BracketPolicy::Optional);
try {
PscfNsTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
// Run all unit test methods
int failures = runner.run();
if (failures != 0) {
failures = 1;
}
return failures;
} catch (...) {
std::cerr << "Uncaught exception in pscf/tests/Test.cc" << std::endl;
return 1;
}
}
| 1,437
|
C++
|
.cc
| 46
| 27.391304
| 75
| 0.718135
|
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,534,983
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/solvers/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/solvers directory.
*/
#include <util/global.h>
#include "SolversTestComposite.h"
#include <util/param/BracketPolicy.h>
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
BracketPolicy::set(BracketPolicy::Optional);
SolversTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 525
|
C++
|
.cc
| 21
| 22.047619
| 71
| 0.716867
|
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,534,984
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/mesh/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
//#include "MeshTest.h"
//#include "MeshIteratorTest.h"
#include "MeshTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
// TEST_RUNNER(MeshTest) runner;
//TEST_RUNNER(MeshIteratorTest) runner;
MeshTestComposite runner;
#if 0
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
#endif
runner.run();
}
| 611
|
C++
|
.cc
| 26
| 20.653846
| 68
| 0.701724
|
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,534,985
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/chem/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
#include "ChemTestComposite.h"
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
ChemTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 429
|
C++
|
.cc
| 19
| 19.631579
| 68
| 0.693827
|
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,534,986
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/crystal/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
#include "CrystalTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
CrystalTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
int failures = runner.run();
return (failures != 0);
}
| 505
|
C++
|
.cc
| 21
| 21.190476
| 68
| 0.699374
|
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,534,987
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/homogeneous/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
#include "HomogeneousTestComposite.h"
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
HomogeneousTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 443
|
C++
|
.cc
| 19
| 20.368421
| 68
| 0.704057
|
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,534,988
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/inter/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
#include "InterTestComposite.h"
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
InterTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 431
|
C++
|
.cc
| 19
| 19.736842
| 68
| 0.695332
|
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,534,989
|
Test.cc
|
dmorse_pscfpp/src/pscf/tests/math/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests/math directory.
*/
#include <util/global.h>
#include "MathTestComposite.h"
#include <test/CompositeTestRunner.h>
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
MathTestComposite runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 429
|
C++
|
.cc
| 19
| 19.631579
| 68
| 0.693827
|
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,534,990
|
Test.cc
|
dmorse_pscfpp/src/fd1d/tests/Test.cc
|
/*
* This program runs all unit tests in the fd1d/tests directory.
*/
#include <util/global.h>
#include <util/param/BracketPolicy.h>
#include "Fd1dTestComposite.h"
#include <test/CompositeTestRunner.h>
using namespace Fd1d;
using namespace Util;
int main(int argc, char* argv[])
{
BracketPolicy::set(BracketPolicy::Optional);
try {
Fd1dTestComposite runner;
// Optionally add file prefix given as command line argument
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
// Run all unit test functions
int failures = runner.run();
return (failures != 0);
} catch (...) {
std::cerr << "Uncaught exception in fd1d/tests/Test.cc" << std::endl;
return 1;
}
}
| 822
|
C++
|
.cc
| 29
| 23.310345
| 75
| 0.652455
|
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,534,991
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/Test.cc
|
/*
* This program runs all unit tests in the pscf/tests directory.
*/
#include <test/CompositeTestRunner.h>
#include "field/FieldTestComposite.h"
#include "solvers/SolverTestComposite.h"
#include "system/SystemTest.h"
#include "sweep/SweepTestComposite.h"
#include "iterator/IteratorTestComposite.h"
#include <util/param/BracketPolicy.h>
#include <util/global.h>
TEST_COMPOSITE_BEGIN(PspcNsTestComposite)
addChild(new FieldTestComposite, "field/");
addChild(new IteratorTestComposite, "iterator/");
addChild(new SolverTestComposite, "solvers/");
addChild(new TEST_RUNNER(SystemTest), "system/");
addChild(new SweepTestComposite, "sweep/");
TEST_COMPOSITE_END
using namespace Pscf;
using namespace Util;
int main(int argc, char* argv[])
{
BracketPolicy::set(BracketPolicy::Optional);
try {
PspcNsTestComposite runner;
// Add any file prefix given as command line argument
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
// Run all unit test methods
int failures = runner.run();
if (failures != 0) {
failures = 1;
}
return failures;
} catch (...) {
std::cerr << "Uncaught exception in pspc/tests/Test.cc" << std::endl;
return 1;
}
}
| 1,320
|
C++
|
.cc
| 43
| 26.55814
| 75
| 0.701587
|
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,534,992
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/iterator/Test.cc
|
/*
* This program runs all unit tests in the pspc/tests/iterator directory.
*/
#include <util/global.h>
#include "IteratorTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
IteratorTestComposite runner;
runner.run();
}
| 296
|
C++
|
.cc
| 12
| 22.916667
| 72
| 0.765957
|
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,534,993
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/solvers/Test.cc
|
/*
* This program runs all unit tests in the pspc/tests/fftw directory.
*/
#include <util/global.h>
#include "SolverTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
SolverTestComposite runner;
#if 0
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
#endif
runner.run();
}
| 436
|
C++
|
.cc
| 20
| 18.7
| 68
| 0.678832
|
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,534,994
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/sweep/Test.cc
|
/*
* This program runs all unit tests in the pspc/tests/sweep directory.
*/
#include <util/global.h>
#include "SweepTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
SweepTestComposite runner;
runner.run();
}
| 288
|
C++
|
.cc
| 12
| 22.166667
| 69
| 0.758242
|
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,534,995
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/system/Test.cc
|
/*
* This program runs all unit tests in the pspc/tests/fftw directory.
*/
#include <util/global.h>
#include "SystemTest.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
TEST_RUNNER(SystemTest) runner;
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
runner.run();
}
| 412
|
C++
|
.cc
| 18
| 19.888889
| 68
| 0.676093
|
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,534,996
|
Test.cc
|
dmorse_pscfpp/src/pspc/tests/field/Test.cc
|
/*
* This program runs all unit tests in the pspc/tests/fftw directory.
*/
#include <util/global.h>
//#include "RFieldTest.h"
#include "FieldTestComposite.h"
#include <test/TestRunner.h>
#include <test/CompositeTestRunner.h>
int main(int argc, char* argv[])
{
FieldTestComposite runner;
#if 0
if (argc > 2) {
UTIL_THROW("Too many arguments");
}
if (argc == 2) {
runner.addFilePrefix(argv[1]);
}
#endif
runner.run();
}
| 460
|
C++
|
.cc
| 21
| 18.904762
| 68
| 0.679724
|
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,534,997
|
AmIteratorOld.h
|
dmorse_pscfpp/docs/notes/attic/pspg/AmIteratorOld.h
|
#ifndef PSPG_AM_ITERATOR_OLD_H
#define PSPG_AM_ITERATOR_OLD_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 <pspg/iterator/Iterator.h> // base class
#include <pspg/solvers/Mixture.h>
#include <pscf/math/LuSolver.h>
#include <util/containers/DArray.h>
#include <util/containers/DMatrix.h>
#include <util/containers/RingBuffer.h>
#include <pspg/iterator/HistMatOld.h>
#include <pspg/field/RDField.h>
#include <util/containers/FArray.h>
// Always defined. Locks out legacy code that does nothing.
// Eventually remove all legacy code that references memory in cpu
//#define GPU_OUTER
// Define this if you want to use scft
//#define GPU_SCFT
namespace Pscf {
namespace Pspg {
using namespace Util;
/**
* Anderson mixing iterator for the pseudo spectral method
*
* \ingroup Pspg_Iterator_Module
*/
template <int D>
class AmIteratorOld : public Iterator<D>
{
public:
typedef RDField<D> WField;
typedef RDField<D> CField;
/**
* Constructor
*
* \param system pointer to a system object
*/
AmIteratorOld(System<D>& system);
/**
* Destructor
*/
~AmIteratorOld();
/**
* Read all parameters and initialize.
*
* \param in input filestream
*/
void readParameters(std::istream& in);
/**
* Allocate all arrays
*
*/
void setup();
/**
* Iterate to a solution
*
*/
int solve();
/**
* Getter for epsilon
*/
double epsilon();
/**
* Getter for the maximum number of field histories to
* convolute into a new field
*/
int maxHist();
/**
* Getter for the maximum number of iteration before convergence
*/
int maxItr();
/**
* Compute the deviation of wFields from a mean field solution
*/
void computeDeviation();
/**
* Compute the error from deviations of wFields and compare with epsilon_
* \return true for error < epsilon and false for error >= epsilon
*/
bool isConverged();
/**
* Determine the coefficients that would minimize invertMatrix_ Umn
*
*/
int minimizeCoeff(int itr);
/**
* Rebuild wFields for the next iteration from minimized coefficients
*/
void buildOmega(int itr);
private:
///error tolerance
double epsilon_;
/// Type of error checked for convergence.
/// Either maxResid or normResid.
std::string errorType_;
/// Flexible unit cell (1) or rigid cell (0), default value = 0
bool isFlexible_;
///free parameter for minimization
double lambda_;
///number of histories to convolute into a new solution [0,maxHist_]
int nHist_;
//maximum number of histories to convolute into a new solution
//AKA size of matrix
int maxHist_;
///number of maximum iteration to perform
int maxItr_;
/// holds histories of deviation for each monomer
/// 1st index = history, 2nd index = monomer, 3rd index = ngrid
// The ringbuffer used is now slightly modified to return by reference
RingBuffer< DArray < RDField<D> > > d_resHists_;
RingBuffer< DArray < RDField<D> > > d_omHists_;
/// holds histories of deviation for each cell parameter
/// 1st index = history, 2nd index = cell parameter
// The ringbuffer used is now slightly modified to return by reference
RingBuffer< FArray <double, 6> > devCpHists_;
RingBuffer< FSArray<double, 6> > CpHists_;
FSArray<double, 6> cellParameters_;
/// Umn, matrix to be minimized
DMatrix<double> invertMatrix_;
/// Cn, coefficient to convolute previous histories with
DArray<double> coeffs_;
DArray<double> vM_;
/// bigW, blended omega fields
DArray<RDField<D> > wArrays_;
/// bigWcP, blended parameter
FArray <double, 6> wCpArrays_;
/// bigDCp, blened deviation parameter. new wParameter = bigWCp + lambda * bigDCp
FArray <double, 6> dCpArrays_;
/// bigD, blened deviation fields. new wFields = bigW + lambda * bigD
DArray<RDField<D> > dArrays_;
DArray<RDField<D> > tempDev;
HistMatOld <cudaReal> histMat_;
cudaReal* d_temp_;
cudaReal* temp_;
using Iterator<D>::setClassName;
using Iterator<D>::system;
using ParamComposite::read;
using ParamComposite::readOptional;
//friend:
//for testing purposes
};
template<int D>
inline double AmIteratorOld<D>::epsilon()
{
return epsilon_;
}
template<int D>
inline int AmIteratorOld<D>::maxHist()
{
return maxHist_;
}
template<int D>
inline int AmIteratorOld<D>::maxItr()
{
return maxItr_;
}
#ifndef PSPG_AM_ITERATOR_OLD_TPP
// Suppress implicit instantiation
extern template class AmIteratorOld<1>;
extern template class AmIteratorOld<2>;
extern template class AmIteratorOld<3>;
#endif
}
}
#endif
| 5,217
|
C++
|
.h
| 169
| 25.053254
| 87
| 0.652061
|
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,534,998
|
CompositionSweep.h
|
dmorse_pscfpp/docs/notes/attic/fd1d/CompositionSweep.h
|
#ifndef FD1D_COMPOSITION_SWEEP_H
#define FD1D_COMPOSITION_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 <util/global.h>
namespace Pscf {
namespace Fd1d
{
class System;
using namespace Util;
/**
* Base class for solution along a line in parameter space.
*
* \ingroup Fd1d_Sweep_Module
*/
class CompositionSweep : public Sweep
{
public:
/**
* Constructor.
*/
CompositionSweep(System& system);
/**
* Destructor.
*/
~CompositionSweep();
/**
* Read parameters.
*
* \param in input stream
*/
virtual void readParameters(std::istream& in);
/**
* Initialization at beginning sweep.
*/
virtual void setup();
/**
* Iterate to solution.
*
* \param s path length coordinate, in [0,1]
*/
virtual void setParameters(double s);
/**
* Output data to a running summary.
*
* \param out output file, open for writing
*/
virtual void outputSummary(std::ostream& out);
private:
/**
* Molecular volume fractions at beginning of sweep (s=0).
*/
DArray<double> phi0_;
/**
* Change in molecule volume fractions over sweep s=[0,1].
*/
DArray<double> dPhi_;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 1,581
|
C++
|
.h
| 66
| 18.424242
| 67
| 0.605474
|
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,534,999
|
LengthSweep.h
|
dmorse_pscfpp/docs/notes/attic/fd1d/LengthSweep.h
|
#ifndef FD1D_LENGTH_SWEEP_H
#define FD1D_LENGTH_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 <util/global.h>
namespace Pscf {
namespace Fd1d
{
class System;
using namespace Util;
/**
* Base class for solution along a line in parameter space.
*
* \ingroup Fd1d_Sweep_Module
*/
class LengthSweep : public Sweep
{
public:
/**
* Constructor.
*
* \param system reference to parent system
*/
LengthSweep(System& system);
/**
* Destructor.
*/
~LengthSweep();
/**
* Read parameters.
*
* \param in input stream
*/
virtual void readParameters(std::istream& in);
/**
* Initialization at beginning sweep.
*/
virtual void setup();
/**
* Iterate to solution.
*
* \param s path length coordinate, in [0,1]
*/
virtual void setParameters(double s);
#if 0
/**
* Output data to a running summary.
*
* \param out output file, open for writing
*/
virtual void outputSummary(std::ostream& out);
#endif
private:
/**
* Id of polymer that is being swept
*/
int polymerId_;
/**
* Id of block in the polymer that is being swept
*/
int blockId_;
/**
* Length homopolymer at start of sweep (s=0).
*/
double length0_;
/**
* Change in kuhn length over sweep s=[0,1].
*/
double dLength_;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 1,785
|
C++
|
.h
| 78
| 17.089744
| 67
| 0.580913
|
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,000
|
MuSweep.h
|
dmorse_pscfpp/docs/notes/attic/fd1d/MuSweep.h
|
#ifndef FD1D_MU_SWEEP_H
#define FD1D_MU_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 <util/global.h>
namespace Pscf {
namespace Fd1d
{
class System;
using namespace Util;
/**
* Base class for solution along a line in parameter space.
*
* \ingroup Fd1d_Sweep_Module
*/
class MuSweep : public Sweep
{
public:
/**
* Constructor.
*
* \param system reference to parent System
*/
MuSweep(System& system);
/**
* Destructor.
*/
~MuSweep();
/**
* Read parameters.
*
* \param in input stream
*/
virtual void readParameters(std::istream& in);
/**
* Initialization at beginning sweep.
*/
virtual void setup();
/**
* Iterate to solution.
*
* \param s path length coordinate, in [0,1]
*/
virtual void setParameters(double s);
/**
* Output data to a running summary.
*
* \param out output file, open for writing
*/
virtual void outputSummary(std::ostream& out);
private:
/**
* Chemical potential at beginning of sweep (s=0).
*/
DArray<double> mu0_;
/**
* Change in chemical potential over sweep s=[0,1].
*/
DArray<double> dMu_;
};
} // namespace Fd1d
} // namespace Pscf
#endif
| 1,577
|
C++
|
.h
| 68
| 17.617647
| 67
| 0.590483
|
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,001
|
BFieldComparison.h
|
dmorse_pscfpp/docs/notes/draft/pspg/BFieldComparison.h
|
#ifndef PSPC_B_FIELD_COMPARISON_H
#define PSPC_B_FIELD_COMPARISON_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 <pscf/math/FieldComparison.h>
//#include <pspg/field/RDField.h>
#include <util/containers/DArray.h>
#include <pspg/field/DField.h>
#include <pspg/math/GpuResources.h>
namespace Pscf {
namespace Pspg {
using namespace Util;
/**
* Comparator for fields in symmetry-adapted basis format.
*/
class BFieldComparison
{
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);
double compare(DField<cudaReal> const& a, DField<cudaReal> const& b);
double compare(DArray<DField<cudaReal>> const& a, DArray<DField<cudaReal>> const& b);
// Get maxDiff from FieldComparison
double maxDiff() const
{ return fieldComparison_.maxDiff(); }
// Get rmsDiff from FieldComparison
double rmsDiff() const
{ return fieldComparison_.rmsDiff(); }
private:
// True if a comparison has been made, false otherwise.
bool compared_;
// Composition usage of FieldComparison, rather than inheritance.
FieldComparison< DArray< cudaReal > > fieldComparison_;
};
} // namespace Pspc
} // namespace Pscf
#endif
| 2,087
|
C++
|
.h
| 57
| 31.421053
| 91
| 0.70065
|
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,002
|
Helpers.h
|
dmorse_pscfpp/docs/notes/draft/pspg/Helpers.h
|
#ifndef PSPG_HELPERS_H
#define PSPG_HELPERS_H
#include "GpuTypes.h"
namespace Pscf {
namespace Pspg {
__global__ void helmholtzHelper(cudaReal* result, const cudaReal* composition,
const cudaReal* pressure, double chi, int size);
__global__ void reformField(cudaReal* Wa, cudaReal* Wb,
const cudaReal* pressureF,const cudaReal* compositionF, int size);
__global__ void mcftsStepHelper(cudaReal* result, const cudaReal* A2, const cudaReal* sqrtSq, int size);
__global__ void mcftsScale(cudaReal* result, cudaReal scale, int size);
}
}
#endif
| 554
|
C++
|
.h
| 14
| 37.642857
| 104
| 0.772983
|
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,003
|
Block_unused.h
|
dmorse_pscfpp/docs/notes/draft/pspg/Block_unused.h
|
static __global__
void pointwiseMul(const cudaReal* a,
const cudaReal* b,
cudaReal* result, int size)
{
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x + threadIdx.x;
for (int i = startID; i < size; i += nThreads) {
result[i] = a[i] * b[i];
}
}
static __global__
void pointwiseFloatMul(const cudaReal* a,
const float* b,
cudaReal* result, int size)
{
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x + threadIdx.x;
for (int i = startID; i < size; i += nThreads) {
result[i] = a[i] * b[i];
// printf("result[%d], = %d\n", i , result[i]);
}
}
static __global__
void equalize (const cudaReal* a, double* result, int size)
{
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x + threadIdx.x;
for (int i = startID; i < size; i += nThreads) {
result [i] = a [i];
}
}
static __global__
void pointwiseMulUnroll2(const cudaReal* a, const cudaReal* b,
cudaReal* result, int size)
{
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x * 2 + threadIdx.x * 2;
cudaReal localResult[2];
for (int i = startID; i < size; i += nThreads * 2) {
localResult[0] = a[i] * b[i];
localResult[1] = a[i + 1] * b[i + 1];
result[i] = localResult[0];
result[i + 1] = localResult[1];
//result[i] = a[i] * b[i];
//result[i + 1] = a[i + 1] * b[i + 1];
}
}
static __global__
void pointwiseMulCombi(cudaReal* a,const cudaReal* b,
cudaReal* c,const cudaReal* d,
const cudaReal* e, int size)
{
//c = a * b
//a = d * e
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x + threadIdx.x;
cudaReal tempA;
for (int i = startID; i < size; i += nThreads) {
tempA = a[i];
c[i] = tempA * b[i];
a[i] = d[i] * e[i];
}
}
static __global__
void richardsonExp(cudaReal* qNew, const cudaReal* q1,
const cudaReal* q2, int size)
{
int nThreads = blockDim.x * gridDim.x;
int startID = blockIdx.x * blockDim.x + threadIdx.x;
for (int i = startID; i < size; i += nThreads) {
qNew[i] = (4.0 * q2[i] - q1[i]) / 3.0;
}
}
| 2,586
|
C++
|
.h
| 74
| 25.945946
| 66
| 0.507594
|
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,004
|
HistMatOld.h
|
dmorse_pscfpp/docs/notes/draft/pspg/HistMatOld.h
|
#ifndef PSPG_HIST_MAT_H
#define PSPG_HIST_MAT_H
#include <util/containers/DMatrix.h>
namespace Pscf {
namespace Pspg
{
using namespace Util;
template <typename Data>
//upper triangular
class HistMatOld : public DMatrix<double> {
public:
HistMatOld();
HistMatOld(int n);
~HistMatOld();
//allocate an internal matrix of size maxHist + 1 to keep d(k)d'(k) values
//requires maxHist to be constant within simulation.
void allocate(int capacity);
//reset the state of the HistMatOld
//the matrix remains allocated with all values set to zero
//boolean flags all reset to initial state
void reset();
void clearColumn(int nHist);
//insert new d(k)d'(k) value
void evaluate(float elm, int nHist, int columnId);
double makeUmn(int i,int j, int nHist);
double makeVm(int i, int nHist);
private:
int maxHist_; //keeps a copy of max history
bool filled_ = false;
};
template<typename Data>
HistMatOld<Data>::HistMatOld()
: maxHist_(0){}
template<typename Data>
HistMatOld<Data>::HistMatOld(int n)
: maxHist_(n){}
template<typename Data>
HistMatOld<Data>::~HistMatOld() {}
template<typename Data>
void HistMatOld<Data>::allocate(int capacity) {
maxHist_ = capacity - 1;
DMatrix<double>::allocate(capacity, capacity);
}
template<typename Data>
void HistMatOld<Data>::reset() {
filled_ = false;
for (int i = 0; i < maxHist_ + 1; ++i) {
for (int j = 0; j < maxHist_ + 1; ++j) {
(*this)(i, j) = 0;
}
}
}
template<typename Data>
void HistMatOld<Data>::clearColumn(int nHist) {
//if the matrix is not entirely filled
if (nHist <= maxHist_ && !filled_) {
//set to zero
for (int i = maxHist_; i > maxHist_ - nHist - 1; --i) {
(*this)(maxHist_ - nHist, i) = 0;
}
if (nHist == maxHist_) {
filled_ = true;
}
}
else { //out of space
for (int i = maxHist_; i > 0; i--) {
for (int j = maxHist_; j > i - 1; j--) {
(*this)(i, j) = (*this)(i - 1, j - 1);
}
}
for (int i = 0; i < maxHist_ + 1; i++) {
(*this)(0, i) = 0;
}
}
}
template<typename Data>
void HistMatOld<Data>::evaluate(float elm, int nHist, int columnId) {
if (nHist < maxHist_) { //if matrix is not filled, something tricky
(*this)(maxHist_ - nHist, columnId + maxHist_ - nHist) = (double)elm;
}
else { //just fill the first row
(*this)(0, columnId) = (double)elm;
}
}
template<typename Data>
double HistMatOld<Data>::makeUmn(int i, int j, int nHist) {
int offset;
if (nHist < maxHist_) { //matrix is not filled, soemthing tricky
offset = maxHist_ - nHist;
}
else { //matrix is filled
offset = 0;
}
return (*this)(offset, offset) + (*this)(offset + 1 + i , offset + 1 + j) -
(*this)(offset, offset + 1 + i) - (*this)(offset, offset + 1 + j);
}
template<typename Data>
double HistMatOld<Data>::makeVm(int i, int nHist) {
int offset;
if (nHist < maxHist_) {
offset = maxHist_ - nHist;
}
else {
offset = 0;
}
return (*this)(offset, offset) - (*this)(offset, offset + i + 1);
}
}
}
#endif
| 3,451
|
C++
|
.h
| 110
| 24.618182
| 81
| 0.567038
|
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,005
|
Interaction.h
|
dmorse_pscfpp/docs/notes/draft/pscf/Interaction.h
|
#ifndef PSCF_INTERACTION_H
#define PSCF_INTERACTION_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 <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;
/**
* Base class for excess free energy models.
*
* \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);
/**
* Compute excess Helmholtz free energy per monomer.
*
* \param c array of concentrations, for each type (input)
*/
virtual
double fHelmholtz(Array<double> const & c) const = 0;
/**
* Compute interaction contributions to chemical potentials.
*
* The resulting chemical potential fields are those obtained
* with a vanishing Lagrange multiplier / pressure field, xi = 0.
*
* \param c array of concentrations, for each type (input)
* \param w array of chemical potentials, for each type (output)
*/
virtual
void computeW(Array<double> const & c, Array<double>& w)
const = 0;
/**
* Compute concentration and xi from chemical potentials.
*
* \param w array of chemical potentials, for each type (input)
* \param c array of concentrations, for each type (output)
* \param xi Lagrange multiplier pressure (output)
*/
virtual
void computeC(Array<double> const & w,
Array<double>& c, double& xi) const = 0;
/**
* Compute Langrange multiplier xi from chemical potentials.
*
* \param w array of chemical potentials, for each type (input)
* \param xi Lagrange multiplier pressure (output)
*/
virtual
void computeXi(Array<double> const & w, double& xi) const = 0;
/**
* Compute matrix of derivatives of w fields w/ respect to c fields.
*
* Upon return, the elements of the matrix dWdC are given by
* derivatives elements dWdC(i,j) = dW(i)/dC(j), which are also
* second derivatives of fHelmholtz with respect to concentrations.
*
* \param c array of concentrations, for each type (input)
* \param dWdC square symmetric matrix of derivatives (output)
*/
virtual
void computeDwDc(Array<double> const & c, Matrix<double>& dWdC)
const = 0;
/**
* Get number of monomer types.
*/
int nMonomer() const;
private:
/// Number of monomers
int nMonomer_;
};
/**
* Get number of monomer types.
*/
inline
int Interaction::nMonomer() const
{ return nMonomer_; }
} // namespace Pscf
#endif
| 3,230
|
C++
|
.h
| 102
| 25.45098
| 73
| 0.629665
|
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.