NAMD
Public Member Functions | List of all members
LincsSolver Class Reference

#include <LincsSolver.h>

Public Member Functions

void setUpSolver (atomData *, constraintTuple *)
 interface to set up the solver with two given arrays of data. More...
 
void solve ()
 interface to run the solver with CG. More...
 
 LincsSolver (int loop=10000, BigReal r=1e-12)
 
 ~LincsSolver ()
 

Detailed Description

This class is for solving the long-chain constraints for the Martini model with LINCS algorithm by the conjugate gradient method.

Definition at line 13 of file LincsSolver.h.

Constructor & Destructor Documentation

◆ LincsSolver()

LincsSolver::LincsSolver ( int  loop = 10000,
BigReal  r = 1e-12 
)
inline

The constructor of the class.

Definition at line 52 of file LincsSolver.h.

52  : B(NULL), constraintList(NULL), globalIndex(NULL),
53  patchID(NULL), offset(NULL), inv_mass(NULL), ref(NULL), num_atoms(0), num_constraints(0), maxLoops(loop), tol(r) {}

◆ ~LincsSolver()

LincsSolver::~LincsSolver ( )
inline

Definition at line 54 of file LincsSolver.h.

55  {
56  destroy();
57  }

Member Function Documentation

◆ setUpSolver()

void LincsSolver::setUpSolver ( atomData data,
constraintTuple constraints 
)

interface to set up the solver with two given arrays of data.

Definition at line 419 of file LincsSolver.C.

420 {
421  destroy();
422  copy(data, constraints);
423  sortAtom(0, num_atoms-1);
424  sortConstraints();
425  buildBMatrix();
426  #ifdef DEBUG
427  showDataRead(data, constraints);
428  checkConvergence();
429  #endif
430 }

◆ solve()

void LincsSolver::solve ( )

interface to run the solver with CG.

Definition at line 432 of file LincsSolver.C.

References constraintTuple::dist, constraintTuple::i, constraintTuple::j, and Malloc().

433 {
434  BigReal* b = (BigReal*)Malloc(sizeof(BigReal)*num_constraints);
435  BigReal* x = (BigReal*)Malloc(sizeof(BigReal)*num_constraints);
436  multiplyR(b, ref);
437  for(int i = 0; i < num_constraints; ++i)
438  b[i] -= constraintList[i].dist;
439  memset(x, 0 , sizeof(BigReal)*num_constraints);
440  conjugateGradient(x, b);
441  BigReal* tmp = (BigReal*)Malloc(sizeof(BigReal)*num_atoms*3);
442  multiplyC(tmp, x);
443  for(int i = 0; i < num_atoms; ++i)
444  {
445  BigReal m = inv_mass[i];
446  ref[3*i+0] -= tmp[3*i+0]*m;
447  ref[3*i+1] -= tmp[3*i+1]*m;
448  ref[3*i+2] -= tmp[3*i+2]*m;
449  }
450  multiplyR(b, ref);
451  for(int idx = 0; idx < num_constraints; ++idx)
452  {
453  int i = constraintList[idx].i;
454  int j = constraintList[idx].j;
455  BigReal d = constraintList[idx].dist;
456  int col_i = Map(i);
457  int col_j = Map(j);
458  BigReal x1, x2, y1, y2, z1, z2;
459  x1 = ref[3*col_i+0];
460  x2 = ref[3*col_j+0];
461  y1 = ref[3*col_i+1];
462  y2 = ref[3*col_j+1];
463  z1 = ref[3*col_i+2];
464  z2 = ref[3*col_j+2];
465  BigReal l = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
466 
467  b[idx] -= sqrt(2.0*d*d-l);
468  }
469  memset(x, 0 , sizeof(BigReal)*num_constraints);
470  conjugateGradient(x, b);
471  multiplyC(tmp, x);
472  for(int i = 0; i < num_atoms; ++i)
473  {
474  BigReal m = inv_mass[i];
475  ref[3*i+0] -= tmp[3*i+0]*m;
476  ref[3*i+1] -= tmp[3*i+1]*m;
477  ref[3*i+2] -= tmp[3*i+2]*m;
478  }
479  #ifdef DEBUG
480  checkConvergence();
481  #endif
482  free(b);
483  free(x);
484  free(tmp);
485 }
static void * Malloc(size_t size)
Definition: LincsSolver.C:37
double BigReal
Definition: common.h:123

The documentation for this class was generated from the following files: