Skip to content
Snippets Groups Projects
Commit e706b03e authored by Sachin Krishnan T V's avatar Sachin Krishnan T V
Browse files

Update regression tests

parent cf94da13
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,13 @@
#include "minter.h"
template<int spatial_dim, typename vector_type, typename MatType = EMatrixXd, typename VecType = EVectorXd>
template<int spatial_dim, typename MatType = EMatrixXd, typename VecType = EVectorXd>
class PolyLevelset
{
minter::LevelsetPoly<spatial_dim, MatType, VecType> *model;
public:
template<typename vector_type>
PolyLevelset(vector_type &vd, double tol)
{
constexpr int dim = vector_type::dims;
......@@ -50,8 +51,9 @@ public:
delete model;
}
// TODO: Make the return types more generic
double eval(Point<vector_type::dims, typename vector_type::stype> pos)
// T : Point<vector_type::dims, typename vector_type::stype>
template<typename T>
double eval(T pos)
{
int dim = pos.dims;
MatType point(1,dim);
......@@ -61,8 +63,10 @@ public:
return model->eval(point)(0);
}
double deriv(Point<vector_type::dims, typename vector_type::stype> pos, \
Point<vector_type::dims, int> deriv_order)
// T1 : Point<vector_type::dims, typename vector_type::stype>
// T2 : Point<vector_type::dims, int>
template<typename T1, typename T2>
double deriv(T1 pos, T2 deriv_order)
{
int dim = pos.dims;
MatType point(1,dim);
......@@ -76,14 +80,16 @@ public:
return model->deriv_eval(point, order)(0);
}
Point<vector_type::dims, typename vector_type::stype> estimate_normals_at(Point<vector_type::dims, typename vector_type::stype> pos)
// T : Point<vector_type::dims, typename vector_type::stype>
template<typename T>
T estimate_normals_at(T pos)
{
int dim = pos.dims;
MatType point(1,dim);
for(int j = 0;j < dim;++j)
point(0,j) = pos.get(j);
Point<vector_type::dims, typename vector_type::stype> normal;
T normal;
auto normal_minter = model->estimate_normals_at(point);
for(int j = 0;j < dim;++j)
......@@ -92,7 +98,9 @@ public:
return normal;
}
double estimate_mean_curvature_at(Point<vector_type::dims, typename vector_type::stype> pos)
// T : Point<vector_type::dims, typename vector_type::stype>
template<typename T>
double estimate_mean_curvature_at(T pos)
{
int dim = pos.dims;
MatType point(1,dim);
......
......@@ -18,15 +18,15 @@ BOOST_AUTO_TEST_SUITE( Regression_test )
BOOST_AUTO_TEST_CASE ( PolyLevelset_Sphere )
{
Box<3,float> domain({-2.0,-2.0,-2.0},{2.0,2.0,2.0});
Box<3,double> domain({-2.0,-2.0,-2.0},{2.0,2.0,2.0});
// Here we define the boundary conditions of our problem
size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
// extended boundary around the domain, and the processor domain
Ghost<3,float> g(0.01);
Ghost<3,double> g(0.01);
using vectorType = vector_dist<3,float, aggregate<double, double> >;
using vectorType = vector_dist<3,double, aggregate<double, double> >;
vectorType vd(1024,domain,bc,g);
......@@ -52,14 +52,15 @@ BOOST_AUTO_TEST_CASE ( PolyLevelset_Sphere )
}
vd.map();
auto model = new PolyLevelset<3, vectorType>(vd, 1e-4);
auto model = PolyLevelset<3>(vd, 1e-4);
double max_err = -1.0;
auto it2 = vd.getDomainIterator();
while (it2.isNext())
{
auto key = it2.get();
vd.template getProp<mean_curvature>(key) = model->estimate_mean_curvature_at(vd.getPos(key));
Point<3, double> pos = {vd.getPos(key)[0], vd.getPos(key)[1], vd.getPos(key)[2]};
vd.template getProp<mean_curvature>(key) = model.estimate_mean_curvature_at(pos);
// vd.template getProp<gauss_curvature>(key) = model->estimate_gauss_curvature_at(vd.getPos(key));
double val = vd.getProp<mean_curvature>(key);
......@@ -80,8 +81,8 @@ BOOST_AUTO_TEST_CASE ( PolyLevelset_Sphere )
std::cout<<"Max err (poly level) = "<<max_err<<"\n";
BOOST_TEST( check );
if(model)
delete model;
// if(model)
// delete model;
}
......
......@@ -47,7 +47,7 @@ public:
}
};
template<int spatial_dim, unsigned int prp_id, typename vector_type, typename MatType = EMatrixXd, typename VecType = EVectorXd>
template<int spatial_dim, unsigned int prp_id, typename MatType = EMatrixXd, typename VecType = EVectorXd>
class RegressionModel
{
......@@ -55,7 +55,7 @@ public:
minter::PolyModel<spatial_dim, MatType, VecType> *model = nullptr;
minter::PolyModel<spatial_dim, MatType, VecType> *deriv_model[spatial_dim];
template<typename dom_type>
template<typename vector_type, typename dom_type>
RegressionModel(vector_type &vd, dom_type &domain, unsigned int poly_degree, float lp_degree = 2.0)
{
int num_particles = domain->getNumParticles();
......@@ -82,6 +82,7 @@ public:
// Constructor for all points in a proc (domain + ghost) and a specified poly_degree
template<typename vector_type>
RegressionModel(vector_type &vd, unsigned int poly_degree, float lp_degree = 2.0)
{
int num_particles = vd.size_local_with_ghost();
......@@ -112,6 +113,7 @@ public:
}
// Constructor for all points in a proc (domain + ghost) within a tolerance
template<typename vector_type>
RegressionModel(vector_type &vd, double tolerance)
{
int num_particles = vd.size_local_with_ghost();
......@@ -180,7 +182,8 @@ public:
}
}
double eval(Point<vector_type::dims, typename vector_type::stype> pos)
template<typename T> // Typical: Point<vector_type::dims, typename vector_type::stype>
double eval(T pos)
{
int dim = pos.dims;
MatType point(1,dim);
......@@ -190,8 +193,10 @@ public:
return model->eval(point)(0);
}
double deriv(Point<vector_type::dims, typename vector_type::stype> pos, \
Point<vector_type::dims, int> deriv_order)
// T1 : Point<vector_type::dims, typename vector_type::stype>
// T2 : Point<vector_type::dims, int>
template<typename T1, typename T2>
double deriv(T1 pos, T2 deriv_order)
{
int dim = pos.dims;
......@@ -216,9 +221,11 @@ public:
}
}
Point<vector_type::dims, typename vector_type::stype> eval_grad(Point<vector_type::dims, typename vector_type::stype> pos)
// T: Point<vector_type::dims, typename vector_type::stype>
template<typename T>
T eval_grad(T pos)
{
Point<vector_type::dims, typename vector_type::stype> res;
T res;
if(!deriv_model[0])
compute_grad();
......
......@@ -14,7 +14,7 @@
BOOST_AUTO_TEST_SUITE( Regression_test )
/*
BOOST_AUTO_TEST_CASE ( Regression_domain_initialization )
{
Box<2,float> domain({0.0,0.0},{1.0,1.0});
......@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE ( Regression_domain_initialization )
delete dom;
}
*/
BOOST_AUTO_TEST_CASE ( Regression_without_domain_initialization)
......@@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE ( Regression_without_domain_initialization)
}
vd.map();
auto model = new RegressionModel<2, 0, vectorType>(vd, static_cast<unsigned int>(10));
auto model = RegressionModel<2, 0>(vd, 1e-6);
double max_err = -1.0;
for(double x = 0.75; x < 0.85;x+=0.01)
......@@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE ( Regression_without_domain_initialization)
for(double y = 0.75; y < 0.85; y+=0.01)
{
Point<2, double> pos{x,y};
double val = model->eval(pos);
double val = model.eval(pos);
double actual = sin(x*y);
double err = std::abs(actual - val);
if (err > max_err) max_err = err;
......@@ -137,10 +137,10 @@ BOOST_AUTO_TEST_CASE ( Regression_without_domain_initialization)
std::cout<<"Max err = "<<max_err<<"\n";
BOOST_TEST( check );
if(model)
delete model;
// if(model)
// delete model;
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment