Skip to content
Snippets Groups Projects
Commit b822430e authored by Nicolas Marsic's avatar Nicolas Marsic
Browse files

Interpolation (0form)

parent 162192e3
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@
using namespace std;
int test(int argc, char** argv){
int basisTest(int argc, char** argv){
// Init Gmsh //
GmshInitialize(argc, argv);
......@@ -24,7 +24,7 @@ int test(int argc, char** argv){
Mesh msh(argv[1]);
// Plot Basis //
HexEdgeBasis b(1);
TriEdgeBasis b(5);
PlotBasis plot(msh.getGroup(2), b);
plot.write("basis");
......
......@@ -22,6 +22,7 @@ set(SRC
HexEdgeBasis.cpp
FunctionSpace.cpp
FunctionSpaceNode.cpp
)
file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
......
......@@ -4,6 +4,9 @@
using namespace std;
FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order){
// DofManager //
dofM = NULL;
// Save GroupOfElement //
this->goe = &goe;
......@@ -12,6 +15,7 @@ FunctionSpace::FunctionSpace(const GroupOfElement& goe, int basisType, int order
int elementType = goe.get(0).getType();
// Init Struct //
type = basisType;
basis = BasisGenerator::generate(elementType, basisType, order);
// Count Function per Entity //
......
......@@ -7,6 +7,7 @@
#include "GroupOfElement.h"
#include "MElement.h"
#include "Dof.h"
#include "DofManager.h"
/**
@class FunctionSpace
......@@ -19,26 +20,32 @@
*/
class ElementComparator;
class DofManager;
class FunctionSpace{
private:
protected:
const Basis* basis;
const GroupOfElement* goe;
const DofManager* dofM;
int fPerVertex;
int fPerEdge;
int fPerFace;
int fPerCell;
int type;
public:
FunctionSpace(const GroupOfElement& goe,
int basisType, int order);
~FunctionSpace(void);
virtual ~FunctionSpace(void);
const GroupOfElement& getSupport(void) const;
const Basis& getBasis(const MElement& element) const;
int getType(void) const;
void associate(const DofManager& dofM);
const std::vector<Dof*> getKeys(const MElement& element) const;
int getNFunctionPerVertex(const MElement& element) const;
......@@ -59,6 +66,14 @@ inline const Basis& FunctionSpace::getBasis(const MElement& element) const{
return *basis;
}
inline int FunctionSpace::getType(void) const{
return type;
}
inline void FunctionSpace::associate(const DofManager& dofM){
this->dofM = &dofM;
}
inline int FunctionSpace::getNFunctionPerVertex(const MElement& element) const{
return fPerVertex;
}
......
#include "FunctionSpaceNode.h"
#include "Polynomial.h"
#include "BasisScalar.h"
#include "Exception.h"
using namespace std;
FunctionSpaceNode::FunctionSpaceNode(const GroupOfElement& goe, int order):
FunctionSpace(goe, 0, order){
// Just Call Super Constructor with basisType = 0
}
FunctionSpaceNode::~FunctionSpaceNode(void){
}
vector<double> FunctionSpaceNode::
interpolateAtNodes(const MElement& elem,
const vector<double>& coef) const{
// Check
unsigned int wS = coef.size();
unsigned int bS = basis->getSize();
if(wS < bS)
throw Exception
("Not enough coefs for interpolation:\nBasis: %d -- coefs: %d",
bS, wS);
if(wS > bS)
throw Exception
("Too much coefs for interpolation:\nBasis: %d -- coefs: %d",
bS, wS);
// Get Nodes
MElement& element = const_cast<MElement&>(elem);
vector<MVertex*> node;
element.getVertices(node);
unsigned int N = node.size();
// Get Functions
const vector<Polynomial>& fun =
static_cast<const BasisScalar*>(basis)->getBasis();
// Init Vector
vector<double> value(N);
// Interpolate
for(unsigned int n = 0; n < N; n++){
const double x = node[n]->x();
const double y = node[n]->y();
const double z = node[n]->z();
value[n] = 0;
for(unsigned int i = 0; i < bS; i++)
value[n] += fun[i].at(x, y, z) * coef[i];
}
return value;
}
#ifndef _FUNCTIONSPACENODE_H_
#define _FUNCTIONSPACENODE_H_
#include "FunctionSpace.h"
class FunctionSpaceNode: public FunctionSpace{
FunctionSpaceNode(const GroupOfElement& goe, int order);
virtual ~FunctionSpaceNode(void);
std::vector<double> interpolateAtNodes(const MElement& element,
const std::vector<double>& coef) const;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment