Commit 70f20e57 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Fixed a bunch of things, especially a severe bug with defocus averaging.

parent fedf63ac
What's new
==========
STEMsalabim 5.0.0
-----------------
January XX, 2019
**IMPORTANT**
STEMsalabim 4.0.1, 4.0.2
------------------------
......
# Tries to find Gperftools.
#
# Usage of this module as follows:
#
# find_package(Gperftools)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# Gperftools_ROOT_DIR Set this variable to the root installation of
# Gperftools if the module has problems finding
# the proper installation path.
#
# Variables defined by this module:
#
# GPERFTOOLS_FOUND System has Gperftools libs/headers
# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler)
# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers
find_library(GPERFTOOLS_TCMALLOC
NAMES tcmalloc
HINTS ${Gperftools_ROOT_DIR}/lib)
find_library(GPERFTOOLS_PROFILER
NAMES profiler
HINTS ${Gperftools_ROOT_DIR}/lib)
find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER
NAMES tcmalloc_and_profiler
HINTS ${Gperftools_ROOT_DIR}/lib)
find_path(GPERFTOOLS_INCLUDE_DIR
NAMES gperftools/heap-profiler.h
HINTS ${Gperftools_ROOT_DIR}/include)
set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Gperftools
DEFAULT_MSG
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
mark_as_advanced(
Gperftools_ROOT_DIR
GPERFTOOLS_TCMALLOC
GPERFTOOLS_PROFILER
GPERFTOOLS_TCMALLOC_AND_PROFILER
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
\ No newline at end of file
......@@ -18,8 +18,6 @@ include(FindPackageHandleStandardArgs)
if((NOT MKL_ROOT) AND (DEFINED ENV{MKLROOT}))
set(MKL_ROOT $ENV{MKLROOT} CACHE PATH "Folder contains MKL")
else()
message( FATAL_ERROR "MKL not found! Specify MKL_ROOT!" )
endif()
if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
......
......@@ -66,7 +66,8 @@ include_directories(
3rdparty/pybind11/include
3rdparty/jsoncpp/json
3rdparty/sole
3rdparty/tinyformat)
3rdparty/tinyformat
3rdparty/variant-lite/include)
# linking ################################################
......
......@@ -30,8 +30,13 @@ void GridManager::generateGrids() {
Params &p = Params::getInstance();
double density = Params::getInstance().samplingDensity();
_sampling_x = (unsigned int)algorithms::getFFTEfficientSize((int)ceil(density * _crystal->sizeX()));
_sampling_y = (unsigned int)algorithms::getFFTEfficientSize((int)ceil(density * _crystal->sizeY()));
if(p.isFixedGrid()) {
_sampling_x = p.fixedGridX();
_sampling_y = p.fixedGridY();
} else {
_sampling_x = (unsigned int)algorithms::getFFTEfficientSize((int)ceil(density * _crystal->sizeX()));
_sampling_y = (unsigned int)algorithms::getFFTEfficientSize((int)ceil(density * _crystal->sizeY()));
}
generateKSpace();
......@@ -182,7 +187,7 @@ void GridManager::generateGrids() {
// first value is spread, second value is center, third value is number
for(double d = mean - fwhm; d <= mean + fwhm; d += 2 * fwhm / (num_defoci - 1)) {
double val = (double) exp(-0.5 * pow(d - mean, 2) / pow(sigma, 2));
float val = (float)exp(-0.5 * pow(d - mean, 2) / pow(sigma, 2));
running_sum += val;
_defocus_weights.push_back(val);
......
......@@ -473,7 +473,7 @@ namespace stemsalabim {
* determined simulating a Gaussian profile around the center defocus. This
* is a simulated chromatic aberration.
*/
const std::vector<double> &defocusWeights() const {
const std::vector<float> &defocusWeights() const {
return _defocus_weights;
}
......@@ -559,7 +559,7 @@ namespace stemsalabim {
std::vector<double> _cbed_slice_coords;
std::vector<float> _slice_coords;
std::vector<double> _defoci;
std::vector<double> _defocus_weights;
std::vector<float> _defocus_weights;
std::vector<ScanPoint> _scan_points;
std::vector<double> _kx_space;
......
This diff is collapsed.
......@@ -170,7 +170,7 @@ namespace stemsalabim {
bool _created{false};
double _running_weight{0};
float _running_weight{0};
std::vector<float> _com_buffer;
std::vector<float> _adf_intensities_buffer;
......
......@@ -36,14 +36,6 @@ using namespace std;
using namespace stemsalabim;
Params::Params() {
_params.push_back(std::make_shared<ParamInterface>("random_seed", "simulation", "The random seed of the run"));
_params.push_back(std::make_shared<ParamInterface>("title", "simulation", "Title of the simulation"));
}
void Params::readParamsFromString(const string &prms) {
try {
......@@ -57,11 +49,6 @@ void Params::readParamsFromString(const string &prms) {
output::error("Parse error at %s:%d - %s", pex.getFile(), pex.getLine(), pex.getError());
}
// for(auto & prm: _params) {
// auto path = output::fmt("%s.%s", prm->group(), prm->name());
// _cfg.lookupValue(path, prm.val());
// }
//Setting &root = _cfg.getRoot();
_cfg.lookupValue("application.random_seed", _random_seed);
......@@ -146,14 +133,6 @@ void Params::readParamsFromString(const string &prms) {
_cfg.lookupValue("adf.average_configurations", _adf_average_configurations);
_cfg.lookupValue("adf.average_defoci", _adf_average_defoci);
_cfg.lookupValue("adf.save_slices_every", _adf_save_every_n_slices);
// when we calculate a single defocus only, set average_defoci to false.
if(_adf_average_defoci && _probe_num_defoci == 1)
_adf_average_defoci = false;
// when defoci are averaged, configurations need to be averaged as well.
if(_adf_average_defoci)
_adf_average_configurations = true;
}
if(_tmp_dir.empty()) {
......@@ -165,6 +144,9 @@ void Params::readParamsFromString(const string &prms) {
_tmp_dir = _output_file.substr(0, found);
}
if(!_fp_enabled && _number_configurations > 1)
_number_configurations = 1;
if(_random_seed == 0)
_random_seed = (unsigned int) chrono::system_clock::now().time_since_epoch().count();
_rgen.seed(_random_seed);
......@@ -326,6 +308,8 @@ void Params::readParamsFromNCFile(const std::string & path) {
_sample_density = gg.att<double>("nominal_density");
_slice_thickness = gg.att<double>("slice_thickness");
_nkx = gg.att<unsigned int>("nx");
_nky = gg.att<unsigned int>("ny");
}
{
......@@ -341,7 +325,7 @@ void Params::readParamsFromNCFile(const std::string & path) {
get<0>(_adf_detector_angles) = gg.att<double>("detector_min_angle");
get<1>(_adf_detector_angles) = gg.att<double>("detector_max_angle");
get<2>(_adf_detector_angles) = gg.att<unsigned int>("detector_num_angles");
_adf_detector_interval_exponent = gg.att<float>("detector_interval_exponent");
_adf_detector_interval_exponent = gg.att<double>("detector_interval_exponent");
_adf_average_configurations = gg.is("average_configurations");
_adf_average_defoci = gg.is("average_defoci");
......@@ -350,10 +334,6 @@ void Params::readParamsFromNCFile(const std::string & path) {
// when we calculate a single defocus only, set average_defoci to false.
if(_adf_average_defoci && _probe_num_defoci == 1)
_adf_average_defoci = false;
// when defoci are averaged, configurations need to be averaged as well.
if(_adf_average_defoci)
_adf_average_configurations = true;
}
{
......@@ -372,13 +352,10 @@ void Params::readParamsFromNCFile(const std::string & path) {
_cbed_average_defoci = gg.is("average_defoci");
_cbed_save_every_n_slices = gg.att<unsigned int>("save_slices_every");
// when we calculate a single defocus only, set average_defoci to false.
if(_cbed_average_defoci && _probe_num_defoci == 1)
_cbed_average_defoci = false;
if(!_fp_enabled && _number_configurations > 1) {
_number_configurations = 1;
}
// when defoci are averaged, configurations need to be averaged as well.
if(_cbed_average_defoci)
_cbed_average_configurations = true;
}
{
......
......@@ -35,40 +35,6 @@
namespace stemsalabim {
class ParamInterface {
public:
ParamInterface(std::string name, std::string group, std::string description)
: _name(std::move(name))
, _group(std::move(group))
, _description(std::move(description)) {}
const std::string &name() const {
return _name;
}
const std::string &group() const {
return _group;
}
const std::string &description() const {
return _description;
}
private:
std::string _name{""};
std::string _group{""};
std::string _description{""};
};
template<typename T>
class Param : public ParamInterface {
public:
private:
T _val;
};
/*!
* A singleton class containing all simulation parameters, which are collected from command line
* arguments and the input parameter file. In addition, it generates (if required) a random seed
......@@ -90,10 +56,16 @@ namespace stemsalabim {
*/
void initFromCLI(int argc, const char **argv);
/*!
* Make the Params class know the cell...
*/
void setCell(const std::shared_ptr<atomic::Cell> &cell) {
_cell = cell;
}
/*!
* Access to the cell associated with params class.
*/
std::shared_ptr<atomic::Cell> cell() const {
return _cell;
}
......@@ -426,7 +398,7 @@ namespace stemsalabim {
* 1 - linear interval (default)
* > 1 - adaptive interval (smaller angles -> finer sampling)
*/
float adfDetectorIntervalExponent() const {
double adfDetectorIntervalExponent() const {
return _adf_detector_interval_exponent;
}
......@@ -437,6 +409,21 @@ namespace stemsalabim {
return _adf_average_configurations;
}
/*!
* When some fixed grid size is given, return true
*/
bool isFixedGrid() const {
return _nkx > 0 && _nky > 0;
}
unsigned int fixedGridX() const {
return _nkx;
}
unsigned int fixedGridY() const {
return _nky;
}
/*!
* Return whether different defoci simulations are averaged in the output file.
*/
......@@ -537,7 +524,7 @@ namespace stemsalabim {
std::string _param_file{""};
private:
Params();
Params() = default;
std::string _command_line_arguments{""};
......@@ -613,7 +600,8 @@ namespace stemsalabim {
std::shared_ptr<atomic::Cell> _cell;
std::vector<std::shared_ptr<ParamInterface>> _params;
unsigned int _nkx{0};
unsigned int _nky{0};
public:
Params(Params const &) = delete;
......
......@@ -314,7 +314,7 @@ void Simulation::calculatePixel(ScanPoint &point, const double defocus) {
for(unsigned int iy = 0; iy < _gridman->samplingY(); iy++) {
auto intens = (float) pow(abs(wave(ix, iy)), 2);
cx += intens * _gridman->kx(ix);
cy += intens * _gridman->kx(iy);
cy += intens * _gridman->ky(iy);
}
}
cx /= total_intensity;
......
......@@ -110,8 +110,10 @@ int main(int argc, const char **argv) {
p.setParamsFileName(p.outputFilename());
p.readParamsFromNCFile(p.outputFilename());
p.setCell(IO::initCrystalFromNCFile(p.outputFilename()));
if(mpi_env.isMaster()) {
p.readParamsFromNCFile(p.outputFilename());
p.setCell(IO::initCrystalFromNCFile(p.outputFilename()));
}
if(mpi_env.isMpi())
p.broadcast(mpi::Environment::MASTER);
......
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