Exemplo n.º 1
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void ComputeSiteForces ()
{
  VecR dr, shift;
  real fcVal, rr, rrCut, rri, rri3, uVal;
  int j1, j2, m1, m2, ms1, ms2, n, typeSum;

  rrCut = Sqr (rCut);
  for (n = 0; n < nMol * sitesMol; n ++) VZero (site[n].f);
  uSum = 0.;
  for (m1 = 0; m1 < nMol - 1; m1 ++) {
    for (m2 = m1 + 1; m2 < nMol; m2 ++) {
      VSub (dr, mol[m1].r, mol[m2].r);
      VZero (shift);
      VShiftAll (dr);
      VVAdd (dr, shift);
      rr = VLenSq (dr);
      if (rr < rrCut) {
        ms1 = m1 * sitesMol;
        ms2 = m2 * sitesMol;
        for (j1 = 0; j1 < sitesMol; j1 ++) {
          for (j2 = 0; j2 < sitesMol; j2 ++) {
            typeSum = mSite[j1].typeF + mSite[j2].typeF;
            if (mSite[j1].typeF == mSite[j2].typeF || typeSum == 5) {
              VSub (dr, site[ms1 + j1].r, site[ms2 + j2].r);
              VVAdd (dr, shift);
              rr = VLenSq (dr);
              rri = 1. / rr;
              switch (typeSum) {
                case 2:
                  rri3 = Cube (rri);
                  uVal = 4. * rri3 * (rri3 - 1.);
                  fcVal = 48. * rri3 * (rri3 - 0.5) * rri;
                  break;
                case 4:
                  uVal = 4. * bCon * sqrt (rri);
                  fcVal = uVal * rri;
                  break;
                case 5:
                  uVal = -2. * bCon * sqrt (rri);
                  fcVal = uVal * rri;
                  break;
                case 6:
                  uVal = bCon * sqrt (rri);
                  fcVal = uVal * rri;
                  break;
              }
              VVSAdd (site[ms1 + j1].f, fcVal, dr);
              VVSAdd (site[ms2 + j2].f, - fcVal, dr);
              uSum += uVal;
            }
          }
        }
      }
    }
  }
}
Exemplo n.º 2
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void InitAccels ()
{
  int n;

  DO_MOL {
    VZero (mol[n].ra);
    VZero (mol[n].ra1);
    VZero (mol[n].ra2);
  }
}
Exemplo n.º 3
0
Arquivo: pr_13_1.c Projeto: qnu/mdoch
void InitAngAccels ()
{
  int n;

  DO_MOL {
    VZero (mol[n].sa);
    VZero (mol[n].sa1);
    VZero (mol[n].sa2);
  }
}
Exemplo n.º 4
0
void SingleEvent ()
{
  real vvSum;
  int n;

  NextEvent ();
  if (evIdB < MOL_LIMIT) {
    ProcessCollision ();
    EvalFreePath ();
    ++ collCount;
  } else if (evIdB >= MOL_LIMIT + 100) {
    ProcessCellCrossing ();
    ++ crossCount;
  } else if (evIdB == MOL_LIMIT + 6) {
    UpdateSystem ();
    nextSumTime += intervalSum;
    ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime);
    VZero (vSum);
    vvSum = 0.;
    DO_MOL {
      VVAdd (vSum, mol[n].rv);
      vvSum += VLenSq (mol[n].rv);
    }
    kinEnVal = vvSum * 0.5 / nMol;
    PrintSummary (stdout);
  }
Exemplo n.º 5
0
static FeatureData
Combine_Plane_Plane_Constraints(FeaturePtr c1, FeaturePtr c2)
{
	FeatureData	result;
	Vector		cross;

	/* The result is inconsistent if the planes are parallel and not
	** coincident, a plane if they are parallel and coincident and 
	** their line of intersection otherwise.
	*/

	VCross(c1->f_vector, c2->f_vector, cross);
	if ( VZero(cross) )
	{
		/* The planes are parallel. */
		if ( Point_On_Plane(c1->f_vector, c1->f_value, c2->f_point) )
			return *c1;

		result.f_type = inconsistent_feature;
		return result;
	}

	result.f_type = line_feature;
	result.f_vector = cross;

	/* Project one of the plane points onto the line to get the point. */
	if ( ! IsZero(cross.z) )
	{
		result.f_point.x = ( c2->f_vector.y * c1->f_value -
							 c1->f_vector.y * c2->f_value ) / cross.z;
		result.f_point.y = ( c1->f_vector.x * c2->f_value -
							 c2->f_vector.x * c1->f_value ) / cross.z;
		result.f_point.z = 0;
	}
	else if ( ! IsZero(cross.y) )
	{
		result.f_point.x = ( c1->f_vector.z * c2->f_value -
							 c2->f_vector.z * c1->f_value ) / cross.y;
		result.f_point.y = 0;
		result.f_point.z = ( c2->f_vector.x * c1->f_value -
							 c1->f_vector.x * c2->f_value ) / cross.y;
	}
	else
	{
		result.f_point.x = 0;
		result.f_point.y = ( c2->f_vector.z * c1->f_value -
							 c1->f_vector.z * c2->f_value ) / cross.x;
		result.f_point.z = ( c1->f_vector.y * c2->f_value -
							 c2->f_vector.y * c1->f_value ) / cross.x;
	}

	/* Now project a plane point onto the line to get a better point. */
	/* The reasons relate to interactive dragging along a line constraint,
	** where the distance between the mouse and the origin pt of the line
	** affects the accuracy of the motion. */
	result.f_point = Closest_Line_Point(cross, result.f_point, c1->f_point);

	return result;

}
Exemplo n.º 6
0
Arquivo: pr_15_1.c Projeto: qnu/mdoch
void SingleEvent ()
{
  real vvSum;
  real sp;
  int n;

  NextEvent ();
  if (evIdB < MOL_LIMIT) {
    ProcessCollision ();
    ++ collCount;
  } else if (evIdB < MOL_LIMIT + NDIM * 2 || evIdB >= MOL_LIMIT + 100) {
    ProcessCellCrossing ();
    ++ crossCount;
  } else if (evIdB == MOL_LIMIT + 6) {
    UpdateSystem ();
    nextSumTime += intervalSum;
    ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime);
    VZero (vSum);
    vvSum = 0.;
    sp = 0.;
    DO_MOL {
      VVAdd (vSum, mol[n].rv);
      vvSum += VLenSq (mol[n].rv);
      sp += VDot (mol[n].r, gravField);
    }
    kinEnVal = vvSum * 0.5 / nMol;
    totEnVal = kinEnVal - sp / nMol;
    PrintSummary (stdout);
  } else if (evIdB == MOL_LIMIT + 7) {
Exemplo n.º 7
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void ComputeTorqs ()
{
  RMat rMat;
  VecR dr, t, torqS;
  int j, n;

  DO_MOL {
    VZero (mol[n].ra);
    VZero (torqS);
    for (j = 0; j < sitesMol; j ++) {
      VVAdd (mol[n].ra, site[n * sitesMol + j].f);
      VSub (dr, site[n * sitesMol + j].r, mol[n].r);
      VCross (t, dr, site[n * sitesMol + j].f);
      VVAdd (torqS, t);
    }
    BuildRotMatrix (&rMat, &mol[n].q, 0);
    MVMul (mol[n].torq, rMat.u, torqS);
  }
}
Exemplo n.º 8
0
void ComputeTorqs ()
{
  VecR dr, t, torqS, waB;
  int j, n;

  DO_MOL {
    VZero (mol[n].ra);
    VZero (torqS);
    for (j = 0; j < sitesMol; j ++) {
      VVAdd (mol[n].ra, site[n * sitesMol + j].f);
      VSub (dr, site[n * sitesMol + j].r, mol[n].r);
      VCross (t, dr, site[n * sitesMol + j].f);
      VVAdd (torqS, t);
    }
    MVMulT (waB, mol[n].rMatT.u, torqS);
    VDiv (waB, waB, mInert);
    MVMul (mol[n].wa, mol[n].rMatT.u, waB);
  }
}
Exemplo n.º 9
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void EvalRdf ()
{
  VecR dr, shift;
  real deltaR, normFac, rr;
  int j1, j2, k, m1, m2, ms1, ms2, n, rdfType, typeSum;

  if (countRdf == 0) {
    for (k = 0; k < 3; k ++) {
      for (n = 0; n < sizeHistRdf; n ++) histRdf[k][n] = 0.;
    }
  }
  deltaR = rangeRdf / sizeHistRdf;
  for (m1 = 0; m1 < nMol - 1; m1 ++) {
    for (m2 = m1 + 1; m2 < nMol; m2 ++) {
      VSub (dr, mol[m1].r, mol[m2].r);
      VZero (shift);
      VShiftAll (dr);
      VVAdd (dr, shift);
      rr = VLenSq (dr);
      if (rr < Sqr (rangeRdf)) {
        ms1 = m1 * sitesMol;
        ms2 = m2 * sitesMol;
        for (j1 = 0; j1 < sitesMol; j1 ++) {
          for (j2 = 0; j2 < sitesMol; j2 ++) {
            typeSum = mSite[j1].typeRdf + mSite[j2].typeRdf;
            if (typeSum >= 2) {
              VSub (dr, site[ms1 + j1].r, site[ms2 + j2].r);
              VVAdd (dr, shift);
              rr = VLenSq (dr);
              if (rr < Sqr (rangeRdf)) {
                n = sqrt (rr) / deltaR;
                if (typeSum == 2) rdfType = 0;
                else if (typeSum == 3) rdfType = 1;
                else rdfType = 2;
                ++ histRdf[rdfType][n];
              }
            }
          }
        }
      }
    }
  }
  ++ countRdf;
  if (countRdf == limitRdf) {
    normFac = VProd (region) / (2. * M_PI * Cube (deltaR) *
       Sqr (nMol) * countRdf);
    for (k = 0; k < 3; k ++) {
      for (n = 0; n < sizeHistRdf; n ++)
         histRdf[k][n] *= normFac / Sqr (n - 0.5);
    }
    PrintRdf (stdout);
    countRdf = 0;
  }
}
Exemplo n.º 10
0
Arquivo: pr_13_1.c Projeto: qnu/mdoch
void EvalProps ()
{
  VecR w;
  int n;

  VZero (vSum);
  vvSum = 0.;
  DO_MOL {
    VVAdd (vSum, mol[n].rv);
    vvSum += VLenSq (mol[n].rv);
  }
  vvsSum = 0.;
  DO_MOL vvsSum += mInert * VLenSq (mol[n].sv);
  vvSum += vvsSum;
  kinEnergy.val = 0.5 * vvSum / nMol;
  totEnergy.val = kinEnergy.val + uSum / nMol;
  VZero (w);
  DO_MOL VVAdd (w, mol[n].s);
  dipoleOrder.val = VLen (w) / nMol;
}
Exemplo n.º 11
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void InitVels ()
{
  int n;

  VZero (vSum);
  DO_MOL {
    VRand (&mol[n].rv);
    VScale (mol[n].rv, velMag);
    VVAdd (vSum, mol[n].rv);
  }
  DO_MOL VVSAdd (mol[n].rv, - 1. / nMol, vSum);
}
Exemplo n.º 12
0
Arquivo: pr_13_1.c Projeto: qnu/mdoch
void AdjustTemp ()
{
  real vFac;
  int n;

  VZero (vSum);
  DO_MOL VVAdd (vSum, mol[n].rv);
  DO_MOL VVSAdd (mol[n].rv, - 1. / nMol, vSum);
  vvSum = 0.;
  DO_MOL vvSum += VLenSq (mol[n].rv);
  vFac = velMag / sqrt (vvSum / nMol);
  DO_MOL VScale (mol[n].rv, vFac);
  vvsSum = 0.;
  DO_MOL vvsSum += mInert * VLenSq (mol[n].sv);
  vFac = velMag / sqrt (1.5 * vvsSum / nMol);
  DO_MOL VScale (mol[n].sv, vFac);
}
Exemplo n.º 13
0
void DefineMol ()
{
  int j;

  for (j = 0; j < sitesMol; j ++) VZero (mSite[j].r);
  mSite[0].r.z = -0.0206;
  mSite[1].r.z = 0.0274;
  mSite[2].r.y = 0.240;
  mSite[2].r.z = 0.165;
  mSite[3].r.y = - mSite[2].r.y;
  mSite[3].r.z = mSite[2].r.z;
  VSet (mInert, 0.00980, 0.00340, 0.00640);
  bCon = 183.5;
  mSite[0].typeF = 1;
  mSite[1].typeF = 2;
  mSite[2].typeF = 3;
  mSite[3].typeF = 3;
}
Exemplo n.º 14
0
Arquivo: pr_08_1.c Projeto: qnu/mdoch
void EvalProps ()
{
  VecR w;
  int n;

  VZero (vSum);
  vvSum = 0.;
  DO_MOL {
    VVAdd (vSum, mol[n].rv);
    vvSum += VLenSq (mol[n].rv);
  }
  vvqSum = 0.;
  DO_MOL {
    ComputeAngVel (n, &w);
    vvqSum += VWLenSq (mInert, w);
  }
  vvSum += vvqSum;
  kinEnergy.val = 0.5 * vvSum / nMol;
  totEnergy.val = kinEnergy.val + uSum / nMol;
}
Exemplo n.º 15
0
static FeatureData
Combine_Line_Line_Constraints(FeaturePtr c1, FeaturePtr c2)
{
	Vector		cross;
	double		param1;
	Vector		temp_v1, temp_v2, temp_v3, temp_v4;
	Vector		point1;
	FeatureData	result;

	/* The result is inconsistent if the lines don't intersect, a point
	** otherwise (their point of intersection.
	*/

	VCross(c1->f_vector, c2->f_vector, cross);

	if ( VZero(cross) )
	{
		/* The lines are parallel. */
		if ( Point_On_Line( c1->f_vector, c1->f_point,
							c2->f_point) )
			return *c1;
		else
		{
			result.f_type = inconsistent_feature;
			return result;
		}
	}

	/* They still may or may not intersect. */
	VSub(c1->f_point, c2->f_point, temp_v1);
	VCross(c2->f_vector, temp_v1, temp_v2);
	VCross(c1->f_vector, temp_v1, temp_v3);

	/* temp_v3 and temp_v2 are both perp to temp_v1. */
	/* If temp_v2 is 0, then the lines intersect at c1->f_point1. */
	/* If temp_v3 is 0, then the lines intersect at c1->f_point2. */
	/* If temp_v2 and temp_v3 are parallel, the lines intersect somewhere. */
	/* Otherwise they don't. */
	if ( VZero(temp_v2) )
	{
		result.f_type = point_feature;
		result.f_point = c1->f_point;
		return result;
	}
	else if ( VZero(temp_v2) )
	{
		result.f_type = point_feature;
		result.f_point = c2->f_point;
		return result;
	}

	VCross(temp_v2, temp_v3, temp_v4);
	if ( ! VZero(temp_v4) )
	{
		result.f_type = inconsistent_feature;
		return result;
	}


	/* Get the parameter for the point of intersection. */
	if ( ! IsZero(cross.z) )
		param1 = temp_v2.z / cross.z;
	else if ( ! IsZero(cross.y) )
		param1 = temp_v2.y / cross.y;
	else
		param1 = temp_v2.x / cross.x;

	VScalarMul(c1->f_vector, param1, temp_v1);
	VAdd(temp_v1, c1->f_point, point1);

	result.f_type = point_feature;
	result.f_point = point1;
	return result;
}