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

Dev bug 2 d #59

Merged
merged 17 commits into from
Feb 17, 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
Refactoring and multidimensional potential print
  • Loading branch information
GabrielePisciotta committed Feb 13, 2019
commit eaa47bf7d0c5f98cb3648e1d8c5a5fd71eb5f11d
8 changes: 4 additions & 4 deletions src/Basis/ContinuousBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ ContinuousBase::ContinuousBase(double start, double end, unsigned int nbox)

std::vector<double> ContinuousBase::evaluate()
{
std::vector<double> coord;
coord.reserve(this->nbox);
for (std::vector<double>::size_type i = 0; i < this->nbox; i++)
coord.push_back(this->start + this->mesh * i);
std::vector<double> coord;
for (int i = 0; i < this->nbox; i++)
coord.push_back(this->start + (this->mesh * i));

return coord;
}

Expand Down
22 changes: 17 additions & 5 deletions src/Potential/Potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Potential::Potential() {
throw std::invalid_argument("Can't initialize a potential without specifying parameters");
}

Potential::Potential(Base base, PotentialType type, double k, double width, double height, bool separable)
{
this->base = base;
Expand All @@ -12,6 +13,7 @@ Potential::Potential(Base base, PotentialType type, double k, double width, doub
this->type = type;
this->separable = separable;

// If is not separable, evaluate it
if (!this->separable) {
switch(type) {
case BOX_POTENTIAL:
Expand All @@ -27,6 +29,7 @@ Potential::Potential(Base base, PotentialType type, double k, double width, doub
throw std::invalid_argument("Wrong potential type or initialization meaningless!");
}
}

// If the potential is separable, then n potentials (one for each base's representation)
else {
for (ContinuousBase this_base : base.getContinuous()) {
Expand Down Expand Up @@ -98,7 +101,7 @@ std::vector<double> Potential::getCoordsFromBase()
return this->base.getContinuous().at(0).getCoords();

else if (this->base.getDiscrete().size() == 1) {
// tricky conversion taking each std::vector<int> value and returning a final std::vector<double>
// In DiscreteBase we have int, so this is a way to return a vector of double
std::vector<int> original_coords = this->base.getDiscrete().at(0).getCoords();
return std::vector<double>(original_coords.begin(), original_coords.end());
}
Expand All @@ -115,10 +118,19 @@ std::vector<Potential> Potential::getSeparatedPotentials() {

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();
if (this->isSeparated()) {
if (myfile.is_open()) {
int potential_length = this->separated_potentials.at(0).size();
for(int i = 0; i < potential_length; i ++)
myfile << i << " ";

for (Potential p : this->separated_potentials)
myfile << p.getValues().at(i) << " ";

myfile << std::endl ;
myfile.close();
}
}
}

std::ostream& operator<<(std::ostream& stream, Potential& potential) {
Expand Down