Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multidimensional basis and other improvements #43

Merged
merged 13 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Printing wavefunction and potential to file when evaluating
  • Loading branch information
GabrielePisciotta committed Feb 11, 2019
commit 7c4f096642ed6dcca5e696e0936557a1616d7716
14 changes: 14 additions & 0 deletions src/Potential/Potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void Potential::finite_well_potential()

std::vector<double> Potential::getValues()
{
this->printToFile();
return this->v;
}

Expand All @@ -102,3 +103,16 @@ std::vector<double> Potential::getCoordsFromBase()
}
}

void Potential::printToFile() {
std::ofstream myfile ("potential.dat");
if (myfile.is_open())
{

for(int i = 0; i < this->v.size(); i ++){
myfile << i <<" " << this->v.at(i)<< std::endl ;
}
myfile.close();
}
}


3 changes: 2 additions & 1 deletion src/Potential/Potential.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>
#include <stdexcept>
#include <stdbool.h>
#include <fstream>
#include "../Basis/Base.h"

/*! Class Potential contains the potential used in the Schroedinger equation.
Expand Down Expand Up @@ -41,7 +42,7 @@ class Potential {
std::vector<double> getValues();
std::vector<double> getCoordsFromBase();
Base getBase();

void printToFile();
class Builder{
private:
Base base;
Expand Down
27 changes: 13 additions & 14 deletions src/Solver/Numerov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ double trap_array(int a, int b, double stepx, double *func) {
return trapez_sum;
}

void wavefuctionToFile(double *wavefunction) {
std::ofstream myfile ("wavefunction.dat");
if (myfile.is_open())
{

for(int i = 0; i < sizeof(wavefunction); i ++){
myfile << i <<" " << wavefunction[i] << std::endl ;
}
myfile.close();
}
}
/*! Numerov Algorithm solves
f''(x) + v(x)f(x) = 0,
by considering
Expand Down Expand Up @@ -110,12 +99,22 @@ double solve_Numerov(double Emin, double Emax, double Estep,
norm = trap_array(0., nbox, dx, probab);
std::cout << "# norm=" << norm << std::endl;

for (int i = 0; i <= nbox; i++)
wavefunction[i] = wavefunction[i] / sqrt(norm);
std::ofstream myfile ("wavefunction.dat");
if (myfile.is_open())
{

for (int i = 0; i <= nbox; i++) {
wavefunction[i] = wavefunction[i] / sqrt(norm);
myfile << i << " "<< wavefunction[i] << std::endl;
}
std::cout << std::endl;
myfile.close();
}


// for (int i = 0; i <= nbox; i++)
// std::cout << (-nbox / 2 + i) * dx << " " << wavefunction[i] << " " << (*potential)((-nbox / 2 + i) * dx) << std::endl;

wavefuctionToFile(wavefunction);
return Solution_Energy;
}

Expand Down