forked from laserkelvin/Pickett
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpinvEngine.cpp
More file actions
154 lines (139 loc) · 4.77 KB
/
SpinvEngine.cpp
File metadata and controls
154 lines (139 loc) · 4.77 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
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
#include <cstring>
#include <cstdlib>
#include "spinv_internal.h"
#include "SpinvEngine.hpp"
SpinvEngine::SpinvEngine()
{
// Zero out the entire context first
memset(&m_context, 0, sizeof(SpinvContext));
// Apply specific initializations
m_context.sptzero[0] = 1;
m_context.sptzero[1] = 0;
m_context.ssp_head.next = NULL; // ssp_head itself needs init
m_context.ssp_head.sspt = m_context.sptzero;
m_context.ssp_head.ssize = 1;
m_context.ssp_head.nitot = 0;
m_context.revsym[0] = 0;
m_context.revsym[1] = 3;
m_context.revsym[2] = 2;
m_context.revsym[3] = 1;
m_context.isoddk[0] = 0;
m_context.isoddk[1] = 1;
m_context.isoddk[2] = 1;
m_context.isoddk[3] = 0;
m_context.ixphase[0] = 0;
m_context.ixphase[1] = 1;
m_context.ixphase[2] = 2;
m_context.ixphase[3] = 3;
m_context.ipwr2[0] = 0;
m_context.ipwr2[1] = 1;
m_context.ipwr2[2] = 2;
m_context.ipwr2[3] = 4;
// Initialize pointers to static fallback members
m_context.vinfo = &m_context.vinfo1; // vinfo1 itself needs full init
memset(&m_context.vinfo1, 0, sizeof(SVIB)); // Zero vinfo1
m_context.vinfo1.spt = m_context.sptzero; // Then set its specific pointers
m_context.dipinfo = &m_context.dipinfo0; // dipinfo0 needs full init
memset(&m_context.dipinfo0, 0, sizeof(SDIP));
// Pointing arrays to their single static "zero" element is okay for initial state
// as setopt/setblk will realloc them.
m_context.moldv = &m_context.zmoldv;
m_context.blkptr = &m_context.zblkptr;
m_context.ipder = &m_context.zipder;
m_context.ivs = &m_context.zivs;
m_context.wk = &m_context.zwk;
m_context.idx = &m_context.zidx;
m_context.jdx = &m_context.zjdx;
m_context.iqnsep = &m_context.ziqnsep;
m_context.ibkptr = &m_context.zibkptr;
m_context.ikmin = &m_context.zikmin;
// The single static elements themselves
m_context.zwk = 0.0;
m_context.zmoldv = 0;
m_context.zblkptr = 0;
m_context.zivs = 0;
m_context.zipder = 0; // ipder values are significant; -1 is often "not fitted"
m_context.zidx = 0;
m_context.zjdx = 0;
m_context.ziqnsep = 0;
m_context.zibkptr = 0;
m_context.zikmin = 0;
// Initialize glob explicitly too (setopt overwrites many but not all)
memset(&m_context.glob, 0, sizeof(GLOB));
// setopt then sets: glob.lsym=TRUE, glob.esym=TRUE, glob.esymdec=100 etc.
}
SpinvEngine::~SpinvEngine()
{
// Free any dynamically allocated memory in the context
if (m_context.vinfo != &m_context.vinfo1) {
free(m_context.vinfo);
}
if (m_context.moldv != &m_context.zmoldv) {
free(m_context.moldv);
}
if (m_context.blkptr != &m_context.zblkptr) {
free(m_context.blkptr);
}
if (m_context.ipder != &m_context.zipder) {
free(m_context.ipder);
}
if (m_context.ivs != &m_context.zivs) {
free(m_context.ivs);
}
if (m_context.wk != &m_context.zwk) {
free(m_context.wk);
}
if (m_context.idx != &m_context.zidx) {
free(m_context.idx);
}
if (m_context.jdx != &m_context.zjdx) {
free(m_context.jdx);
}
if (m_context.iqnsep != &m_context.ziqnsep) {
free(m_context.iqnsep);
}
if (m_context.ibkptr != &m_context.zibkptr) {
free(m_context.ibkptr);
}
if (m_context.ikmin != &m_context.zikmin) {
free(m_context.ikmin);
}
}
int SpinvEngine::hamx(int iblk, int nsize, int npar, bcd_t *idpar, double *par,
double *egy, double *t, double *dedp,
double *pmix, const BOOL ifdump)
{
return ::hamx(&m_context, iblk, nsize, npar, idpar, par, egy, t, dedp, pmix, ifdump);
}
int SpinvEngine::setint(FILE *lu, BOOL *ifdiag, int *nsav, const int ndip,
bcd_t *idip, int *isimag)
{
return ::setint(&m_context, lu, ifdiag, nsav, ndip, idip, isimag);
}
int SpinvEngine::intens(const int iblk, const int isiz, const int jblk,
const int jsiz, const int ndip, const bcd_t *idip,
const double *dip, double *s)
{
return ::intens(&m_context, iblk, isiz, jblk, jsiz, ndip, idip, dip, s);
}
int SpinvEngine::getqn(const int iblk, const int indx, const int maxqn,
short *iqn, int *idgn)
{
return ::getqn(&m_context, iblk, indx, maxqn, iqn, idgn);
}
int SpinvEngine::setopt(FILE *lu, int *nfmt, int *itd, int *ndbcd, char *namfil)
{
printf("DEBUG setopt at entry: m_context.glob.nqn0 = %d\n", m_context.glob.nqn0);
int retval = ::setopt(&m_context, lu, nfmt, itd, ndbcd, namfil);
printf("DEBUG setopt at exit: m_context.glob.nqn0 = %d\n", m_context.glob.nqn0);
return retval;
}
int SpinvEngine::setfmt(int *iqnfmt, int nfmt)
{
return ::setfmt(&m_context, iqnfmt, nfmt);
}
int SpinvEngine::setblk(FILE *lu, int npar, bcd_t *idpar, double *par,
int *nblkpf, int *negy)
{
return ::setblk(&m_context, lu, npar, idpar, par, nblkpf, negy);
}