Commit 6541c044 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

More bug fixes. Pleaaase let it work now.

parent 741aca1e
......@@ -738,7 +738,7 @@ void IO::copyFromTemporaryFile(const shared_ptr<GridManager> &gridman,
auto tmpfile = std::ifstream(getTempFileName(), std::ifstream::binary);
tmpfile.seekg(0, std::ios::end);
const int length = tmpfile.tellg();
const std::streamoff length = tmpfile.tellg();
tmpfile.seekg(0, std::ios::beg);
// first, read rank (and check, if it is correct...)
......@@ -769,7 +769,7 @@ void IO::copyFromTemporaryFile(const shared_ptr<GridManager> &gridman,
unsigned int iconf;
unsigned int pix_idx;
while((int) tmpfile.tellg() < length) {
while(tmpfile.tellg() < length) {
tmpfile.read(reinterpret_cast<char *>(&idefocus), sizeof(idefocus));
tmpfile.read(reinterpret_cast<char *>(&iconf), sizeof(iconf));
tmpfile.read(reinterpret_cast<char *>(&pix_idx), sizeof(pix_idx));
......@@ -979,7 +979,6 @@ std::shared_ptr<stemsalabim::atomic::Cell> IO::initCrystalFromXYZFile(const std:
}
cell->addElement(elp.elementBySymbol(tokens[0]));
sf.initPotential(elp.elementBySymbol(tokens[0]));
atom_id++;
}
......@@ -990,7 +989,7 @@ std::shared_ptr<stemsalabim::atomic::Cell> IO::initCrystalFromXYZFile(const std:
std::shared_ptr<stemsalabim::atomic::Cell> IO::initCrystalFromNCFile(const std::string &filename) {
atomic::ElementProvider elp = atomic::ElementProvider::getInstance();
atomic::Scattering &sf = atomic::Scattering::getInstance();
vector<short> element_ids;
vector<float> lattice_coords;
......@@ -1029,7 +1028,6 @@ std::shared_ptr<stemsalabim::atomic::Cell> IO::initCrystalFromNCFile(const std::
for(const auto &at: atom_types) {
cell->addElement(elp.elementBySymbol(at));
sf.initPotential(elp.elementBySymbol(at));
}
for(size_t i_atom = 0; i_atom < e_len[1]; i_atom++) {
......
......@@ -37,6 +37,10 @@ using namespace stemsalabim;
void Simulation::init() {
// int i = 0;
// while(0==i)
// sleep(5);
high_resolution_clock::time_point init_start = high_resolution_clock::now();
Params &p = Params::getInstance();
......@@ -197,8 +201,7 @@ void Simulation::run() {
output::fmt("Finished calculation of transmission functions in %s.\n",
output::humantime(algorithms::getTimeSince(t1))));
if(mpi_env.isMpi())
_io->generateTemporaryResultFile();
_io->generateTemporaryResultFile();
if(mpi_env.isMaster()) {
multisliceMaster(st);
......@@ -207,7 +210,7 @@ void Simulation::run() {
}
// each MPI process now (sequentially) writes his pixels to the NC file.
if(mpi_env.isMpi()) {
//if(mpi_env.isMpi()) {
//This barrier is not really required.
mpi_env.barrier();
......@@ -229,8 +232,9 @@ void Simulation::run() {
printMaster(st,
output::fmt("Gathering result files took %s.\n",
output::humantime(algorithms::getTimeSince(start_io))));
}
//}
break;
};
if(mpi_env.isMaster()) {
......@@ -516,6 +520,8 @@ void Simulation::multisliceMaster(const SimulationState &st) {
}
} while(!scan_work.finished());
scan_work.waitUntilFinished();
for(unsigned int px_idx : scan_work.getDirtyAndClean()) {
ScanPoint &sp = work_packages[px_idx];
IO::writeTemporaryResult(st.idefocus(),
......@@ -526,8 +532,6 @@ void Simulation::multisliceMaster(const SimulationState &st) {
_cbed_intensity_buffer);
}
scan_work.waitUntilFinished();
printLine(st,
output::fmt("Received all results, calculation took %s.\n",
output::humantime(algorithms::getTimeSince(t1))));
......@@ -545,7 +549,21 @@ void Simulation::multisliceMaster(const SimulationState &st) {
scan_work.finish(pix_index);
// store finished intensities
io_duration += storeDirtyResults(st, work_packages, scan_work);
for(unsigned int px_idx : scan_work.getDirtyAndClean()) {
ScanPoint &sp = work_packages[px_idx];
// we store only pixels with intensities, as all others are the ones
// which are calculated by a different MPI worker.
if(sp.hasAdfIntensities() || sp.hasCbedIntensities())
IO::writeTemporaryResult(st.idefocus(),
st.iconf(),
sp,
_com_buffer,
_adf_intensity_buffer,
_cbed_intensity_buffer);
}
//io_duration += storeDirtyResults(st, work_packages, scan_work);
float p = scan_work.progress();
......@@ -561,9 +579,23 @@ void Simulation::multisliceMaster(const SimulationState &st) {
}
}
//io_duration += storeDirtyResults(st, work_packages, scan_work);
scan_work.waitUntilFinished();
io_duration += storeDirtyResults(st, work_packages, scan_work);
for(unsigned int px_idx : scan_work.getDirtyAndClean()) {
ScanPoint &sp = work_packages[px_idx];
// we store only pixels with intensities, as all others are the ones
// which are calculated by a different MPI worker.
if(sp.hasAdfIntensities() || sp.hasCbedIntensities()) {
IO::writeTemporaryResult(st.idefocus(),
st.iconf(),
sp,
_com_buffer,
_adf_intensity_buffer,
_cbed_intensity_buffer);
}
}
printLine(st,
output::fmt("Calculation took %s and I/O took %s.\n",
......@@ -572,8 +604,9 @@ void Simulation::multisliceMaster(const SimulationState &st) {
}
// join the threads
for(auto &t: threads)
for(auto &t: threads) {
t.join();
}
}
......
......@@ -32,6 +32,7 @@
#include "Element.hpp"
#include "Atom.hpp"
#include "Scattering.hpp"
namespace stemsalabim { namespace atomic {
......@@ -104,6 +105,12 @@ namespace stemsalabim { namespace atomic {
_elements.insert(el);
}
void initScattering() {
Scattering &sf = Scattering::getInstance();
for(auto & e : _elements)
sf.initPotential(e);
}
/*!
* Add an element to the collection of elements.
*/
......
......@@ -44,17 +44,17 @@ namespace stemsalabim { namespace atomic {
static Scattering instance(cache_grating, cutoff_radius);
return instance;
}
/*!
* Get the grating scale of the (cached) atomic potentials. Note, that this scale
* is different to that of the Crystal and phase gratings, to make it more precise.
*/
static double gratingScale() {
Params &p = Params::getInstance();
int grating_atompot = 8 * algorithms::round_even(p.samplingDensity() * p.maxPotentialRadius());
double length_atompot = 2 * p.maxPotentialRadius();
return grating_atompot / length_atompot;
}
//
// /*!
// * Get the grating scale of the (cached) atomic potentials. Note, that this scale
// * is different to that of the Crystal and phase gratings, to make it more precise.
// */
// static double gratingScale() {
// Params &p = Params::getInstance();
// int grating_atompot = 8 * algorithms::round_even(p.samplingDensity() * p.maxPotentialRadius());
// double length_atompot = 2 * p.maxPotentialRadius();
// return grating_atompot / length_atompot;
// }
/*!
* Get index of the potential vector given some distance
......
......@@ -120,6 +120,8 @@ int main(int argc, const char **argv) {
if(mpi_env.isMpi())
p.broadcast(mpi::Environment::MASTER);
p.cell()->initScattering();
// create the simulation instance an pass the parameters instance
// to it.
Simulation s;
......
......@@ -115,8 +115,11 @@ int main(int argc, const char **argv) {
p.setCell(IO::initCrystalFromNCFile(p.outputFilename()));
}
if(mpi_env.isMpi())
if(mpi_env.isMpi()) {
p.broadcast(mpi::Environment::MASTER);
}
p.cell()->initScattering();
// create the simulation instance an pass the parameters instance
// to it.
......
......@@ -55,6 +55,8 @@ namespace stemsalabim {
io->writeParams(gridman);
io->writeGrids(gridman);
p.cell()->initScattering();
SimulationStateManager state_manager(gridman);
// loop over simulations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment