Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90392194
main.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 1, 06:28
Size
1 KB
Mime Type
text/x-c
Expires
Sun, Nov 3, 06:28 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22065863
Attached To
R8929 Conjugate Gradient Solver
main.cpp
View Options
/**
* @file main.cpp
* @author Sergio Hernandez
* This file is part of the Conjugate Gradient Project
*
* Ths is the entry point of the project.
*
*/
#include <iostream>
#include<vector>
#include "CG_Serial.hpp"
int main() {
//TODO Temporal - using Tridiagonal matrix
int N = 1000;
std::vector<double> A(N*N,0.0);//Filled with 0.0
std::vector<double> b(N, 1.0);//Filled with 1.0
for (int i=0; i<N; i++){
for (int j=0; j<N; j++){
if (j == i+1){
if (i < N-1 ) {
A[i + N * j] = 1.0; //Upper
}
}
if (j == i-1){
if (i > 0 ){
A[i+N*j] = 1.0; //Downer
}
}
if (j == i){
A[i+N*j] = -2.0; //Main diagonal
}
}
}
double tol = 1e-10;
int max_iter = 10*N;
std::vector<double> x_0 (N,0.0);
CG_Serial solver = CG_Serial(A,b,tol,max_iter);
std::tuple<std::vector<double>,int> result = solver.computeCG(x_0);
std::vector<double> x = std::get<0>(result);
int k = std::get<1>(result);
std::cout << "Solution was found after : "<<k<<" iterations.\n";
std::cout<<"Solution x: \n";
for(int i=0;i<x.size();i++){
std::cout<< x[i]<<"\n";
}
return 0;
}
Event Timeline
Log In to Comment