Commit 6cc03766 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Removed double precision support and optimized the propagator.

parent e49a2c5b
application: {
random_seed = 0;
verbose = true;
precision = "single";
}
simulation: {
title = "sim";
bandwidth_limiting = true;
normalize_always = false;
output_file = "Si.nc";
skip_simulation = false;
output_compress = false;
}
probe: {
c5 = 5.0e6; # in nm
cs = 2.0e3; # in nm
defocus = -2.0; # in nm
fwhm_defocus = 6.0; # in nm
num_defoci = 1;
astigmatism_ca = 0.0; # in nm
astigmatism_angle = 0.0; # in rad
min_apert = 0.0; # in rad
max_apert = 24.0; # in mrad
beam_energy = 200.0; # in kV
scan_density = 20.0;
}
specimen: {
max_potential_radius = 0.30; # in nm
crystal_file = "cell.xyz";
# field_file = "pot_valence.xyz";
}
grating: {
density = 180;
slice_thickness = 0.543; # in nm
}
adf: {
enabled = true;
x = (0, 1.0);
y = (0, 1.0);
detector_min_angle = 1.0;
detector_max_angle = 300.0;
detector_num_angles = 300;
detector_interval_exponent = 1.0;
save_slices_every = 0;
average_configurations = true;
average_defoci = true;
}
cbed: {
enabled = false;
x = (0, 1.0);
y = (0, 1.0);
#size = [87,87];
save_slices_every = 0;
average_configurations = true;
average_defoci = true;
}
frozen_phonon: {
number_configurations = 1;
fixed_slicing = true;
}
http_reporting: {
reporting = false;
url = "https://samples.wzmw.uni-marburg.de/api/stemsalabim_reporting/";
parameters: {
username = "duschekl";
api_token = "2e41946e-e609-4cac-b6fb-8365d9c398ff";
}
}
This diff is collapsed.
......@@ -19,22 +19,22 @@
#
SET(BUILD_SHARED_LIBS ON)
#SET(BUILD_SHARED_LIBS ON)
# compilation
add_library(stemsalabim_lib
classes/StructureFactors.cpp classes/StructureFactors.hpp
classes/StructureFactors.hpp
classes/Crystal.cpp classes/Crystal.hpp
classes/Slice.cpp classes/Slice.hpp
classes/Params.cpp classes/Params.hpp
classes/Simulation.cpp classes/Simulation.hpp
classes/IO.cpp classes/IO.hpp
classes/GridManager.cpp classes/GridManager.hpp
classes/FPConfManager.cpp classes/FPConfManager.hpp
classes/Slice.cpp classes/Slice.hpp
classes/Atom.hpp
classes/Element.hpp
classes/SimulationState.hpp
utilities/Complex2D.hpp
utilities/Wave.hpp
utilities/elements_json.hpp
utilities/mpi.hpp
utilities/memory.hpp
......
......@@ -30,8 +30,8 @@
using namespace std;
using namespace stemsalabim;
template<typename prec_t>
void stemsalabim::Crystal<prec_t>::init(const std::string &crystal_file_content) {
void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
// this order is very important!
ElementProvider p = ElementProvider::getInstance();
......@@ -116,8 +116,8 @@ void stemsalabim::Crystal<prec_t>::init(const std::string &crystal_file_content)
}
template<typename prec_t>
void stemsalabim::Crystal<prec_t>::readFieldFile(const std::string &field_file_content) {
void stemsalabim::Crystal::readFieldFile(const std::string &field_file_content) {
// some useful variable declarations
istringstream iss(field_file_content);
......@@ -156,8 +156,8 @@ void stemsalabim::Crystal<prec_t>::readFieldFile(const std::string &field_file_c
}
}
template<typename prec_t>
void stemsalabim::Crystal<prec_t>::generateSlices() {
void stemsalabim::Crystal::generateSlices() {
Params &p = Params::getInstance();
double dz = p.sliceThickness();
......@@ -171,14 +171,14 @@ void stemsalabim::Crystal<prec_t>::generateSlices() {
// taken care of.
unsigned int c = 0;
for(double z = slice_top_offset; z < _size_z; z += dz, c++)
_slices.push_back(shared_ptr<Slice<prec_t>>(new Slice<prec_t>(z, dz, c)));
_slices.push_back(shared_ptr<Slice>(new Slice(z, dz, c)));
}
template<typename prec_t>
void Crystal<prec_t>::assignFieldsToSlices() {
for(shared_ptr<Slice<prec_t>> &slic: _slices)
void Crystal::assignFieldsToSlices() {
for(shared_ptr<Slice> &slic: _slices)
slic->clearFields();
size_t i = 0;
......@@ -193,10 +193,3 @@ void Crystal<prec_t>::assignFieldsToSlices() {
i++;
}
}
template
class stemsalabim::Crystal<float>;
template
class stemsalabim::Crystal<double>;
\ No newline at end of file
......@@ -37,7 +37,7 @@
namespace stemsalabim {
template<typename prec_t>
class Slice;
/*!
......@@ -46,7 +46,7 @@ namespace stemsalabim {
* In addition, it contains the real and k-space grids on which the simulation's wave functions
* are discretized.
*/
template<typename prec_t>
class Crystal {
public:
......@@ -128,7 +128,7 @@ namespace stemsalabim {
* Get a vector of pointers to the Slice objects of the multi-slice algorithm
* @return Slice objects
*/
const std::vector<std::shared_ptr<Slice<prec_t>>> &slices() const {
const std::vector<std::shared_ptr<Slice>> &slices() const {
return _slices;
}
......@@ -136,7 +136,7 @@ namespace stemsalabim {
* Get a vector of pointers to the Slice objects of the multi-slice algorithm. const version
* @return Slice objects
*/
std::vector<std::shared_ptr<Slice<prec_t>>> &slices() {
std::vector<std::shared_ptr<Slice>> &slices() {
return _slices;
}
......@@ -171,7 +171,7 @@ namespace stemsalabim {
private:
std::vector<std::shared_ptr<Atom>> _atoms;
std::vector<std::shared_ptr<Slice<prec_t>>> _slices;
std::vector<std::shared_ptr<Slice>> _slices;
std::set<std::shared_ptr<Element>> _elements;
std::vector<std::tuple<double, double, double, double>> _fields;
double _size_x, _size_y, _size_z;
......
......@@ -27,8 +27,8 @@
using namespace std;
using namespace stemsalabim;
template<typename prec_t>
void FPConfManager<prec_t>::init(const std::vector<double> &random_numbers) {
void FPConfManager::init(const std::vector<double> &random_numbers) {
// atomic displacements are cached for all configurations
bool fixed_slicing = Params::getInstance().isFixedSlicing();
......@@ -54,10 +54,10 @@ void FPConfManager<prec_t>::init(const std::vector<double> &random_numbers) {
}
}
template<typename prec_t>
void FPConfManager<prec_t>::assignAtomsToSlices() {
for(shared_ptr<Slice<prec_t>> &slic: _crystal->slices())
void FPConfManager::assignAtomsToSlices() {
for(shared_ptr<Slice> &slic: _crystal->slices())
slic->clearAtoms();
size_t i = 0;
......@@ -71,9 +71,3 @@ void FPConfManager<prec_t>::assignAtomsToSlices() {
i++;
}
}
template
class stemsalabim::FPConfManager<float>;
template
class stemsalabim::FPConfManager<double>;
\ No newline at end of file
......@@ -30,9 +30,9 @@ namespace stemsalabim {
* Management class of Frozen Phonon configurations.
* It is responsible for generating and returning atomic displacements based on
* the current configuration index.
* @tparam prec_t precision type, float or double
* @tparam float precision type, float or double
*/
template<typename prec_t>
class FPConfManager {
public:
......@@ -41,7 +41,7 @@ namespace stemsalabim {
* @param num_confs Number of FP configurations
* @param crystal reference to the Crystal class
*/
FPConfManager(std::shared_ptr<Crystal<prec_t>> &crystal)
FPConfManager(std::shared_ptr<Crystal> &crystal)
: _crystal(crystal)
, _total_configurations(Params::getInstance().numberOfConfigurations() *
Params::getInstance().numberOfDefoci())
......@@ -142,7 +142,7 @@ namespace stemsalabim {
}
private:
std::shared_ptr<Crystal<prec_t>> _crystal;
std::shared_ptr<Crystal> _crystal;
std::vector<std::vector<std::tuple<double, double, double>>> _displacements;
unsigned int _total_configurations;
......
......@@ -25,8 +25,8 @@
using namespace std;
using namespace stemsalabim;
template<typename prec_t>
void GridManager<prec_t>::generateGrids() {
void GridManager::generateGrids() {
Params &p = Params::getInstance();
generateKSpace();
......@@ -155,8 +155,8 @@ void GridManager<prec_t>::generateGrids() {
// check FFTW conventions!
template<typename prec_t>
void stemsalabim::GridManager<prec_t>::generateKSpace() {
void stemsalabim::GridManager::generateKSpace() {
unsigned int lx = samplingX();
unsigned int ly = samplingY();
......@@ -184,17 +184,4 @@ void stemsalabim::GridManager<prec_t>::generateKSpace() {
else
_ky_space[i] = i / _crystal->sizeY();
}
}
template
class stemsalabim::GridManager<float>;
template
class stemsalabim::GridManager<double>;
template
class stemsalabim::ScanPoint<float>;
template
class stemsalabim::ScanPoint<double>;
\ No newline at end of file
}
\ No newline at end of file
......@@ -32,13 +32,13 @@ namespace stemsalabim {
* Wrapper class that contains information about a single STEM scan point,
* along with information where the related intensities are stored after
* successful calculation.
* @tparam prec_t precision type, float or double
* @tparam float precision type, float or double
*/
template<typename prec_t>
class ScanPoint {
public:
typedef typename std::shared_ptr<memory::buffer::number_buffer<prec_t>> ptr_buf_t;
typedef typename std::shared_ptr<memory::buffer::number_buffer<float>> ptr_buf_t;
/*!
* Empty constructor needed for serialization
......@@ -71,20 +71,20 @@ namespace stemsalabim {
/*!
* Stores intensities in the member vector.
* @param in intensities as a vector of prec_t
* @param in intensities as a vector of float
* @param buf memory buffer where the data is stored
*/
void storeAdfIntensities(const std::vector<prec_t> &in, ptr_buf_t &buf) {
void storeAdfIntensities(const std::vector<float> &in, ptr_buf_t &buf) {
adf_intensities = buf->add(in);
_adf_intensities_stored = true;
}
/*!
* Stores CBED intensities in the member vector.
* @param in CBED intensities as a vector of prec_t
* @param in CBED intensities as a vector of float
* @param buf memory buffer where the data is stored
*/
void storeCBEDIntensities(const std::vector<prec_t> &in, ptr_buf_t &buf) {
void storeCBEDIntensities(const std::vector<float> &in, ptr_buf_t &buf) {
cbed_intensities = buf->add(in);
_cbed_intensities_stored = true;
}
......@@ -138,8 +138,8 @@ namespace stemsalabim {
bool _adf_intensities_stored{false};
bool _cbed_intensities_stored{false};
memory::buffer::entry<prec_t> adf_intensities;
memory::buffer::entry<prec_t> cbed_intensities;
memory::buffer::entry<float> adf_intensities;
memory::buffer::entry<float> cbed_intensities;
/*!
* Function to write data to a vector<char> serialization buffer.
......@@ -193,7 +193,7 @@ namespace stemsalabim {
* @param pos Position that is advanced.
*/
static void
deserializePoint(const std::vector<char> &in, ptr_buf_t &ibuf, ptr_buf_t &cbuf, ScanPoint<prec_t> &d,
deserializePoint(const std::vector<char> &in, ptr_buf_t &ibuf, ptr_buf_t &cbuf, ScanPoint &d,
size_t &pos) {
readFromSerializationBuffer(pos, in, d.adf_row);
......@@ -209,14 +209,14 @@ namespace stemsalabim {
readFromSerializationBuffer(pos, in, d._cbed_intensities_stored);
if(d.hasAdfIntensities()) {
typename std::vector<prec_t>::size_type int_size;
typename std::vector<float>::size_type int_size;
readFromSerializationBuffer(pos, in, int_size);
d.adf_intensities = ibuf->add_empty();
readFromSerializationBuffer(pos, in, ibuf->get(d.adf_intensities));
}
if(d.hasCbedIntensities()) {
typename std::vector<prec_t>::size_type cbed_int_size;
typename std::vector<float>::size_type cbed_int_size;
readFromSerializationBuffer(pos, in, cbed_int_size);
d.cbed_intensities = cbuf->add_empty();
readFromSerializationBuffer(pos, in, cbuf->get(d.cbed_intensities));
......@@ -233,7 +233,7 @@ namespace stemsalabim {
* @return A vector ScanPoint objects with all data restored.
*/
static std::vector<unsigned int>
deserialize(const std::vector<char> &in, std::vector<ScanPoint<prec_t>> &work_packages, ptr_buf_t &ibuf,
deserialize(const std::vector<char> &in, std::vector<ScanPoint> &work_packages, ptr_buf_t &ibuf,
ptr_buf_t &cbuf) {
size_t pos = 0;
......@@ -244,7 +244,7 @@ namespace stemsalabim {
for(size_t i = 0; i < total_size; ++i) {
readFromSerializationBuffer(pos, in, received_indices[i]);
ScanPoint<prec_t> &d = work_packages[received_indices[i]];
ScanPoint &d = work_packages[received_indices[i]];
deserializePoint(in, ibuf, cbuf, d, pos);
}
......@@ -259,14 +259,14 @@ namespace stemsalabim {
* @param cbuf The memory buffer with the cbed data
* @return A vector ScanPoint objects with all data restored.
*/
static std::vector<ScanPoint<prec_t>>
static std::vector<ScanPoint>
deserialize(const std::vector<char> &in, ptr_buf_t &ibuf, ptr_buf_t &cbuf) {
size_t pos = 0;
size_t total_size;
readFromSerializationBuffer(pos, in, total_size);
std::vector<ScanPoint<prec_t>> out_vec;
std::vector<ScanPoint> out_vec;
out_vec.resize(total_size);
for(ScanPoint &d: out_vec) {
......@@ -286,7 +286,7 @@ namespace stemsalabim {
* @param pos the position that is advanced.
*/
static void
serializePoint(std::vector<char> &buf, const ptr_buf_t &ibuf, const ptr_buf_t &cbuf, const ScanPoint<prec_t> &d,
serializePoint(std::vector<char> &buf, const ptr_buf_t &ibuf, const ptr_buf_t &cbuf, const ScanPoint &d,
size_t &pos) {
writeToSerializationBuffer(pos, buf, d.index);
......@@ -324,7 +324,7 @@ namespace stemsalabim {
* @return The number of bytes of the serialized data.
*/
static size_t serialize(std::vector<char> &buf, const std::vector<unsigned int> &indices,
const std::vector<ScanPoint<prec_t>> &work_packages, ptr_buf_t &ibuf, ptr_buf_t &cbuf) {
const std::vector<ScanPoint> &work_packages, ptr_buf_t &ibuf, ptr_buf_t &cbuf) {
size_t pos = 0;
size_t npoints = indices.size();
......@@ -332,7 +332,7 @@ namespace stemsalabim {
writeToSerializationBuffer(pos, buf, npoints);
for(unsigned int index: indices) {
const ScanPoint<prec_t> &d = work_packages[index];
const ScanPoint &d = work_packages[index];
serializePoint(buf, ibuf, cbuf, d, pos);
}
......@@ -348,7 +348,7 @@ namespace stemsalabim {
* @param cbuf The memory buffer with the cbed data
* @return The number of bytes of the serialized data..
*/
static size_t serialize(std::vector<char> &buf, const std::vector<ScanPoint<prec_t>> &data, ptr_buf_t &ibuf,
static size_t serialize(std::vector<char> &buf, const std::vector<ScanPoint> &data, ptr_buf_t &ibuf,
ptr_buf_t &cbuf) {
size_t pos = 0;
......@@ -356,7 +356,7 @@ namespace stemsalabim {
writeToSerializationBuffer(pos, buf, npoints);
for(const ScanPoint<prec_t> &d: data) {
for(const ScanPoint &d: data) {
serializePoint(buf, ibuf, cbuf, d, pos);
}
......@@ -367,13 +367,13 @@ namespace stemsalabim {
/*!
* Management class for the various parameter sweeps/grids required in the simulation.
* @tparam prec_t precision type, float or double
* @tparam float precision type, float or double
*/
template<typename prec_t>
class GridManager {
public:
explicit GridManager(const std::shared_ptr<Crystal<prec_t>> &crystal)
explicit GridManager(const std::shared_ptr<Crystal> &crystal)
: _crystal(crystal) {}
/*!
......@@ -411,7 +411,7 @@ namespace stemsalabim {
* Return all ScanPoint objects for all the pixels that are calculated by the simulation.
* @return vector of ScanPoints
*/
const std::vector<ScanPoint<prec_t>> scanPoints() const {
const std::vector<ScanPoint> scanPoints() const {
return _scan_points;
}
......@@ -678,14 +678,14 @@ namespace stemsalabim {
private:
const std::shared_ptr<Crystal<prec_t>> &_crystal;
const std::shared_ptr<Crystal> &_crystal;
std::vector<double> _detector_grid;
std::vector<double> _adf_slice_coords;
std::vector<double> _cbed_slice_coords;
std::vector<double> _defoci;
std::vector<double> _defocus_weights;
std::vector<ScanPoint<prec_t>> _scan_points;
std::vector<ScanPoint> _scan_points;
std::vector<double> _kx_space;
std::vector<double> _ky_space;
......
......@@ -179,9 +179,9 @@ putVara(int ncid, int var_id, const vector<size_t> &index, const vector<size_t>
}
template<typename prec_t>
void
IO<prec_t>::initNcFile(const shared_ptr<GridManager<prec_t>> &gridman, const shared_ptr<Crystal<prec_t>> &crystal) {
IO::initNcFile(const shared_ptr<GridManager> &gridman, const shared_ptr<Crystal> &crystal) {
Params &p = Params::getInstance();
auto &mpi_env = mpi::Environment::getInstance();
......@@ -508,8 +508,8 @@ IO<prec_t>::initNcFile(const shared_ptr<GridManager<prec_t>> &gridman, const sha
}
template<typename prec_t>
void IO<prec_t>::writeParams(const shared_ptr<GridManager<prec_t>> &gridman) {
void IO::writeParams(const shared_ptr<GridManager> &gridman) {
int id;
Params &p = Params::getInstance();
auto &mpi_env = mpi::Environment::getInstance();
......@@ -635,9 +635,9 @@ void IO<prec_t>::writeParams(const shared_ptr<GridManager<prec_t>> &gridman) {
nc_close(id);
}
template<typename prec_t>
void
IO<prec_t>::writeCrystal(const shared_ptr<FPConfManager<prec_t>> &fpman, const shared_ptr<Crystal<prec_t>> &crystal) {
IO::writeCrystal(const shared_ptr<FPConfManager> &fpman, const shared_ptr<Crystal> &crystal) {
int id;
auto &mpi_env = mpi::Environment::getInstance();
......@@ -725,10 +725,10 @@ IO<prec_t>::writeCrystal(const shared_ptr<FPConfManager<prec_t>> &fpman, const s
nc_close(id);
}
template<typename prec_t>
void IO<prec_t>::writeAdfIntensities(unsigned int idefocus, unsigned int iconf,
const shared_ptr<GridManager<prec_t>> &gridman, const ScanPoint<prec_t> &point,
std::shared_ptr<memory::buffer::number_buffer<prec_t>> &ibuf) {
void IO::writeAdfIntensities(unsigned int idefocus, unsigned int iconf,
const shared_ptr<GridManager> &gridman, const ScanPoint &point,
std::shared_ptr<memory::buffer::number_buffer<float>> &ibuf) {
unique_lock<mutex> qlck(_io_lock);
Params &p = Params::getInstance();
......@@ -809,10 +809,10 @@ void IO<prec_t>::writeAdfIntensities(unsigned int idefocus, unsigned int iconf,
nc_close(f_id);
}
template<typename prec_t>
void IO<prec_t>::writeCBEDIntensities(unsigned int idefocus, unsigned int iconf,
const shared_ptr<GridManager<prec_t>> &gridman, const ScanPoint<prec_t> &point,
std::shared_ptr<memory::buffer::number_buffer<prec_t>> &cbuf) {
void IO::writeCBEDIntensities(unsigned int idefocus, unsigned int iconf,
const shared_ptr<GridManager> &gridman, const ScanPoint &point,
std::shared_ptr<memory::buffer::number_buffer<float>> &cbuf) {
unique_lock<mutex> qlck(_io_lock);
Params &p = Params::getInstance();
......@@ -896,8 +896,8 @@ void IO<prec_t>::writeCBEDIntensities(unsigned int idefocus, unsigned int iconf,
}
template<typename prec_t>
void IO<prec_t>::writeGrids(const shared_ptr<GridManager<prec_t>> &gridman) {
void IO::writeGrids(const shared_ptr<GridManager> &gridman) {
Params &p = Params::getInstance();
int id;
......@@ -998,8 +998,8 @@ void IO<prec_t>::writeGrids(const shared_ptr<GridManager<prec_t>> &gridman) {
nc_close(id);
}
template<typename prec_t>
IO<prec_t>::~IO() {
IO::~IO() {
int id, rt_id;
try {
......@@ -1019,8 +1019,8 @@ IO<prec_t>::~IO() {
nc_close(id);
}
template<typename prec_t>
void IO<prec_t>::dumpWave(string filename, const Complex2D<prec_t> &wave) {
void IO::dumpWave(string filename, const Wave &wave) {
FILE *f = fopen(filename.c_str(), "w");
for(unsigned int ix = 0; ix < wave.lx(); ix++)
for(unsigned int iy = 0; iy < wave.ly(); iy++)
......@@ -1033,10 +1033,3 @@ void IO<prec_t>::dumpWave(string filename, const Complex2D<prec_t> &wave) {
sqrt(pow(wave(ix, iy).real(), 2) + pow(wave(ix, iy).imag(), 2)));
fclose(f);
}
template
class stemsalabim::IO<float>;
template
class stemsalabim::IO<double>;
\ No newline at end of file
......@@ -30,27 +30,27 @@
#include <netcdf.h>
#include "Params.hpp"
#include "../utilities/memory.hpp"
#include "../utilities/Complex2D.hpp"
#include "../utilities/Wave.hpp"
namespace stemsalabim {
template<typename prec_t>
class Crystal;
template<typename prec_t>
class GridManager;
template<typename prec_t>
class ScanPoint;
template<typename prec_t>
class FPConfManager;
/*!
* Class for writing the output NetCDF file of STEMsalabim.
* @tparam prec_t precision type, double or float
* @tparam float precision type, double or float
*/
template<typename prec_t>
class IO {
public:
/*!
......@@ -65,18 +65,18 @@ namespace stemsalabim {
* is written to the file.
* @param gridman Reference to the GridManager required for writing some information.
*/
void initNcFile(const std::shared_ptr<GridManager<prec_t>> &gridman, const std::shared_ptr<Crystal<prec_t>> &crystal);
void initNcFile(const std::shared_ptr<GridManager> &gridman, const std::shared_ptr<Crystal> &crystal);
/*!
* Appends the atomic positions of the current FP configuration to the AMBER group.
* @param fpman FP configuration manager
*/
void writeCrystal(const std::shared_ptr<FPConfManager<prec_t>> &fpman, const std::shared_ptr<Crystal<prec_t>> &crystal);
void writeCrystal(const std::shared_ptr<FPConfManager> &fpman, const std::shared_ptr<Crystal> &crystal);
/*!