Skip to content

Commit d0e7153

Browse files
committed
SOF-7449: break cutoffFromPseudo into two smaller functions
1 parent ad02f55 commit d0e7153

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/context/providers/PlanewaveCutoffsContextProvider.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,38 @@ export class PlanewaveCutoffsContextProvider extends mix(ContextProvider).with(
4040
return cutoffConfig[this.application.name];
4141
}
4242

43+
/**
44+
* @summary Find cutoff values corresponding to wavefunction or charge
45+
* density with accuracy level in the pseudo method data
46+
* @param data {Object}: the data object from pseudo method data
47+
* @param cutoffEntity {String}: "wavefunction", or "density"
48+
* @param accuracyLevel {String}: "standard", "high", or "low"
49+
* @return {number}: if cutoff value present returns value else return 0
50+
*/
51+
_cutoffFromPseudoData = (data, cutoffEntity, accuracyLevel = "standard") => {
52+
const cutoff = data?.cutoffs?.[cutoffEntity] || [];
53+
return cutoff.find((obj) => obj.accuracy_level === accuracyLevel)?.value ?? 0;
54+
};
55+
56+
/**
57+
* @summary Set highest cutoff of all elements present, in case wavefunction
58+
* cutoff is present but no charge density cutoff, set charge density cutoff
59+
* to 4 or 8 times that of wavefunction cutoff
60+
* @return {Array<number>}: tuple of wavefunction and density cutoffs
61+
*/
4362
get _cutoffsFromPseudos() {
44-
const pseudos = this.methodData?.pseudo || [];
4563
let ecutwfc = 0;
4664
let ecutrho = 0;
65+
const pseudos = this.methodData?.pseudo || [];
4766

4867
pseudos.forEach((data) => {
49-
const wfcCutoff = data?.cutoffs?.wavefunction || [];
50-
const wfcCutoffStandardAccuracy =
51-
wfcCutoff.find((obj) => obj.accuracy_level === "standard")?.value ?? 0;
68+
const ecutwfcStandard = this._cutoffFromPseudoData(data, "wavefunction");
69+
const ecutrhoStandard = this._cutoffFromPseudoData(data, "density");
5270
// set the highest cutoff of all elements
53-
ecutwfc = Math.max(ecutwfc, wfcCutoffStandardAccuracy);
71+
ecutwfc = Math.max(ecutwfc, ecutwfcStandard);
5472

55-
const rhoCutoff = data?.cutoffs?.density || [];
56-
const rhoCutoffStandardAccuracy =
57-
rhoCutoff.find((obj) => obj.accuracy_level === "standard")?.value ?? 0;
58-
if (rhoCutoffStandardAccuracy > ecutrho) {
59-
ecutrho = rhoCutoffStandardAccuracy;
73+
if (ecutrhoStandard > ecutrho) {
74+
ecutrho = ecutrhoStandard;
6075
} else {
6176
// if rho cutoff is not present, set it based on wfc cutoff
6277
// if it is ultrasoft pseudopotential set rho cutoff 8 times

0 commit comments

Comments
 (0)