-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy patharbitrary_floattype.jl
More file actions
50 lines (44 loc) · 2.04 KB
/
Copy patharbitrary_floattype.jl
File metadata and controls
50 lines (44 loc) · 2.04 KB
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
# # Arbitrary floating-point types
#
# Since DFTK is completely generic in the floating-point type
# in its routines, there is no reason to perform the computation
# using double-precision arithmetic (i.e.`Float64`).
# Other floating-point types such as `Float32` (single precision)
# or elevated precision using
# [DoubleFloats.jl](https://github.com/JuliaMath/DoubleFloats.jl)
# are supported as well.
# In this example, however, we will concentrate on single-precision
# computations with `Float32`.
#
# The setup of such a reduced-precision calculation is basically identical
# to the regular case, since Julia automatically compiles all routines
# of DFTK at the precision, which is used for the lattice vectors.
# Apart from setting up the model with an explicit cast of the lattice
# vectors to `Float32`, there is thus no change in user code required:
#
using DFTK
using PseudoPotentialData
using AtomsBuilder
## Use AtomsBuilder to setup silicon lattice and cast model to Float32
pseudopotentials = PseudoFamily("cp2k.nc.sr.lda.v0_1.largecore.gth")
model = model_DFT(bulk(:Si); functionals=LDA(), pseudopotentials)
basis = PlaneWaveBasis(convert(Model{Float32}, model), Ecut=7, kgrid=[4, 4, 4])
## Run the SCF
scfres = self_consistent_field(basis, tol=1e-3);
# To check the calculation has really run in Float32,
# we check the energies and density are expressed in this floating-point type:
scfres.energies
#-
eltype(scfres.energies.total)
#-
eltype(scfres.ρ)
#
# !!! note "Generic linear algebra routines"
# For more unusual floating-point types (like IntervalArithmetic or DoubleFloats),
# which are not directly supported in the standard `LinearAlgebra` and `FFTW`
# libraries one additional step is required: One needs to explicitly enable the generic
# versions of standard linear-algebra operations like `cholesky` or `qr` or standard
# `fft` operations, which DFTK requires. THis is done by loading the
# `GenericLinearAlgebra` package in the user script
# (i.e. just add ad `using GenericLinearAlgebra` next to your `using DFTK` call).
#