1414 * limitations under the License.
1515 */
1616
17+ #include " libxc/libxc.hpp"
1718#include " xc.hpp"
1819#include < simde/integration_grids/collocation_matrix.hpp>
1920
@@ -25,38 +26,6 @@ DensityCollocationMatrix
2526-----------------
2627)" ;
2728
28- struct Kernel {
29- using buffer_base = tensorwrapper::buffer::BufferBase;
30-
31- template <typename FloatType>
32- auto run (const buffer_base& aos_on_grid, const buffer_base& X,
33- parallelzone::runtime::RuntimeView& rv) {
34- tensorwrapper::allocator::Eigen<FloatType> allocator (rv);
35-
36- const auto & eigen_aos_on_grid = allocator.rebind (aos_on_grid);
37- const auto * paos_on_grid = eigen_aos_on_grid.get_immutable_data ();
38- const auto & eigen_X = allocator.rebind (X);
39- const auto * pX = eigen_X.get_immutable_data ();
40- const auto & shape_X = eigen_X.layout ().shape ().as_smooth ();
41- auto n_aos = shape_X.extent (0 );
42- auto n_grid = shape_X.extent (1 );
43-
44- tensorwrapper::shape::Smooth rv_shape{n_grid};
45- tensorwrapper::layout::Physical rv_layout (rv_shape);
46- auto rv_buffer = allocator.allocate (rv_layout);
47-
48- // AOs on rows, grid points on columns
49- for (std::size_t grid_i = 0 ; grid_i < n_grid; ++grid_i) {
50- FloatType sum = 0 ;
51- for (std::size_t ao_i = 0 ; ao_i < n_aos; ++ao_i) {
52- const auto idx = ao_i * n_grid + grid_i;
53- sum += paos_on_grid[idx] * pX[idx];
54- }
55- rv_buffer->set_elem (std::vector{grid_i}, sum);
56- }
57- return simde::type::tensor (rv_shape, std::move (rv_buffer));
58- }
59- };
6029} // namespace
6130
6231using pt = simde::EDensityCollocationMatrix;
@@ -78,16 +47,11 @@ MODULE_RUN(Density2Grid) {
7847 auto & ao2grid_mod = submods.at (" AOs on a grid" );
7948 auto aos_on_grid = ao2grid_mod.run_as <ao2grid_pt>(grid, aos);
8049
81- simde::type::tensor X;
82- X (" m,i" ) = rho (" m,n" ) * aos_on_grid (" n,i" );
50+ simde::type::tensor X, rho2;
51+ rho2 (" m,n" ) = rho (" m,n" ) * 2.0 ; // Assumes restricted orbitals
52+ X (" m,i" ) = rho2 (" m,n" ) * aos_on_grid (" n,i" );
8353
84- using tensorwrapper::utilities::floating_point_dispatch;
85- Kernel k;
86- auto & runtime = get_runtime ();
87- const auto & aos_buffer = aos_on_grid.buffer ();
88- const auto & X_buffer = X.buffer ();
89- auto rho_on_grid =
90- floating_point_dispatch (k, aos_buffer, X_buffer, runtime);
54+ auto rho_on_grid = libxc::batched_dot (aos_on_grid, X);
9155
9256 auto rv = results ();
9357 return pt::wrap_results (rv, std::move (rho_on_grid));
0 commit comments