SIRIUS 7.5.0
Electronic structure library and applications
simulation_context.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2019 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file simulation_context.hpp
21 *
22 * \brief Contains definition and implementation of Simulation_context class.
23 */
24
25#ifndef __SIMULATION_CONTEXT_HPP__
26#define __SIMULATION_CONTEXT_HPP__
27
28#include <algorithm>
29#include <memory>
30#include <spla/spla.hpp>
31
33#include "core/fft/fft.hpp"
34#include "core/mpi/mpi_grid.hpp"
35#include "core/acc/acc.hpp"
36#include "core/env/env.hpp"
37#include "core/time_tools.hpp"
38#include "core/system_tools.hpp"
41#include "symmetry/rotation.hpp"
43
44#ifdef SIRIUS_GPU
45extern "C" void generate_phase_factors_gpu(int num_gvec_loc__, int num_atoms__, int const* gvec__,
46 double const* atom_pos__, std::complex<double>* phase_factors__);
47#endif
48
49namespace sirius {
50
51template <typename OUT>
52void
53print_memory_usage(OUT&& out__, std::string file_and_line__ = "")
54{
55 if (!env::print_memory_usage()) {
56 return;
57 }
58
59 auto res = get_proc_status();
60
61 std::stringstream s;
62 s << "rank" << std::setfill('0') << std::setw(4) << mpi::Communicator::world().rank();
63 out__ << "[" << s.str() << " at " << file_and_line__ << "] "
64 << "VmHWM: " << (res.VmHWM >> 20) << " Mb, "
65 << "VmRSS: " << (res.VmRSS >> 20) << " Mb";
66
67 if (acc::num_devices() > 0) {
68 size_t gpu_mem = acc::get_free_mem();
69 out__ << ", GPU: " << (gpu_mem >> 20) << " Mb";
70 }
71 out__ << std::endl;
72
73 std::vector<std::string> labels = {"host"};
74 std::vector<sddk::memory_pool*> mp = {&get_memory_pool(sddk::memory_t::host)};
75
76 int np{1};
77 if (acc::num_devices() > 0) {
78 labels.push_back("host pinned");
79 labels.push_back("device");
80 mp.push_back(&get_memory_pool(sddk::memory_t::host_pinned));
81 mp.push_back(&get_memory_pool(sddk::memory_t::device));
82 np = 3;
83 }
84
85 for (int i = 0; i < np; i++) {
86 out__ << "[mem.pool] " << labels[i] << ": total capacity: " << (mp[i]->total_size() >> 20) << " Mb, "
87 << "free: " << (mp[i]->free_size() >> 20) << " Mb, "
88 << "num.blocks: " << mp[i]->num_blocks() << std::endl;
89 }
90}
91
92/// Store all callback functions in one place.
94{
95 /// Callback function provided by the host code to compute radial integrals of beta projectors.
96 std::function<void(int, double, double*, int)> beta_ri_{nullptr};
97
98 /// Callback function provided by the host code to compute radial integrals of beta projectors with
99 /// derivatives of spherical Bessel functions.
100 std::function<void(int, double, double*, int)> beta_ri_djl_{nullptr};
101
102 /// Callback function provided by the host code to compute radial integrals of augmentation operator.
103 std::function<void(int, double, double*, int, int)> aug_ri_{nullptr};
104
105 /// Callback function provided by the host code to compute radial integrals of augmentation operator with
106 /// derivatives of spherical Bessel functions.
107 std::function<void(int, double, double*, int, int)> aug_ri_djl_{nullptr};
108
109 /// Callback function provided by the host code to compute radial integrals of pseudo core charge density.
110 std::function<void(int, int, double*, double*)> rhoc_ri_{nullptr};
111
112 /// Callback function provided by the host code to compute radial integrals of pseudo core charge density with
113 /// derivatives of spherical Bessel functions.
114 std::function<void(int, int, double*, double*)> rhoc_ri_djl_{nullptr};
115
116 /// Callback function provided by the host code to compute radial integrals of pseudo charge density.
117 std::function<void(int, int, double*, double*)> ps_rho_ri_{nullptr};
118
119 /// Callback function provided by the host code to compute radial integrals of pseudo atomic wave-functions.
120 std::function<void(int, double, double*, int)> ps_atomic_wf_ri_{nullptr};
121
122 /// Callback function provided by the host code to compute radial integrals of pseudo atomic wave-functions with
123 /// derivatives of spherical Bessel functions.
124 std::function<void(int, double, double*, int)> ps_atomic_wf_ri_djl_{nullptr};
125
126 /// Callback function to compute radial integrals of local potential.
127 std::function<void(int, int, double*, double*)> vloc_ri_{nullptr};
128
129 /// Callback function to compute radial integrals of local potential with derivatives of spherical Bessel functions.
130 std::function<void(int, int, double*, double*)> vloc_ri_djl_{nullptr};
131
132 /// Callback function to compute band occupancies.
133 std::function<void(void)> band_occ_{nullptr};
134
135 /// Callback function to compute effective potential.
136 std::function<void(void)> veff_{nullptr};
137};
138
139/// Store all radial integrals in one place.
141{
142 /// Radial integrals of beta-projectors.
143 std::unique_ptr<Radial_integrals_beta<false>> beta_;
144
145 /// Radial integrals of beta-projectors with derivatives of spherical Bessel functions.
146 std::unique_ptr<Radial_integrals_beta<true>> beta_djl_;
147
148 /// Radial integrals of augmentation operator.
149 std::unique_ptr<Radial_integrals_aug<false>> aug_;
150
151 /// Radial integrals of augmentation operator with derivatives of spherical Bessel functions.
152 std::unique_ptr<Radial_integrals_aug<true>> aug_djl_;
153
154 /// Radial integrals of atomic wave-functions.
155 std::unique_ptr<Radial_integrals_atomic_wf<false>> ps_atomic_wf_;
156
157 /// Radial integrals of atomic wave-functions with derivatives of spherical Bessel functions.
158 std::unique_ptr<Radial_integrals_atomic_wf<true>> ps_atomic_wf_djl_;
159
160 /// Radial integrals of pseudo-core charge density.
161 std::unique_ptr<Radial_integrals_rho_core_pseudo<false>> ps_core_;
162
163 /// Radial integrals of pseudo-core charge density with derivatives of spherical Bessel functions.
164 std::unique_ptr<Radial_integrals_rho_core_pseudo<true>> ps_core_djl_;
165
166 /// Radial integrals of total pseudo-charge density.
167 std::unique_ptr<Radial_integrals_rho_pseudo> ps_rho_;
168
169 /// Radial integrals of the local part of pseudopotential.
170 std::unique_ptr<Radial_integrals_vloc<false>> vloc_;
171
172 /// Radial integrals of the local part of pseudopotential with derivatives of spherical Bessel functions.
173 std::unique_ptr<Radial_integrals_vloc<true>> vloc_djl_;
174};
175
176/// Simulation context is a set of parameters and objects describing a single simulation.
177/** The order of initialization of the simulation context is the following: first, the default parameter
178 values are set in the constructor, then (optionally) import() method is called and the parameters are
179 overwritten with the those from the input file, and finally, the user sets the values with setter metods.
180 Then the unit cell can be populated and the context can be initialized.
181 */
183{
184 private:
185 /// Communicator for this simulation.
187
188 mpi::Communicator comm_k_;
189 mpi::Communicator comm_band_;
190
191 /// Auxiliary communicator for the coarse-grid FFT transformation.
193
194 /// Unit cell of the simulation.
195 std::unique_ptr<Unit_cell> unit_cell_;
196
197 /// MPI grid for this simulation.
198 std::unique_ptr<mpi::Grid> mpi_grid_;
199
200 /// 2D BLACS grid for distributed linear algebra operations.
201 std::unique_ptr<la::BLACS_grid> blacs_grid_;
202
203 /// Grid descriptor for the fine-grained FFT transform.
205
206 /// Fine-grained FFT for density and potential.
207 /** This is the FFT driver to transform periodic functions such as density and potential on the fine-grained
208 * FFT grid. The transformation is parallel. */
209 std::unique_ptr<spfft::Transform> spfft_transform_;
210 std::unique_ptr<spfft::Grid> spfft_grid_;
211#if defined(SIRIUS_USE_FP32)
212 std::unique_ptr<spfft::TransformFloat> spfft_transform_float_;
213 std::unique_ptr<spfft::GridFloat> spfft_grid_float_;
214#endif
215
216 /// Grid descriptor for the coarse-grained FFT transform.
218
219 /// Coarse-grained FFT for application of local potential and density summation.
220 std::unique_ptr<spfft::Transform> spfft_transform_coarse_;
221 std::unique_ptr<spfft::Grid> spfft_grid_coarse_;
222#if defined(SIRIUS_USE_FP32)
223 std::unique_ptr<spfft::TransformFloat> spfft_transform_coarse_float_;
224 std::unique_ptr<spfft::GridFloat> spfft_grid_coarse_float_;
225#endif
226
227 /// G-vectors within the Gmax cutoff.
228 std::shared_ptr<fft::Gvec> gvec_;
229
230 std::shared_ptr<fft::Gvec_fft> gvec_fft_;
231
232 /// G-vectors within the 2 * |Gmax^{WF}| cutoff.
233 std::shared_ptr<fft::Gvec> gvec_coarse_;
234
235 std::shared_ptr<fft::Gvec_fft> gvec_coarse_fft_;
236
237 std::shared_ptr<fft::Gvec_shells> remap_gvec_;
238
239 /// Creation time of the parameters.
240 timeval start_time_;
241
242 /// A tag string based on the the starting time.
243 std::string start_time_tag_;
244
245 /// 1D phase factors for each atom coordinate and G-vector index.
247
248 /// 1D phase factors of the symmetry operations.
250
251 /// Phase factors for atom types.
253
254 /// Lattice coordinats of G-vectors in a GPU-friendly ordering.
256
257 /// Volume of the initial unit cell.
258 /** This is needed to estimate the new cutoff for radial integrals. */
259 double omega0_;
260
261 /// Initial lattice vectors.
263
264 /// List of real-space point indices for each of the atoms.
265 std::vector<std::vector<std::pair<int, double>>> atoms_to_grid_idx_;
266
267 /// Step function in real-space and reciprocal domains.
269
270 /// Augmentation operator for each atom type.
271 /** The augmentation operator is used by Density, Potential, Q_operator, and Non_local_functor classes. */
272 std::vector<std::unique_ptr<Augmentation_operator>> augmentation_op_;
273
274 /// Standard eigen-value problem solver.
275 std::unique_ptr<la::Eigensolver> std_evp_solver_;
276
277 /// Generalized eigen-value problem solver.
278 std::unique_ptr<la::Eigensolver> gen_evp_solver_;
279
280 /// Type of host memory (pagable or page-locked) for the arrays that participate in host-to-device memory copy.
281 sddk::memory_t host_memory_t_{sddk::memory_t::none};
282
283 /// SPLA library context.
284 std::shared_ptr<::spla::Context> spla_ctx_{new ::spla::Context{SPLA_PU_HOST}};
285
286 std::ostream* output_stream_{nullptr};
287 std::ofstream output_file_stream_;
288
289 /// External pointers to periodic functions.
290 std::map<std::string, periodic_function_ptr_t<double>> pf_ext_ptr;
291
292 /// Stores all callback functions.
294
295 /// Stores all radial integrals.
297
298 mutable double evp_work_count_{0};
299 mutable int num_loc_op_applied_{0};
300 /// Total number of iterative solver steps.
301 mutable int num_itsol_steps_{0};
302
303 /// True if the context is already initialized.
304 bool initialized_{false};
305
306 /// Initialize FFT coarse and fine grids.
307 void init_fft_grid();
308
309 /// Initialize communicators.
310 void init_comm();
311
312 /// Find a list of real-space grid points around each atom.
313 void init_atoms_to_grid_idx(double R__);
314
315 /// Common init function called by all constructors.
317 {
318 gettimeofday(&start_time_, NULL);
319 start_time_tag_ = timestamp("%Y%m%d_%H%M%S");
320
321 unit_cell_ = std::make_unique<Unit_cell>(*this, comm_);
322
323 this->import(env::config_file());
324 }
325
326 /* copy constructor is forbidden */
327 Simulation_context(Simulation_context const&) = delete;
328
329 public:
330 /// Create an empty simulation context with an explicit communicator.
331 Simulation_context(mpi::Communicator const& comm__ = mpi::Communicator::world())
332 : comm_(comm__)
333 {
334 init_common();
335 }
336
337 Simulation_context(mpi::Communicator const& comm__, mpi::Communicator const& comm_k__, mpi::Communicator const& comm_band__)
338 : comm_(comm__)
339 , comm_k_(comm_k__)
340 , comm_band_(comm_band__)
341 {
342 init_common();
343 }
344
345 /// Create a simulation context with world communicator and load parameters from JSON string or JSON file.
346 Simulation_context(std::string const& str__)
347 : comm_(mpi::Communicator::world())
348 {
349 init_common();
350 import(str__);
351 unit_cell_->import(cfg().unit_cell());
352 }
353
354 explicit Simulation_context(nlohmann::json const& dict__)
355 : comm_(mpi::Communicator::world())
356 {
357 init_common();
358 import(dict__);
359 unit_cell_->import(cfg().unit_cell());
360 }
361
362 // /// Create a simulation context with world communicator and load parameters from JSON string or JSON file.
363 Simulation_context(std::string const& str__, mpi::Communicator const& comm__)
364 : comm_(comm__)
365 {
366 init_common();
367 import(str__);
368 unit_cell_->import(cfg().unit_cell());
369 }
370
371 /// Destructor.
373 {
374 if (!comm().is_finalized() && initialized_) {
375 print_memory_usage(this->out(), FILE_LINE);
376 }
377 }
378
379 /// Initialize the similation (can only be called once).
380 void initialize();
381
382 void print_info(std::ostream& out__) const;
383
384 /// Update context after setting new lattice vectors or atomic coordinates.
385 void update();
386
387 auto const& atoms_to_grid_idx_map(int ia__) const
388 {
389 return atoms_to_grid_idx_[ia__];
390 };
391
392 auto& unit_cell()
393 {
394 return *unit_cell_;
395 }
396
397 /// Return const reference to unit cell object.
398 auto const& unit_cell() const
399 {
400 return *unit_cell_;
401 }
402
403 /// Return const reference to Gvec object.
404 auto const& gvec() const
405 {
406 return *gvec_;
407 }
408
409 /// Return shared pointer to Gvec object.
410 auto gvec_sptr() const
411 {
412 return gvec_;
413 }
414
415 /// Return const reference to Gvec_fft object.
416 auto const& gvec_fft() const
417 {
418 return *gvec_fft_;
419 }
420
421 /// Return shared pointer to Gvec_fft object.
422 auto gvec_fft_sptr() const
423 {
424 return gvec_fft_;
425 }
426
427 auto const& gvec_coarse() const
428 {
429 return *gvec_coarse_;
430 }
431
432 auto const& gvec_coarse_sptr() const
433 {
434 return gvec_coarse_;
435 }
436
437 auto const& gvec_coarse_fft_sptr() const
438 {
439 return gvec_coarse_fft_;
440 }
441
442 auto const& remap_gvec() const
443 {
444 return *remap_gvec_;
445 }
446
447 auto const& blacs_grid() const
448 {
449 return *blacs_grid_;
450 }
451
452 /// Total communicator of the simulation.
453 mpi::Communicator const& comm() const
454 {
455 return comm_;
456 }
457
458 /// Communicator between k-points.
459 /** This communicator is used to split k-points */
460 auto const& comm_k() const
461 {
462 return comm_k_;
463 }
464
465 /// Band parallelization communicator.
466 /** This communicator is used to parallelize the band problem. However it is not necessarily used
467 to create the BLACS grid. Diagonalization might be sequential. */
468 auto const& comm_band() const
469 {
470 return comm_band_;
471 }
472
473 /// Communicator of the dense FFT grid.
474 /** This communicator is passed to the spfft::Transform constructor. */
475 auto const& comm_fft() const
476 {
477 /* use entire communicator of the simulation */
478 return comm();
479 }
480
481 auto const& comm_ortho_fft() const
482 {
483 return mpi::Communicator::self();
484 }
485
486 /// Communicator of the coarse FFT grid.
487 /** This communicator is passed to the spfft::Transform constructor. */
488 auto const& comm_fft_coarse() const
489 {
490 if (cfg().control().fft_mode() == "serial") {
491 return mpi::Communicator::self();
492 } else {
493 return mpi_grid_->communicator(1 << 0);
494 }
495 }
496
497 /// Communicator, which is orthogonal to comm_fft_coarse within a band communicator.
498 /** This communicator is used in reshuffling the wave-functions for the FFT-friendly distribution. It will be
499 used to parallelize application of local Hamiltonian over bands. */
500 auto const& comm_band_ortho_fft_coarse() const
501 {
502 if (cfg().control().fft_mode() == "serial") {
503 return comm_band();
504 } else {
505 return mpi_grid_->communicator(1 << 1);
506 }
507 }
508
509 auto const& comm_ortho_fft_coarse() const
510 {
512 }
513
514 void create_storage_file(std::string name__) const;
515
516 inline std::string const& start_time_tag() const
517 {
518 return start_time_tag_;
519 }
520
521 inline auto& std_evp_solver()
522 {
523 return *std_evp_solver_;
524 }
525
526 inline auto const& std_evp_solver() const
527 {
528 return *std_evp_solver_;
529 }
530
531 inline auto& gen_evp_solver()
532 {
533 return *gen_evp_solver_;
534 }
535
536 inline auto const& gen_evp_solver() const
537 {
538 return *gen_evp_solver_;
539 }
540
541 inline auto phase_factors_t(int igloc__, int iat__) const
542 {
543 return phase_factors_t_(igloc__, iat__);
544 }
545
546 inline auto const& phase_factors_t() const
547 {
548 return phase_factors_t_;
549 }
550
551 /// Phase factors \f$ e^{i {\bf G} {\bf r}_{\alpha}} \f$
552 inline auto gvec_phase_factor(r3::vector<int> G__, int ia__) const
553 {
554 return phase_factors_(0, G__[0], ia__) * phase_factors_(1, G__[1], ia__) * phase_factors_(2, G__[2], ia__);
555 }
556
557 /// Phase factors \f$ e^{i {\bf G} {\bf r}_{\alpha}} \f$
558 inline auto gvec_phase_factor(int ig__, int ia__) const
559 {
560 return gvec_phase_factor(gvec().gvec<index_domain_t::global>(ig__), ia__);
561 }
562
563 inline auto const& gvec_coord() const
564 {
565 return gvec_coord_;
566 }
567
568 /// Generate phase factors \f$ e^{i {\bf G} {\bf r}_{\alpha}} \f$ for all atoms of a given type.
569 void generate_phase_factors(int iat__, sddk::mdarray<std::complex<double>, 2>& phase_factors__) const;
570
571 /// Find the lambda parameter used in the Ewald summation.
572 /** Lambda parameter scales the erfc function argument:
573 * \f[
574 * {\rm erf}(\sqrt{\lambda}x)
575 * \f]
576 */
577 double ewald_lambda() const;
578
579 auto const& sym_phase_factors() const
580 {
581 return sym_phase_factors_;
582 }
583
584 inline bool initialized() const
585 {
586 return initialized_;
587 }
588
589 /// Return plane-wave coefficient of the step function.
590 inline auto const& theta_pw(int ig__) const
591 {
592 return theta_.pw[ig__];
593 }
594
595 /// Return the value of the step function for the grid point ir.
596 inline double theta(int ir__) const
597 {
598 return theta_.rg[ir__];
599 }
600
601 /// Returns a constant pointer to the augmentation operator of a given atom type.
602 inline auto const& augmentation_op(int iat__) const
603 {
604 RTE_ASSERT(augmentation_op_[iat__] != nullptr);
605 return *augmentation_op_[iat__];
606 }
607
608 inline auto& augmentation_op(int iat__)
609 {
610 RTE_ASSERT(augmentation_op_[iat__] != nullptr);
611 return *augmentation_op_[iat__];
612 }
613
614 /// Type of the host memory for arrays used in linear algebra operations.
615 /** For CPU execution this is normal host memory, for GPU execution this is pinned memory. */
616 inline auto host_memory_t() const
617 {
618 return host_memory_t_;
619 }
620
621 /// Return the memory type for processing unit.
622 inline auto processing_unit_memory_t() const
623 {
624 return (this->processing_unit() == sddk::device_t::CPU) ? sddk::memory_t::host : sddk::memory_t::device;
625 }
626
627 /// Set the size of the fine-grained FFT grid.
628 void fft_grid_size(std::array<int, 3> fft_grid_size__)
629 {
630 cfg().settings().fft_grid_size(fft_grid_size__);
631 }
632
633 template <typename T>
634 fft::spfft_grid_type<T>& spfft_grid_coarse();
635
636 template <typename T>
637 fft::spfft_transform_type<T>& spfft();
638
639 template <typename T>
640 fft::spfft_transform_type<T> const& spfft() const;
641
642 template <typename T>
643 fft::spfft_transform_type<T>& spfft_coarse();
644
645 template <typename T>
646 fft::spfft_transform_type<T> const& spfft_coarse() const;
647
648 auto const& fft_grid() const
649 {
650 return fft_grid_;
651 }
652
653 auto const& fft_coarse_grid() const
654 {
655 return fft_coarse_grid_;
656 }
657
658 auto const& spla_context() const
659 {
660 return *spla_ctx_;
661 }
662
663 auto& spla_context()
664 {
665 return *spla_ctx_;
666 }
667
668 inline double evp_work_count(double w__ = 0) const
669 {
670 evp_work_count_ += w__;
671 return evp_work_count_;
672 }
673
674 /// Keep track of the total number of wave-functions to which the local operator was applied.
675 inline int num_loc_op_applied(int n = 0) const
676 {
677 num_loc_op_applied_ += n;
678 return num_loc_op_applied_;
679 }
680
681 inline int num_itsol_steps(int n = 0) const
682 {
683 num_itsol_steps_ += n;
684 return num_itsol_steps_;
685 }
686
687 inline auto& cb()
688 {
689 return cb_;
690 }
691
692 inline auto const& cb() const
693 {
694 return cb_;
695 }
696
697 inline auto& ri()
698 {
699 return ri_;
700 }
701
702 inline auto const& ri() const
703 {
704 return ri_;
705 }
706
707 inline std::function<void(void)> band_occ_callback() const
708 {
709 return cb_.band_occ_;
710 }
711
712 inline std::function<void(void)> veff_callback() const
713 {
714 return cb_.veff_;
715 }
716
717 /// Export parameters of simulation context as a JSON dictionary.
718 nlohmann::json serialize()
719 {
720 nlohmann::json dict;
721 dict["config"] = cfg().dict();
722 bool const cart_pos{false};
723 dict["config"]["unit_cell"] = unit_cell().serialize(cart_pos);
724 auto fftgrid = {spfft_transform_coarse_->dim_x(), spfft_transform_coarse_->dim_y(),
725 spfft_transform_coarse_->dim_z()};
726 dict["fft_coarse_grid"] = fftgrid;
727 dict["mpi_grid"] = mpi_grid_dims();
728 dict["omega"] = unit_cell().omega();
729 dict["chemical_formula"] = unit_cell().chemical_formula();
730 dict["num_atoms"] = unit_cell().num_atoms();
731 return dict;
732 }
733
734 /// Return output stream.
735 inline std::ostream& out() const
736 {
737 RTE_ASSERT(output_stream_ != nullptr);
738 return *output_stream_;
739 }
740
741 /// Return output stream based on the verbosity level.
742 inline std::ostream& out(int level__) const
743 {
744 if (this->verbosity() >= level__) {
745 return this->out();
746 } else {
747 return null_stream();
748 }
749 }
750
751 inline rte::ostream out(int level__, const char* label__) const
752 {
753 if (this->verbosity() >= level__) {
754 return rte::ostream(this->out(), label__);
755 } else {
756 return rte::ostream(null_stream(), label__);
757 }
758 }
759
760 /// Print message from the stringstream.
761 inline void message(int level__, char const* label__, std::stringstream const& s) const
762 {
763 if (this->verbosity() >= level__) {
764 auto strings = split(s.str(), '\n');
765 for (auto& e : strings) {
766 this->out() << "[" << label__ << "] " << e << std::endl;
767 }
768 }
769 }
770
771 inline void set_periodic_function_ptr(std::string label__, periodic_function_ptr_t<double> ptr__)
772 {
773 pf_ext_ptr[label__] = ptr__;
774 }
775
776 inline auto periodic_function_ptr(std::string label__) const
777 {
778 periodic_function_ptr_t<double> const* ptr{nullptr};
779 if (pf_ext_ptr.count(label__)) {
780 ptr = &pf_ext_ptr.at(label__);
781 }
782 return ptr;
783 }
784};
785
786} // namespace sirius
787
788#endif
Interface to accelerators API.
Contains implementation of sirius::Augmentation_operator class.
Simulation context is a set of parameters and objects describing a single simulation.
Simulation_context(std::string const &str__)
Create a simulation context with world communicator and load parameters from JSON string or JSON file...
std::unique_ptr< spfft::Transform > spfft_transform_
Fine-grained FFT for density and potential.
auto gvec_phase_factor(r3::vector< int > G__, int ia__) const
Phase factors .
std::vector< std::vector< std::pair< int, double > > > atoms_to_grid_idx_
List of real-space point indices for each of the atoms.
sddk::mdarray< int, 2 > gvec_coord_
Lattice coordinats of G-vectors in a GPU-friendly ordering.
mpi::Communicator const & comm_
Communicator for this simulation.
nlohmann::json serialize()
Export parameters of simulation context as a JSON dictionary.
void init_atoms_to_grid_idx(double R__)
Find a list of real-space grid points around each atom.
mpi::Communicator comm_ortho_fft_coarse_
Auxiliary communicator for the coarse-grid FFT transformation.
timeval start_time_
Creation time of the parameters.
std::string start_time_tag_
A tag string based on the the starting time.
auto const & gvec() const
Return const reference to Gvec object.
auto const & comm_band() const
Band parallelization communicator.
void init_common()
Common init function called by all constructors.
double omega0_
Volume of the initial unit cell.
std::unique_ptr< Unit_cell > unit_cell_
Unit cell of the simulation.
int num_itsol_steps_
Total number of iterative solver steps.
auto const & augmentation_op(int iat__) const
Returns a constant pointer to the augmentation operator of a given atom type.
auto processing_unit_memory_t() const
Return the memory type for processing unit.
void fft_grid_size(std::array< int, 3 > fft_grid_size__)
Set the size of the fine-grained FFT grid.
auto const & comm_fft_coarse() const
Communicator of the coarse FFT grid.
sddk::mdarray< std::complex< double >, 3 > sym_phase_factors_
1D phase factors of the symmetry operations.
void update()
Update context after setting new lattice vectors or atomic coordinates.
std::shared_ptr< fft::Gvec > gvec_coarse_
G-vectors within the 2 * |Gmax^{WF}| cutoff.
void init_comm()
Initialize communicators.
std::shared_ptr< fft::Gvec > gvec_
G-vectors within the Gmax cutoff.
std::vector< std::unique_ptr< Augmentation_operator > > augmentation_op_
Augmentation operator for each atom type.
void init_fft_grid()
Initialize FFT coarse and fine grids.
callback_functions_t cb_
Stores all callback functions.
auto gvec_phase_factor(int ig__, int ia__) const
Phase factors .
void initialize()
Initialize the similation (can only be called once).
sddk::mdarray< std::complex< double >, 3 > phase_factors_
1D phase factors for each atom coordinate and G-vector index.
std::unique_ptr< la::BLACS_grid > blacs_grid_
2D BLACS grid for distributed linear algebra operations.
auto const & unit_cell() const
Return const reference to unit cell object.
std::map< std::string, periodic_function_ptr_t< double > > pf_ext_ptr
External pointers to periodic functions.
auto const & comm_fft() const
Communicator of the dense FFT grid.
auto host_memory_t() const
Type of the host memory for arrays used in linear algebra operations.
std::ostream & out(int level__) const
Return output stream based on the verbosity level.
auto const & comm_k() const
Communicator between k-points.
std::shared_ptr<::spla::Context > spla_ctx_
SPLA library context.
void generate_phase_factors(int iat__, sddk::mdarray< std::complex< double >, 2 > &phase_factors__) const
Generate phase factors for all atoms of a given type.
std::unique_ptr< la::Eigensolver > std_evp_solver_
Standard eigen-value problem solver.
sddk::memory_t host_memory_t_
Type of host memory (pagable or page-locked) for the arrays that participate in host-to-device memory...
auto const & gvec_fft() const
Return const reference to Gvec_fft object.
Simulation_context(mpi::Communicator const &comm__=mpi::Communicator::world())
Create an empty simulation context with an explicit communicator.
auto gvec_fft_sptr() const
Return shared pointer to Gvec_fft object.
std::unique_ptr< spfft::Transform > spfft_transform_coarse_
Coarse-grained FFT for application of local potential and density summation.
r3::matrix< double > lattice_vectors0_
Initial lattice vectors.
std::ostream & out() const
Return output stream.
sddk::mdarray< std::complex< double >, 2 > phase_factors_t_
Phase factors for atom types.
double theta(int ir__) const
Return the value of the step function for the grid point ir.
double ewald_lambda() const
Find the lambda parameter used in the Ewald summation.
auto const & theta_pw(int ig__) const
Return plane-wave coefficient of the step function.
std::unique_ptr< la::Eigensolver > gen_evp_solver_
Generalized eigen-value problem solver.
mpi::Communicator const & comm() const
Total communicator of the simulation.
fft::Grid fft_grid_
Grid descriptor for the fine-grained FFT transform.
auto gvec_sptr() const
Return shared pointer to Gvec object.
int num_loc_op_applied(int n=0) const
Keep track of the total number of wave-functions to which the local operator was applied.
bool initialized_
True if the context is already initialized.
std::unique_ptr< mpi::Grid > mpi_grid_
MPI grid for this simulation.
step_function_t theta_
Step function in real-space and reciprocal domains.
auto const & comm_band_ortho_fft_coarse() const
Communicator, which is orthogonal to comm_fft_coarse within a band communicator.
radial_integrals_t ri_
Stores all radial integrals.
fft::Grid fft_coarse_grid_
Grid descriptor for the coarse-grained FFT transform.
void message(int level__, char const *label__, std::stringstream const &s) const
Print message from the stringstream.
Set of basic parameters of a simulation.
std::vector< int > mpi_grid_dims(std::vector< int > mpi_grid_dims__)
Set dimensions of MPI grid for band diagonalization problem.
Helper class to create FFT grids of given sizes and compute indices in space- and frequency domains.
Definition: fft3d_grid.hpp:38
MPI communicator wrapper.
Simple implementation of 3d vector.
Definition: r3.hpp:45
Multidimensional array with the column-major (Fortran) order.
Definition: memory.hpp:660
Get the environment variables.
Contains helper functions for the interface with SpFFT library.
memory_t
Memory types where the code can store data.
Definition: memory.hpp:71
Contains declaration and implementation of sddk::MPI_grid class.
int num_devices()
Get the number of devices.
Definition: acc.cpp:32
Namespace of the SIRIUS library.
Definition: sirius.f90:5
auto timestamp(std::string fmt)
Return the timestamp string in a specified format.
Definition: time_tools.hpp:34
int num_blocks(int length__, int block_size__)
Return the maximum number of blocks (with size 'block_size') needed to split the 'length' elements.
Definition: splindex.hpp:36
auto split(std::string const str__, char delim__)
Split multi-line string into a list of strings.
Representation of various radial integrals.
Generate rotation matrices and related entities.
Contains definition and implementation of sirius::Simulation_parameters class.
Generate unit step function for LAPW method.
Store all callback functions in one place.
std::function< void(int, int, double *, double *)> ps_rho_ri_
Callback function provided by the host code to compute radial integrals of pseudo charge density.
std::function< void(int, int, double *, double *)> rhoc_ri_djl_
std::function< void(int, double, double *, int)> ps_atomic_wf_ri_
Callback function provided by the host code to compute radial integrals of pseudo atomic wave-functio...
std::function< void(int, double, double *, int)> beta_ri_djl_
std::function< void(void)> veff_
Callback function to compute effective potential.
std::function< void(int, double, double *, int)> beta_ri_
Callback function provided by the host code to compute radial integrals of beta projectors.
std::function< void(int, double, double *, int, int)> aug_ri_
Callback function provided by the host code to compute radial integrals of augmentation operator.
std::function< void(void)> band_occ_
Callback function to compute band occupancies.
std::function< void(int, double, double *, int)> ps_atomic_wf_ri_djl_
std::function< void(int, int, double *, double *)> vloc_ri_djl_
Callback function to compute radial integrals of local potential with derivatives of spherical Bessel...
std::function< void(int, int, double *, double *)> rhoc_ri_
Callback function provided by the host code to compute radial integrals of pseudo core charge density...
std::function< void(int, int, double *, double *)> vloc_ri_
Callback function to compute radial integrals of local potential.
std::function< void(int, double, double *, int, int)> aug_ri_djl_
Describe external pointers to periodic function.
Definition: typedefs.hpp:256
Store all radial integrals in one place.
std::unique_ptr< Radial_integrals_beta< true > > beta_djl_
Radial integrals of beta-projectors with derivatives of spherical Bessel functions.
std::unique_ptr< Radial_integrals_rho_pseudo > ps_rho_
Radial integrals of total pseudo-charge density.
std::unique_ptr< Radial_integrals_rho_core_pseudo< true > > ps_core_djl_
Radial integrals of pseudo-core charge density with derivatives of spherical Bessel functions.
std::unique_ptr< Radial_integrals_rho_core_pseudo< false > > ps_core_
Radial integrals of pseudo-core charge density.
std::unique_ptr< Radial_integrals_aug< true > > aug_djl_
Radial integrals of augmentation operator with derivatives of spherical Bessel functions.
std::unique_ptr< Radial_integrals_vloc< true > > vloc_djl_
Radial integrals of the local part of pseudopotential with derivatives of spherical Bessel functions.
std::unique_ptr< Radial_integrals_aug< false > > aug_
Radial integrals of augmentation operator.
std::unique_ptr< Radial_integrals_atomic_wf< true > > ps_atomic_wf_djl_
Radial integrals of atomic wave-functions with derivatives of spherical Bessel functions.
std::unique_ptr< Radial_integrals_atomic_wf< false > > ps_atomic_wf_
Radial integrals of atomic wave-functions.
std::unique_ptr< Radial_integrals_beta< false > > beta_
Radial integrals of beta-projectors.
std::unique_ptr< Radial_integrals_vloc< false > > vloc_
Radial integrals of the local part of pseudopotential.
Representation of the unit step function.
sddk::mdarray< std::complex< double >, 1 > pw
Plane wave expansion coefficients of the step function (global array).
sddk::mdarray< double, 1 > rg
Step function on the real-space grid.
System-level helper functions.
Timing functions.