1#include "EnergyAnalysis.h"
9 template<typename TDataType>
10 EnergyAnalysis<TDataType>::EnergyAnalysis()
15 template<typename TDataType>
16 EnergyAnalysis<TDataType>::~EnergyAnalysis() {
22 template <typename Real, typename Coord>
23 __global__ void EAM_EnergyAnalysis(
30 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
31 if (pId >= posArr.size()) return;
33 Energy[pId] = 0.5 * mass * velArr[pId].norm() * velArr[pId].norm();
37 template <typename Real, typename Coord>
38 __global__ void EAM_NeighborCount(
41 DArrayList<int> neighbors,
45 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
46 if (pId >= pos.size()) return;
48 List<int>& list_i = neighbors[pId];
49 count[pId] = (Real)(list_i.size());
52 template<typename TDataType>
53 void EnergyAnalysis<TDataType>::constrain() {
57 this->initializeImpl();
61 int num = this->inPosition()->getData().size();
63 if (m_Energy.size() != num)
67 m_reduce = Reduction<float>::Create(num);
68 m_arithmetic = Arithmetic<float>::Create(num);
69 m_reduce_real = Reduction<float>::Create(num);
73 cuExecute(num, EAM_EnergyAnalysis,
75 this->inPosition()->getData(),
76 this->inVelocity()->getData(),
80 cuExecute(num, EAM_NeighborCount,
82 this->inPosition()->getData(),
83 this->inNeighborIds()->getData(),
87 Real total_energy = m_arithmetic->Dot(m_Energy, m_Energy);
88 auto average_count = m_reduce_real->average(m_Count.begin(), m_Count.size());
89 std::cout << "*** average_count :" << average_count << std::endl;
92 *m_output << average_count << std::endl;
101 template<typename TDataType>
102 bool EnergyAnalysis<TDataType>::initializeImpl() {
103 std::cout << "EnergyAnalysis initializeImpl " << std::endl;
105 std::string filename = mOutpuPath + mOutputPrefix + std::string(".txt");
107 m_output.reset(new std::fstream(filename.c_str(), std::ios::out));
114 template<typename TDataType>
115 void EnergyAnalysis<TDataType>::setNamePrefix(std::string prefix)
117 mOutputPrefix = prefix;
120 template<typename TDataType>
121 void EnergyAnalysis<TDataType>::setOutputPath(std::string path)
128 DEFINE_CLASS(EnergyAnalysis);