Remove old LFC code

parent 7d965b9b
Pipeline #105082615 failed with stage
in 2 minutes and 38 seconds
......@@ -5,7 +5,7 @@ import numpy as np
from ase.units import Bohr
import _gpaw
from gpaw import debug, extra_parameters
from gpaw import debug
from gpaw.grid_descriptor import GridDescriptor, GridBoundsError
from gpaw.utilities import smallest_safe_grid_spacing
......@@ -25,7 +25,6 @@ b
w
Global grid point number (*G*) for a 7*6 grid::
-------------
|5 . . . . . .|
|4 . . . . . .|
......@@ -222,8 +221,8 @@ class BaseLFC:
mem.setsize(nbytes / self.gd.comm.size) # Assume equal distribution
class NewLocalizedFunctionsCollection(BaseLFC):
"""New LocalizedFunctionsCollection
class LocalizedFunctionsCollection(BaseLFC):
"""LocalizedFunctionsCollection
Utilizes that localized functions can be stored on a spherical subset of
the uniform grid, as opposed to LocalizedFunctionsCollection which is just
......@@ -258,6 +257,7 @@ class NewLocalizedFunctionsCollection(BaseLFC):
self.integral_a = None
self.my_atom_indices = None
self.lfc = None
def set_positions(self, spos_ac, atom_partition=None):
assert len(spos_ac) == len(self.sphere_a)
......@@ -922,25 +922,25 @@ class NewLocalizedFunctionsCollection(BaseLFC):
return self.sphere_a[a].get_function_count()
class BasisFunctions(NewLocalizedFunctionsCollection):
class BasisFunctions(LocalizedFunctionsCollection):
def __init__(self, gd, spline_aj, kd=None, cut=False, dtype=float,
integral=None, forces=None):
NewLocalizedFunctionsCollection.__init__(self, gd, spline_aj,
kd, cut,
dtype, integral,
forces)
LocalizedFunctionsCollection.__init__(self, gd, spline_aj,
kd, cut,
dtype, integral,
forces)
self.use_global_indices = True
self.Mstart = None
self.Mstop = None
def set_positions(self, spos_ac):
NewLocalizedFunctionsCollection.set_positions(self, spos_ac)
LocalizedFunctionsCollection.set_positions(self, spos_ac)
self.Mstart = 0
self.Mstop = self.Mmax
def _update(self, spos_ac):
sdisp_Wc = NewLocalizedFunctionsCollection._update(self, spos_ac)
sdisp_Wc = LocalizedFunctionsCollection._update(self, spos_ac)
if not self.gamma or self.dtype == complex:
self.x_W, self.sdisp_xc = self.create_displacement_arrays(sdisp_Wc)
......@@ -1183,137 +1183,6 @@ class BasisFunctions(NewLocalizedFunctionsCollection):
return F_av
from gpaw.localized_functions import LocFuncs, LocFuncBroadcaster
from gpaw.mpi import run
class OldLocalizedFunctionsCollection(BaseLFC):
def __init__(self, gd, spline_aj, kpt_comm=None,
cut=False, dtype=float,
integral=None, forces=False):
self.gd = gd
self.spline_aj = spline_aj
self.cut = cut
self.forces = forces
self.dtype = dtype
self.integral_a = integral
self.spos_ac = None
self.lfs_a = {}
self.ibzk_qc = None
self.gamma = True
self.kpt_comm = kpt_comm
self.my_atom_indices = None
def set_positions(self, spos_ac):
if self.kpt_comm:
lfbc = LocFuncBroadcaster(self.kpt_comm)
else:
lfbc = None
for a, spline_j in enumerate(self.spline_aj):
if self.spos_ac is None or (self.spos_ac[a] != spos_ac[a]).any():
lfs = LocFuncs(spline_j, self.gd, spos_ac[a],
self.dtype, self.cut, self.forces, lfbc)
if len(lfs.box_b) > 0:
if not self.gamma:
lfs.set_phase_factors(self.ibzk_qc)
self.lfs_a[a] = lfs
elif a in self.lfs_a:
del self.lfs_a[a]
if lfbc:
lfbc.broadcast()
rank = self.gd.comm.rank
self.my_atom_indices = [a for a, lfs in self.lfs_a.items()
if lfs.root == rank]
self.my_atom_indices.sort()
self.atom_indices = [a for a, lfs in self.lfs_a.items()]
self.atom_indices.sort()
if debug:
# Holm-Nielsen check:
natoms = len(spos_ac)
assert (self.gd.comm.sum(float(sum(self.my_atom_indices))) ==
natoms * (natoms - 1) // 2)
if self.integral_a is not None:
if isinstance(self.integral_a, (float, int)):
integral = self.integral_a
for a in self.atom_indices:
self.lfs_a[a].normalize(integral)
else:
for a in self.atom_indices:
lfs = self.lfs_a[a]
integral = self.integral_a[a]
if abs(integral) > 1e-15:
lfs.normalize(integral)
self.spos_ac = spos_ac
def get_dtype(self): # old LFC uses the dtype attribute for dicts
return self.dtype
def add(self, a_xG, c_axi=1.0, q=-1):
if isinstance(c_axi, float):
assert q == -1
c_xi = np.array([c_axi])
run([lfs.iadd(a_xG, c_xi) for lfs in self.lfs_a.values()])
else:
run([self.lfs_a[a].iadd(a_xG, c_axi.get(a), q, True)
for a in self.atom_indices])
def integrate(self, a_xG, c_axi, q=-1):
for c_xi in c_axi.values():
c_xi.fill(0.0)
run([self.lfs_a[a].iintegrate(a_xG, c_axi.get(a), q)
for a in self.atom_indices])
def derivative(self, a_xG, c_axiv, q=-1):
for c_xiv in c_axiv.values():
c_xiv.fill(0.0)
run([self.lfs_a[a].iderivative(a_xG, c_axiv.get(a), q)
for a in self.atom_indices])
def add1(self, n_g, scale, I_a):
scale_i = np.array([scale], float)
for lfs in self.lfs_a.values():
lfs.add(n_g, scale_i)
for a, lfs in self.lfs_a.items():
I_ic = np.zeros((1, 4))
for box in lfs.box_b:
box.norm(I_ic)
I_a[a] += I_ic[0, 0] * scale
def add2(self, n_g, D_asp, s, scale, I_a):
for a, lfs in self.lfs_a.items():
I_a[a] += lfs.add_density2(n_g, scale * D_asp[a][s])
def get_function_count(self, a):
return self.lfs_a[a].ni
def estimate_memory(self, mem):
count = 0
for spline_j in self.spline_aj:
for spline in spline_j:
l = spline.get_angular_momentum_number()
sidelength = 2 * spline.get_cutoff()
count += (2 * l + 1) * sidelength**3 / self.gd.dv
bytes = count * mem.floatsize / self.gd.comm.size
mem.subnode('Boxes', bytes)
if self.forces:
mem.subnode('Derivatives', 3 * bytes)
mem.subnode('Work', bytes)
if extra_parameters.get('usenewlfc', True):
LocalizedFunctionsCollection = NewLocalizedFunctionsCollection
else:
LocalizedFunctionsCollection = OldLocalizedFunctionsCollection
def LFC(gd, spline_aj, kd=None,
cut=False, dtype=float,
integral=None, forces=False):
......
This diff is collapsed.
from __future__ import print_function
from math import sqrt, pi
import numpy as np
from gpaw.setup import create_setup
from gpaw.grid_descriptor import GridDescriptor
from gpaw.localized_functions import create_localized_functions
from gpaw.lfc import LFC
from gpaw.xc import XC
n = 60#40 /8 * 10
n = 60 # 40 /8 * 10
a = 10.0
gd = GridDescriptor((n, n, n), (a, a, a))
c_LL = np.identity(9, float)
......@@ -16,9 +15,10 @@ xc = XC('LDA')
for soft in [False]:
s = create_setup('Cu', xc, lmax=2)
ghat_l = s.ghat_l
ghat_Lg = create_localized_functions(ghat_l, gd, (0.54321, 0.5432, 0.543))
ghat_Lg = LFC(gd, [ghat_l])
ghat_Lg.set_positions([(0.54321, 0.5432, 0.543)])
a_Lg[:] = 0.0
ghat_Lg.add(a_Lg, c_LL)
ghat_Lg.add(a_Lg, {0: c_LL})
for l in range(3):
for m in range(2 * l + 1):
L = l**2 + m
......
from __future__ import print_function, division
import numpy as np
import numpy.random as ra
from gpaw.test import equal
from gpaw.setup import create_setup
from gpaw.grid_descriptor import GridDescriptor
from gpaw.localized_functions import create_localized_functions
from gpaw.lfc import LFC
from gpaw.spline import Spline
from gpaw.xc import XC
from gpaw.utilities import pack
......@@ -31,11 +30,11 @@ for name in ['LDA', 'PBE']:
n = 70
n = 90
gd = GridDescriptor((n, n, n), (a, a, a), comm=serial_comm)
pr = create_localized_functions(wt_j, gd, (0.5, 0.5, 0.5))
pr = LFC(gd, [wt_j])
pr.set_positions([(0.5, 0.5, 0.5)])
coefs = np.identity(nao, float)
psit_ig = np.zeros((nao, n, n, n))
pr.add(psit_ig, coefs)
pr.add(psit_ig, {0: np.eye(nao)})
nii = ni * (ni + 1) // 2
D_p = np.zeros(nii)
......@@ -56,8 +55,9 @@ for name in ['LDA', 'PBE']:
p += 1
p += ni - nao
p = create_localized_functions([s.nct], gd, (0.5, 0.5, 0.5))
p.add(n_g[0], np.ones(1))
p = LFC(gd, [[s.nct]])
p.set_positions([(0.5, 0.5, 0.5)])
p.add(n_g[0], 1.0)
e_g = gd.zeros()
xc.calculate(gd, n_g, v_g, e_g)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment