Exemple #1
0
void SFGCalculator::DipoleDipoleContribution (morita::MoritaH2O& water, std::vector<double>& dipolePotential) {
	/*********************************************************************************************
	 * Calculation of the frequency shift due to dipole-dipole interaction with neighboring waters
	 *********************************************************************************************/

	//int coord = static_cast<int>(graph->WaterCoordination(&water));
	//int N = graph->NumHBonds(&water);
	//if (N > 3) {
	// two OH bonds on the target water, so we will have two sets of shifts from dipole-dipole interactions

	// the dipole moment derivatives for each OH bond are calculated along the O->H vector, and have a magnitude of the same vector as in the MH paper.
	// For the dipole moment derivative, we can just take the one from the molecular frame and rotate it out to the lab frame
	// Originally the dipole moment derivative was assumed to be along the OH bond... as per DSW below:
	VecR oh1_unit (water.OH1()->normalized());
	VecR oh2_unit (water.OH2()->normalized());

	VecR mu1 (oh1_unit * MU_DERIV_LENGTH);	// these are in atomic units
	VecR mu2 (oh2_unit * MU_DERIV_LENGTH);
	// But perhaps another idea, if taking the actual dipole deriv. doesn't work, is to take the dot product of the actual one with the OH bond unit vector. (?)

	// find the center of mass locations for both target OH bonds
	VecR com1 (water.O()->Position() + (oh1_unit * OH_COM_LENGTH/sfg_units::ANG2BOHR));	// this is in Angstroms...
	VecR com2 (water.O()->Position() + (oh2_unit * OH_COM_LENGTH/sfg_units::ANG2BOHR));

	// Now we go through the calculation of each neighboring H-bonded water (the "source" waters, acting as the "source" of the dipole-dipole interactions) and find the contribution from each OH dipole. First we'll start with source OH's that are bound through the target oxygen. (I'll use the nomenclature of sH to mean source-hydrogen, and tO to mean target oxygen, etc.)

	Atom_ptr_vec hbonds = t.Graph().BondedAtoms(water.O(), hbond);	// all the H's H-bonding to the target O
	for (Atom_it sH = hbonds.begin(); sH != hbonds.end(); sH++) {

		// find the source hydrogen, oxygen, center of mass, oh vector, etc.
		morita::MoritaH2O * sH2O = static_cast<morita::MoritaH2O *>((*sH)->ParentMolecule());
		Atom * sO = sH2O->GetAtom("O");

		VecR sOH (MDSystem::Distance (sO, *sH));
		//VecR sOH (sO->Position().MinVector (sH->Position(), MDSystem::Dimensions()));	// source OH vector
		VecR sCOM (sO->Position() + (sOH.normalized() * (OH_COM_LENGTH/sfg_units::ANG2BOHR)));		// source OH center of mass in angstroms

		// now we have to find the center of mass separation vectors, and also the dipole moment derivatives for each of the source OHs
		VecR sMu (sOH.normalized() * MU_DERIV_LENGTH);		// in atomic units
		// The R vectors point from the source to the target
		VecR R1 (MDSystem::Distance(sCOM,com1));
		VecR R2 (MDSystem::Distance(sCOM,com2));

		// but we are dealing with atomic units, so let's rescale the R vectors to reflect this
		R1 *= sfg_units::ANG2BOHR;
		R2 *= sfg_units::ANG2BOHR;

		dipolePotential[0] += this->DipolePotential (mu1, sMu, R1);		// the result is in atomic units
		dipolePotential[1] += this->DipolePotential (mu2, sMu, R2);
	}

	HDipoleDipoleContribution (water.H1(), mu1, com1, 0, dipolePotential);
	HDipoleDipoleContribution (water.H2(), mu2, com2, 1, dipolePotential);
	//}

	return;
}
Exemple #2
0
  double evaluate(const vectord& x)
  {
    vectord mu1(2), mu2(2), mu3(2);
    matrixd s1(2,2), s2(2,2), s3(2,2);

    mu1 <<= 0,0;
    mu2 <<= 1,1;
    mu3 <<= -4,2;
    
    s1 <<= 1,0, 
      0,1;

    s2 <<= 4,0,
      0,0.6;

    s3 <<= 4,0,
      0,0.6;
  
    return gauss(x,mu1,s1) + gauss(x,mu2,s2) + gauss(x,mu3,s3);
  }
Exemple #3
0
cv::Scalar SSIM::computeSSIM(const cv::Mat& img1, const cv::Mat& img2)
{

	int ht = img1.rows;
	int wt = img1.cols;
	int w = wt - 10;
	int h = ht - 10;

	cv::Mat mu1(h,w,CV_32F), mu2(h,w,CV_32F);
	cv::Mat mu1_sq(h,w,CV_32F), mu2_sq(h,w,CV_32F), mu1_mu2(h,w,CV_32F);
	cv::Mat img1_sq(ht,wt,CV_32F), img2_sq(ht,wt,CV_32F), img1_img2(ht,wt,CV_32F);
	cv::Mat sigma1_sq(h,w,CV_32F), sigma2_sq(h,w,CV_32F), sigma12(h,w,CV_32F);
	cv::Mat tmp1(h,w,CV_32F), tmp2(h,w,CV_32F), tmp3(h,w,CV_32F);
	cv::Mat ssim_map(h,w,CV_32F), cs_map(h,w,CV_32F);

	// mu1 = filter2(window, img1, 'valid');
	applyGaussianBlur(img1, mu1, 11, 1.5);

	// mu2 = filter2(window, img2, 'valid');
	applyGaussianBlur(img2, mu2, 11, 1.5);

	// mu1_sq = mu1.*mu1;
	cv::multiply(mu1, mu1, mu1_sq);
	// mu2_sq = mu2.*mu2;
	cv::multiply(mu2, mu2, mu2_sq);
	// mu1_mu2 = mu1.*mu2;
	cv::multiply(mu1, mu2, mu1_mu2);

	cv::multiply(img1, img1, img1_sq);
	cv::multiply(img2, img2, img2_sq);
	cv::multiply(img1, img2, img1_img2);

	// sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq;
	applyGaussianBlur(img1_sq, sigma1_sq, 11, 1.5);
	sigma1_sq -= mu1_sq;

	// sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq;
	applyGaussianBlur(img2_sq, sigma2_sq, 11, 1.5);
	sigma2_sq -= mu2_sq;

	// sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2;
	applyGaussianBlur(img1_img2, sigma12, 11, 1.5);
	sigma12 -= mu1_mu2;

	// cs_map = (2*sigma12 + C2)./(sigma1_sq + sigma2_sq + C2);
	tmp1 = 2*sigma12 + C2;
	tmp2 = sigma1_sq + sigma2_sq + C2;
	cv::divide(tmp1, tmp2, cs_map);
	// ssim_map = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))./((mu1_sq + mu2_sq + C1).*(sigma1_sq + sigma2_sq + C2));
	tmp3 = 2*mu1_mu2 + C1;
	cv::multiply(tmp1, tmp3, tmp1);
	tmp3 = mu1_sq + mu2_sq + C1;
	cv::multiply(tmp2, tmp3, tmp2);
	cv::divide(tmp1, tmp2, ssim_map);

	// mssim = mean2(ssim_map);
	double mssim = cv::mean(ssim_map).val[0];
	// mcs = mean2(cs_map);
	double mcs = cv::mean(cs_map).val[0];

	cv::Scalar res(mssim, mcs);

	return res;
}
Exemple #4
0
RcppExport SEXP nsem3b(SEXP data,  
		      SEXP theta,
		      SEXP Sigma,
		      SEXP modelpar,
		    SEXP control
		    ) {   

  //  srand ( time(NULL) ); /* initialize random seed: */
  
  Rcpp::NumericVector Theta(theta);  
  Rcpp::NumericMatrix D(data);
  unsigned nobs = D.nrow(), k = D.ncol();
  mat Data(D.begin(), nobs, k, false); // Avoid copying
  Rcpp::NumericMatrix V(Sigma);  
  mat S(V.begin(), V.nrow(), V.ncol()); 
  S(0,0) = 1;
  mat iS = inv(S);
  double detS = det(S);
 

  Rcpp::List Modelpar(modelpar);
  // Rcpp::IntegerVector _nlatent = Modelpar["nlatent"]; unsigned nlatent = _nlatent[0];
  Rcpp::IntegerVector _ny0 = Modelpar["nvar0"]; unsigned ny0 = _ny0[0];
  Rcpp::IntegerVector _ny1 = Modelpar["nvar1"]; unsigned ny1 = _ny1[0];
  Rcpp::IntegerVector _ny2 = Modelpar["nvar2"]; unsigned ny2 = _ny2[0];
  Rcpp::IntegerVector _npred0 = Modelpar["npred0"]; unsigned npred0 = _npred0[0];
  Rcpp::IntegerVector _npred1 = Modelpar["npred1"]; unsigned npred1 = _npred1[0];
  Rcpp::IntegerVector _npred2 = Modelpar["npred2"]; unsigned npred2 = _npred2[0];
  Rcpp::List Control(control);   
  Rcpp::NumericVector _lambda = Control["lambda"]; double lambda = _lambda[0];
  Rcpp::NumericVector _niter = Control["niter"]; double niter = _niter[0];
  Rcpp::NumericVector _Dtol = Control["Dtol"]; double Dtol = _Dtol[0];


  rowvec mu0(ny0), lambda0(ny0);
  rowvec mu1(ny1), lambda1(ny1);
  rowvec mu2(ny2), lambda2(ny2);
  rowvec beta0(npred0); 
  rowvec beta1(npred1); 
  rowvec beta2(npred2);
  rowvec gamma(2);
  rowvec gamma2(2);  
  unsigned pos=0;
  for (unsigned i=0; i<ny0; i++) {
    mu0(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<ny1; i++) {
    mu1(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<ny2; i++) {
    mu2(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<ny0; i++) {
    lambda0(i) = Theta[pos];
    pos++;
  }
  lambda1(0) = 1;
  for (unsigned i=1; i<ny1; i++) {
    lambda1(i) = Theta[pos];
    pos++;
  }
  lambda2(0) = 1;
  for (unsigned i=1; i<ny2; i++) {
    lambda2(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<npred0; i++) {
    beta0(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<npred1; i++) {
    beta1(i) = Theta[pos];
    pos++;
  }
  for (unsigned i=0; i<npred2; i++) {
    beta2(i) = Theta[pos];
    pos++;
  }
  gamma(0) = Theta[pos]; gamma(1) = Theta[pos+1];
  gamma2(0) = Theta[pos+2]; gamma2(1) = Theta[pos+3];

  // cerr << "mu0=" << mu0 << endl;
  // cerr << "mu1=" << mu1 << endl;
  // cerr << "mu2=" << mu2 << endl;
  // cerr << "lambda0=" << lambda0 << endl;
  // cerr << "lambda1=" << lambda1 << endl;
  // cerr << "lambda2=" << lambda2 << endl;
  // cerr << "beta0=" << beta0 << endl;
  // cerr << "beta1=" << beta1 << endl;
  // cerr << "beta2=" << beta2 << endl;
  // cerr << "gamma=" << gamma << endl;
  // cerr << "gamma2=" << gamma2 << endl;
  
  mat lap(nobs,4);
  for (unsigned i=0; i<nobs; i++) {
    rowvec newlap = laNRb(Data.row(i), iS, detS,
			  mu0, mu1, mu2, 
			  lambda0, lambda1, lambda2, 
			  beta0,beta1, beta2, gamma, gamma2,
			  Dtol,niter,lambda);
    lap.row(i) = newlap;
  }

  List  res;
  res["indiv"] = lap;
  res["logLik"] = sum(lap.col(0)) + (3-V.nrow())*log(2.0*datum::pi)*nobs/2;
  res["norm0"] = (3-V.nrow())*log(2*datum::pi)/2;
  return res;
}
Exemple #5
0
void main()
{ int x,y,x0,y0;
  int flag=0;
  int flag1=1;
  struct node * head;
  struct node * head2;
  int m[1]={0};
  int r[21];
  int po1[378]={0};
  char po[24]={0};
  beijing1();
  beijing2();
  choose(po);
  mukuai();
  suiji(r,po1);
  head=creat(po1); 
//  print(head);
  while(1)
  {
    HANDLE hOut,hIn;
    DWORD Result;
    INPUT_RECORD Buf;
 
	 hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	 hIn=GetStdHandle(STD_INPUT_HANDLE);
	 int a[2];
	 do
		{
			ReadConsoleInput(hIn,&Buf,1,&Result);
			if(Buf.EventType==MOUSE_EVENT)
			{
				HandleMouse(Buf.Event.MouseEvent,a);
				x=a[0];
	   			y=a[1];
			}
		} while(!(Buf.EventType==MOUSE_EVENT&&Buf.Event.MouseEvent.dwEventFlags==DOUBLE_CLICK));


  
	HANDLE hOut1,hIn1;
	DWORD Result1;
	INPUT_RECORD Buf1;
	hOut1=GetStdHandle(STD_OUTPUT_HANDLE);
	hIn1=GetStdHandle(STD_INPUT_HANDLE);
	int a0[2];
    do
		{
			ReadConsoleInput(hIn1,&Buf1,1,&Result1);
			if(Buf1.EventType==MOUSE_EVENT)
			{
				HandleMouse1(Buf1.Event.MouseEvent,a0);
				x0=a0[0];
	   			y0=a0[1];
			}
		} while(!(Buf1.EventType==MOUSE_EVENT&&Buf1.Event.MouseEvent.dwEventFlags==DOUBLE_CLICK)); 
     

	//  清屏的按钮
   /*  if(x0>=86&&x0<=100&&y0>=8&&y0<=10)
     {   clear(r,po1,po);
	     free(head);

	     continue;
	 }*/
	  if(x0>=74&&x0<=82&&y0>=25&&y0<=27)	
         flag=save(head);
	 
	  // if(x0>=85&&x0<=93&&y0>=25&&y0<=27)	
       //  open();
	 
	   if(x0>=96&&x0<=104&&y0>=25&&y0<=27)	
	   {   ////// 上次运行的结果
		   if(flag1==1)
			{ flag1=0;
		      //print(head);
		      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
              COORD pos1;
	          pos1.X=0;
		      pos1.Y=60;
	          SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos1);
			}  
		    
		   if(flag==1)
			{ flag=0;
		      print(head);
		      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
              COORD pos1;
	          pos1.X=0;
		      pos1.Y=60;
	          SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos1);
              break; 
			}
		  else if(flag==0)
			{   
			  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
              COORD pos0;
	          pos0.X=10;
		      pos0.Y=32;
	          SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos0);
			  printf("    请您先保存 !    ");
			}
			  //   保存
	 }
		
		

     if(x0>=10&&x0<=51&&y0>=7&&y0<=28)
	 {  x0=x0/2*2;  //   取偶数点
		    if(x>=68&&x<=69&&y>=8&&y<=10)            
			{ 
				mu1(x0,y0-2,po,1);    head2=insert(po,head); // print(head2);  
			}
			          
		    else if(x>=76&&x<=81&&y==9)                
			{ 
			    mu2(x0-4,y0,po,1);    head2=insert(po,head);  // print(head2);
			}     
		    else if(x>=68&&x<=73&&y>=14&&y<=16)        
			{ mu3(x0-2,y0-1,po,1);    head2=insert(po,head);  // print(head2);   
			}    
			else if(x>=76&&x<=81&&y>=14&&y<=16)        
			{ mu4(x0-2,y0-1,po,1);      head2=insert(po,head);  // print(head2);   
			}  
			else if(x>=86&&x<=91&&y>=14&&y<=16)        
			{ mu5(x0-2,y0+1,po,1);      head2=insert(po,head);   // print(head2);   
			}   
			else if(x>=98&&x<=103&&y>=14&&y<=16)       
			{ mu6(x0-5,y0,po,1);      head2=insert(po,head);   // print(head2);    
			}                 
			else if(x>=68&&x<=73&&y>=20&&y<=22)        
			{ mu7(x0,y0-2,po,1);      head2=insert(po,head);  // print(head2);   
			}                 
			else if(x>=76&&x<=81&&y>=20&&y<=22)        
			{ mu8(x0-4,y0-1,po,1);    head2=insert(po,head);  // print(head2);    
			}
			else if(x>=86&&x<=91&&y>=20&&y<=22)        
			{ mu9(x0,y0-2,po,1);      head2=insert(po,head);  // print(head2);   
			}              
			else if(x>=99&&x<=104&&y>=20&&y<=22)       
			{ mu10(x0,y0,po,1);       head2=insert(po,head);  // print(head2);   
			} 
			else if(x>=68&&x<=71&&y>=26&&y<=28)        
			{ mu11(x0-2,y0-1,po,1);   head2=insert(po,head);  // print(head2);    
			}
	}
  }	
}
Exemple #6
0
void choose(char po[24])
{   mu1(68,8,po,0);mu2(76,9,po,0);mu3(68,14,po,0);mu4(76,14,po,0);mu5(86,16,po,0);mu6(98,14,po,0);mu7(68,20,po,0);mu8(76,21,po,0);mu9(88,20,po,0);mu10(100,21,po,0);mu11(68,26,po,0);
}
// GAUSS-LOBATTO QUADRATURE ALONG EDGE
void SetEdgeDataGL_Unst(const mesh& Mesh, 
			int NumQuadPoints, 
			int NumBasisOrder, 
			edge_data_Unst* EdgeData)
{
  // Quick error check
  if (NumQuadPoints<2 || NumQuadPoints>6 || NumBasisOrder<1 || NumBasisOrder>5)
    {
      printf(" \n");
      printf(" Error in SetEdgeData_Unst.cpp \n");
      printf("   NumQuadPoints must be 2,3,4,5, or 6.\n");
      printf("   NumBasisOrder must be 1,2,3,4, or 5.\n");
      printf("     NumQuadPoints = %i\n",NumQuadPoints);
      printf("     NumBasisOrder = %i\n",NumBasisOrder);
      printf("\n");
      exit(1);
    }

  // ---------------------------------
  // Set quadrature weights and points
  // ---------------------------------
  switch( NumQuadPoints )
    {
    case 2:
      EdgeData->GL_wgts1d->set(1,  1.0 );
      EdgeData->GL_wgts1d->set(2,  1.0 );
      
      EdgeData->GL_xpts1d->set(1,  1.0 );
      EdgeData->GL_xpts1d->set(2, -1.0 );
      break;
      
    case 3:
      EdgeData->GL_wgts1d->set(1,  onethird );
      EdgeData->GL_wgts1d->set(2,  4.0*onethird );
      EdgeData->GL_wgts1d->set(3,  onethird );
      
      EdgeData->GL_xpts1d->set(1,  1.0 );
      EdgeData->GL_xpts1d->set(2,  0.0 );
      EdgeData->GL_xpts1d->set(3, -1.0 );
      break;
      
    case 4:
      EdgeData->GL_wgts1d->set(1,  0.5*onethird );
      EdgeData->GL_wgts1d->set(2,  2.5*onethird );
      EdgeData->GL_wgts1d->set(3,  2.5*onethird );
      EdgeData->GL_wgts1d->set(4,  0.5*onethird );
      
      EdgeData->GL_xpts1d->set(1,  1.0  );
      EdgeData->GL_xpts1d->set(2,  osq5 );
      EdgeData->GL_xpts1d->set(3, -osq5 );
      EdgeData->GL_xpts1d->set(4, -1.0  );
      break;
      
    case 5:
      EdgeData->GL_wgts1d->set(1,  0.1  );
      EdgeData->GL_wgts1d->set(2,  49.0/90.0 );
      EdgeData->GL_wgts1d->set(3,  32.0/45.0 );
      EdgeData->GL_wgts1d->set(4,  49.0/90.0 );
      EdgeData->GL_wgts1d->set(5,  0.1 );
      
      EdgeData->GL_xpts1d->set(1,  1.0      );
      EdgeData->GL_xpts1d->set(2,  sq3*osq7 );
      EdgeData->GL_xpts1d->set(3,  0.0      );
      EdgeData->GL_xpts1d->set(4, -sq3*osq7 );
      EdgeData->GL_xpts1d->set(5, -1.0      );        
      break;
      
    case 6:      
      EdgeData->GL_wgts1d->set(1,  0.2*onethird  );
      EdgeData->GL_wgts1d->set(2,  (1.4 - 0.1*sq7)*onethird );
      EdgeData->GL_wgts1d->set(3,  (1.4 + 0.1*sq7)*onethird );
      EdgeData->GL_wgts1d->set(4,  (1.4 + 0.1*sq7)*onethird );
      EdgeData->GL_wgts1d->set(5,  (1.4 - 0.1*sq7)*onethird );
      EdgeData->GL_wgts1d->set(6,  0.2*onethird );
      
      EdgeData->GL_xpts1d->set(1,  1.0                           );
      EdgeData->GL_xpts1d->set(2,  (1/21.0)*sqrt(147.0+42.0*sq7) );
      EdgeData->GL_xpts1d->set(3,  (1/21.0)*sqrt(147.0-42.0*sq7) );
      EdgeData->GL_xpts1d->set(4, -(1/21.0)*sqrt(147.0-42.0*sq7) );
      EdgeData->GL_xpts1d->set(5, -(1/21.0)*sqrt(147.0+42.0*sq7) );
      EdgeData->GL_xpts1d->set(6, -1.0                           );
      break;
    }

  // ---------------------------------
  // Legendre basis functions on the 
  // left and right of each edge
  // ---------------------------------
  const int NumEdges = Mesh.get_NumEdges();
  const int NumBasisComps = (NumBasisOrder*(NumBasisOrder+1))/2;
  dTensor1 xp1(3);
  dTensor1 yp1(3);
  dTensor1 xp2(3);
  dTensor1 yp2(3);
  dTensor1 xy1(2);
  dTensor1 xy2(2);
  dTensor1 mu1(NumBasisComps);
  dTensor1 mu2(NumBasisComps);

  for (int i=1; i<=NumEdges; i++)
    {   
      // Get edge information
      const double x1 = Mesh.get_edge(i,1);
      const double y1 = Mesh.get_edge(i,2);
      const double x2 = Mesh.get_edge(i,3);
      const double y2 = Mesh.get_edge(i,4);
      
      const int e1 = Mesh.get_eelem(i,1);
      const int e2 = Mesh.get_eelem(i,2);

      // Get element information about
      // the two elements that meet at
      // the current edge
      const double Area1 = Mesh.get_area_prim(e1);
      const double Area2 = Mesh.get_area_prim(e2);

      for (int k=1; k<=3; k++)
	{
	  xp1.set(k, Mesh.get_node(Mesh.get_tnode(e1,k),1) );
	  yp1.set(k, Mesh.get_node(Mesh.get_tnode(e1,k),2) );

	  xp2.set(k, Mesh.get_node(Mesh.get_tnode(e2,k),1) );
	  yp2.set(k, Mesh.get_node(Mesh.get_tnode(e2,k),2) );
	}

      const double xc1 = (xp1.get(1) + xp1.get(2) + xp1.get(3))/3.0;
      const double yc1 = (yp1.get(1) + yp1.get(2) + yp1.get(3))/3.0;
      const double xc2 = (xp2.get(1) + xp2.get(2) + xp2.get(3))/3.0;
      const double yc2 = (yp2.get(1) + yp2.get(2) + yp2.get(3))/3.0;

      // quadrature points on the edge
      for (int m=1; m<=NumQuadPoints; m++)
	{
	  // Take integration point s (in [-1,1])
	  // and map to physical domain
	  const double s = EdgeData->GL_xpts1d->get(m);
	  const double x = x1 + 0.5*(s+1.0)*(x2-x1);
	  const double y = y1 + 0.5*(s+1.0)*(y2-y1);

	  // Take physical point (x,y)
	  // and map into the coordinates
	  // of the two triangles that are
	  // adjacent to the current edge
	  xy1.set(1, ((yp1.get(3)-yp1.get(1))*(x-xc1) 
		    + (xp1.get(1)-xp1.get(3))*(y-yc1))/(2.0*Area1) );
	  xy1.set(2, ((yp1.get(1)-yp1.get(2))*(x-xc1) 
		    + (xp1.get(2)-xp1.get(1))*(y-yc1))/(2.0*Area1) );
	  
	  xy2.set(1, ((yp2.get(3)-yp2.get(1))*(x-xc2) 
		    + (xp2.get(1)-xp2.get(3))*(y-yc2))/(2.0*Area2) );
	  xy2.set(2, ((yp2.get(1)-yp2.get(2))*(x-xc2) 
		    + (xp2.get(2)-xp2.get(1))*(y-yc2))/(2.0*Area2) );

	  // Evaluate monomials at locations xy1
	  double xi = xy1.get(1);
	  double xi2 = xi*xi;
	  double xi3 = xi*xi2;
	  double xi4 = xi*xi3;

	  double eta = xy1.get(2);
	  double eta2 = eta*eta;
	  double eta3 = eta*eta2;
	  double eta4 = eta*eta3;

	  switch( NumBasisOrder )
	    {
	    case 5:  // fifth order		    		    
	      mu1.set(15, eta4     );
	      mu1.set(14, xi4      );
	      mu1.set(13, xi2*eta2 );
	      mu1.set(12, eta3*xi  );
	      mu1.set(11, xi3*eta  );
	      
	    case 4:  // fourth order
	      mu1.set(10, eta3     );
	      mu1.set(9,  xi3      );
	      mu1.set(8,  xi*eta2  );
	      mu1.set(7,  eta*xi2  );
	      
	    case 3:  // third order
	      mu1.set(6,  eta2     );
	      mu1.set(5,  xi2      );
	      mu1.set(4,  xi*eta   );		    
	      
	    case 2:  // second order		    
	      mu1.set(3, eta       );
	      mu1.set(2, xi        );
	      
	    case 1:  // first order
	      mu1.set(1, 1.0       );
	      
	      break;		    
	    }
	  
	  // Evaluate monomials at locations xy2
	  xi = xy2.get(1);
	  xi2 = xi*xi;
	  xi3 = xi*xi2;
	  xi4 = xi*xi3;
	  
	  eta = xy2.get(2);
	  eta2 = eta*eta;
	  eta3 = eta*eta2;
	  eta4 = eta*eta3;

	  switch( NumBasisOrder )
	    {
	    case 5:  // fifth order		    		    
	      mu2.set(15, eta4     );
	      mu2.set(14, xi4      );
	      mu2.set(13, xi2*eta2 );
	      mu2.set(12, eta3*xi  );
	      mu2.set(11, xi3*eta  );
	      
	    case 4:  // fourth order
	      mu2.set(10, eta3     );
	      mu2.set(9,  xi3      );
	      mu2.set(8,  xi*eta2  );
	      mu2.set(7,  eta*xi2  );
	      
	    case 3:  // third order
	      mu2.set(6,  eta2     );
	      mu2.set(5,  xi2      );
	      mu2.set(4,  xi*eta   );		    
	      
	    case 2:  // second order		    
	      mu2.set(3, eta       );
	      mu2.set(2, xi        );
	      
	    case 1:  // first order
	      mu2.set(1, 1.0       );
	      
	      break;		    
	    }
	  
	  // Finally, convert monomials to Legendre Polys
	  // on the two adjacent triangle
	  for (int k=1; k<=NumBasisComps; k++)
	    {
	      double tmp1 = 0.0;
	      double tmp2 = 0.0;
	      for (int j=1; j<=k; j++)
		{  
		  tmp1 = tmp1 + Mmat[k-1][j-1]*mu1.get(j);
		  tmp2 = tmp2 + Mmat[k-1][j-1]*mu2.get(j);
		}
	      
	      EdgeData->GL_phi_left->set(i,m,k,  tmp1 );
	      EdgeData->GL_phi_right->set(i,m,k, tmp2 );
	    }
	}
    }
  
}