Made fix adapt work with bond_harmonic.

This commit is contained in:
Stefan Paquay
2017-04-04 12:35:26 -04:00
parent ae56b9ad89
commit 28e86917a0
5 changed files with 153 additions and 5 deletions

View File

@ -16,6 +16,7 @@
#include <stdlib.h>
#include "fix_adapt.h"
#include "atom.h"
#include "bond.h"
#include "update.h"
#include "group.h"
#include "modify.h"
@ -35,7 +36,7 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
enum{PAIR,KSPACE,ATOM};
enum{PAIR,KSPACE,ATOM,BOND};
enum{DIAMETER,CHARGE};
/* ---------------------------------------------------------------------- */
@ -68,6 +69,10 @@ nadapt(0), id_fix_diam(NULL), id_fix_chg(NULL), adapt(NULL)
if (iarg+3 > narg) error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 3;
} else if (strcmp(arg[iarg],"bond") == 0 ){
if (iarg+5 > narg) error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 5;
} else break;
}
@ -103,6 +108,25 @@ nadapt(0), id_fix_diam(NULL), id_fix_chg(NULL), adapt(NULL)
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 6;
} else if (strcmp(arg[iarg],"bond") == 0 ){
if (iarg+5 > narg) error->all(FLERR, "Illegal fix adapt command");
adapt[nadapt].which = BOND;
int n = strlen(arg[iarg+1]) + 1;
adapt[nadapt].bstyle = new char[n];
strcpy(adapt[nadapt].bstyle,arg[iarg+1]);
n = strlen(arg[iarg+2]) + 1;
adapt[nadapt].bparam = new char[n];
adapt[nadapt].bond = NULL;
strcpy(adapt[nadapt].bparam,arg[iarg+2]);
force->bounds(FLERR,arg[iarg+3],atom->ntypes,
adapt[nadapt].ilo,adapt[nadapt].ihi);
if (strstr(arg[iarg+4],"v_") == arg[iarg+4]) {
n = strlen(&arg[iarg+4][2]) + 1;
adapt[nadapt].var = new char[n];
strcpy(adapt[nadapt].var,&arg[iarg+4][2]);
} else error->all(FLERR,"Illegal fix adapt command");
nadapt++;
iarg += 5;
} else if (strcmp(arg[iarg],"kspace") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt command");
adapt[nadapt].which = KSPACE;
@ -160,6 +184,13 @@ nadapt(0), id_fix_diam(NULL), id_fix_chg(NULL), adapt(NULL)
for (int m = 0; m < nadapt; m++)
if (adapt[m].which == PAIR)
memory->create(adapt[m].array_orig,n+1,n+1,"adapt:array_orig");
// allocate bond style arrays:
n = atom->nbondtypes;
for (int m = 0; m < nadapt; ++m)
if (adapt[m].which == BOND)
// For now just use same storage and fake it to be one-dimensional:
memory->create(adapt[m].vector_orig,n+1,"adapt:vector_orig");
}
/* ---------------------------------------------------------------------- */
@ -172,6 +203,10 @@ FixAdapt::~FixAdapt()
delete [] adapt[m].pstyle;
delete [] adapt[m].pparam;
memory->destroy(adapt[m].array_orig);
} else if (adapt[m].which == BOND) {
delete [] adapt[m].bstyle;
delete [] adapt[m].bparam;
memory->destroy(adapt[m].vector_orig);
}
}
delete [] adapt;
@ -282,6 +317,7 @@ void FixAdapt::init()
// setup and error checks
anypair = 0;
anybond = 0;
for (int m = 0; m < nadapt; m++) {
Adapt *ad = &adapt[m];
@ -350,7 +386,48 @@ void FixAdapt::init()
}
delete [] pstyle;
} else if (ad->which == BOND){
ad->bond = NULL;
anybond = 1;
// Use same routines from pair to strip any suffices:
int n = strlen(ad->bstyle) + 1;
char *bstyle = new char[n];
strcpy(bstyle,ad->bstyle);
if (lmp->suffix_enable) {
int len = 2 + strlen(bstyle) + strlen(lmp->suffix);
char *bsuffix = new char[len];
strcpy(bsuffix,bstyle);
strcat(bsuffix,"/");
strcat(bsuffix,lmp->suffix);
ad->bond = force->bond_match(bsuffix);
delete [] bsuffix;
}
// If not set grab regular one instead:
if (ad->bond == NULL) ad->bond = force->bond_match(bstyle);
if (ad->bond == NULL )
error->all(FLERR,"Fix adapt bond style does not exist");
void *ptr = ad->bond->extract(ad->bparam,ad->bdim);
if( comm->me == 0 ){
fprintf(screen,"Attempting to extract %s\n", ad->bparam);
fprintf(screen,"Got back %p\n", ptr);
}
if (ptr == NULL)
error->all(FLERR,"Fix adapt bond style param not supported");
// For bond styles you should use a vector
if (ad->bdim == 1) ad->vector = (double *) ptr;
if (strcmp(force->bond_style,"hybrid") == 0 ||
strcmp(force->bond_style,"hybrid_overlay") == 0)
error->all(FLERR,"Fix adapt does not support bond_style hybrid");
delete [] bstyle;
} else if (ad->which == KSPACE) {
if (force->kspace == NULL)
error->all(FLERR,"Fix adapt kspace style does not exist");
@ -368,7 +445,7 @@ void FixAdapt::init()
}
}
// make copy of original pair array values
// make copy of original pair/bond array values
for (int m = 0; m < nadapt; m++) {
Adapt *ad = &adapt[m];
@ -378,7 +455,12 @@ void FixAdapt::init()
ad->array_orig[i][j] = ad->array[i][j];
}else if (ad->which == PAIR && ad->pdim == 0){
ad->scalar_orig = *ad->scalar;
}else if (ad->which == BOND && ad->bdim == 1){
for (i = ad->ilo; i <= ad->ihi; ++i )
ad->vector_orig[i] = ad->vector[i];
}
}
// fixes that store initial per-atom values
@ -470,6 +552,18 @@ void FixAdapt::change_settings()
ad->array[i][j] = value;
}
// set bond type array values:
} else if (ad->which == BOND) {
if (ad->pdim == 1){
if (scaleflag)
for (i = ad->ilo; i <= ad->ihi; ++i )
ad->vector[i] = value*ad->vector_orig[i];
else
for (i = ad->ilo; i <= ad->ihi; ++i )
ad->vector[i] = value;
}
// set kspace scale factor
} else if (ad->which == KSPACE) {
@ -532,6 +626,14 @@ void FixAdapt::change_settings()
}
}
}
if (anybond) {
for (int m = 0; m < nadapt; ++m ) {
Adapt *ad = &adapt[m];
if (ad->which == BOND) {
ad->bond->reinit();
}
}
}
// reset KSpace charges if charges have changed
@ -554,6 +656,12 @@ void FixAdapt::restore_settings()
ad->array[i][j] = ad->array_orig[i][j];
}
} else if (ad->which == BOND) {
if (ad->pdim == 1) {
for (int i = ad->ilo; i <= ad->ihi; i++)
ad->vector[i] = ad->vector_orig[i];
}
} else if (ad->which == KSPACE) {
*kspace_scale = 1.0;
@ -588,6 +696,7 @@ void FixAdapt::restore_settings()
}
if (anypair) force->pair->reinit();
if (anybond) force->bond->reinit();
if (chgflag && force->kspace) force->kspace->qsum_qsq();
}