Skip to content

Commit

Permalink
Doprowadzanie raportowania błędów do stanu działania
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Nov 20, 2011
1 parent 01d3b49 commit ce21c9e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 41 deletions.
15 changes: 12 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#plik make używający skryptu komilujacego pakietu octave

NLS_sovler.oct : NLS_solver.cpp input_test.cpp solve.cpp
mkoctfile NLS_solver.cpp input_test.cpp solve.cpp
CXX=g++
CXXFLAGS=-Wall -std=c++0x -c

OCT_CXX=mkoctfile
OCT_LDFLAGS=-lfftw3

NLS_solver.oct : NLS_solver.cpp solve.o input_test.cpp
$(OCT_CXX) $(OCT_LDFLAGS) NLS_solver.cpp solve.o input_test.cpp

clean :
rm solve.o input_test.o NLS_solver.o
rm solve.o NLS_solver.o input_test.o NLS_solver.oct

solve.o: solve.cpp
$(CXX) $(CXXFLAGS) solve.cpp

install :
mv NLS_solver.oct ../octave_scripts
36 changes: 28 additions & 8 deletions src/NLS_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ DEFUN_DLD( NLS_solver, args, nargout , "Non-linear Schrodinger equation solver."
// args(3) - wektor wierszowy oświetlanie przez laser rzeczywisty wektor
// args(4) - wektor wierszowy kroki czasowe rzeczywisty wektor
// args(5) - wektor wierszowy stałe w problemie, rzeczywisty wektor

//----------------------KONTROLA WEJŚCIA ZE WZGLĘDU NA TYP--------------------------
input_test_val error_state_str;
if(error_state)
{
Expand Down Expand Up @@ -80,7 +82,6 @@ DEFUN_DLD( NLS_solver, args, nargout , "Non-linear Schrodinger equation solver."
error("Bad number of simulation constants provided");

//punkt czasowy z którego zaczynamy


std_complex x;
std::vector<std_complex> in_psi0( 0);
Expand All @@ -106,23 +107,43 @@ DEFUN_DLD( NLS_solver, args, nargout , "Non-linear Schrodinger equation solver."
double xstep = constants(7);
double tstep = constants(8);

//--------------------------------KONTROLA WEJŚCIA ZE WZGLĘDU NA ZAKRES WARTOŚCI---------------------------
if(xstep == 0) error("Spatial step must be positve value.");
if(tstep == 0) error("Time step must be positve value.");
if(constants(0) == 0) error(" 'h_bar' must be non-zero value.");
if(constants(5) == 0) error(" 'm' must be non-zero value.");


//--------------------------------CZĘŚĆ SYMULACYJNA FUNKCJI-----------------------------------------

solution NLS_solver=solution( in_psi0, in_V, in_n_r0, in_P_l, xstep, tstep, in_consts );

dim_vector dv (2);
dv(0) = spatial_size; dv(1) = time_steps.nelem();
dv(0) = spatial_size;
dv(1) = time_steps.nelem();
octave_value_list retval;
ComplexNDArray output_psi(dv);
ComplexNDArray output_n_r(dv);
double time = 0.0;

//ZMIENNA PRZECHOWUJĄCA INFORMACJE O BŁĘDACH WEWNĄTRZ SYMULACJI
num_exception::exception sim_error;

for( int index=0; index < time_steps.nelem(); index++)
{

//raportuj o wszystkich napotkanych nieskończonościach i NANach
sim_error = NLS_solver.report_exception();
if( sim_error.error_state )
{
printf(sim_error.report.c_str() );
}

double delta_time = time_steps(index) - time ;
if(delta_time >= std::abs(tstep) || index == 0)
{
{
//iteruje aż do momentu wyplucia danych w momencie zadanym przez tablice time_steps
NLS_solver.evolution( std::floor( delta_time/ std::abs(tstep) ) );

for(int i=0; i< spatial_size; ++i)
{
//co istotne indeksy dla typów array są pojedyńczymi liczbami(!) macierza mają dodatkowo (,) dla podwójnego indeksowania
Expand All @@ -131,14 +152,13 @@ DEFUN_DLD( NLS_solver, args, nargout , "Non-linear Schrodinger equation solver."
}
}
//żeby poprawnie liczyć czas
time += std::floor(delta_time/std::abs(tstep)) * tstep;
time += std::floor(delta_time/std::abs(tstep)) * std::abs(tstep);
//dodawanie rozwiązania do macierzy rozwiązań
}

//---------------------------------CZĘŚĆ INTERAKCJI WYJŚCIE------------------------------------------------
octave_value_list retval;
retval(1) = output_n_r;
retval(0) = output_psi;
retval.append( output_psi );
retval.append( output_n_r );

return retval;
}
Expand Down
48 changes: 33 additions & 15 deletions src/solve.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include"solve.h"

//c++11:: SPRAWDŹ CZY MOŻLIWA JEST KONWERSJA
static_assert( sizeof(fftw_complex) == sizeof(std_complex), "fftw complex not compatibile with std::complex<double>" );


const double PI = 3.1415926535;

solution::solution(const std::vector<std_complex>& temp, const std::vector<std_complex>& temp_V,
Expand Down Expand Up @@ -35,7 +39,6 @@ solution::solution(const std::vector<std_complex>& temp, const std::vector<std_c
psi[i] = temp[i];
}

error_state = 0;
step = 0;

}//spoko
Expand Down Expand Up @@ -182,40 +185,40 @@ const double solution::output_n_r(int i)
return n_r[i];
}//spoko loko

const std::string solution::report_exceptions()
const num_exception::exception solution::report_exception()
{
//FIXME -- czy takie operacje dają wynik niezależny od implementacji "int"
error_state = 0;
int error_state = 0;
std::ostringstream report;

std::string comment("NAN value found in: ");
std::string comment("NAN or infinite value found in: ");

for(int i = 0;i<data_size; ++i)
{
if( nan_exception::is_nan(n_r[i]) && (error_state & nan_exception::nan_n_r) )
if( num_exception::is_finite(n_r[i])==0 && (error_state & num_exception::nan_n_r) == 0)
{
error_state = error_state | nan_exception::nan_n_r;
error_state = error_state | num_exception::nan_n_r;
report << comment;
report << std::string("n_r");
report << std::endl;
}
if( nan_exception::is_nan(psi[i]) && (error_state & nan_exception::nan_psi) )
if( num_exception::is_finite(psi[i])==0 && (error_state & num_exception::nan_psi) == 0 )
{
error_state = error_state | nan_exception::nan_psi;
error_state = error_state | num_exception::nan_psi;
report << comment;
report << std::string("psi");
report << std::endl;
}
if( nan_exception::is_nan(V[i]) && ( error_state & nan_exception::nan_V) )
if( num_exception::is_finite(V[i])==0 && ( error_state & num_exception::nan_V) == 0 )
{
error_state = error_state | nan_exception::nan_V;
error_state = error_state | num_exception::nan_V;
report << comment;
report << std::string("V");
report << std::endl;
}
if( nan_exception::is_nan(P_l[i]) && (error_state & nan_exception::nan_P_l) )
if( num_exception::is_finite(P_l[i])==0 && (error_state & num_exception::nan_P_l) == 0 )
{
error_state = error_state | nan_exception::nan_P_l;
error_state = error_state | num_exception::nan_P_l;
report << comment;
report << std::string("P_l");
report << std::endl;
Expand All @@ -224,13 +227,18 @@ const std::string solution::report_exceptions()

if(error_state == 0)
{
report << std::string("No exception::isnans found in step");
report << std::string("No exception found ");
}

report << std::string("in step: ");
report << step;
report << std::endl;

return report.str();
num_exception::exception temp;
temp.report = report.str();
temp.error_state = error_state;

return temp;
}//spoko loko

//-------------------------PHYSICAL_CONSTANTS------------------------------
Expand All @@ -245,7 +253,7 @@ physical_constants::physical_constants()
R=0.0;
}

//-------------------FFTW3-------------------------------------------------
//-------------------FFTW3---------------------------------------------------

//fftw może używać tego samego planu jak długo rozmiar tablicy jest ten sam
fourier_transform::~fourier_transform()
Expand All @@ -254,3 +262,13 @@ fourier_transform::~fourier_transform()
fftw_destroy_plan( backward_plan );
}


//------------------num_exception namespace-----------------------------------
bool num_exception::is_finite( std_complex x )
{
if( std::isfinite( x.real() ) && std::isfinite( x.imag() ) )
return true;
else
return false;
}

31 changes: 16 additions & 15 deletions src/solve.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
//
//
//

#include<vector>
#include<complex>
//funkcje matematyczne
#include<cmath>
//transformata fouriera
#include <fftw3.h>

//raportowanie błędów
#include<sstream>

//transformata fouriera
#include <fftw3.h>
//PRZESTRZEŃ NAZW - chyba nie potrzebna jak na razie
typedef std::complex<double> std_complex;



enum direction
{
forward = -1,
backward = 1
};

namespace nan_exception
//--------------NAMESPACE::nan_exception----------------------------------------------
namespace num_exception
{

enum Enum
Expand All @@ -36,16 +37,17 @@ enum Enum
nan_V = 8,
};

bool inline is_nan( std_complex x )
struct exception
{
if( std::isnan( x.real() ) || std::isnan( x.imag() ) )
return true;
else
return false;
}
std::string report;
int error_state;
};

}
//sprawdza czy liczba jest skończona (tzn nie jest nieskończona albo NaN)
bool is_finite( std_complex x );

}
//--------------ENDOF_NAMESPACE::nan_exception---------------------------------------

//TRANSFORMACJA FOURIERA
class fourier_transform
Expand Down Expand Up @@ -132,8 +134,7 @@ class solution
void make_time_step();
void apply_boundary_condition(std_complex start, std_complex end, double falloff);

//DANE KONTROLNE
int error_state;
//NUMER KROKU
int step;

public:
Expand All @@ -149,5 +150,5 @@ class solution
double abs_val();

//FUNKCJA RAPORTUJĄCA O WSZELKICH WARTOŚCIACH NAN
const std::string report_exceptions();
const num_exception::exception report_exception();
};

0 comments on commit ce21c9e

Please sign in to comment.