Skip to content

Instantly share code, notes, and snippets.

@kritzikratzi
Created November 21, 2009 23:05
Show Gist options
  • Save kritzikratzi/240329 to your computer and use it in GitHub Desktop.
Save kritzikratzi/240329 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "../include/Stiffness_main.h"
#include "../include/Mesh.h"
#include "../include/TriMatrix.h"
#include "../include/Preconditioner.h"
using namespace std;
//====================================
// f(x):=8
double f( double x )
{
return 8;
}
//====================================
void exercise28( int intervals )
{
int n = intervals + 1;
cout << "-- Mesh detail: " << n << endl;
// create mesh
Mesh mesh = Mesh( 0, 1, n-1 );
// Create and assemble stiffness matrix
TriMatrix stiffnessMatrix = TriMatrix( n );
AssembleStiffnessMatrix( mesh, stiffnessMatrix );
// Create and assemble element load vector
Vector loadVector = Vector( n );
AssembleLoadVector( &f, mesh, loadVector );
// Add boundary conditions
ImplementDirichletBC( 0, -1, mesh, stiffnessMatrix, loadVector );
ImplementRobinBC( n-1, 1, 1, mesh, stiffnessMatrix, loadVector );
stiffnessMatrix.print();
loadVector.print();
Vector x = Vector( n );
TridiagonalSolve( stiffnessMatrix, loadVector, x );
cout << "-- Solution: " << endl;
x.print();
}
int main(){
exercise28( 10 );
exercise28( 20 );
exercise28( 100 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment