LCOV - code coverage report
Current view: top level - pairinteraction - Interface.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 48 56.2 %
Date: 2024-04-29 00:41:50 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Sebastian Weber, Henri Menke. All rights reserved.
       3             :  *
       4             :  * This file is part of the pairinteraction library.
       5             :  *
       6             :  * The pairinteraction library is free software: you can redistribute it and/or modify
       7             :  * it under the terms of the GNU Lesser General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * The pairinteraction library is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public License
      17             :  * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "Interface.hpp"
      21             : #include "ConfParser.hpp"
      22             : #include "HamiltonianOne.hpp"
      23             : #include "HamiltonianTwo.hpp"
      24             : #include "filesystem.hpp"
      25             : 
      26             : #include <fmt/format.h>
      27             : 
      28             : #include <iostream>
      29             : #include <locale>
      30             : #include <memory>
      31             : 
      32             : /*
      33             : ///////////////////// TODOs /////////////////////
      34             : 
      35             : * parallelize construction of Hamiltonian
      36             : * construct only one half of symmetric matrices
      37             : * check why very small Bz fields (e.g. 1e-12) leads to a large basis -> numerical error?
      38             : 
      39             : */
      40             : 
      41             : template <typename Scalar>
      42           3 : int compute(const std::string &config_name, const std::string &output_name) {
      43           3 :     std::cout << std::unitbuf;
      44             : 
      45           3 :     Eigen::setNbThreads(1); // TODO set it to setNbThreads(0) when Eigen's multithreading is needed
      46             : 
      47           6 :     fs::path path_config = fs::absolute(config_name);
      48           6 :     fs::path path_cache = fs::absolute(output_name);
      49             : 
      50             :     // === Load configuration ===
      51           6 :     Configuration config;
      52           3 :     config.load_from_json(path_config.string());
      53             : 
      54          12 :     bool existAtom1 = (config.count("species1") != 0u) && (config.count("n1") != 0u) &&
      55          15 :         (config.count("l1") != 0u) && (config.count("j1") != 0u) && (config.count("m1") != 0u);
      56          12 :     bool existAtom2 = (config.count("species2") != 0u) && (config.count("n2") != 0u) &&
      57          15 :         (config.count("l2") != 0u) && (config.count("j2") != 0u) && (config.count("m2") != 0u);
      58             : 
      59             :     // === Solve the system ===
      60           3 :     bool combined = config["samebasis"].str() == "true";
      61             : 
      62           3 :     if (combined) {
      63           3 :         if (config["species1"].str() != config["species2"].str()) {
      64             :             std::cout
      65           0 :                 << "species1 and species2 has to be the same in order to use the same basis set."
      66           0 :                 << std::endl;
      67           0 :             return 1;
      68             :         }
      69           3 :         std::shared_ptr<HamiltonianOne<Scalar>> hamiltonian_one;
      70           3 :         if (existAtom1 && existAtom2) {
      71           6 :             std::cout << fmt::format(">>TYP{:7d}", 3) << std::endl;
      72           3 :             auto basisnames_one = std::make_shared<BasisnamesOne>(BasisnamesOne::fromBoth(config));
      73           3 :             hamiltonian_one =
      74           6 :                 std::make_shared<HamiltonianOne<Scalar>>(config, path_cache, basisnames_one);
      75             :         }
      76           3 :         std::shared_ptr<HamiltonianTwo<Scalar>> hamiltonian_two;
      77           6 :         if (existAtom1 && existAtom2 && (config.count("minR") != 0u)) {
      78           4 :             std::cout << fmt::format(">>TYP{:7d}", 2) << std::endl;
      79           2 :             hamiltonian_two =
      80           4 :                 std::make_shared<HamiltonianTwo<Scalar>>(config, path_cache, hamiltonian_one);
      81             :         }
      82             :     } else {
      83           0 :         std::shared_ptr<HamiltonianOne<Scalar>> hamiltonian_one1;
      84           0 :         if (existAtom1) {
      85           0 :             std::cout << fmt::format(">>TYP{:7d}", 0) << std::endl;
      86           0 :             auto basisnames_one1 =
      87           0 :                 std::make_shared<BasisnamesOne>(BasisnamesOne::fromFirst(config));
      88           0 :             hamiltonian_one1 =
      89           0 :                 std::make_shared<HamiltonianOne<Scalar>>(config, path_cache, basisnames_one1);
      90             :         }
      91           0 :         std::shared_ptr<HamiltonianOne<Scalar>> hamiltonian_one2;
      92           0 :         if (existAtom2) {
      93           0 :             std::cout << fmt::format(">>TYP{:7d}", 1) << std::endl;
      94           0 :             auto basisnames_one2 =
      95           0 :                 std::make_shared<BasisnamesOne>(BasisnamesOne::fromSecond(config));
      96           0 :             hamiltonian_one2 =
      97           0 :                 std::make_shared<HamiltonianOne<Scalar>>(config, path_cache, basisnames_one2);
      98             :         }
      99           0 :         std::shared_ptr<HamiltonianTwo<Scalar>> hamiltonian_two;
     100           0 :         if (existAtom1 && existAtom2 && (config.count("minR") != 0u)) {
     101           0 :             std::cout << fmt::format(">>TYP{:7d}", 2) << std::endl;
     102           0 :             hamiltonian_two = std::make_shared<HamiltonianTwo<Scalar>>(
     103             :                 config, path_cache, hamiltonian_one1, hamiltonian_one2);
     104             :         }
     105             :     }
     106             : 
     107             :     // === Communicate that everything has finished ===
     108           3 :     std::cout << ">>END" << std::endl;
     109             : 
     110           3 :     return 0;
     111             : }
     112             : 
     113             : template int compute<std::complex<double>>(std::string const &config_name,
     114             :                                            std::string const &output_name);
     115             : template int compute<double>(std::string const &config_name, std::string const &output_name);

Generated by: LCOV version 1.14