T2345: Walking back nullptr changes to lib/awpmd

This commit is contained in:
Anne Gunn
2020-09-11 10:24:51 -06:00
parent ed57554e18
commit 96b01f2383
8 changed files with 56 additions and 56 deletions

View File

@ -129,7 +129,7 @@ public:
message_logger(const string &descriptor_="", int out_level=vblALLBAD|vblMESS1, message_logger(const string &descriptor_="", int out_level=vblALLBAD|vblMESS1,
int stop_level=vblFATAL, int throw_exceptions=0, int use_globally=0) int stop_level=vblFATAL, int throw_exceptions=0, int use_globally=0)
:descriptor(descriptor_),prev(nullptr),next(nullptr){ :descriptor(descriptor_),prev(NULL),next(NULL){
set_throw(throw_exceptions); set_throw(throw_exceptions);
set_levels(out_level,stop_level); set_levels(out_level,stop_level);
extra_levels(0,0); extra_levels(0,0);
@ -157,8 +157,8 @@ public:
return -1; return -1;
glogp=prev; glogp=prev;
if(glogp) if(glogp)
glogp->next=nullptr; glogp->next=NULL;
prev=nullptr; prev=NULL;
} }
return 1; return 1;
} }
@ -244,7 +244,7 @@ public:
FILE *out=stdout, FILE *err=stderr, FILE *out=stdout, FILE *err=stderr,
int out_level=vblALLBAD|vblMESS1,int stop_level=vblFATAL, int out_level=vblALLBAD|vblMESS1,int stop_level=vblFATAL,
int use_globally=0) int use_globally=0)
: message_logger(descriptor_,out_level,stop_level,throw_exceptions,use_globally),fout(nullptr), ferr(nullptr){ : message_logger(descriptor_,out_level,stop_level,throw_exceptions,use_globally),fout(NULL), ferr(NULL){
set_out(out); set_out(out);
set_err(err); set_err(err);
} }

View File

@ -146,7 +146,7 @@ public:
public: public:
iterator(const iterator &other):ptr(other.ptr),incr(other.incr){ iterator(const iterator &other):ptr(other.ptr),incr(other.incr){
} }
iterator():ptr(nullptr),incr(0){} iterator():ptr(NULL),incr(0){}
iterator &operator++(){ // prefix iterator &operator++(){ // prefix
ptr+=incr; ptr+=incr;
return *this; return *this;
@ -173,13 +173,13 @@ public:
size_t sizex, sizey; size_t sizex, sizey;
//e default constructor //e default constructor
recmatrix(): parr(nullptr,1) { recmatrix(): parr(NULL,1) {
sizey=sizex=0; sizey=sizex=0;
arr=nullptr; arr=NULL;
} }
//e copy constructor: makes a managed copy //e copy constructor: makes a managed copy
recmatrix(const recmatrix &other):sizex(0),sizey(0),arr(nullptr){ recmatrix(const recmatrix &other):sizex(0),sizey(0),arr(NULL){
*this=other; *this=other;
} }
@ -222,7 +222,7 @@ public:
virtual int init(size_t nx, size_t ny, int smanaged=-1){ virtual int init(size_t nx, size_t ny, int smanaged=-1){
int managed=parr.managed(); int managed=parr.managed();
if(managed && (sizex!=nx || sizey!=ny)){ if(managed && (sizex!=nx || sizey!=ny)){
parr.reset(nullptr,0); parr.reset(NULL,0);
} }
if(smanaged>=0){ // for changing the managed flag? if(smanaged>=0){ // for changing the managed flag?
parr.reset(parr.ptr(),smanaged ? smanaged|0x8 : 0 ); parr.reset(parr.ptr(),smanaged ? smanaged|0x8 : 0 );
@ -355,7 +355,7 @@ public:
public: public:
iterator(const iterator &other):ptr(other.ptr),incr(other.incr){ iterator(const iterator &other):ptr(other.ptr),incr(other.incr){
} }
iterator():ptr(nullptr),incr(0){} iterator():ptr(NULL),incr(0){}
iterator &operator++(){ // prefix iterator &operator++(){ // prefix
ptr+=incr; ptr+=incr;
return *this; return *this;
@ -382,13 +382,13 @@ public:
size_t size; size_t size;
//e default constructor //e default constructor
sqmatrix(): parr(nullptr,1) { sqmatrix(): parr(NULL,1) {
size=0; size=0;
arr=nullptr; arr=NULL;
} }
//e copy constructor: makes a managed copy //e copy constructor: makes a managed copy
sqmatrix(const sqmatrix &other):size(0),arr(nullptr){ sqmatrix(const sqmatrix &other):size(0),arr(NULL){
*this=other; *this=other;
} }
@ -430,7 +430,7 @@ public:
virtual int init(size_t n, int smanaged=-1){ virtual int init(size_t n, int smanaged=-1){
int managed=parr.managed(); int managed=parr.managed();
if(managed && size!=n){ if(managed && size!=n){
parr.reset(nullptr,0); parr.reset(NULL,0);
} }
if(smanaged>=0){ // for changing the managed flag? if(smanaged>=0){ // for changing the managed flag?
parr.reset(parr.ptr(),smanaged ? smanaged|0x8 : 0 ); parr.reset(parr.ptr(),smanaged ? smanaged|0x8 : 0 );
@ -600,9 +600,9 @@ class PairHash{
public: public:
//e find the value with indexes i, j //e find the value with indexes i, j
//e @return 0 if not found, 1 otherwise //e @return 0 if not found, 1 otherwise
//e if retval is not nullptr, puts the found value there //e if retval is not NULL, puts the found value there
virtual int Find(long i, long j, T *retval=nullptr)=0; virtual int Find(long i, long j, T *retval=NULL)=0;
virtual int Find(long i, long j, T **retval=nullptr)=0; virtual int Find(long i, long j, T **retval=NULL)=0;
virtual int Del(long i, long j)=0; virtual int Del(long i, long j)=0;
virtual int Put(long i, long j, const T *value)=0; virtual int Put(long i, long j, const T *value)=0;
virtual int Put(long i, long j, const T& value)=0; virtual int Put(long i, long j, const T& value)=0;
@ -621,7 +621,7 @@ public:
indm.Set(-1); indm.Set(-1);
arr= new T[n*(n+1)/2]; arr= new T[n*(n+1)/2];
} }
int Find(long i, long j, T *retval=nullptr){ int Find(long i, long j, T *retval=NULL){
long ind=indm(i,j); long ind=indm(i,j);
if(ind>=0){ if(ind>=0){
if(retval){ if(retval){

View File

@ -158,7 +158,7 @@ public:
using base_t::second; using base_t::second;
using base_t::first; using base_t::first;
mngptr(T* ptr=nullptr, int managed=0): pair<T*,int>(ptr,managed){ mngptr(T* ptr=NULL, int managed=0): pair<T*,int>(ptr,managed){
//if(managed==2)ptr= new T(*ptr); //if(managed==2)ptr= new T(*ptr);
} }
mngptr(const mngarg<T> &arg): pair<T*,int>(arg.first,arg.second){} mngptr(const mngarg<T> &arg): pair<T*,int>(arg.first,arg.second){}
@ -166,7 +166,7 @@ public:
reset(arg.first,arg.second); reset(arg.first,arg.second);
return *this; return *this;
} }
void reset(T* ptr=nullptr, int managed=0){ void reset(T* ptr=NULL, int managed=0){
if(second && first && first!=ptr){ if(second && first && first!=ptr){
if(second&0x8)delete [] first; if(second&0x8)delete [] first;
else delete first; else delete first;
@ -313,7 +313,7 @@ template<class T, class delete_t=delete_ptr<T> >
class shptr{ class shptr{
template<class Y, class Z> friend class shptr; template<class Y, class Z> friend class shptr;
T *p; T *p;
int *num; //if num==nullptr than p is not managed (as in mngptr) int *num; //if num==NULL than p is not managed (as in mngptr)
void set(T *p_, int managed){ void set(T *p_, int managed){
p=p_; p=p_;
@ -321,7 +321,7 @@ class shptr{
num=new int; num=new int;
*num=1; *num=1;
} }
else num=nullptr; else num=NULL;
} }
template<class Y> template<class Y>
void set(const Y &other){ void set(const Y &other){
@ -330,7 +330,7 @@ class shptr{
num=other.num; num=other.num;
if(num)(*num)++; if(num)(*num)++;
} }
else num=nullptr; else num=NULL;
} }
void set(const shptr &other){ void set(const shptr &other){
p=other.p; p=other.p;
@ -338,11 +338,11 @@ class shptr{
num=other.num; num=other.num;
if(num)(*num)++; if(num)(*num)++;
} }
else num=nullptr; else num=NULL;
} }
public: public:
shptr(T* p=nullptr, int managed=1){ shptr(T* p=NULL, int managed=1){
set(p,managed); set(p,managed);
} }
shptr(const mngarg<T> &arg){ shptr(const mngarg<T> &arg){
@ -398,14 +398,14 @@ public:
delete_t()(p); delete_t()(p);
delete num; delete num;
} }
num=nullptr; num=NULL;
} }
p=nullptr; p=NULL;
} }
} }
bool valid() const { bool valid() const {
return p!=nullptr; return p!=NULL;
} }
T* ptr() const { T* ptr() const {

View File

@ -374,7 +374,7 @@ struct Vector_Nt {
} }
T maxcoord(int *ind=nullptr) const { T maxcoord(int *ind=NULL) const {
int im=0; int im=0;
T vv=v[0]; T vv=v[0];
for (int i=1; i<N; i++) { for (int i=1; i<N; i++) {
@ -389,7 +389,7 @@ struct Vector_Nt {
//e returns the corrd having maximal absolute value //e returns the corrd having maximal absolute value
T maxabscoord(int *ind=nullptr) const { T maxabscoord(int *ind=NULL) const {
int im=0; int im=0;
T vv=fabs(v[0]); T vv=fabs(v[0]);
for (int i=1; i<N; i++) { for (int i=1; i<N; i++) {
@ -403,7 +403,7 @@ struct Vector_Nt {
} }
//e returns the corrd having minimal absolute value //e returns the corrd having minimal absolute value
T minabscoord(int *ind=nullptr) const { T minabscoord(int *ind=NULL) const {
int im=0; int im=0;
T vv=fabs(v[0]); T vv=fabs(v[0]);
for (int i=1; i<N; i++) { for (int i=1; i<N; i++) {
@ -417,7 +417,7 @@ struct Vector_Nt {
} }
T mincoord(int *ind=nullptr) const { T mincoord(int *ind=NULL) const {
int im=0; int im=0;
T vv=v[0]; T vv=v[0];
for (int i=1; i<N; i++) { for (int i=1; i<N; i++) {
@ -485,7 +485,7 @@ vec_type dist_av(Vector_3 *va1,Vector_3 *va2,int n);
//e finds the average difference norm between two vector sets of the same length //e finds the average difference norm between two vector sets of the same length
/*e optionally gives the indexes for maximal and minimal difference /*e optionally gives the indexes for maximal and minimal difference
va2 can be nullptr, then the norm of va1 is used */ va2 can be NULL, then the norm of va1 is used */
vec_type diff_av(Vector_3 *va1,Vector_3 *va2,int n, int *minind=0, int *maxind=0); vec_type diff_av(Vector_3 *va1,Vector_3 *va2,int n, int *minind=0, int *maxind=0);
@ -615,9 +615,9 @@ inline Vector_3 randdir(){
///\en Calculates extent of the vector container. ///\en Calculates extent of the vector container.
/// \return the center of the vector set, optionally /// \return the center of the vector set, optionally
/// (if arguments are not nullptr) fills the bounding box in \a box_min, \a box_max. /// (if arguments are not NULL) fills the bounding box in \a box_min, \a box_max.
template<class vec_inp_it> template<class vec_inp_it>
Vector_3 get_extent(vec_inp_it beg,vec_inp_it end, Vector_3* box_min=nullptr,Vector_3* box_max=nullptr){ Vector_3 get_extent(vec_inp_it beg,vec_inp_it end, Vector_3* box_min=NULL,Vector_3* box_max=NULL){
if(beg==end) if(beg==end)
return Vector_3(); return Vector_3();
Vector_3 center(*beg++); Vector_3 center(*beg++);

View File

@ -13,7 +13,7 @@ message_logger &message_logger::global(){
return *glogp; return *glogp;
} }
message_logger *message_logger::glogp=nullptr; message_logger *message_logger::glogp=NULL;
stdfile_logger default_log("",0,stdout,stderr,vblALLBAD|vblMESS1,vblFATAL,1); stdfile_logger default_log("",0,stdout,stderr,vblALLBAD|vblMESS1,vblFATAL,1);
const char *logfmt(const char *format,...){ const char *logfmt(const char *format,...){

View File

@ -255,7 +255,7 @@ public:
} }
//e Create NormDeriv object and calculate the derivatived for the given WP //e Create NormDeriv object and calculate the derivatived for the given WP
void set2(const WavePacket& w2_, const cdouble *I0_=nullptr){ void set2(const WavePacket& w2_, const cdouble *I0_=NULL){
w2=w2_; w2=w2_;
d2.set(w2); d2.set(w2);
w12=conj(w1)*w2; w12=conj(w1)*w2;
@ -558,13 +558,13 @@ public:
//e if PBCs are used, the corresponding coordinates of electrons and ions //e if PBCs are used, the corresponding coordinates of electrons and ions
//e in periodic directions must be within the range [0, cell[per_dir]) //e in periodic directions must be within the range [0, cell[per_dir])
//e @returns 1 if OK //e @returns 1 if OK
int set_pbc(const Vector_3P pcell=nullptr, int pbc_=0x7); int set_pbc(const Vector_3P pcell=NULL, int pbc_=0x7);
///\en Setup electrons: forms internal wave packet representations. ///\en Setup electrons: forms internal wave packet representations.
/// If PBCs are used the coords must be within a range [0, cell). /// If PBCs are used the coords must be within a range [0, cell).
/// Default electron mass is AWPMD::me. /// Default electron mass is AWPMD::me.
/// Default (q=nullptr )electron charges are -1. /// Default (q=NULL )electron charges are -1.
int set_electrons(int spin, int n, Vector_3P x, Vector_3P v, double* w, double* pw, double mass=-1, double *q=nullptr); int set_electrons(int spin, int n, Vector_3P x, Vector_3P v, double* w, double* pw, double mass=-1, double *q=NULL);
//e setup ion charges and coordinates //e setup ion charges and coordinates
//e if PBCs are used the coords must be within a range [0, cell) //e if PBCs are used the coords must be within a range [0, cell)
@ -593,16 +593,16 @@ public:
// 0x2 -- add ion forces to the existing set // 0x2 -- add ion forces to the existing set
// 0x4 -- calculate derivatives for electronic time step (NOT IMPLEMENTED) // 0x4 -- calculate derivatives for electronic time step (NOT IMPLEMENTED)
//e if PBCs are used the coords must be within a range [0, cell) //e if PBCs are used the coords must be within a range [0, cell)
virtual int interaction(int flag=0, Vector_3P fi=nullptr, Vector_3P fe_x=nullptr, virtual int interaction(int flag=0, Vector_3P fi=NULL, Vector_3P fe_x=NULL,
Vector_3P fe_p=nullptr, double *fe_w=nullptr, double *fe_pw=nullptr, Vector_2P fe_c=nullptr); Vector_3P fe_p=NULL, double *fe_w=NULL, double *fe_pw=NULL, Vector_2P fe_c=NULL);
//e same as interaction, but using Hartee factorization (no antisymmetrization) //e same as interaction, but using Hartee factorization (no antisymmetrization)
virtual int interaction_hartree(int flag=0, Vector_3P fi=nullptr, Vector_3P fe_x=nullptr, virtual int interaction_hartree(int flag=0, Vector_3P fi=NULL, Vector_3P fe_x=NULL,
Vector_3P fe_p=nullptr, double *fe_w=nullptr, double *fe_pw=nullptr, Vector_2P fe_c=nullptr); Vector_3P fe_p=NULL, double *fe_w=NULL, double *fe_pw=NULL, Vector_2P fe_c=NULL);
///\en Calculates ion-ion interactions and updates Eii and ion forces if requested. This function ///\en Calculates ion-ion interactions and updates Eii and ion forces if requested. This function
/// is called form intaraction() and interaction_hartree if calc_ii is set. /// is called form intaraction() and interaction_hartree if calc_ii is set.
virtual int interaction_ii(int flag,Vector_3P fi=nullptr); virtual int interaction_ii(int flag,Vector_3P fi=NULL);
//e Calculates Norm matrix //e Calculates Norm matrix
//e The result is saved in AWPMD::Norm[s] //e The result is saved in AWPMD::Norm[s]
@ -643,7 +643,7 @@ public:
///\en Prepares force arrays according to \a flag setting for interaction() ///\en Prepares force arrays according to \a flag setting for interaction()
virtual void clear_forces(int flagi,Vector_3P fi, Vector_3P fe_x, virtual void clear_forces(int flagi,Vector_3P fi, Vector_3P fe_x,
Vector_3P fe_p, double *fe_w, double *fe_pw, Vector_2P fe_c=nullptr); Vector_3P fe_p, double *fe_w, double *fe_pw, Vector_2P fe_c=NULL);
///\en Creates wave packet according to the given physical parameters. ///\en Creates wave packet according to the given physical parameters.

View File

@ -312,7 +312,7 @@ void AWPMD_split::clear_forces(int flag,Vector_3P fi, Vector_3P fe_x,
void AWPMD_split::get_el_forces(int flag, Vector_3P fe_x, void AWPMD_split::get_el_forces(int flag, Vector_3P fe_x,
Vector_3P fe_p, double *fe_w, double *fe_pw, Vector_2P fe_c){ Vector_3P fe_p, double *fe_w, double *fe_pw, Vector_2P fe_c){
if(flag&0x4) //need to replace the forces if(flag&0x4) //need to replace the forces
clear_forces(0x4,nullptr,fe_x,fe_p,fe_w,fe_pw,fe_c); clear_forces(0x4,NULL,fe_x,fe_p,fe_w,fe_pw,fe_c);
// recalculating derivatives // recalculating derivatives
if(flag&(0x8|0x4)){ //electron forces needed if(flag&(0x8|0x4)){ //electron forces needed
@ -622,7 +622,7 @@ void AWPMD_split::y_deriv(cdouble v,int s,int c2, int c1){
/// 0x4 -- calculate electronic forces \n /// 0x4 -- calculate electronic forces \n
/// 0x8 -- add electronic forces to the existing arrays \n /// 0x8 -- add electronic forces to the existing arrays \n
/// 0x10 -- calculate internal electronic derivatives only: \n /// 0x10 -- calculate internal electronic derivatives only: \n
/// will not update electronic force arrays, which may be nullptr, \n /// will not update electronic force arrays, which may be NULL, \n
/// the forces may be obtained then using \ref get_el_forces() for all WPs \n /// the forces may be obtained then using \ref get_el_forces() for all WPs \n
/// or separately for each WP using \ref get_wp_force() /// or separately for each WP using \ref get_wp_force()
/// if PBCs are used the coords must be within a range [0, cell) /// if PBCs are used the coords must be within a range [0, cell)

View File

@ -116,8 +116,8 @@ public:
/// \a n is the number of electrons of a given spin component /// \a n is the number of electrons of a given spin component
/// Electron velocity v is multiplied by mass to obtain momentum. /// Electron velocity v is multiplied by mass to obtain momentum.
/// Default mass (-1) means me. /// Default mass (-1) means me.
/// Electronic charges q are -1 by default (when q=nullptr), otherwise the charges are assigned for each split /// Electronic charges q are -1 by default (when q=NULL), otherwise the charges are assigned for each split
int set_electrons(int s, int nel, Vector_3P x, Vector_3P v, double* w, double* pw, Vector_2 *c, int *splits, double mass=-1, double *q=nullptr); int set_electrons(int s, int nel, Vector_3P x, Vector_3P v, double* w, double* pw, Vector_2 *c, int *splits, double mass=-1, double *q=NULL);
///\en Starts adding new electron: continue with \ref add_split functions. ///\en Starts adding new electron: continue with \ref add_split functions.
@ -141,7 +141,7 @@ public:
///\en gets current electronic coordinates, and (optionally) number of wave packets for each electron ///\en gets current electronic coordinates, and (optionally) number of wave packets for each electron
int get_electrons(int spin, Vector_3P x, Vector_3P v, double* w, double* pw, cdouble *c, int *splits=nullptr, double mass=-1); int get_electrons(int spin, Vector_3P x, Vector_3P v, double* w, double* pw, cdouble *c, int *splits=NULL, double mass=-1);
void eterm_deriv(int ic1,int s1, int c1,int k1,int ic2,int s2, int c2,int j2,cdouble pref, void eterm_deriv(int ic1,int s1, int c1,int k1,int ic2,int s2, int c2,int j2,cdouble pref,
@ -164,8 +164,8 @@ public:
cdouble overlap(int ic1, int s1, int c1,int ic2, int s2, int c2); cdouble overlap(int ic1, int s1, int c1,int ic2, int s2, int c2);
//e same as interaction, but using Hartee factorization (no antisymmetrization) //e same as interaction, but using Hartee factorization (no antisymmetrization)
int interaction_hartree(int flag=0, Vector_3P fi=nullptr, Vector_3P fe_x=nullptr, int interaction_hartree(int flag=0, Vector_3P fi=NULL, Vector_3P fe_x=NULL,
Vector_3P fe_p=nullptr, double *fe_w=nullptr, double *fe_pw=nullptr, Vector_2P fe_c=nullptr); Vector_3P fe_p=NULL, double *fe_w=NULL, double *fe_pw=NULL, Vector_2P fe_c=NULL);
///\en Calculates interaction in the system of ni ions + electrons ///\en Calculates interaction in the system of ni ions + electrons
/// the electonic subsystem must be previously setup by set_electrons, ionic by set_ions /// the electonic subsystem must be previously setup by set_electrons, ionic by set_ions
@ -174,12 +174,12 @@ public:
/// 0x4 -- calculate electronic forces \n /// 0x4 -- calculate electronic forces \n
/// 0x8 -- add electronic forces to the existing arrays \n /// 0x8 -- add electronic forces to the existing arrays \n
/// 0x10 -- calculate internal electronic derivatives only: \n /// 0x10 -- calculate internal electronic derivatives only: \n
/// will not update electronic force arrays, which may be nullptr, \n /// will not update electronic force arrays, which may be NULL, \n
/// the forces may be obtained then using \ref get_el_forces() for all WPs \n /// the forces may be obtained then using \ref get_el_forces() for all WPs \n
/// or separately for each WP using \ref get_wp_force() /// or separately for each WP using \ref get_wp_force()
/// if PBCs are used the coords must be within a range [0, cell) /// if PBCs are used the coords must be within a range [0, cell)
int interaction(int flag=0, Vector_3P fi=nullptr, Vector_3P fe_x=nullptr, int interaction(int flag=0, Vector_3P fi=NULL, Vector_3P fe_x=NULL,
Vector_3P fe_p=nullptr, double *fe_w=nullptr, double *fe_pw=nullptr, Vector_2P fe_c=nullptr); Vector_3P fe_p=NULL, double *fe_w=NULL, double *fe_pw=NULL, Vector_2P fe_c=NULL);
///\en Get electronic forcess in the arrays provided, using calculated internal representation ///\en Get electronic forcess in the arrays provided, using calculated internal representation
/// Valid flag settings are:\n /// Valid flag settings are:\n