Commit d3984b77 authored by Matthias Möller's avatar Matthias Möller

moved functiondefinition to sourcecode file for exported classes

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@280 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 9c8578eb
#include "FiniteElementProblem.hh"
namespace COMISO {
// FiniteElementProblem
/// Default constructor
FiniteElementProblem::FiniteElementProblem(const unsigned int _n)
: NProblemInterface(), n_(_n), x_(_n,0.0)
{
}
/// Destructor
FiniteElementProblem::~FiniteElementProblem()
{
}
void FiniteElementProblem::add_set(FiniteElementSetBase* _fe_set)
{
fe_sets_.push_back(_fe_set);
}
void FiniteElementProblem::clear_sets()
{
fe_sets_.clear();
}
std::vector<double>& FiniteElementProblem::x()
{
return x_;
}
int FiniteElementProblem::n_unknowns()
{
return n_;
}
void FiniteElementProblem::initial_x(double* _x)
{
if(n_ > 0)
memcpy(_x, &(x_[0]), n_*sizeof(double));
}
double FiniteElementProblem::eval_f(const double* _x)
{
double f(0.0);
for(unsigned int i=0; i<fe_sets_.size(); ++i)
f += fe_sets_[i]->eval_f(_x);
return f;
}
void FiniteElementProblem::eval_gradient( const double* _x, double* _g)
{
// clear gradient (assume floating point 0 has only zero bits)
memset(_g, 0, n_*sizeof(double));
for(unsigned int i=0; i<fe_sets_.size(); ++i)
fe_sets_[i]->accumulate_gradient(_x, _g);
}
void FiniteElementProblem::eval_hessian ( const double* _x, SMatrixNP& _H)
{
triplets_.clear();
for(unsigned int i=0; i<fe_sets_.size(); ++i)
fe_sets_[i]->accumulate_hessian(_x, triplets_);
// set data
_H.resize(n_unknowns(), n_unknowns());
_H.setFromTriplets(triplets_.begin(), triplets_.end());
}
void FiniteElementProblem::store_result ( const double* _x )
{
if(n_ > 0)
memcpy(&(x_[0]), _x, n_*sizeof(double));
}
// advanced properties (ToDo better handling)
bool FiniteElementProblem::constant_gradient() const
{
return false;
}
bool FiniteElementProblem::constant_hessian() const
{
return false;
}
}
......@@ -214,78 +214,34 @@ public:
typedef FiniteElementSetBase::Triplet Triplet;
/// Default constructor
FiniteElementProblem(const unsigned int _n) : NProblemInterface(), n_(_n), x_(_n,0.0)
{}
FiniteElementProblem(const unsigned int _n);
/// Destructor
virtual ~FiniteElementProblem()
{}
virtual ~FiniteElementProblem();
void add_set(FiniteElementSetBase* _fe_set)
{
fe_sets_.push_back(_fe_set);
}
void add_set(FiniteElementSetBase* _fe_set);
void clear_sets()
{
fe_sets_.clear();
}
void clear_sets();
std::vector<double>& x() {return x_;}
std::vector<double>& x();
// problem definition
virtual int n_unknowns ( )
{
return n_;
}
virtual int n_unknowns ( );
virtual void initial_x ( double* _x )
{
if(n_ > 0)
memcpy(_x, &(x_[0]), n_*sizeof(double));
}
virtual void initial_x ( double* _x );
virtual double eval_f ( const double* _x )
{
double f(0.0);
virtual double eval_f ( const double* _x );
for(unsigned int i=0; i<fe_sets_.size(); ++i)
f += fe_sets_[i]->eval_f(_x);
virtual void eval_gradient( const double* _x, double* _g);
return f;
}
virtual void eval_hessian ( const double* _x, SMatrixNP& _H);
virtual void eval_gradient( const double* _x, double* _g)
{
// clear gradient (assume floating point 0 has only zero bits)
memset(_g, 0, n_*sizeof(double));
for(unsigned int i=0; i<fe_sets_.size(); ++i)
fe_sets_[i]->accumulate_gradient(_x, _g);
}
virtual void eval_hessian ( const double* _x, SMatrixNP& _H)
{
triplets_.clear();
for(unsigned int i=0; i<fe_sets_.size(); ++i)
fe_sets_[i]->accumulate_hessian(_x, triplets_);
// set data
_H.resize(n_unknowns(), n_unknowns());
_H.setFromTriplets(triplets_.begin(), triplets_.end());
}
virtual void store_result ( const double* _x )
{
if(n_ > 0)
memcpy(&(x_[0]), _x, n_*sizeof(double));
}
virtual void store_result ( const double* _x );
// advanced properties (ToDo better handling)
virtual bool constant_gradient() const { return false; }
virtual bool constant_hessian() const { return false; }
virtual bool constant_gradient() const;
virtual bool constant_hessian() const;
private:
......
//== COMPILE-TIME PACKAGE REQUIREMENTS ========================================
#include <CoMISo/Config/config.hh>
#if COMISO_EIGEN3_AVAILABLE
//== INCLUDES =================================================================
#include "LinearProblem.hh"
namespace COMISO {
LinearProblem::LinearProblem (unsigned int _dimension)
{
// resize and zero elements
coeffs_.resize(_dimension,0.0);
x_.resize(_dimension, 0.0);
}
LinearProblem::~LinearProblem()
{
}
int LinearProblem::n_unknowns()
{
return coeffs_.size();
}
void LinearProblem::initial_x(double* _x)
{
if(!x_.empty())
memcpy(_x, &(x_[0]), x_.size()*sizeof(double));
}
double LinearProblem::eval_f( const double* _x)
{
double d(0.0);
for(unsigned int i=0; i<coeffs_.size(); ++i)
d += coeffs_[i]*_x[i];
return d;
}
void LinearProblem::eval_gradient( const double* _x, double* _g)
{
if(!coeffs_.empty())
memcpy(_g, &(coeffs_[0]), coeffs_.size()*sizeof(double));
}
void LinearProblem::eval_hessian ( const double* _x, SMatrixNP& _H)
{
// resize and set to zero
_H.resize(n_unknowns(), n_unknowns());
_H.setZero();
}
void LinearProblem::store_result ( const double* _x )
{
if(!x_.empty())
memcpy(&(x_[0]), _x, x_.size()*sizeof(double));
}
bool LinearProblem::constant_gradient() const
{
return true;
}
bool LinearProblem::constant_hessian() const
{
return true;
}
std::vector<double>& LinearProblem::coeffs()
{
return coeffs_;
}
std::vector<double>& LinearProblem::x()
{
return x_;
}
//=============================================================================
} // namespace COMISO
//=============================================================================
#endif // COMISO_EIGEN3_AVAILABLE
//=============================================================================
......@@ -43,62 +43,33 @@ class COMISODLLEXPORT LinearProblem : public NProblemInterface
public:
/// Default constructor
LinearProblem (unsigned int _dimension = 0)
{
// resize and zero elements
coeffs_.resize(_dimension,0.0);
x_.resize(_dimension, 0.0);
}
LinearProblem (unsigned int _dimension = 0);
/// Destructor
virtual ~LinearProblem() {}
virtual ~LinearProblem();
// problem definition
virtual int n_unknowns()
{ return coeffs_.size(); }
virtual void initial_x(double* _x)
{
if(!x_.empty())
memcpy(_x, &(x_[0]), x_.size()*sizeof(double));
}
virtual double eval_f( const double* _x)
{
double d(0.0);
for(unsigned int i=0; i<coeffs_.size(); ++i)
d += coeffs_[i]*_x[i];
return d;
}
virtual void eval_gradient( const double* _x, double* _g)
{
if(!coeffs_.empty())
memcpy(_g, &(coeffs_[0]), coeffs_.size()*sizeof(double));
}
virtual void eval_hessian ( const double* _x, SMatrixNP& _H)
{
// resize and set to zero
_H.resize(n_unknowns(), n_unknowns());
_H.setZero();
}
virtual void store_result ( const double* _x )
{
if(!x_.empty())
memcpy(&(x_[0]), _x, x_.size()*sizeof(double));
}
virtual int n_unknowns();
virtual void initial_x(double* _x);
virtual double eval_f( const double* _x);
virtual void eval_gradient( const double* _x, double* _g);
virtual void eval_hessian ( const double* _x, SMatrixNP& _H);
virtual void store_result ( const double* _x );
// advanced properties
virtual bool constant_gradient() const { return true; }
virtual bool constant_hessian() const { return true; }
virtual bool constant_gradient() const;
virtual bool constant_hessian() const;
// give access to coefficients to define the problem
std::vector<double>& coeffs() { return coeffs_;}
std::vector<double>& coeffs();
// give access to result
std::vector<double>& x() { return x_;}
std::vector<double>& x();
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment