Hey, what's going on?

Pemecahan persamaan difusi neutron 1D single-group secara numerik dalam c++

Posted by Syeilendra Pramuditya on June 11, 2014

//Pemecahan persamaan difusi neutron 1D single-group secara numerik dalam c++
//Created: 11 Juni 2014
//Last Modified: -
//Programmer: Syeilendra Pramuditya

#include <iostream>
#include <cmath>
using namespace std;

float findflux(float a, float b, float c, float d, float e, float f){
float out1;
//Diturunkan dari persamaan difusi neutron 1D single-group
//Metode finite difference
out1=(((a+b)/(c*c))+(d/e)) / ((f/e)+(2/(c*c)));
return out1;
}

int main(){

int nx,itermax,i,iter,konvergen;
float L,dx,sigma_a,D,errormax,error,dummy;
float FluxOld[50],FluxNew[50],S[50];

//=============input===================
nx=50;//jumlah partisi
L=3;//dimensi domain
dx=L/nx;//lebar partisi
sigma_a=1;//cross section makroskopik
D=1.0/6;//koefisien difusi
errormax=1e-3;//kriteria konvergensi
itermax=1000;//loop limit
//=====================================

//==========syarat batas===============
FluxOld[0]=0; //flux di x=0 harus nol
FluxOld[nx]=0; //flux di x=L harus nol
FluxNew[0]=0; //flux di x=0 harus nol
FluxNew[nx]=0; //flux di x=L harus nol
S[0]=0; //source di x=0 harus nol
S[nx]=0; //source di x=L harus nol
//=====================================

//==========tebakan awal===============
for (i=1; i<=nx-1; i++){
FluxOld[i]=300; //tebakan awal flux
S[i]=100; //tebakan awal source
};
//=====================================

iter=0;
do{
iter++;
konvergen=1;
	for(i=1;i<=nx-1;i++){
	FluxNew[i]=findflux(FluxOld[i+1],FluxOld[i-1],dx,S[i],D,sigma_a); //Jacobi	
	}
	
	for(i=0;i<=nx;i++){
	error=fabs(FluxNew[i]-FluxOld[i]);
	if (error > errormax) konvergen=0; 
	}
	
	for(i=1;i<=nx-1;i++){FluxOld[i]=FluxNew[i];}
cout<<"Iterasi "<<iter<<"\n";
}while(konvergen==0 && iter<itermax);

cout<<"\n";
cout<<"Distribusi Flux\n";
for (i=0; i<=nx; i++){
cout<<FluxNew[i]<<"\n";
}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: