/
nlj_orbital.cpp
985 lines (831 loc) · 28.2 KB
/
nlj_orbital.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
/****************************************************************
nlj_orbital.cpp
Mark A. Caprio, Patrick J. Fasano
University of Notre Dame
****************************************************************/
#include <cstddef>
#include <algorithm>
#include <iomanip> // for debugging output
#include <set>
#include <istream>
#include <sstream>
#include "am/am.h"
#include "mcutils/parsing.h"
#include "nlj_orbital.h"
#include "basis.h"
#include "many_body.h"
#include "proton_neutron.h"
namespace basis {
////////////////////////////////////////////////////////////////
// orbital truncation
////////////////////////////////////////////////////////////////
OrbitalPNList TruncateOrbitalList(
const WeightMax& weight_max, const OrbitalPNList& orbital_list
)
{
OrbitalPNList output_orbitals;
for (const auto& orbital : orbital_list)
{
if (orbital.weight <= weight_max.one_body[int(orbital.orbital_species)])
output_orbitals.push_back(orbital);
}
return output_orbitals;
}
////////////////////////////////////////////////////////////////
// single-particle definition file parsing
////////////////////////////////////////////////////////////////
/**
* Read orbital definitions from a stream.
*
* @param[in] is input stream containing MFDn-formatted orbital definitions
* @return list of flattened orbital parameters
*/
OrbitalPNList ParseOrbitalPNStream(
std::istream& is,
bool standalone,
MFDnOrbitalFormat format
)
{
// set up line counter for use in error messages
std::string line;
int line_count = 0;
int num_orbitals_p, num_orbitals_n;
if (standalone)
{
// line 1: version
{
mcutils::GetLine(is,line,line_count);
std::istringstream line_stream(line);
int version;
line_stream >> version;
mcutils::ParsingCheck(line_stream,line_count,line);
format = static_cast<MFDnOrbitalFormat>(version);
assert((format==MFDnOrbitalFormat::kVersion15099)
||(format==MFDnOrbitalFormat::kVersion15200));
}
// line 2: number of p,n orbitals
{
mcutils::GetLine(is,line,line_count);
std::istringstream line_stream(line);
line_stream >> num_orbitals_p >> num_orbitals_n;
mcutils::ParsingCheck(line_stream,line_count,line);
}
}
// lines 3+: orbital definitions
OrbitalPNList states;
int num_orbitals_p_extracted=0, num_orbitals_n_extracted=0;
while (mcutils::GetLine(is,line,line_count))
{
// set up for parsing
std::istringstream line_stream(line);
int index;
int n, l, twice_j;
basis::OrbitalSpeciesPN species;
double weight;
if (format==MFDnOrbitalFormat::kVersion15099)
{
int species_code;
line_stream >> index >> n >> l >> twice_j >> species_code >> weight;
species = kDecimalCodeOrbitalSpeciesPN.at(species_code);
}
else if (format==MFDnOrbitalFormat::kVersion15200)
{
int twice_tz;
line_stream >> index >> n >> l >> twice_j >> twice_tz >> weight;
species = kTzCodeOrbitalSpeciesPN.at(HalfInt(twice_tz,2));
}
mcutils::ParsingCheck(line_stream,line_count,line);
OrbitalPNInfo state(species, n, l, HalfInt(twice_j, 2), weight);
// count orbitals by type
num_orbitals_p_extracted +=
static_cast<int>(state.orbital_species == OrbitalSpeciesPN::kP);
num_orbitals_n_extracted +=
static_cast<int>(state.orbital_species == OrbitalSpeciesPN::kN);
states.push_back(state);
}
if (standalone)
{
assert(num_orbitals_p==num_orbitals_p_extracted);
assert(num_orbitals_n==num_orbitals_n_extracted);
}
return states;
}
/**
* Output orbital info as a string suitable for MFDn version 15.
*
* @param[in] orbitals list of flattened orbital parameters
* @return output stream containing MFDn-formatted orbital definitions
*/
std::string OrbitalDefinitionStr(
const OrbitalPNList& orbitals,
bool standalone,
MFDnOrbitalFormat format
)
{
// sanity check
assert((format==MFDnOrbitalFormat::kVersion15099)
||(format==MFDnOrbitalFormat::kVersion15200));
std::ostringstream header;
std::ostringstream body;
std::ostringstream os;
// construct body
const int width = 3;
const int precision = 8;
// orbital indices
int p_index = 0;
int n_index = 0;
int output_index = 0;
for (const OrbitalPNInfo& orbital_info: orbitals)
// iterate over states
{
if (orbital_info.orbital_species == OrbitalSpeciesPN::kP) {
output_index = ++p_index;
} else if (orbital_info.orbital_species == OrbitalSpeciesPN::kN) {
output_index = ++n_index;
}
if (format==MFDnOrbitalFormat::kVersion15099)
{
body << " " << std::setw(width) << output_index
<< " " << std::setw(width) << orbital_info.n
<< " " << std::setw(width) << orbital_info.l
<< " " << std::setw(width) << TwiceValue(orbital_info.j)
<< " " << std::setw(width) << kOrbitalSpeciesPNCodeDecimal[static_cast<int>(orbital_info.orbital_species)] // 1-based
<< " " << std::fixed << std::setw(width+1+precision)
<< std::setprecision(precision) << orbital_info.weight
<< std::endl;
}
else if (format==MFDnOrbitalFormat::kVersion15200)
{
output_index = p_index + n_index;
body << " " << std::setw(width) << output_index
<< " " << std::setw(width) << orbital_info.n
<< " " << std::setw(width) << orbital_info.l
<< " " << std::setw(width) << TwiceValue(orbital_info.j)
<< " " << std::setw(width) << kOrbitalSpeciesPNCodeTz[static_cast<int>(orbital_info.orbital_species)].TwiceValue()
<< " " << std::fixed << std::setw(width+1+precision)
<< std::setprecision(precision) << orbital_info.weight
<< std::endl;
}
}
// construct header
//
// We defer constructing the header until after constructing the
// body, since we need statistics obtained while constructing the
// body.
if (standalone)
{
// header comments
header << "# MFDn SPorbital file" << std::endl;
header << "# version" << std::endl;
header << "# norb_p norb_n" << std::endl;
header << "# index n l 2*j species weight" << std::endl;
// header line 1: version
int version = static_cast<int>(format);
header << " " << version << std::endl;
// header line 2: dimensions
header << " " << p_index << " " << n_index << std::endl;
}
// assemble file
os << header.str() << body.str();
return os.str();
}
////////////////////////////////////////////////////////////////
// single-particle orbitals
////////////////////////////////////////////////////////////////
/**
* Construct an Nmax-truncated single-particle subspace with a particular
* species.
*
* @param[in] orbital_species species type for subspace
* @param[in] Nmax number of oscillator quanta
*/
OrbitalSubspacePN::OrbitalSubspacePN(OrbitalSpeciesPN orbital_species, int Nmax)
: BaseSubspace{{orbital_species}}, weight_max_{double(Nmax)},
is_oscillator_like_{true}, Nmax_{Nmax}
{
// iterate over total oscillator quanta
for (int N = 0; N <= Nmax; ++N)
// iterate over j within shell
for (HalfInt j = HalfInt(1,2); j <= N+HalfInt(1,2); ++j)
{
// recover derived quantum numbers (n,l) from (N,j)
int l = (TwiceValue(j)-1)/2 + (N+(TwiceValue(j)-1)/2)%2;
int n = (N-l)/2;
// save state
PushStateLabels(StateLabelsType(n,l,j));
// save oscillator quantum number as weight
weights_.push_back(double(N));
}
}
/**
* Construct a subspace with a particular species from a list of orbitals.
*
* @param[in] orbital_species species type for subspace
* @param[in] states vector of orbitals
*/
OrbitalSubspacePN::OrbitalSubspacePN(OrbitalSpeciesPN orbital_species,
const OrbitalPNList& states)
: BaseSubspace{{orbital_species}}, weight_max_{0.}
{
// iterate over all states, picking out those which belong to this subspace
for (const OrbitalPNInfo& state : states) {
if (state.orbital_species == orbital_species) {
PushStateLabels(StateLabelsType(state.n,state.l,state.j));
weights_.push_back(state.weight);
weight_max_ = std::max(weight_max_,state.weight);
}
}
// check if oscillator-like and set Nmax
if (IsOscillatorLike_()) {
is_oscillator_like_ = true;
Nmax_ = int(weight_max_);
} else {
is_oscillator_like_ = false;
Nmax_ = -1;
}
}
/**
* Do a deep comparison to oscillator-truncated basis.
* @return true if truncation is like Nmax-truncated oscillator
*/
bool OrbitalSubspacePN::IsOscillatorLike_() const
{
// oscillators have states
if (size()==0)
return false;
// maximum weight should be an integer
int Nmax = int(weight_max());
if (Nmax != weight_max())
return false;
// only positive Nmax is allowed
if (Nmax < 0)
return false;
// compare to equivalent Nmax-truncated subspace
OrbitalSubspacePN reference_subspace(orbital_species(),Nmax);
if (reference_subspace.OrbitalInfo() != OrbitalInfo())
return false;
// if it looks like an oscillator, swims like an oscillator, and quacks
// like an oscillator, it's probably like an oscillator
return true;
}
/**
* Generate a string representation of the subspace labels.
* @return subspace labels as a string
*/
std::string OrbitalSubspacePN::LabelStr() const
{
std::ostringstream os;
const int width = 0; // for now, no fixed width
os << "["
<< " " << std::setw(width) << int(orbital_species())
<< " " << "]";
return os.str();
}
/**
* Generate a string representation, useful for debugging.
* @return debug string
*/
std::string OrbitalSubspacePN::DebugStr() const
{
std::ostringstream os;
const int width = 3;
std::string oscillator_like_indicator = (is_oscillator_like() ? "true" : "false");
os << " weight_max " << weight_max();
if (is_oscillator_like())
os << " Nmax " << Nmax();
os << " (oscillator-like: " << oscillator_like_indicator << ")"
<< std::endl;
for (std::size_t state_index=0; state_index<size(); ++state_index)
{
OrbitalStatePN state(*this,state_index);
os
<< " " << "index"
<< " " << std::setw(width) << state_index
<< " " << "nlj"
<< " " << std::setw(width) << state.n()
<< " " << std::setw(width) << state.l()
<< " " << std::setw(width+2) << state.j().Str()
<< " " << "weight"
<< " " << state.weight()
<< std::endl;
}
return os.str();
}
/**
* Flatten subspace into a vector of OrbitalPNInfo objects.
*
* @return vector representation of subspace
*/
OrbitalPNList OrbitalSubspacePN::OrbitalInfo() const
{
OrbitalPNList orbitals;
for (std::size_t state_index=0; state_index<size(); ++state_index)
{
OrbitalStatePN state(*this,state_index);
orbitals.push_back(state.OrbitalInfo());
}
return orbitals;
}
/**
* Flatten state into an OrbitalPNInfo object.
*
* @return OrbitalPNInfo representation of state
*/
OrbitalPNInfo OrbitalStatePN::OrbitalInfo() const
{
OrbitalPNInfo orbital;
orbital.orbital_species = orbital_species();
orbital.n = n();
orbital.l = l();
orbital.j = j();
orbital.weight = weight();
return orbital;
}
/**
* Generate a string representation of the orbital labels.
* @return orbital labels as a string
*/
std::string OrbitalStatePN::LabelStr() const
{
std::ostringstream os;
const int width = 0; // for now, no fixed width
os << "["
<< " " << std::setw(width) << int(orbital_species())
<< " " << std::setw(width) << index()
<< " :"
<< " " << std::setw(width) << n()
<< " " << std::setw(width) << l()
<< " " << std::setw(width) << j()
<< " :"
<< " " << std::setw(width) << weight()
<< " " << "]";
return os.str();
}
/**
* Construct an Nmax-truncated single-particle space with species subspaces.
*
* @param[in] Nmax number of oscillator quanta
*/
OrbitalSpacePN::OrbitalSpacePN(int Nmax)
{
// save truncation
weight_max_ = double(Nmax);
is_oscillator_like_ = true;
Nmax_ = Nmax;
// iterate over species
for (OrbitalSpeciesPN orbital_species : {OrbitalSpeciesPN::kP,OrbitalSpeciesPN::kN})
{
OrbitalSubspacePN subspace(orbital_species,Nmax);
PushSubspace(subspace);
}
}
/**
* Construct a space with species subspaces from a list of orbitals.
*
* @param[in] states vector of orbitals
*/
OrbitalSpacePN::OrbitalSpacePN(const OrbitalPNList& states)
{
weight_max_ = 0.0;
// collect orbital_species subspace labels sorted in canonical order
std::set<OrbitalSubspacePNLabels> subspace_labels_set;
for (std::size_t state_index=0; state_index<states.size(); ++state_index)
{
OrbitalPNInfo state = states[state_index];
OrbitalSubspacePNLabels labels(state.orbital_species);
subspace_labels_set.insert(labels);
}
// construct subspaces
for (const OrbitalSubspacePNLabels& labels : subspace_labels_set)
{
OrbitalSpeciesPN orbital_species;
std::tie(orbital_species) = labels;
OrbitalSubspacePN subspace(orbital_species,states);
PushSubspace(subspace);
weight_max_ = std::max(weight_max_,subspace.weight_max());
}
// check if oscillator-like and set Nmax
if (IsOscillatorLike_()) {
is_oscillator_like_ = true;
Nmax_ = int(weight_max_);
} else {
is_oscillator_like_ = false;
Nmax_ = -1;
}
}
/**
* Check if space is truncated like an Nmax oscillator truncation.
*
* @return true if all subspaces are Nmax truncated with the same Nmax.
*/
bool OrbitalSpacePN::IsOscillatorLike_() const
{
// first check that the space contains subspaces
if (size() < 1)
return false;
// check if subspaces are individually Nmax truncated
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
if (!subspace.is_oscillator_like())
return false;
}
// see if can extract viable Nmax
int Nmax = GetSubspace(0).Nmax();
for (std::size_t subspace_index=1; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
if (subspace.Nmax() != Nmax)
return false;
}
// orbitals are oscillator like!
return true;
}
/**
* Generate a string representation, useful for debugging.
* @return debug string
*/
std::string OrbitalSpacePN::DebugStr() const
{
std::ostringstream os;
const int width = 3;
std::string oscillator_like_indicator = (is_oscillator_like() ? "true" : "false");
os << " weight_max " << weight_max();
if (is_oscillator_like())
os << " Nmax " << Nmax();
os << " (oscillator-like: " << oscillator_like_indicator << ")"
<< std::endl;
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
os
<< " " << "index"
<< " " << std::setw(width) << subspace_index
<< " " << "species"
<< " " << std::setw(width) << int(subspace.orbital_species())
<< " " << "dim"
<< " " << std::setw(width) << subspace.size()
<< " " << std::endl;
}
return os.str();
}
/**
* Flatten space into a vector of OrbitalPNInfo objects.
*
* @return vector representation of space
*/
OrbitalPNList OrbitalSpacePN::OrbitalInfo() const
{
OrbitalPNList orbitals;
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
OrbitalPNList subspace_orbitals;
// get orbitals for subspace and append to vector
subspace_orbitals = subspace.OrbitalInfo();
orbitals.insert(orbitals.end(),
subspace_orbitals.begin(),
subspace_orbitals.end()
);
}
return orbitals;
}
////////////////////////////////////////////////////////////////
// single-particle orbitals - lj subspaces
////////////////////////////////////////////////////////////////
/**
* Construct an Nmax-truncated single-particle subspace with a particular
* species.
*
* @param[in] orbital_species species type for subspace
* @param[in] l orbital angular momentum quantum number
* @param[in] j total angular momentum quantum number
* @param[in] Nmax number of oscillator quanta
*/
OrbitalSubspaceLJPN::OrbitalSubspaceLJPN(
OrbitalSpeciesPN orbital_species, int l, HalfInt j, int Nmax
)
: BaseSubspace{{orbital_species,l,j}}, weight_max_{double(Nmax)},
is_oscillator_like_{true}, Nmax_{Nmax}
{
// iterate over radial quantum number
for (int n = 0; (2*n+l) <= Nmax; ++n) {
// save state
PushStateLabels(StateLabelsType(n));
// save oscillator quantum number as weight
weights_.push_back(double(2*n+l));
}
}
/**
* Construct a subspace with a particular l, j, and species from a list
* of orbitals.
*
* @param[in] orbital_species species type for subspace
* @param[in] l orbital angular momentum quantum number
* @param[in] j total angular momentum quantum number
* @param[in] states vector of orbitals
*/
OrbitalSubspaceLJPN::OrbitalSubspaceLJPN(
OrbitalSpeciesPN orbital_species, int l, HalfInt j,
const OrbitalPNList& states
)
: BaseSubspace{{orbital_species,l,j}}, weight_max_{0.0}
{
for (auto&& state : states) {
if (state.orbital_species == orbital_species
&& state.l == l && state.j == j) {
PushStateLabels(StateLabelsType(state.n));
weights_.push_back(state.weight);
weight_max_ = std::max(weight_max_,state.weight);
}
}
// check if oscillator-like and set Nmax
if (IsOscillatorLike_()) {
is_oscillator_like_ = true;
Nmax_ = static_cast<int>(weight_max_);
} else {
is_oscillator_like_ = false;
Nmax_ = -1;
}
}
/**
* Do a deep comparison to oscillator-truncated basis.
* @return true if truncation is like Nmax-truncated oscillator
*/
bool OrbitalSubspaceLJPN::IsOscillatorLike_() const
{
// oscillators have states
if (size()==0)
return false;
// maximum weight should be an integer
int Nmax = int(weight_max());
if (Nmax != weight_max())
return false;
// only positive Nmax is allowed
if (Nmax < 0)
return false;
// compare to equivalent Nmax-truncated subspace
OrbitalSubspacePN reference_subspace(orbital_species(),Nmax);
if (reference_subspace.OrbitalInfo() != OrbitalInfo())
return false;
// if it looks like an oscillator, swims like an oscillator, and quacks
// like an oscillator, it's probably like an oscillator
return true;
}
/**
* Generate a string representation of the subspace labels.
* @return subspace labels as a string
*/
std::string OrbitalSubspaceLJPN::LabelStr() const {
std::ostringstream os;
const int width = 3;
os << "["
<< " " << std::setw(width) << int(orbital_species())
<< " " << std::setw(width) << l()
<< " " << std::setw(width+2) << j().Str()
<< " " << "]";
return os.str();
}
/**
* Generate a string representation, useful for debugging.
* @return debug string
*/
std::string OrbitalSubspaceLJPN::DebugStr() const {
std::ostringstream os;
const int width = 3;
for (std::size_t state_index=0; state_index<size(); ++state_index) {
OrbitalStateLJPN state(*this,state_index);
os
<< " " << "index"
<< " " << std::setw(width) << state_index
<< " " << "nlj"
<< " " << std::setw(width) << state.n()
<< " " << std::setw(width) << state.l()
<< " " << std::setw(width+2) << state.j().Str()
<< " " << "weight"
<< " " << state.weight()
<< std::endl;
}
return os.str();
}
/**
* Flatten subspace into a vector of OrbitalPNInfo objects.
*
* @return vector representation of subspace
*/
OrbitalPNList OrbitalSubspaceLJPN::OrbitalInfo() const
{
OrbitalPNList orbitals;
for (std::size_t state_index=0; state_index<size(); ++state_index)
{
OrbitalStateLJPN state(*this,state_index);
orbitals.push_back(state.OrbitalInfo());
}
return orbitals;
}
/**
* Generate a string representation of the orbital labels.
* @return orbital labels as a string
*/
std::string OrbitalStateLJPN::LabelStr() const
{
std::ostringstream os;
const int width = 0; // for now, no fixed width
os << "["
<< " " << std::setw(width) << int(orbital_species())
<< " " << std::setw(width) << index()
<< " :"
<< " " << std::setw(width) << n()
<< " " << std::setw(width) << l()
<< " " << std::setw(width) << j()
<< " :"
<< " " << std::setw(width) << weight()
<< " " << "]";
return os.str();
}
/**
* Flatten state into an OrbitalPNInfo object.
*
* @return OrbitalPNInfo representation of state
*/
OrbitalPNInfo OrbitalStateLJPN::OrbitalInfo() const
{
OrbitalPNInfo orbital;
orbital.orbital_species = orbital_species();
orbital.n = n();
orbital.l = l();
orbital.j = j();
orbital.weight = weight();
return orbital;
}
/**
* Construct an Nmax-truncated single-particle space divided into LJPN
* subspaces.
*
* @param[in] Nmax number of oscillator quanta
*/
OrbitalSpaceLJPN::OrbitalSpaceLJPN(int Nmax)
: weight_max_{double(Nmax)}, is_oscillator_like_{true}, Nmax_{Nmax}
{
// iterate over species
for (OrbitalSpeciesPN orbital_species :
{OrbitalSpeciesPN::kP,OrbitalSpeciesPN::kN}) {
for (int l=0; l<=Nmax; ++l) {
for (HalfInt j = l-HalfInt(1,2); j<=(l+HalfInt(1,2)); ++j) {
if (j<0) continue;
OrbitalSubspaceLJPN subspace(orbital_species,l,j,Nmax);
PushSubspace(subspace);
}
}
}
}
/**
* Construct a space with LJPN subspaces from a list of orbitals.
*
* @param[in] states vector of orbitals
*/
OrbitalSpaceLJPN::OrbitalSpaceLJPN(const OrbitalPNList& states)
: weight_max_{0.0}
{
// collect (l,j) subspace labels sorted in canonical order
std::set<OrbitalSubspaceLJPNLabels> subspace_labels_set;
for (std::size_t state_index=0; state_index<states.size(); ++state_index)
{
OrbitalPNInfo state = states[state_index];
OrbitalSubspaceLJPNLabels labels(state.orbital_species,state.l,state.j);
subspace_labels_set.insert(labels);
}
// construct subspaces
for (const OrbitalSubspaceLJPNLabels& labels : subspace_labels_set)
{
OrbitalSpeciesPN orbital_species;
int l;
HalfInt j;
std::tie(orbital_species,l,j) = labels;
OrbitalSubspaceLJPN subspace(orbital_species,l,j,states);
PushSubspace(subspace);
weight_max_ = std::max(weight_max_,subspace.weight_max());
}
// check if oscillator-like and set Nmax
if (IsOscillatorLike_()) {
is_oscillator_like_ = true;
Nmax_ = int(weight_max_);
} else {
is_oscillator_like_ = false;
Nmax_ = -1;
}
}
/**
* Check if space is truncated like an Nmax oscillator truncation.
*
* @return true if all subspaces are Nmax truncated with the same Nmax.
*/
bool OrbitalSpaceLJPN::IsOscillatorLike_() const
{
// first check that the space contains subspaces
if (size() < 1)
return false;
// check if subspaces are individually Nmax truncated
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
if (!subspace.is_oscillator_like())
return false;
}
// see if can extract viable Nmax
int Nmax = GetSubspace(0).Nmax();
for (std::size_t subspace_index=1; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
if (subspace.Nmax() != Nmax)
return false;
}
// orbitals are oscillator like!
return true;
}
/**
* Generate a string representation, useful for debugging.
* @return debug string
*/
std::string OrbitalSpaceLJPN::DebugStr() const {
std::ostringstream os;
const int width = 3;
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index) {
const SubspaceType& subspace = GetSubspace(subspace_index);
os
<< " " << "index"
<< " " << std::setw(width) << subspace_index
<< " " << "species"
<< " " << std::setw(width) << int(subspace.orbital_species())
<< " " << "dim"
<< " " << std::setw(width) << subspace.size()
<< " " << std::endl;
}
return os.str();
}
/**
* Flatten space into a vector of OrbitalPNInfo objects.
*
* @return vector representation of space
*/
OrbitalPNList OrbitalSpaceLJPN::OrbitalInfo() const
{
OrbitalPNList orbitals;
for (std::size_t subspace_index=0; subspace_index<size(); ++subspace_index)
{
const SubspaceType& subspace = GetSubspace(subspace_index);
OrbitalPNList subspace_orbitals;
// get orbitals for subspace and append to vector
subspace_orbitals = subspace.OrbitalInfo();
orbitals.insert(orbitals.end(),
subspace_orbitals.begin(),
subspace_orbitals.end()
);
}
return orbitals;
}
#ifdef BASIS_ALLOW_DEPRECATED
OrbitalSectorsLJPN::OrbitalSectorsLJPN(
const OrbitalSpaceLJPN& bra_space, const OrbitalSpaceLJPN& ket_space
)
: BaseSectors(bra_space, ket_space), J0_(-1), g0_(-1), Tz0_(1)
{
for (std::size_t bra_subspace_index=0; bra_subspace_index<bra_space.size(); ++bra_subspace_index) {
for (std::size_t ket_subspace_index=0; ket_subspace_index<ket_space.size(); ++ket_subspace_index) {
// retrieve subspaces
const SubspaceType& bra_subspace = bra_space.GetSubspace(bra_subspace_index);
const SubspaceType& ket_subspace = ket_space.GetSubspace(ket_subspace_index);
// push sector
PushSector(bra_subspace_index,ket_subspace_index);
}
}
}
#endif // BASIS_ALLOW_DEPRECATED
/**
* Generate a string representation, useful for debugging.
* @return debug string
*/
std::string OrbitalSectorsLJPN::DebugStr() const
{
std::ostringstream os;
int width = 3;
for (std::size_t sector_index=0; sector_index<size(); ++sector_index) {
// const basis::OrbitalSectorLJPN& sector = GetSector(sector_index);
// os << sector_index+1 << sector.DebugStr();
const SectorType& sector = GetSector(sector_index);
os << std::setw(width) << sector_index
<< " bra " << std::setw(width) << sector.bra_subspace_index()
<< " (" << int(sector.bra_subspace().orbital_species())
<< ", " << sector.bra_subspace().l()
<< ", " << sector.bra_subspace().j().Str() << ")"
<< " ket " << std::setw(width) << sector.ket_subspace_index()
<< " (" << int(sector.ket_subspace().orbital_species())
<< ", " << sector.ket_subspace().l()
<< ", " << sector.ket_subspace().j().Str() << ")"
<< std::endl;
}
return os.str();
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
} // namespace