-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3774 from PDoakORNL/mccoords_abstraction
Monte Carlo Coords Abstraction
- Loading branch information
Showing
7 changed files
with
242 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
// See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2022 developers. | ||
// | ||
// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
// | ||
// File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "MCCoords.hpp" | ||
|
||
namespace qmcplusplus | ||
{ | ||
template<CoordsType MCT> | ||
void MCCoords<MCT>::resize(const std::size_t size) | ||
{ | ||
positions.resize(size); | ||
} | ||
|
||
template struct MCCoords<CoordsType::POS>; | ||
template struct MCCoords<CoordsType::POS_SPIN>; | ||
} // namespace qmcplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
// See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2022 developers. | ||
// | ||
// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
// | ||
// File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef QMCPLUSPLUS_MCCOORDS_HPP | ||
#define QMCPLUSPLUS_MCCOORDS_HPP | ||
|
||
#include "Configuration.h" | ||
#include "type_traits/complex_help.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace qmcplusplus | ||
{ | ||
|
||
enum class CoordsType | ||
{ | ||
POS, | ||
POS_SPIN | ||
}; | ||
|
||
template<CoordsType MCT = CoordsType::POS> | ||
struct MCCoords | ||
{ | ||
// This cleans up some other code. | ||
void resize(const std::size_t size); | ||
std::vector<QMCTraits::PosType> positions; | ||
}; | ||
|
||
template<> | ||
struct MCCoords<CoordsType::POS_SPIN> | ||
{ | ||
// This cleans up some other code. | ||
void resize(const std::size_t size) | ||
{ | ||
positions.resize(size); | ||
spins.resize(size); | ||
} | ||
std::vector<QMCTraits::PosType> positions; | ||
std::vector<QMCTraits::FullPrecRealType> spins; | ||
}; | ||
|
||
/** Object to encapsulate appropriate tau derived values | ||
* for a particular MCCoords specialization | ||
*/ | ||
template<typename Real, CoordsType CT = CoordsType::POS> | ||
struct Taus | ||
{ | ||
Real tauovermass; | ||
Real oneover2tau; | ||
Real sqrttau; | ||
Taus(Real tau, Real grp_inv_mass) | ||
{ | ||
tauovermass = tau * grp_inv_mass; | ||
oneover2tau = 0.5 / (tauovermass); | ||
sqrttau = std::sqrt(tauovermass); | ||
} | ||
}; | ||
|
||
template<typename Real> | ||
struct Taus<Real, CoordsType::POS_SPIN> : public Taus<Real, CoordsType::POS> | ||
{ | ||
using Base = Taus<Real, CoordsType::POS>; | ||
Real spin_tauovermass; | ||
Real spin_oneover2tau; | ||
Real spin_sqrttau; | ||
Taus(Real tau, Real grp_inv_mass, Real spin_mass) : Base(tau, grp_inv_mass) | ||
{ | ||
spin_tauovermass = Base::tauovermass / spin_mass; | ||
spin_oneover2tau = 0.5 / (spin_tauovermass); | ||
spin_sqrttau = std::sqrt(spin_tauovermass); | ||
} | ||
}; | ||
|
||
/** Factory function for Taus based on MCCoordsTypes | ||
* Note as in previous code value of tau derived values is not full precision. | ||
*/ | ||
template<CoordsType CT, typename... ARGS> | ||
auto makeTaus(MCCoords<CT>& mc_coords, const ARGS&... args) | ||
{ | ||
return Taus<QMCTraits::RealType, CT>(args...); | ||
} | ||
|
||
extern template struct MCCoords<CoordsType::POS>; | ||
extern template struct MCCoords<CoordsType::POS_SPIN>; | ||
} // namespace qmcplusplus | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
// See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2022 QMCPACK developers. | ||
// | ||
// File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
// | ||
// File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "catch.hpp" | ||
#include "MCCoords.hpp" | ||
#include "Utilities/StlPrettyPrint.hpp" | ||
#include "Utilities/StdRandom.h" | ||
#include "ParticleBase/RandomSeqGenerator.h" | ||
|
||
namespace qmcplusplus | ||
{ | ||
|
||
TEST_CASE("MCCoords", "[Particle]") | ||
{ | ||
{ | ||
constexpr auto mct = CoordsType::POS; | ||
auto mc_coords = MCCoords<mct>(); | ||
REQUIRE(mc_coords.positions.size() == 0); | ||
mc_coords.resize(3); | ||
REQUIRE(mc_coords.positions.size() == 3); | ||
} | ||
{ | ||
constexpr auto mct = CoordsType::POS_SPIN; | ||
auto mc_coords = MCCoords<mct>(); | ||
REQUIRE(mc_coords.spins.size() == 0); | ||
mc_coords.resize(3); | ||
REQUIRE(mc_coords.positions.size() == 3); | ||
REQUIRE(mc_coords.spins.size() == 3); | ||
} | ||
} | ||
|
||
TEST_CASE("Taus", "[Particle]") | ||
{ | ||
MCCoords<CoordsType::POS> mc_coords_rs; | ||
auto tau = 1.0; | ||
auto invmass = 0.2; | ||
auto taus_rs{makeTaus(mc_coords_rs, tau, invmass)}; | ||
CHECK(Approx(taus_rs.tauovermass) == 0.2); | ||
CHECK(Approx(taus_rs.oneover2tau) == 2.5); | ||
CHECK(Approx(taus_rs.sqrttau) == 0.447213595499957927703605); | ||
MCCoords<CoordsType::POS_SPIN> mc_coords_rsspins; | ||
auto spin_mass = 0.5; | ||
auto taus_rsspins = makeTaus(mc_coords_rsspins, tau, invmass, spin_mass); | ||
CHECK(Approx(taus_rsspins.spin_tauovermass) == 0.4); | ||
CHECK(Approx(taus_rsspins.spin_oneover2tau) == 1.25); | ||
CHECK(Approx(taus_rsspins.spin_sqrttau) == 0.632455532033675882352952); | ||
} | ||
|
||
} // namespace qmcplusplus |