Permalink
Browse files

Merge pull request #12878 from permcody/remove_unused_code

Removing old deprecated and used code
  • Loading branch information...
rwcarlsen committed Feb 8, 2019
2 parents 34faf52 + 2834008 commit e5a4292361b36c0797ef2d971202e3a04cb78cf6
@@ -55,18 +55,6 @@ class LinearInterpolation
*/
Real sampleDerivative(Real x) const;

/**
* This function will dump GNUPLOT input files that can be run to show the data points and
* function fits
*/
void dumpSampleFile(std::string base_name,
std::string x_label = "X",
std::string y_label = "Y",
Real xmin = 0,
Real xmax = 0,
Real ymin = 0,
Real ymax = 0);

/**
* This function returns the size of the array holding the points, i.e. the number of sample
* points
@@ -33,18 +33,6 @@ class PolynomialFit : public LeastSquaresFitBase

virtual Real sample(Real x) override;

/**
* Dump GNUPLOT input files that can be run to show the data points and
* function fits
*/
void dumpSampleFile(std::string base_name,
std::string x_label = "X",
std::string y_label = "Y",
float xmin = 0,
float xmax = 0,
float ymin = 0,
float ymax = 0);

protected:
virtual void fillMatrix() override;
/// Order of the polynomial
@@ -58,18 +58,6 @@ class SplineInterpolation : public SplineInterpolationBase

Real sample2ndDerivative(Real x) const;

/**
* This function will dump GNUPLOT input files that can be run to show the data points and
* function fits
*/
void dumpSampleFile(std::string base_name,
std::string x_label = "X",
std::string y_label = "Y",
float xmin = 0,
float xmax = 0,
float ymin = 0,
float ymax = 0);

/**
* This function returns the size of the array holding the points, i.e. the number of sample
* points
@@ -97,71 +97,6 @@ LinearInterpolation::range(int i) const
return _y[i];
}

void
LinearInterpolation::dumpSampleFile(std::string base_name,
std::string x_label,
std::string y_label,
Real xmin,
Real xmax,
Real ymin,
Real ymax)
{
std::stringstream filename, filename_pts;
const unsigned char fill_character = '0';
const unsigned int field_width = 4;

filename.fill(fill_character);
filename << base_name;
filename.width(field_width);
filename << _file_number << ".plt";

filename_pts.fill(fill_character);
filename_pts << base_name << "_pts";
filename_pts.width(field_width);
filename_pts << _file_number << ".dat";

/* First dump the GNUPLOT file with the Piecewise Linear Equations */
std::ofstream out(filename.str().c_str());
out.precision(15);
out.fill(fill_character);

out << "set terminal postscript color enhanced\n"
<< "set output \"" << base_name;
out.width(field_width);
out << _file_number << ".eps\"\n"
<< "set xlabel \"" << x_label << "\"\n"
<< "set ylabel \"" << y_label << "\"\n";
if (xmin != 0 && xmax != 0)
out << "set xrange [" << xmin << ":" << xmax << "]\n";
if (ymin != 0 && ymax != 0)
out << "set yrange [" << ymin << ":" << ymax << "]\n";
out << "set key left top\n"
<< "f(x)=";

for (unsigned int i = 1; i < _x.size(); ++i)
{
Real m = (_y[i] - _y[i - 1]) / (_x[i] - _x[i - 1]);
Real b = (_y[i] - m * _x[i]);

out << _x[i - 1] << "<=x && x<" << _x[i] << " ? " << m << "*x+(" << b << ") : ";
}
out << " 1/0\n";

out << "\nplot f(x) with lines, '" << filename_pts.str() << "' using 1:2 title \"Points\"\n";
out.close();

assert(_x.size() == _y.size());

out.open(filename_pts.str().c_str());
/* Next dump the data points into a separate file */
for (unsigned int i = 0; i < _x.size(); ++i)
out << _x[i] << " " << _y[i] << "\n";
out << std::endl;

++_file_number;
out.close();
}

unsigned int
LinearInterpolation::getSampleSize()
{
@@ -71,71 +71,3 @@ PolynomialFit::sample(Real x)
}
return value;
}

void
PolynomialFit::dumpSampleFile(std::string base_name,
std::string x_label,
std::string y_label,
float xmin,
float xmax,
float ymin,
float ymax)
{
std::stringstream filename, filename_pts;
const unsigned char fill_character = '0';
const unsigned int field_width = 4;

filename.fill(fill_character);
filename << base_name;
filename.width(field_width);
filename << _file_number << ".plt";

filename_pts.fill(fill_character);
filename_pts << base_name << "_pts";
filename_pts.width(field_width);
filename_pts << _file_number << ".dat";

/* First dump the GNUPLOT file with the Least Squares Equations */
std::ofstream out(filename.str().c_str());
out.precision(15);
out.fill(fill_character);

out << "set terminal postscript color enhanced\n"
<< "set output \"" << base_name;
out.width(field_width);
out << _file_number << ".eps\"\n"
<< "set xlabel \"" << x_label << "\"\n"
<< "set ylabel \"" << y_label << "\"\n";
if (xmin != 0 && xmax != 0)
out << "set xrange [" << xmin << ":" << xmax << "]\n";
if (ymin != 0 && ymax != 0)
out << "set yrange [" << ymin << ":" << ymax << "]\n";
out << "set key left top\n"
<< "f(x)=";

for (unsigned int i = 0; i < _coeffs.size(); ++i)
{
if (i)
out << "+";

out << _coeffs[i];
for (unsigned int j = 0; j < i; ++j)
out << "*x";
}
out << "\nplot f(x) with lines, '" << filename_pts.str() << "' using 1:2 title \"Points\"\n";
out.close();

libmesh_assert(_x.size() == _y.size());

out.open(filename_pts.str().c_str());
if (out.fail())
throw std::runtime_error(std::string("Unable to open file ") + filename_pts.str());

/* Next dump the data points into a seperate file */
for (unsigned int i = 0; i < _x.size(); ++i)
out << _x[i] << " " << _y[i] << "\n";
out << std::endl;

++_file_number;
out.close();
}
@@ -94,74 +94,6 @@ SplineInterpolation::range(int i) const
return _y[i];
}

void
SplineInterpolation::dumpSampleFile(std::string base_name,
std::string x_label,
std::string y_label,
float xmin,
float xmax,
float ymin,
float ymax)
{
std::stringstream filename, filename_pts;
const unsigned char fill_character = '0';
const unsigned int field_width = 4;

filename.fill(fill_character);
filename << base_name;
filename.width(field_width);
filename << _file_number << ".plt";

filename_pts.fill(fill_character);
filename_pts << base_name << "_pts";
filename_pts.width(field_width);
filename_pts << _file_number << ".dat";

/* First dump the GNUPLOT file with the Piecewise Linear Equations */
std::ofstream out(filename.str().c_str());
out.precision(15);
out.fill(fill_character);

out << "set terminal postscript color enhanced\n"
<< "set output \"" << base_name;
out.width(field_width);
out << _file_number << ".eps\"\n"
<< "set xlabel \"" << x_label << "\"\n"
<< "set ylabel \"" << y_label << "\"\n";
if (xmin != 0 && xmax != 0)
out << "set xrange [" << xmin << ":" << xmax << "]\n";
if (ymin != 0 && ymax != 0)
out << "set yrange [" << ymin << ":" << ymax << "]\n";
out << "set key left top\n"
<< "f(x)=";

for (unsigned int i = 1; i < _x.size(); ++i)
{
Real m = (_y[i] - _y[i - 1]) / (_x[i] - _x[i - 1]);
Real b = (_y[i] - m * _x[i]);

out << _x[i - 1] << "<=x && x<" << _x[i] << " ? " << m << "*x+(" << b << ") : ";
}
out << " 1/0\n";

out << "\nplot f(x) with lines, '" << filename_pts.str() << "' using 1:2 title \"Points\"\n";
out.close();

libmesh_assert(_x.size() == _y.size());

out.open(filename_pts.str().c_str());
if (out.fail())
throw std::runtime_error(std::string("Unable to open file ") + filename_pts.str());

/* Next dump the data points into a seperate file */
for (unsigned int i = 0; i < _x.size(); ++i)
out << _x[i] << " " << _y[i] << "\n";
out << std::endl;

++_file_number;
out.close();
}

unsigned int
SplineInterpolation::getSampleSize()
{
@@ -12,10 +12,9 @@

#include "Material.h"

#include "LinearInterpolation.h"
#include "PolynomialFit.h"

class LinearInterpolationMaterial;
class LinearInterpolation;
class PolynomialFit;

template <>
InputParameters validParams<LinearInterpolationMaterial>();
@@ -25,14 +24,12 @@ class LinearInterpolationMaterial : public Material
public:
LinearInterpolationMaterial(const InputParameters & parameters);

virtual ~LinearInterpolationMaterial();

protected:
virtual void computeQpProperties();

bool _use_poly_fit;
LinearInterpolation * _linear_interp;
PolynomialFit * _poly_fit;
std::unique_ptr<LinearInterpolation> _linear_interp;
std::unique_ptr<PolynomialFit> _poly_fit;
MaterialProperty<Real> & _property;
};

@@ -8,6 +8,10 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "LinearInterpolationMaterial.h"
#include "LinearInterpolation.h"
#include "PolynomialFit.h"

#include "libmesh/auto_ptr.h"

registerMooseObject("MooseTestApp", LinearInterpolationMaterial);

@@ -19,53 +23,43 @@ validParams<LinearInterpolationMaterial>()
params.addRequiredParam<std::string>(
"prop_name", "The property name that will contain the piecewise function");
params.addRequiredParam<std::vector<Real>>(
"independent_vals", "The vector of indepedent values for building the piecewise function");
"independent_vals", "The vector of independent values for building the piecewise function");
params.addRequiredParam<std::vector<Real>>(
"dependent_vals", "The vector of depedent values for building the piecewise function");
"dependent_vals", "The vector of dependent values for building the piecewise function");
params.addParam<bool>("use_poly_fit",
false,
"Setting to true will use polynomial fit instead of linear interpolation");
return params;
}

LinearInterpolationMaterial::~LinearInterpolationMaterial()
{
delete _poly_fit;
delete _linear_interp;
}

LinearInterpolationMaterial::LinearInterpolationMaterial(const InputParameters & parameters)
: Material(parameters),
_use_poly_fit(getParam<bool>("use_poly_fit")),
_linear_interp(NULL),
_poly_fit(NULL),
_linear_interp(nullptr),
_poly_fit(nullptr),
_property(declareProperty<Real>(getParam<std::string>("prop_name")))
{
if (_use_poly_fit)
{
_poly_fit = new PolynomialFit(getParam<std::vector<Real>>("independent_vals"),
getParam<std::vector<Real>>("dependent_vals"),
4);
_poly_fit = libmesh_make_unique<PolynomialFit>(getParam<std::vector<Real>>("independent_vals"),
getParam<std::vector<Real>>("dependent_vals"),
4);

_poly_fit->generate();
_poly_fit->dumpSampleFile(
getParam<std::string>("prop_name"), "X position", getParam<std::string>("prop_name"));
}
else
{
try
{

_linear_interp = new LinearInterpolation(getParam<std::vector<Real>>("independent_vals"),
getParam<std::vector<Real>>("dependent_vals"));
_linear_interp =
libmesh_make_unique<LinearInterpolation>(getParam<std::vector<Real>>("independent_vals"),
getParam<std::vector<Real>>("dependent_vals"));
}
catch (std::domain_error & e)
{
mooseError("In LinearInterpolationMaterial ", _name, ": ", e.what());
}

_linear_interp->dumpSampleFile(
getParam<std::string>("prop_name"), "X position", getParam<std::string>("prop_name"));
}
}

Oops, something went wrong.

0 comments on commit e5a4292

Please sign in to comment.