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

FunctionSpace can now handle restricted domains

parent 766712de
No related branches found
No related tags found
No related merge requests found
#include <limits.h>
#include <sstream>
#include "ReferenceSpaceManager.h"
......@@ -8,10 +9,15 @@
using namespace std;
const Dof FunctionSpace::rejectedDof(INT_MAX, INT_MAX);
const size_t FunctionSpace::nGeoType = 9;
size_t FunctionSpace::nxtOffset = 0;
FunctionSpace::FunctionSpace(void){
// Clear //
dof.clear();
rejected.clear();
// Alloc Basis Vector for all possible geomtrical types //
basis.resize(nGeoType, NULL);
......@@ -28,13 +34,34 @@ FunctionSpace::~FunctionSpace(void){
delete basis[i];
}
void FunctionSpace::build(const GroupOfElement& goe, string family){
void FunctionSpace::build(const vector<const GroupOfElement*>& goe,
const vector<const GroupOfElement*>& exl,
string family){
// Save Dof type offset //
offset = nxtOffset;
// Save Mesh //
this->mesh = &(goe.getMesh());
// Save Mesh & Get number of GoE//
const size_t nGoe = goe.size();
const size_t nExl = exl.size();
this->mesh = &(goe[0]->getMesh());
// Build Bases //
for(size_t i = 0; i < nGoe; i++)
getBases(*goe[i], family);
// Build Dof to reject //
for(size_t i = 0; i < nExl; i++)
getRejec(*exl[i]);
// Build Dof //
for(size_t i = 0; i < nGoe; i++)
getMyDof(*goe[i]);
// Next Offset for next FunctionSpace
nxtOffset = findMaxType() + 1;
}
void FunctionSpace::getBases(const GroupOfElement& goe, string family){
// Generate Bases //
const vector<size_t>& geoTypeStat = goe.getTypeStats();
const size_t nGeoType = geoTypeStat.size();
......@@ -65,12 +92,9 @@ void FunctionSpace::build(const GroupOfElement& goe, string family){
fPerCell[i] = this->basis[i]->getNCellBased();
}
}
// Build Dof //
buildDof(goe);
}
void FunctionSpace::buildDof(const GroupOfElement& goe){
void FunctionSpace::getMyDof(const GroupOfElement& goe){
// Get Elements //
const size_t nElement = goe.getNumber();
const vector<const MElement*>& element = goe.getAll();
......@@ -96,6 +120,27 @@ void FunctionSpace::buildDof(const GroupOfElement& goe){
getKeys(*(element[i]), myDof[i]);
}
void FunctionSpace::getRejec(const GroupOfElement& goe){
// Get Elements //
const size_t nElement = goe.getNumber();
const vector<const MElement*>& element = goe.getAll();
// Allocate //
vector<vector<Dof> > myDof(nElement);
// Create Dofs //
for(size_t i = 0; i < nElement; i++)
getKeys(*(element[i]), myDof[i]);
// Push in rejection map //
for(size_t i = 0; i < nElement; i++){
size_t nDof = myDof[i].size();
for(size_t j = 0; j < nDof; j++)
rejected.insert(myDof[i][j]);
}
}
size_t FunctionSpace::findMaxType(void){
// Maximum type //
size_t maxType = 0;
......@@ -132,7 +177,7 @@ size_t FunctionSpace::findMaxType(void){
}
void FunctionSpace::getUnorderedKeys(const MElement& elem,
std::vector<Dof>& dof) const{
std::vector<Dof>& dof, bool full) const{
// Const_Cast //
MElement& element = const_cast<MElement&>(elem);
......@@ -199,9 +244,45 @@ void FunctionSpace::getUnorderedKeys(const MElement& elem,
dof[it].setDof(mesh->getGlobalId(element), j + offset);
it++;
}
// Reject Keys or mark them rejected //
if(full)
markMyKeys(dof);
else
rejectKeys(dof);
}
void FunctionSpace::rejectKeys(vector<Dof>& dof) const{
// Temp list
list<Dof> tmp(dof.begin(), dof.end());
// Look in rejection map
list<Dof>::iterator end = tmp.end();
list<Dof>::iterator it = tmp.begin();
while(it != end)
if(rejected.count(*it) == 1)
it = tmp.erase(it);
else
it++;
// Rebuild dof vector (if needed)
if(tmp.size() != dof.size()){
dof.clear();
dof.assign(tmp.begin(), tmp.end());
}
}
void FunctionSpace::markMyKeys(vector<Dof>& dof) const{
const size_t nDof = dof.size();
for(size_t i = 0; i < nDof; i++)
if(rejected.count(dof[i]) == 1)
dof[i] = rejectedDof;
}
void FunctionSpace::getKeys(const MElement& elem, std::vector<Dof>& dof) const{
void FunctionSpace::getKeys(const MElement& elem, std::vector<Dof>& dof,
bool full) const{
// Const_Cast //
MElement& element = const_cast<MElement&>(elem);
......@@ -225,7 +306,7 @@ void FunctionSpace::getKeys(const MElement& elem, std::vector<Dof>& dof) const{
MElement* permElement = factory.create(lowOrderTag, vertex, element.getNum());
// Get Dofs from permuted Element //
getUnorderedKeys(*permElement, dof);
getUnorderedKeys(*permElement, dof, full);
// Free and Return //
delete permElement;
......
......@@ -31,6 +31,9 @@ class GroupOfElement;
class FunctionSpace{
protected:
// A Dof suposed to be rejected
static const Dof rejectedDof;
// Number of possible geomtrical topologies & Dof Type offset //
static const size_t nGeoType;
static size_t nxtOffset;
......@@ -55,6 +58,9 @@ class FunctionSpace{
size_t form;
size_t order;
// Rejected Dofs //
std::set<Dof> rejected;
// Dofs //
std::map<size_t, std::vector<std::vector<Dof> > > dof;
......@@ -76,11 +82,21 @@ class FunctionSpace{
protected:
FunctionSpace(void);
void build(const GroupOfElement& goe, std::string family);
void buildDof(const GroupOfElement& goe);
void build(const std::vector<const GroupOfElement*>& goe,
const std::vector<const GroupOfElement*>& exl,
std::string family);
void getBases(const GroupOfElement& goe, std::string family);
void getMyDof(const GroupOfElement& goe);
void getRejec(const GroupOfElement& goe);
size_t findMaxType(void);
void getUnorderedKeys(const MElement& element, std::vector<Dof>& dof) const;
void getUnorderedKeys(const MElement& element, std::vector<Dof>& dof,
bool full) const;
void rejectKeys(std::vector<Dof>& dof) const;
void markMyKeys(std::vector<Dof>& dof) const;
void getKeys(const MElement& element, std::vector<Dof>& dof, bool full) const;
};
......@@ -176,4 +192,9 @@ inline const Basis& FunctionSpace::getBasis(size_t eType) const{
return *basis[eType];
}
inline
void FunctionSpace::getKeys(const MElement& elem, std::vector<Dof>& dof) const{
getKeys(elem, dof, false);
}
#endif
......@@ -2,51 +2,49 @@
#include "Exception.h"
#include "FunctionSpaceScalar.h"
FunctionSpaceScalar::
FunctionSpaceScalar(const GroupOfElement& goe, size_t order){
// Temp vector
std::vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
using namespace std;
FunctionSpaceScalar::
FunctionSpaceScalar(const vector<const GroupOfElement*>& goe,
const vector<const GroupOfElement*>& exclude,
size_t order, string family){
// Init
init(tmp, order, "hierarchical");
init(goe, exclude, order, family);
}
FunctionSpaceScalar::
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order){
FunctionSpaceScalar(const vector<const GroupOfElement*>& goe,
size_t order, string family){
// Dummy exclude
vector<const GroupOfElement*> dummy;
// Init
init(goe, order, "hierarchical");
init(goe, dummy, order, family);
}
FunctionSpaceScalar::
FunctionSpaceScalar(const GroupOfElement& goe,
size_t order, std::string family){
FunctionSpaceScalar(const GroupOfElement& goe, size_t order, string family){
// Temp vector
std::vector<const GroupOfElement*> tmp(1);
vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
// Init
init(tmp, order, family);
}
// Dummy exclude
vector<const GroupOfElement*> dummy;
FunctionSpaceScalar::
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Init
init(goe, order, family);
init(tmp, dummy, order, family);
}
FunctionSpaceScalar::~FunctionSpaceScalar(void){
// Done by FunctionSpace
}
void FunctionSpaceScalar::init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
void FunctionSpaceScalar::init(const vector<const GroupOfElement*>& goe,
const vector<const GroupOfElement*>& exclude,
size_t order, string family){
// Check
if(order == 0)
throw Exception("%s: %s",
"FunctionSpaceScalar",
throw Exception("FunctionSpaceScalar: "
"Cannot have a order 0 scalar function space");
// Init
this->scalar = true;
......@@ -54,16 +52,11 @@ void FunctionSpaceScalar::init(const std::vector<const GroupOfElement*>& goe,
this->order = order;
// Build FunctionSpace
const size_t nGoe = goe.size();
for(size_t i = 0; i < nGoe; i++)
build(*goe[i], family);
// Next Offset for next FunctionSpace
nxtOffset = findMaxType() + 1;
build(goe, exclude, family);
}
double FunctionSpaceScalar::interpolateInABC(const MElement& element,
const std::vector<double>& coef,
const vector<double>& coef,
double abc[3]) const{
// Get Basis Functions //
const Basis& basis = getBasis(element);
......@@ -72,11 +65,19 @@ double FunctionSpaceScalar::interpolateInABC(const MElement& element,
basis.getFunctions(fun, element, abc[0], abc[1], abc[2]);
// Get All Dofs (even those that are supposed to be rejected)
vector<Dof> myDof;
getKeys(element, myDof, true);
// Interpolate (in Reference Place) //
double val = 0;
for(size_t i = 0; i < nFun; i++)
val += fun(i, 0) * coef[i];
for(size_t i = 0, j = 0; i < nFun; i++){
if(myDof[i] != rejectedDof){
val += fun(i, 0) * coef[j];
j++;
}
}
// Return Interpolated Value //
return val;
......@@ -84,7 +85,7 @@ double FunctionSpaceScalar::interpolateInABC(const MElement& element,
fullVector<double> FunctionSpaceScalar::
interpolateDerivativeInABC(const MElement& element,
const std::vector<double>& coef,
const vector<double>& coef,
double abc[3]) const{
// Get Jacobian //
fullMatrix<double> invJac(3, 3);
......@@ -98,16 +99,24 @@ interpolateDerivativeInABC(const MElement& element,
basis.getDerivative(fun, element, abc[0], abc[1], abc[2]);
// Get All Dofs (even those that are supposed to be rejected)
vector<Dof> myDof;
getKeys(element, myDof, true);
// Interpolate (in Reference Place) //
fullMatrix<double> val(1, 3);
val(0, 0) = 0;
val(0, 1) = 0;
val(0, 2) = 0;
for(size_t i = 0; i < nFun; i++){
val(0, 0) += fun(i, 0) * coef[i];
val(0, 1) += fun(i, 1) * coef[i];
val(0, 2) += fun(i, 2) * coef[i];
for(size_t i = 0, j = 0; i < nFun; i++){
if(myDof[i] != rejectedDof){
val(0, 0) += fun(i, 0) * coef[j];
val(0, 1) += fun(i, 1) * coef[j];
val(0, 2) += fun(i, 2) * coef[j];
j++;
}
}
// Return Interpolated Value //
......
......@@ -16,14 +16,15 @@
class FunctionSpaceScalar : public FunctionSpace{
public:
FunctionSpaceScalar(const GroupOfElement& goe, size_t order);
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order);
const std::vector<const GroupOfElement*>& exclude,
size_t order, std::string family = "hierarchical");
FunctionSpaceScalar(const GroupOfElement& goe, size_t order,
std::string family);
FunctionSpaceScalar(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
size_t order, std::string family = "hierarchical");
FunctionSpaceScalar(const GroupOfElement& goe,
size_t order, std::string family = "hierarchical");
virtual ~FunctionSpaceScalar(void);
......@@ -44,6 +45,7 @@ class FunctionSpaceScalar : public FunctionSpace{
private:
void init(const std::vector<const GroupOfElement*>& goe,
const std::vector<const GroupOfElement*>& exclude,
size_t order, std::string family);
double interpolateInABC(const MElement& element,
......@@ -57,30 +59,16 @@ class FunctionSpaceScalar : public FunctionSpace{
/**
@fn FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement&,size_t)
@param goe A GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement and with the given order
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceScalar::FunctionSpaceScalar(const std::vector<const GroupOfElement*>&,size_t)
@fn FunctionSpaceScalar::FunctionSpaceScalar(const std::vector<const GroupOfElement*>&,const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param exclude An other of GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement%s and with the given order
@param family A string (defaulted to 'hierarchical')
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement and with the given order
on the GroupOfElement%s of 'goe',
with the exception of the GroupOfElement%s of 'exclude',
and with the given order
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
......@@ -92,15 +80,17 @@ class FunctionSpaceScalar : public FunctionSpace{
@fn FunctionSpaceScalar::FunctionSpaceScalar(const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceScalar
on the given GroupOfElement%s and with the given order
@param family A string (defaulted to 'hierarchical')
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
@li If family is equal to 'hierarchical' a hierarchical Basis will be used
Same as FunctionSpaceScalar::FunctionSpaceScalar(goe, [], order, family)
**
@see See BasisGenerator::generate()
@fn FunctionSpaceScalar::FunctionSpaceScalar(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement
@param order A natural number
@param family A string (defaulted to 'hierarchical')
Same as FunctionSpaceScalar::FunctionSpaceScalar([goe], [], order, family)
**
@fn FunctionSpaceScalar::~FunctionSpaceScalar
......
#include "Mapper.h"
#include "FunctionSpaceVector.h"
FunctionSpaceVector::
FunctionSpaceVector(const GroupOfElement& goe, size_t order){
// Temp vector
std::vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
using namespace std;
FunctionSpaceVector::
FunctionSpaceVector(const vector<const GroupOfElement*>& goe,
const vector<const GroupOfElement*>& exclude,
size_t order, string family){
// Init
init(tmp, order, "hierarchical");
init(goe, exclude, order, family);
}
FunctionSpaceVector::
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order){
FunctionSpaceVector(const vector<const GroupOfElement*>& goe,
size_t order, string family){
// Dummy Exclude
vector<const GroupOfElement*> dummy;
// Init
init(goe, order, "hierarchical");
init(goe, dummy, order, family);
}
FunctionSpaceVector::
FunctionSpaceVector(const GroupOfElement& goe,
size_t order, std::string family){
size_t order, string family){
// Temp vector
std::vector<const GroupOfElement*> tmp(1);
vector<const GroupOfElement*> tmp(1);
tmp[0] = &goe;
// Init
init(tmp, order, family);
}
// Dummy Exclude
vector<const GroupOfElement*> dummy;
FunctionSpaceVector::
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
// Init
init(goe, order, family);
init(tmp, dummy, order, family);
}
FunctionSpaceVector::~FunctionSpaceVector(void){
// Done by FunctionSpace
}
void FunctionSpaceVector::init(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family){
void FunctionSpaceVector::init(const vector<const GroupOfElement*>& goe,
const vector<const GroupOfElement*>& exclude,
size_t order, string family){
// Init
this->scalar = false;
this->form = 1;
this->order = order;
// Build FunctionSpace
const size_t nGoe = goe.size();
for(size_t i = 0; i < nGoe; i++)
build(*goe[i], family);
// Next Offset for next FunctionSpace
nxtOffset = findMaxType() + 1;
build(goe, exclude, family);
}
fullVector<double> FunctionSpaceVector::
interpolateInABC(const MElement& element,
const std::vector<double>& coef,
const vector<double>& coef,
double abc[3]) const{
// Get Jacobian //
......@@ -73,16 +68,24 @@ interpolateInABC(const MElement& element,
basis.getFunctions(fun, element, abc[0], abc[1], abc[2]);
// Get All Dofs (even those that are supposed to be rejected)
vector<Dof> myDof;
getKeys(element, myDof, true);
// Interpolate (in Reference Place) //
fullMatrix<double> val(1, 3);
val(0, 0) = 0;
val(0, 1) = 0;
val(0, 2) = 0;
for(size_t i = 0; i < nFun; i++){
val(0, 0) += fun(i, 0) * coef[i];
val(0, 1) += fun(i, 1) * coef[i];
val(0, 2) += fun(i, 2) * coef[i];
for(size_t i = 0, j = 0; i < nFun; i++){
if(myDof[i] != rejectedDof){
val(0, 0) += fun(i, 0) * coef[j];
val(0, 1) += fun(i, 1) * coef[j];
val(0, 2) += fun(i, 2) * coef[j];
j++;
}
}
// Return Interpolated Value //
......@@ -93,7 +96,7 @@ interpolateInABC(const MElement& element,
fullVector<double> FunctionSpaceVector::
interpolateDerivativeInABC(const MElement& element,
const std::vector<double>& coef,
const vector<double>& coef,
double abc[3]) const{
// Get Jacobian //
fullMatrix<double> jac(3, 3);
......@@ -107,16 +110,24 @@ interpolateDerivativeInABC(const MElement& element,
basis.getDerivative(fun, element, abc[0], abc[1], abc[2]);
// Get All Dofs (even those that are supposed to be rejected)
vector<Dof> myDof;
getKeys(element, myDof, true);
// Interpolate (in Reference Place) //
fullMatrix<double> val(1, 3);
val(0, 0) = 0;
val(0, 1) = 0;
val(0, 2) = 0;
for(size_t i = 0; i < nFun; i++){
val(0, 0) += fun(i, 0) * coef[i];
val(0, 1) += fun(i, 1) * coef[i];
val(0, 2) += fun(i, 2) * coef[i];
for(size_t i = 0, j = 0; i < nFun; i++){
if(myDof[i] != rejectedDof){
val(0, 0) += fun(i, 0) * coef[j];
val(0, 1) += fun(i, 1) * coef[j];
val(0, 2) += fun(i, 2) * coef[j];
j++;
}
}
// Return Interpolated Value //
......
......@@ -17,14 +17,15 @@
class FunctionSpaceVector : public FunctionSpace{
public:
FunctionSpaceVector(const GroupOfElement& goe, size_t order);
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order);
const std::vector<const GroupOfElement*>& exclude,
size_t order, std::string family = "hierarchical");
FunctionSpaceVector(const GroupOfElement& goe, size_t order,
std::string family);
FunctionSpaceVector(const std::vector<const GroupOfElement*>& goe,
size_t order, std::string family);
size_t order, std::string family = "hierarchical");
FunctionSpaceVector(const GroupOfElement& goe,
size_t order, std::string family = "hierarchical");
virtual ~FunctionSpaceVector(void);
......@@ -49,6 +50,7 @@ class FunctionSpaceVector : public FunctionSpace{
const fullVector<double>& uvw) const;
private:
void init(const std::vector<const GroupOfElement*>& goe,
const std::vector<const GroupOfElement*>& exclude,
size_t order, std::string family);
fullVector<double>
......@@ -64,30 +66,16 @@ class FunctionSpaceVector : public FunctionSpace{
/**
@fn FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement&,size_t)
@param goe A GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceVector
on the given GroupOfElement and with the given order
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceVector::FunctionSpaceVector(const std::vector<const GroupOfElement*>&,size_t)
@fn FunctionSpaceVector::FunctionSpaceVector(const std::vector<const GroupOfElement*>&,const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param exclude An other of GroupOfElement
@param order A natural number
Instanciates a new FunctionSpaceVector
on the given GroupOfElement%s and with the given order
@param family A string (defaulted to 'hierarchical')
The instanciated FunctionSpace will use a hierarchical Basis
**
@fn FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceVector
on the given GroupOfElement and with the given order
on the GroupOfElement%s of 'goe',
with the exception of the GroupOfElement%s of 'exclude',
and with the given order
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
......@@ -99,15 +87,17 @@ class FunctionSpaceVector : public FunctionSpace{
@fn FunctionSpaceVector::FunctionSpaceVector(const std::vector<const GroupOfElement*>&,size_t,std::string)
@param goe A vector of GroupOfElement
@param order A natural number
@param family A stringr
Instanciates a new FunctionSpaceVector
on the given GroupOfElement%s and with the given order
@param family A string (defaulted to 'hierarchical')
The instanciated FunctionSpace will use the requested Basis family:
@li If family is equal to 'lagrange' a Lagrange Basis will be used
@li If family is equal to 'hierarchical' a hierarchical Basis will be used
Same as FunctionSpaceVector::FunctionSpaceVector(goe, [], order, family)
**
@see See BasisGenerator::generate()
@fn FunctionSpaceVector::FunctionSpaceVector(const GroupOfElement&,size_t,std::string)
@param goe A GroupOfElement
@param order A natural number
@param family A string (defaulted to 'hierarchical')
Same as FunctionSpaceVector::FunctionSpaceVector([goe], [], order, family)
**
@fn FunctionSpaceVector::~FunctionSpaceVector
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment