169
172
for (int m = 0; m < nadapt; m++)
170
173
if (adapt[m].which == PAIR)
171
174
memory->create(adapt[m].array_orig,n+1,n+1,"adapt:array_orig");
176
id_fix_diam = id_fix_chg = NULL;
174
179
/* ---------------------------------------------------------------------- */
194
206
mask |= PRE_FORCE;
195
207
mask |= POST_RUN;
208
mask |= PRE_FORCE_RESPA;
212
/* ----------------------------------------------------------------------
213
if need to restore per-atom quantities, create new fix STORE styles
214
------------------------------------------------------------------------- */
216
void FixAdaptFEP::post_constructor()
218
if (!resetflag) return;
219
if (!diamflag && !chgflag) return;
221
// new id = fix-ID + FIX_STORE_ATTRIBUTE
222
// new fix group = group for this fix
227
char **newarg = new char*[5];
228
newarg[1] = group->names[igroup];
229
newarg[2] = (char *) "STORE";
230
newarg[3] = (char *) "1";
231
newarg[4] = (char *) "1";
234
int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1;
235
id_fix_diam = new char[n];
236
strcpy(id_fix_diam,id);
237
strcat(id_fix_diam,"_FIX_STORE_DIAM");
238
newarg[0] = id_fix_diam;
239
modify->add_fix(5,newarg);
240
fix_diam = (FixStore *) modify->fix[modify->nfix-1];
242
if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
244
double *vec = fix_diam->vstore;
245
double *radius = atom->radius;
246
int *mask = atom->mask;
247
int nlocal = atom->nlocal;
249
for (int i = 0; i < nlocal; i++) {
250
if (mask[i] & groupbit) vec[i] = radius[i];
257
int n = strlen(id) + strlen("_FIX_STORE_CHG") + 1;
258
id_fix_chg = new char[n];
259
strcpy(id_fix_chg,id);
260
strcat(id_fix_chg,"_FIX_STORE_CHG");
261
newarg[0] = id_fix_chg;
262
modify->add_fix(5,newarg);
263
fix_chg = (FixStore *) modify->fix[modify->nfix-1];
265
if (fix_chg->restart_reset) fix_chg->restart_reset = 0;
267
double *vec = fix_chg->vstore;
269
int *mask = atom->mask;
270
int nlocal = atom->nlocal;
272
for (int i = 0; i < nlocal; i++) {
273
if (mask[i] & groupbit) vec[i] = q[i];
199
282
/* ---------------------------------------------------------------------- */
201
284
void FixAdaptFEP::init()
288
// allow a dynamic group only if ATOM attribute not used
290
if (group->dynamic[igroup])
291
for (int i = 0; i < nadapt; i++)
292
if (adapt[i].which == ATOM)
293
error->all(FLERR,"Cannot use dynamic group with fix adapt/fep atom");
205
295
// setup and error checks
218
308
if (ad->which == PAIR) {
221
Pair *pair = force->pair_match(ad->pstyle,1);
222
if (pair == NULL) error->all(FLERR,"Fix adapt/fep pair style does not exist");
312
if (lmp->suffix_enable) {
314
strcpy(psuffix,ad->pstyle);
316
strcat(psuffix,lmp->suffix);
317
pair = force->pair_match(psuffix,1);
319
if (pair == NULL) pair = force->pair_match(ad->pstyle,1);
321
error->all(FLERR, "Fix adapt/fep pair style does not exist");
223
322
void *ptr = pair->extract(ad->pparam,ad->pdim);
225
324
error->all(FLERR,"Fix adapt/fep pair style param not supported");
272
if (comm->me == 0 && screen) {
273
for (int m = 0; m < nadapt; m++) {
274
Adapt *ad = &adapt[m];
275
if (ad->which == PAIR && ad->pdim == 2) {
276
fprintf(screen, "###ADAPT original %s %s\n", ad->pstyle, ad->pparam);
277
fprintf(screen, "###ADAPT I J old_param\n");
278
for (i = ad->ilo; i <= ad->ihi; i++)
279
for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
280
fprintf(screen, "###ADAPT %2d %2d %9.5f\n", i, j,
281
ad->array_orig[i][j]);
370
// fixes that store initial per-atom values
373
int ifix = modify->find_fix(id_fix_diam);
374
if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
375
fix_diam = (FixStore *) modify->fix[ifix];
378
int ifix = modify->find_fix(id_fix_chg);
379
if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
380
fix_chg = (FixStore *) modify->fix[ifix];
383
if (strstr(update->integrate_style,"respa"))
384
nlevels_respa = ((Respa *) update->integrate)->nlevels;
289
387
/* ---------------------------------------------------------------------- */
296
394
/* ---------------------------------------------------------------------- */
396
void FixAdaptFEP::setup_pre_force_respa(int vflag, int ilevel)
398
if (ilevel < nlevels_respa-1) return;
399
setup_pre_force(vflag);
402
/* ---------------------------------------------------------------------- */
298
404
void FixAdaptFEP::pre_force(int vflag)
300
406
if (nevery == 0) return;
314
420
/* ---------------------------------------------------------------------- */
422
void FixAdaptFEP::pre_force_respa(int vflag, int ilevel, int)
424
if (ilevel < nlevels_respa-1) return;
428
/* ---------------------------------------------------------------------- */
316
430
void FixAdaptFEP::post_run()
318
432
if (resetflag) restore_settings();
349
463
for (i = ad->ilo; i <= ad->ihi; i++)
350
464
for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
351
465
ad->array[i][j] = value;
354
if (comm->me == 0 && screen) {
355
fprintf(screen, "###ADAPT change %s %s\n", ad->pstyle, ad->pparam);
356
fprintf(screen, "###ADAPT I J param\n");
357
for (i = ad->ilo; i <= ad->ihi; i++)
358
for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
359
fprintf(screen, "###ADAPT %2d %2d %9.5f\n", i, j, ad->array[i][j]);
365
468
// set kspace scale factor
367
470
} else if (ad->which == KSPACE) {
368
471
*kspace_scale = value;
473
// set per atom values, also make changes for ghost atoms
370
475
} else if (ad->which == ATOM) {
372
// set radius from diameter
477
// reset radius from diameter
373
478
// also scale rmass to new value
375
480
if (ad->aparam == DIAMETER) {
381
486
double *radius = atom->radius;
382
487
double *rmass = atom->rmass;
383
488
int *mask = atom->mask;
384
int natom = atom->nlocal + atom->nghost;
489
int nlocal = atom->nlocal;
490
int nall = nlocal + atom->nghost;
386
492
if (mflag == 0) {
387
for (i = 0; i < natom; i++)
493
for (i = 0; i < nall; i++)
388
494
if (atype[i] >= ad->ilo && atype[i] <= ad->ihi)
389
495
if (mask[i] & groupbit)
390
496
radius[i] = 0.5*value;
392
for (i = 0; i < natom; i++)
498
for (i = 0; i < nall; i++)
393
499
if (atype[i] >= ad->ilo && atype[i] <= ad->ihi)
394
500
if (mask[i] & groupbit) {
395
501
density = rmass[i] / (4.0*MY_PI/3.0 *
403
509
int *atype = atom->type;
404
510
double *q = atom->q;
405
511
int *mask = atom->mask;
406
int natom = atom->nlocal + atom->nghost;
512
int nlocal = atom->nlocal;
513
int nall = nlocal + atom->nghost;
408
for (i = 0; i < natom; i++)
515
for (i = 0; i < nall; i++)
409
516
if (atype[i] >= ad->ilo && atype[i] <= ad->ihi)
410
517
if (mask[i] & groupbit) q[i] = value;
413
if (comm->me == 0 && screen) {
414
fprintf(screen, "###ADAPT change charge\n");
415
fprintf(screen, "###ADAPT atom I q\n");
416
for (i = 0; i < atom->nlocal; i++)
417
if (atype[i] >= ad->ilo && atype[i] <= ad->ihi)
418
if (mask[i] & groupbit)
419
fprintf(screen, "###ADAPT %5d %2d %9.5f\n", i, atype[i], q[i]);
430
526
// and also offset and tail corrections
432
528
if (anypair) force->pair->reinit();
530
// reset KSpace charges if charges have changed
532
if (chgflag && force->kspace) force->kspace->qsum_qsq();
435
535
/* ----------------------------------------------------------------------
452
552
*kspace_scale = 1.0;
454
554
} else if (ad->which == ATOM) {
558
double *vec = fix_diam->vstore;
559
double *radius = atom->radius;
560
double *rmass = atom->rmass;
561
int *mask = atom->mask;
562
int nlocal = atom->nlocal;
564
for (int i = 0; i < nlocal; i++)
565
if (mask[i] & groupbit) {
566
density = rmass[i] / (4.0*MY_PI/3.0 *
567
radius[i]*radius[i]*radius[i]);
569
rmass[i] = 4.0*MY_PI/3.0 * radius[i]*radius[i]*radius[i] * density;
573
double *vec = fix_chg->vstore;
575
int *mask = atom->mask;
576
int nlocal = atom->nlocal;
578
for (int i = 0; i < nlocal; i++)
579
if (mask[i] & groupbit) q[i] = vec[i];
459
584
if (anypair) force->pair->reinit();
585
if (chgflag && force->kspace) force->kspace->qsum_qsq();
588
/* ----------------------------------------------------------------------
589
initialize one atom's storage values, called when atom is created
590
------------------------------------------------------------------------- */
592
void FixAdaptFEP::set_arrays(int i)
594
if (fix_diam) fix_diam->vstore[i] = atom->radius[i];
595
if (fix_chg) fix_chg->vstore[i] = atom->q[i];