Commit 83b493ab authored by Thomas's avatar Thomas
Browse files

Restructure quadrature and qmontecarlo.

parent 16852839
......@@ -2,29 +2,28 @@
#define QUADRATURE_H
#include <blaze/Math.h>
#include <math.h>
#include <random>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Quadrature
{
public:
Quadrature( int order ) {
SetOrder( order );
SetName( ComputeName() );
SetNq( ComputeNq() );
SetPoints( ComputePoints() );
SetWeights( ComputeWeights() );
SetConnectivity( ComputeConnectivity() );
};
virtual ~Quadrature() = 0;
// Virtual methods that every quadrature has to implement
virtual std::string ComputeName();
virtual int ComputeNq();
virtual blaze::DynamicVector<blaze::DynamicVector<double>> ComputePoints();
virtual blaze::DynamicVector<double> ComputeWeights();
virtual blaze::DynamicVector<blaze::DynamicVector<int>> ComputeConnectivity();
Quadrature( int order );
virtual ~Quadrature(){};
virtual std::string ComputeName() = 0;
virtual int ComputeNq() = 0;
virtual blaze::DynamicVector<blaze::DynamicVector<double>> ComputePoints() = 0;
virtual blaze::DynamicVector<double> ComputeWeights() = 0;
virtual blaze::DynamicVector<blaze::DynamicVector<int>> ComputeConnectivity() = 0;
// Aux functions
void PrintWeights();
double SumUpWeights();
// Quadrature Hub
static Quadrature* CreateQuadrature( std::string name, int order );
// Setter
void SetName( std::string name ) { _name = name; };
......
......@@ -3,12 +3,13 @@
#include <mpi.h>
int main( int argc, char** argv ) {
MPI_Init( &argc, &argv );
std::string inputFile = ParseArguments( argc, argv );
Settings* settings = ReadInputFile( inputFile );
InitLogger( settings->GetLogDir(), spdlog::level::info, spdlog::level::info );
PrintLogHeader( settings->GetInputFile() );
Quadrature* Q = GetQuadrature( "montecarlo", 10 );
Quadrature* Q = Quadrature::CreateQuadrature( "montecarlo", 10 );
Q->PrintWeights();
return EXIT_SUCCESS;
}
......@@ -3,9 +3,25 @@
Quadrature::Quadrature( int order ) : _order( order ) {}
Quadrature* GetQuadrature( std::string name, int order ) {
Quadrature* Quadrature::CreateQuadrature( std::string name, int order ) {
if( name == "montecarlo" ) {
return new QMonteCarlo( order );
}
// If nothing has been picked, take this as dummy:
return new QMonteCarlo( order );
}
double Quadrature::SumUpWeights() {
double w = 0;
for( int i = 0; i < _nq; i++ ) {
w += _weights[i];
}
return w;
}
void Quadrature::PrintWeights() {
for( int i = 0; i < _nq; i++ ) {
std::cout << _weights[i] << std::endl;
}
}
#ifndef QUADRATURE_H
#define QUADRATURE_H
#include <blaze/Math.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Quadrature
{
public:
Quadrature( int order );
virtual ~Quadrature(){};
virtual std::string ComputeName() = 0;
virtual int ComputeNq() = 0;
virtual blaze::DynamicVector<blaze::DynamicVector<double>> ComputePoints() = 0;
virtual blaze::DynamicVector<double> ComputeWeights() = 0;
virtual blaze::DynamicVector<blaze::DynamicVector<int>> ComputeConnectivity() = 0;
void PrintWeights() {
for( int i = 0; i < _nq; i++ ) {
std::cout << _weights[i] << std::endl;
}
}
// Setter
void SetName( std::string name ) { _name = name; };
void SetOrder( int order ) { _order = order; };
void SetNq( int nq ) { _nq = nq; };
void SetPoints( blaze::DynamicVector<blaze::DynamicVector<double>> points ) { _points = points; };
void SetWeights( blaze::DynamicVector<double> weights ) { _weights = weights; };
void SetConnectivity( blaze::DynamicVector<blaze::DynamicVector<int>> connectivity ) { _connectivity = connectivity; };
// Getter
std::string GetName() { return _name; };
int GetOrder() { return _order; };
int GetNq() { return _nq; };
blaze::DynamicVector<blaze::DynamicVector<double>> GetPoints() { return _points; };
blaze::DynamicVector<double> GetWeights() { return _weights; };
blaze::DynamicVector<blaze::DynamicVector<int>> GetConnectivity() { return _connectivity; };
protected:
std::string _name;
int _order;
int _nq;
blaze::DynamicVector<blaze::DynamicVector<double>> _points;
blaze::DynamicVector<double> _weights;
blaze::DynamicVector<blaze::DynamicVector<int>> _connectivity;
};
// Quadrature Hub
Quadrature* GetQuadrature( std::string name, int order );
#endif // QUADRATURE_H
Supports Markdown
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