File: monomial_info.cc

package info (click to toggle)
ergo 3.8.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 17,568 kB
  • sloc: cpp: 94,763; ansic: 17,785; sh: 10,701; makefile: 1,403; yacc: 127; lex: 116; awk: 23
file content (157 lines) | stat: -rw-r--r-- 5,397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Ergo, version 3.8.2, a program for linear scaling electronic structure
 * calculations.
 * Copyright (C) 2023 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
 * and Anastasia Kruchinina.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Primary academic reference:
 * Ergo: An open-source program for linear-scaling electronic structure
 * calculations,
 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
 * Kruchinina,
 * SoftwareX 7, 107 (2018),
 * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
 * 
 * For further information about Ergo, see <http://www.ergoscf.org>.
 */

/** @file monomial_info.cc

    @brief Code used to organize monomials; contributions like x, y,
    z, xy, xz etc. that can be used to describe e.g. basis functions
    and basis function products.

    @author: Elias Rudberg <em>responsible</em>
*/

#include "monomial_info.h"
#include <assert.h>
#include <stdexcept>
#include <cstdio>


void monomial_info_struct::init()
{
  // first get count
  int count = 0;
  for(int n1 = 0; n1 <= MONOMIAL_N_MAX; n1++)
    {
      for(int n1x = 0; n1x <= n1; n1x++)
	for(int n1y = 0; n1y <= n1; n1y++)
	  for(int n1z = 0; n1z <= n1; n1z++)
	    {
	      if(n1x+n1y+n1z != n1)
		continue;
	      count++;
	    } /* END FOR n1x n1y n1z */
    } /* END FOR n1 */
  
  noOfMonomialsTot = count;
  monomial_list = new monomial_struct[noOfMonomialsTot];
  
  count = 0;
  for(int n1 = 0; n1 <= MONOMIAL_N_MAX; n1++)
    {
      for(int n1x = 0; n1x <= n1; n1x++)
	for(int n1y = 0; n1y <= n1; n1y++)
	  for(int n1z = 0; n1z <= n1; n1z++)
	    {
	      if(n1x+n1y+n1z != n1)
		continue;
	      assert(count < noOfMonomialsTot);
	      monomial_list[count].ix = n1x;
	      monomial_list[count].iy = n1y;
	      monomial_list[count].iz = n1z;
	      monomial_index_list[n1x][n1y][n1z] = count;
	      count++;
	    } /* END FOR n1x n1y n1z */
      no_of_monomials_list[n1] = count;
    } /* END FOR n1 */
  assert(count == noOfMonomialsTot);
}

monomial_info_struct::monomial_info_struct() : noOfMonomialsTot(0), monomial_list(0) {
  for(int n1 = 0; n1 <= MONOMIAL_N_MAX; n1++)
    no_of_monomials_list[n1] = 0;
  for(int n1x = 0; n1x <= MONOMIAL_N_MAX; n1x++)
    for(int n1y = 0; n1y <= MONOMIAL_N_MAX; n1y++)
      for(int n1z = 0; n1z <= MONOMIAL_N_MAX; n1z++)
	monomial_index_list[n1x][n1y][n1z] = -1;
}

monomial_info_struct::~monomial_info_struct()
{
  delete []monomial_list;
}

/** Function needed for Chunks&Tasks usage. */
monomial_info_struct::monomial_info_struct(const monomial_info_struct & other) 
  : noOfMonomialsTot(other.noOfMonomialsTot)
{  
  monomial_list = new monomial_struct[noOfMonomialsTot];
  memcpy(monomial_list, other.monomial_list, noOfMonomialsTot*sizeof(monomial_struct));
  memcpy(no_of_monomials_list, other.no_of_monomials_list, sizeof(no_of_monomials_list));
  memcpy(monomial_index_list, other.monomial_index_list, sizeof(monomial_index_list));
}

/** Function needed for Chunks&Tasks usage. */
void monomial_info_struct::write_to_buffer ( char * dataBuffer, size_t const bufferSize ) const {
  char* p = dataBuffer;
  if(bufferSize < get_size())
    throw std::runtime_error("Error in monomial_info_struct::write_to_buffer: bufferSize too small.");
  // noOfMonomialsTot
  memcpy(p, &noOfMonomialsTot, sizeof(int));
  p += sizeof(int);
  // monomial_list
  memcpy(p, monomial_list, noOfMonomialsTot*sizeof(monomial_struct));
  p += noOfMonomialsTot*sizeof(monomial_struct);
  // no_of_monomials_list
  memcpy(p, no_of_monomials_list, sizeof(no_of_monomials_list));
  p += sizeof(no_of_monomials_list);
  // monomial_index_list
  memcpy(p, monomial_index_list, sizeof(monomial_index_list));
  p += sizeof(monomial_index_list);
  // DONE!
}

/** Function needed for Chunks&Tasks usage. */
size_t monomial_info_struct::get_size() const {
  return sizeof(int)
    + noOfMonomialsTot*sizeof(monomial_struct) 
    + sizeof(no_of_monomials_list) 
    + sizeof(monomial_index_list);
}

/** Function needed for Chunks&Tasks usage. */
void monomial_info_struct::assign_from_buffer ( char const * dataBuffer, size_t const bufferSize) {
  const char* p = dataBuffer;
  // noOfMonomialsTot
  memcpy(&noOfMonomialsTot, p, sizeof(int));
  p += sizeof(int);
  // monomial_list
  monomial_list = new monomial_struct[noOfMonomialsTot];
  memcpy(monomial_list, p, noOfMonomialsTot*sizeof(monomial_struct));
  p += noOfMonomialsTot*sizeof(monomial_struct);
  // no_of_monomials_list
  memcpy(no_of_monomials_list, p, sizeof(no_of_monomials_list));
  p += sizeof(no_of_monomials_list);
  // monomial_index_list
  memcpy(monomial_index_list, p, sizeof(monomial_index_list));
  p += sizeof(monomial_index_list);
  // DONE!
  if(static_cast<size_t>(p-dataBuffer) > bufferSize)
    throw std::runtime_error("Error: (p > bufferSize).");  
}