1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/STRUCTURE/RDFSection.h>
#include <BALL/FORMAT/parameters.h>
#include <limits>
using namespace std;
namespace BALL
{
RDFSection::RDFSection()
: ParameterSection(),
rdf_()
{
}
RDFSection::RDFSection(const RDFSection& rdf_section)
: ParameterSection(),
rdf_(rdf_section.rdf_)
{
}
RDFSection::~RDFSection()
{
clear();
valid_ = false;
}
void RDFSection::clear()
{
rdf_.clear();
ParameterSection::clear();
}
const RDFSection& RDFSection::operator = (const RDFSection& rdf_section)
{
ParameterSection::operator = (rdf_section);
rdf_ = rdf_section.rdf_;
return *this;
}
const RadialDistributionFunction& RDFSection::getRDF() const
{
return rdf_;
}
bool RDFSection::operator == (const RDFSection& section) const
{
return (ParameterSection::operator == (section)
&& (rdf_ == section.rdf_));
}
bool RDFSection::extractSection(Parameters& parameters,
const String& section_name)
{
if (!parameters.isValid())
{
return false;
}
int type;
// extract the basis information
ParameterSection::extractSection(parameters, section_name);
if (options.has("type"))
{
if (options.get("type") == "piecewise_polynomial")
{
type = PIECEWISE_POLYNOMIAL;
}
else
{
Log.error() << "RDFSection::extractSection(): "
<< "Unknown type." << endl;
return false;
}
}
else
{
Log.warn() << "RDFSection::extractSection(): "
<< "no type given, assuming piecewise_polynomial." << endl;
type = PIECEWISE_POLYNOMIAL;
}
PiecewisePolynomial poly;
Interval interval;
std::vector<Interval> intervals;
Size number_of_intervals;
Size degree;
Coefficients coeffs;
std::vector<Coefficients> coefficients;
String upper_limit;
switch(type)
{
case PIECEWISE_POLYNOMIAL:
if (options.has("degree"))
{
degree = options.get("degree").toInt();
}
else
{
Log.warn() << "RDFSection::extractSection(): "
<< "No degree given, assuming 4." << endl;
degree = 4;
}
coeffs.resize(degree);
number_of_intervals = getNumberOfKeys();
intervals.resize(number_of_intervals);
coefficients.resize(number_of_intervals);
for (Size i = 0; i < number_of_intervals; ++i)
{
interval.first = getValue(i, 0).toFloat();
// special case: an upper limit can be infinity
upper_limit = getValue(i, 1);
if (upper_limit == "inf")
{
interval.second = std::numeric_limits<double>::infinity();
}
else
{
interval.second = getValue(i, 1).toFloat();
}
for (Size col = 0; col < degree; ++col)
{
coeffs[col] = getValue(i, col + 2).toFloat();
}
intervals[i] = interval;
coefficients[i] = coeffs;
}
poly.set(degree, intervals, coefficients);
rdf_ = RadialDistributionFunction(poly);
return true;
default:
Log.error() << "RDFSection::extractSection(): "
<< "Unknown type." << endl;
return false;
}
}
} // namespace BALL
|