Skip to content

Commit

Permalink
Some fixing, still not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
povanberg committed Mar 6, 2019
1 parent d68cf77 commit 00eb072
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Element {

bool hasNode(const int tag);

void getFlux(Eigen::MatrixXd &Flux, const Eigen::Vector3d &a);
void getFlux(Eigen::VectorXd &Flux, const Eigen::Vector3d &a, std::vector<Element> &elements);

// Add face to element
Element &addFace(Face face);
Expand Down
40 changes: 34 additions & 6 deletions src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,46 @@ void Element::getStiffMatrix(Eigen::MatrixXd &stiffMatrix, const Eigen::Vector3d
}
}

void Element::getFlux(Eigen::MatrixXd &Flux, const Eigen::Vector3d &a){
void Element::getFlux(Eigen::VectorXd &Flux, const Eigen::Vector3d &a, std::vector<Element> &elements){
// Independent of numerical flux
Flux = Eigen::MatrixXd::Zero(this->numBasisFcts, this->numBasisFcts);
Eigen::VectorXd numDataIn;
Eigen::VectorXd numDataOut;
Flux = Eigen::VectorXd::Zero(this->numBasisFcts);
for(unsigned int i=0; i<this->numBasisFcts; ++i) {
for (unsigned int j = 0; j < this->numBasisFcts; ++j) {
for(Face &face: this->faces){
if(face.hasNode(this->nodeTags[i]) && face.hasNode(this->nodeTags[j])){
Flux(i, j) += face.getFluxInt(a);
if(face.boundary){
// Not flux at boundaries
Flux(i) += 0.0;
}
else{
Flux(i, j) += 0.0;
else {
// If face is not a boundary
// We get is element other side of face.
int elOutTag = face.getSecondElement(this->tag);
int idElOut;
for(int i=0; i< elements.size(); ++i){
if(elements[i].getTag() == tag)
idElOut= i;
}
Element elOut = elements[idElOut];

// If Node 'i' is in Surface
if(face.hasNode(this->nodeTags[i])){
// Get indice of out solution
for(int k=0; k<elOut.getNumNodes(); ++k) {
if (this->getNodeTags()[i] == elOut.getNodeTags()[k]) {
this->getData(numDataIn);
elOut.getData(numDataOut);
Flux(i) += ((numDataIn(i) + numDataOut(k)) / 2.)*face.getFluxInt(a);
}
}
}
else{
// Shape function is zero on surface
Flux(i) += 0.0;
}
}

}
}
}
Expand Down
48 changes: 33 additions & 15 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,19 @@ Mesh::Mesh(std::string name) : name(name){
}
if(hasFace) {
face.addElement(element->getTag());
}
}
for(auto element = std::begin(this->elements); element!=std::end(this->elements); ++element) {
bool hasFace = true;
for (auto &node : face.getNodeTags()) {
if(!element->hasNode(node))
hasFace = false;
}
if(hasFace) {
element->addFace(face);
}
}

}
Log("Faces loaded");

Expand Down Expand Up @@ -209,21 +219,21 @@ void Mesh::getStiffMatrix(Eigen::SparseMatrix<double> &K, const Eigen::Vector3d

void Mesh::getFlux(Eigen::VectorXd &F, const Eigen::Vector3d &a) {
int offset = 0;
F.resize(this->elements.size()*this->elements[0].getNumNodes());
F.resize(this->elements.size() * this->elements[0].getNumNodes());
// Loop over elements
for(Element& el : this->elements) {
for (Element &el : this->elements) {

Eigen::VectorXd numFlux;
el.getFlux(numFlux, a, this->elements);

Eigen::Vector3d numFlux;
Eigen::MatrixXd elF;
el.getFlux(elF, a);

// Depends on numerical flux : (In+Out)/2
Eigen::VectorXd numDataIn;
/*Eigen::VectorXd numDataIn;
Eigen::VectorXd numDataOut;
for(int i=0; i<el.getNumNodes(); ++i){
for(Face &face: el.faces) {
if(face.boundary){
numFlux(i) = 0.0;
numFlux(i) += 0.0;
}
else {
int elOutTag = face.getSecondElement(el.getTag());
Expand All @@ -232,20 +242,21 @@ void Mesh::getFlux(Eigen::VectorXd &F, const Eigen::Vector3d &a) {
if(el.getNodeTags()[i] == el.getNodeTags()[j]){
el.getData(numDataIn);
elOut.getData(numDataOut);
numFlux(i) = (numDataIn(i)+numDataOut(j))/2;
numFlux(i) = (numDataIn(i)+numDataOut(j))/2.;
}
}
}
}
}
}*/

Eigen::VectorXd FF = elF*numFlux;
F(offset+0)= FF(0);
F(offset+1)= FF(2);
F(offset+1)= FF(2);
F(offset+1)= FF(2);
//Eigen::VectorXd FF = elF*numFlux;
F(offset + 0) = numFlux(0);
F(offset + 1) = numFlux(1);
F(offset + 2) = numFlux(2);
offset += el.getNumNodes();
}
Eigen::VectorXd data;
this->getData(data);
}

Element &Mesh::getElement(const int tag){
Expand Down Expand Up @@ -274,7 +285,14 @@ void Mesh::getData(Eigen::VectorXd &data){
Eigen::VectorXd elData;
for(Element& el : this->elements) {
el.getData(elData);
data << data, elData;
if(data.size() == 0){
data = elData;
}
else{
Eigen::VectorXd temp(data.size()+elData.size());
temp << data, elData;
data = temp;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace solver {
Eigen::SparseMatrix<double> M_inv = solver.solve(I);

// Compute stiffness (or convection) matrix
Eigen::Vector3d a = {1, 1, 0}; // advection coefficient
Eigen::Vector3d a = {1, 0, 0}; // advection coefficient
Eigen::SparseMatrix<double> K;
mesh.getStiffMatrix(K, a);

Expand All @@ -67,7 +67,7 @@ namespace solver {
double t0 = 0;
double tf = 1;
int step = 0;
double dt = 0.1;
double dt = 0.01;
for(double t=t0; t<tf; t+=dt, ++step) {

// Savings
Expand Down

0 comments on commit 00eb072

Please sign in to comment.