From 4a2d865282a8ab51e00fd8b0b1157ef01a94ea4f Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 18 Aug 2021 16:57:29 +0200 Subject: [PATCH] add the option to dump the nonlocal field values for the ASlibs via the programm dump_nonlocal_field. --- src/external/Nonlocal/CMakeLists.txt | 2 + src/external/Nonlocal/cmake/dnlf_config.h.in | 4 + src/external/Nonlocal/prog/CMakeLists.txt | 30 ++ .../Nonlocal/prog/dump_nonlocal_field.cpp | 286 ++++++++++++++++++ 4 files changed, 322 insertions(+) create mode 100644 src/external/Nonlocal/cmake/dnlf_config.h.in create mode 100644 src/external/Nonlocal/prog/CMakeLists.txt create mode 100644 src/external/Nonlocal/prog/dump_nonlocal_field.cpp diff --git a/src/external/Nonlocal/CMakeLists.txt b/src/external/Nonlocal/CMakeLists.txt index d35d5c41..fa906bdd 100644 --- a/src/external/Nonlocal/CMakeLists.txt +++ b/src/external/Nonlocal/CMakeLists.txt @@ -1,5 +1,7 @@ # - Nonlocal library ---------------------------------------------------------- +add_subdirectory(prog) + #--- generate necessary dictionaries ------------------------------------------ set(MUSRFIT_INC ${CMAKE_SOURCE_DIR}/src/include) set(NONLOCAL_INC ${CMAKE_SOURCE_DIR}/src/external/Nonlocal) diff --git a/src/external/Nonlocal/cmake/dnlf_config.h.in b/src/external/Nonlocal/cmake/dnlf_config.h.in new file mode 100644 index 00000000..04f16c07 --- /dev/null +++ b/src/external/Nonlocal/cmake/dnlf_config.h.in @@ -0,0 +1,4 @@ +// dnlf_config.h + +#define PROJECT_VERSION "@PROJECT_VERSION@" + diff --git a/src/external/Nonlocal/prog/CMakeLists.txt b/src/external/Nonlocal/prog/CMakeLists.txt new file mode 100644 index 00000000..ab958ab9 --- /dev/null +++ b/src/external/Nonlocal/prog/CMakeLists.txt @@ -0,0 +1,30 @@ +#--- dump_nonlocal_field ------------------------------------------------------ + +project(dump_nonlocal_field VERSION 1.0.0 LANGUAGES C CXX) + +#--- feed dnlf_config.h ----------------------------------------- +set(HAVE_DNLF_CONFIG_H 1 CACHE INTERNAL "dnlf_config.h is available") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/dnlf_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/dnlf_config.h) + +add_executable(dump_nonlocal_field ${GIT_REV_H} dump_nonlocal_field.cpp) +target_compile_options(dump_nonlocal_field BEFORE PRIVATE "-DHAVE_CONFIG_H" "-DHAVE_DNLF_CONFIG_H" "${HAVE_GIT_REV_H}") +target_include_directories(dump_nonlocal_field + BEFORE PRIVATE + $ + $ + $ + $ + $ +) +target_link_libraries(dump_nonlocal_field ${ROOT_LIBRARIES} ${MUSRFIT_LIBS} PNL_PippardFitter) + +#--- installation info -------------------------------------------------------- +install( + TARGETS + dump_nonlocal_field + RUNTIME DESTINATION + bin +) + + + diff --git a/src/external/Nonlocal/prog/dump_nonlocal_field.cpp b/src/external/Nonlocal/prog/dump_nonlocal_field.cpp new file mode 100644 index 00000000..4efd46bc --- /dev/null +++ b/src/external/Nonlocal/prog/dump_nonlocal_field.cpp @@ -0,0 +1,286 @@ +/*************************************************************************** + + dump_nonlocal_field.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2009-2021 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +#include "PNL_PippardFitter.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_DNLF_CONFIG_H +#include "dnlf_config.h" +#endif +#ifdef HAVE_GIT_REV_H +#include "git-revision.h" +#endif + +void dnlf_syntax() +{ + std::cout << std::endl; + std::cout << "usage: dump_nonlocal_field [ --out [--step ] | --version | --help]" << std::endl; + std::cout << " : nonlocal msr-file name." << std::endl; + std::cout << " --out : ascii field dump output file name." << std::endl; + std::cout << " --step : this optional parameters allows to define the z-value step size in (nm)." << std::endl; + std::cout << " --version : dumps the version" << std::endl; + std::cout << " --help : will dump this help" << std::endl; + std::cout << std::endl << std::endl; +} + +bool dnlf_read_msr(const std::string fln, std::vector ¶m) +{ + std::ifstream fin(fln.c_str(), std::ifstream::in); + if (!fin.is_open()) { + std::cerr << std::endl; + std::cerr << "**ERROR** couldn't open msr-file: " << fln << std::endl; + std::cerr << std::endl; + return false; + } + + std::vector msrData; + std::string line; + while (fin.good()) { + std::getline(fin, line); + msrData.push_back(line); + } + + fin.close(); + + // find userFcn line + line = ""; + for (int i=0; i tok; + boost::split(tok, line, boost::is_any_of(" \t"), boost::token_compress_on); + std::vector paramIdx; + int ival; + for (int i=0; i paramMap; + double dval; + for (int i=0; isecond; + else + dval = 0.0; + param.push_back(dval); + } + + return true; +} + +int main(int argc, char* argv[]) +{ + std::string msrFileName(""); + std::string outFileName(""); + double step(0.0); + bool show_syntax(false); + + if (argc == 1) { + dnlf_syntax(); + return 0; + } + + for (int i=0; i" << std::endl; + show_syntax = true; + break; + } + } else if (!strcmp(argv[i], "--step")) { + if (i < argc-1) { + try { + step = std::stod(argv[i+1]); + } + catch(std::exception& e) { + std::cout << "dump_nonlocal_field: **ERROR** '" << argv[i+1] << "' seems not to be a double." << std::endl; + show_syntax = true; + break; + } + i++; + } else { + std::cerr << std::endl << "dump_nonlocal_field: **ERROR** found option --step without " << std::endl; + show_syntax = true; + break; + } + } + } + + if (show_syntax) { + dnlf_syntax(); + return -1; + } + + std::vector param; + if (!dnlf_read_msr(msrFileName, param)) { + return -2; + } + + + // calculate field and write it to file + PNL_PippardFitterGlobal pip; + pip.CalculateField(param); + + std::ofstream fout(outFileName.c_str(), std::ofstream::out); + if (!fout.is_open()) { + std::cout << std::endl; + std::cerr << "**ERROR** can not write to file '" << outFileName << "'." << std::endl; + std::cout << std::endl; + return -3; + } + // write header + fout << "% z (nm), field (G)" << std::endl; + + // write data + double z=0.0; + if (step == 0.0) + step = 0.1; + double prevField=0.0, field=0.0; + bool done(false); + double deadLayer = param[8]; + double b0 = param[6]; + do { + if (z < deadLayer) { + fout << z << ", " << b0 << std::endl; + } else { + field = pip.GetMagneticField(z-deadLayer); + fout << z << ", " << b0*field << std::endl; + if (fabs(prevField-field) < 1.0e-10) + done = true; + prevField = field; + } + z += step; + } while (!done); + + fout.close(); + + return 0; +}