Exemplo n.º 1
0
/*
 * Evaluate the potential (i.e. the stream function psi) at a particular target location (xt, yt), 
 * given an array of nodes and their expansions 
 */
void evaluate(const Node* nodes, const int node_id, const double *xdata, const double *ydata, const double *mdata,
		const double thetasquared, double * const result, const double xt, const double yt)
{
	// INPUT
	// nodes	array of nodes for the tree of data we're working with
	// node_id	index indicating the node we am considering now (used for recursive call) inside the array of nodes 
	// expansions	array of expansions for these nodes (not needed, we're actually implementing expansion as an attribute of node)
	// xdata	array of x-coordinates of the source-particles (all of them, not just the ones contained in the node. Needed for passing this array down in the recursion)
	// ydata	........ y-coordinates .......................
	// mdata	........ source-values ....................... (vorticities)
	// thetasquared	.
	// xt		x-coordinate of the location of the target
	// yt		y-coordinate .............................
	// OUTPUT
	// result	potential at target location (xt, yt)
	
	
	const Node* const node = nodes + node_id;								// create a pointer to the node we're considering

	if(node->r > -0.5){   													// if this node isn't empty, go on with the evaluation
		if(node->r == 0){ 													// if the node contains only 1 particle 
			const int n_s = node->part_start;								// compute the p2p expansion
			*result += p2p(xdata + n_s, ydata + n_s, mdata + n_s, 1, xt, yt);
			return;
		}
		
		// if the node contains strictly more than one particle, compute the distance between the target and the center of mass of the node 
		double distsquared = ( (node->xcom - xt)*(node->xcom - xt) + (node->ycom - yt)*(node->ycom -yt) ) ; // square of the distance between the target location and the center of mass of the node 

		// recursive algorithm for the evaluation of the potential 			// pseudo-code, cf lecture 4, slide 24
		if( (node->r * node->r) < (distsquared * thetasquared) ){			// if the target and the node are sufficiently far away from each other
																			// return the expansion to particle expression as a potential
			*result += e2p(xt - node->xcom, yt - node->ycom, node->mass, exp_order, node->rxps, node->ixps);
			return;				
																			// and terminate the call to "evaluate"
		} else if(node->child_id == -1){ 									// if they're not sufficiently far away from each other
																			// and if this node is a leaf, 
																			// then we cannot descend deeper into the tree
																			// return the particle-to-particle expansion
			const int n_s = node->part_start;
			const int n_e = node->part_end;
			*result += p2p(xdata + n_s, ydata + n_s, mdata + n_s, n_e - n_s + 1, xt, yt);
			return;
			
		} else {															// in any other case, 
																			// i.e., they are not sufficiently far away from each other, and this node isn't a leaf
																			// continue the descent of the tree
			evaluate(nodes, node->child_id  , xdata, ydata, mdata, thetasquared, result, xt, yt) ;
			evaluate(nodes, node->child_id+1, xdata, ydata, mdata, thetasquared, result, xt, yt) ;
			evaluate(nodes, node->child_id+2, xdata, ydata, mdata, thetasquared, result, xt, yt) ;
			evaluate(nodes, node->child_id+3, xdata, ydata, mdata, thetasquared, result, xt, yt) ;
		}
	}
}
Exemplo n.º 2
0
/*
 * same as "potential", but implemented with O(n^2) p2p expansions
 * without any tree building
 */
void potential_p2p(double theta, 
			  double *xsrc, double *ysrc, double *qsrc, int nsrc,
			  double *xdst, double *ydst, int ndst, double *potdst)
{
	// INPUT
	// theta	parameter used to define which nodes are considered as far neighbors from a certain 2D-location
	// xsrc		array containing the x-coordinates of the source-particles (all)
	// ysrc		.................... y-coordinates .......................
	// qsrc		.................... "masses" (i.e. vorticities) of the source-particles ("source-values")
	// nsrc		number of source particles
	// xdst		array containing the x-coordinates of the target-particles ("destination-particles") (all)
	// ydst		.................... y-coordinates .......................
	// ndst		number of target-particles
	// OUPUT
	// potdst	values of the potential at destination

	// evaluate the potential field at the location of each target point:
	#pragma omp parallel for schedule(static,1)
	for(size_t i=0; i<ndst; i++){
		// compute the potential by particle-to-particle (p2p) expansion
		potdst[i] = p2p(xsrc, ysrc, qsrc, nsrc, xdst[i], ydst[i]);
		// assert that the potential we just computed isn't infinite nor NaN
		assert(std::isfinite(*(potdst+i)));
	}	
}
Exemplo n.º 3
0
MObject MG_poseReader::makePlane(const MVector& p1,const MVector& p2,const MVector& p3){

	MFnMesh meshFn;

	MPoint p1p (p1);
	MPoint p2p (p2);
	MPoint p3p (p3);
	MPointArray pArray;
	pArray.append(p1p);
	pArray.append(p2p);
	pArray.append(p3p);

	MIntArray polyCount;
	polyCount.append(3);
	MIntArray polyConnect;
	polyConnect.append(0);
	polyConnect.append(1);
	polyConnect.append(2);
	

	MFnMeshData data;
	MObject polyData = data.create();

	MStatus stat;
	meshFn.create(3,1,pArray,polyCount,polyConnect,polyData,&stat);
		


	
	return polyData;

}
Exemplo n.º 4
0
int main() {
    // Load images from file
    SimpleImage imgA("a.jpg");
    SimpleImage imgA2("a_2.jpg");
    SimpleImage imgB("b.jpg");
    //float y, i, q;
    // Initialize result image
    SimpleImage result(imgA.width(), imgA.height(), RGBColor(0, 0, 0));
    
    // Iterate over pixels and set color for result image
    for (int y = 0; y < imgA.height(); ++y) {
        for (int x = 0; x < imgA.width(); ++x) {
            RGBColor p1 = imgA(x, y);
            RGBColor p2 = imgA2(x,y);
            RGBColor q1 = imgB(x,y);
            RGBColor q2;
            
            YIQ p1p(p1);
            YIQ p2p(p2);
            
            q2.r = p1p.y;
            q2.g = p1p.i;
            q2.b = p1p.q;
            result.set(x, y, q2);
            
            //printf("RGB: %.2f %.2f %.2f - YIQ %.2f - %.2f - %.2f\n", p.r , p.g , p.b , pp.y, pp.i, pp.q);
        }
    }
    
    // Save result image to file
    result.save("./b_2.jpg");
    //system("pause");
    
    return 0;
}
Exemplo n.º 5
0
opengv::translation_t
opengv::absolute_pose::p2p(
    const AbsoluteAdapterBase & adapter,
    const std::vector<int> & indices )
{
  assert(indices.size()>1);
  return p2p( adapter, indices[0], indices[1] );
}
Exemplo n.º 6
0
static void _direct (PointAccum **points, guint np)
{
  guint i, j;

  for (i=0; i<np; i ++)
    {
      for (j=i+1; j<np; j ++)
        {
          p2p (points[i], points[j]);
        }
    }
}
Exemplo n.º 7
0
void parallel(MPI_Comm comm) {
  int id=0, numprocs, value=42;
  double sum=0.0, gsum=0.0;

  ELG_USER_START("parallel");

  MPI_Comm_size(comm, &numprocs);
  MPI_Comm_rank(comm, &id);
  MPI_Bcast(&value, 1, MPI_INT, numprocs-1, comm);

  sum += sequential(id);
  MPI_Barrier(comm);
  sum += sequential(id);
  MPI_Barrier(comm);
  sum += sequential(id);
  MPI_Allreduce (&sum, &gsum, 1, MPI_DOUBLE, MPI_SUM, comm);

  p2p(comm);

  ELG_USER_END("parallel");
}
Exemplo n.º 8
0
void parallel(MPI_Comm comm) {
  int id=0, numprocs, value=42;
  double sum=0.0, gsum=0.0;

  VT_begin(4);

  MPI_Comm_size(comm, &numprocs);
  MPI_Comm_rank(comm, &id);
  MPI_Bcast(&value, 1, MPI_INT, numprocs-1, comm);

  sum += sequential(id);
  MPI_Barrier(comm);
  sum += sequential(id);
  MPI_Barrier(comm);
  sum += sequential(id);
  MPI_Allreduce (&sum, &gsum, 1, MPI_DOUBLE, MPI_SUM, comm);

  p2p(comm);

  VT_end(4);
}
Exemplo n.º 9
0
int main(int argc, const char *argv[])
{
	int port, n;
	struct sockaddr_in serv_addr;
	struct hostent *server;
	char buffer[1024], temp[25], createport[25];
	bool command_s, exit_s, serv_s = false, logined;
	logined = false;
	if(argc<3){
		fprintf(stderr, "usage %s hostname port", argv[0]);
		exit(0);
	}
	port = atoi(argv[2]);
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if(sockfd<0)
		error("ERROR opening socket");
	server = gethostbyname(argv[1]);
	if(server==NULL){
		fprintf(stderr, "ERROR, no such host");
		exit(0);
	}
	bzero((char*) &serv_addr, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	bcopy((char*) server->h_addr, (char*) &serv_addr.sin_addr.s_addr, server->h_length);
	serv_addr.sin_port = htons(port);
	if(connect(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr))<0)
		error("ERROR connecting");
	printf("Welcome to the system\n");
	bzero(buffer, 1024);
	n = read(sockfd, buffer, 1024);
	printf("%s", buffer);
	while(1){
		printf("\n----------------------------------------------------\n");
		if(!logined)
			printf("1. Register  2. Log In\n");
		else
			printf("1. Account List  2. Exit  3. Pay\n");
		printf("Please enter the service number: ");
		bzero(buffer, 1024);
		scanf("%s", buffer);
		switch(atoi(buffer)){
			case 1:
				if(!logined){
					do{
						printf("Please enter an account name (within 9 characters): ");
						bzero(temp, 25);
						scanf("%s", temp);
						if(strlen(temp)>9)
							printf("Account name is too long, please enter again.\n");
					}while(strlen(temp)>9);
					bzero(buffer, 1024);
					strcpy(buffer, "REGISTER#");
					strcat(buffer, temp);
					bzero(temp, 25);
					printf("Please enter your account balance: ");
					scanf("%s", temp);
					strcat(buffer, "$");
					strcat(buffer, temp);
					command_s = true;
					exit_s = false;
				}
				else{
					bzero(buffer, 1024);
					strcat(buffer, "List");
					command_s = true;
					exit_s = false;
				}
					break;
			case 2:
				if(!logined){
					printf("Please enter your account name: ");
					bzero(buffer, 1024);
					scanf("%s", buffer);
					printf("Please enter your port number: ");
					bzero(temp, 25);
					scanf("%s", temp);
					bzero(createport, 25);
					strcpy(createport, temp);
					strcat(buffer, "#");
					strcat(buffer, temp);
					command_s = true;
					exit_s = false;
				}
				else{
					bzero(buffer, 1024);
					strcat(buffer, "Exit");
					command_s = true;
					exit_s = true;
				}
				break;
			case 3:
				if(!logined){
					printf("Unknown command, please retry\n");
					command_s = false;
					exit_s = false;
				}
				else{//Send "Search#<username>" and get "<ip>#<port>"
					printf("Please enter the account name for payment: ");
					bzero(buffer, 1024);
					strcpy(buffer, "Search#");
					bzero(temp, 25);
					scanf("%s", temp);
					strcat(buffer, temp);
					n = write(sockfd, buffer, 1024);
					if(n<0)
						error("ERROR writing to socket");
					bzero(buffer, 1024);
					n = read(sockfd, buffer, 1024);
					if(buffer[0]=='F'){
						printf("%s", buffer);
						fflush(stdout);
						command_s = false;
						exit_s = false;
					}
					else{//below tell another client for payment, msg to peer: $$$<myname>#<balance>
						char rcvip[25];
						int rcvport, numbersit;
						bzero(rcvip, 25);
						for(n=0;n<strlen(buffer);n++){
							if(buffer[n]=='#'){
								numbersit = n;
								break;
							}
							rcvip[n] = buffer[n];
						}
						bzero(temp, 25);
						for(n=numbersit+1;n<strlen(buffer);n++){
							temp[n-numbersit-1] = buffer[n];
						}
						rcvport = atoi(temp);
						printf("How much for payment: ");
						bzero(temp, 25);
						scanf("%s", temp);
						//create a socket to connect client
						//ip: rcvip, port: rcvport
						printf("%s, %d\n", rcvip, rcvport);
						struct sockaddr_in serv_addr_t;
						struct hostent *server_t;
						int sockfd_t;
						sockfd_t = socket(AF_INET, SOCK_STREAM, 0);
						if(sockfd_t<0)
							error("ERROR opening socket");
						server_t = gethostbyname(rcvip);
						if(server_t==NULL){
							fprintf(stderr, "ERROR, no such host");
							exit(0);
						}
						bzero((char*) &serv_addr_t, sizeof(serv_addr_t));
						serv_addr_t.sin_family = AF_INET;
						bcopy((char*) server_t->h_addr, (char*) &serv_addr_t.sin_addr.s_addr, server->h_length);
						serv_addr_t.sin_port = htons(rcvport);
						if(connect(sockfd_t, (struct sockaddr*) &serv_addr_t, sizeof(serv_addr_t))<0)
							error("ERROR connecting");
						//search myname
						bzero(buffer, 1024);
						strcpy(buffer, "SearchMyname");
						n = write(sockfd, buffer, 1024);
						if(n<0)
							error("ERROR on writing");
						bzero(buffer, 1024);
						n = read(sockfd, buffer, 1024);
						if(n<0)
							error("ERROR on reading");
						//send <myname>#<payment> to peer
						strcat(buffer, "#");
						strcat(buffer, temp);
						n = write(sockfd_t, buffer, 1024);
						if(n<0)
							error("ERROR on writing");
						bzero(buffer, 1024);
						n = read(sockfd_t, buffer, 1024);
						if(n<0)
							error("ERROR on reading");
						printf("%s", buffer);
						fflush(stdout);

						command_s = false;
						exit_s = false;
					}
				}
				break;
			default:
				printf("Unknown command, please retry.\n");
				command_s = false;
				exit_s = false;
				break;
		}
		if(command_s){
			n = write(sockfd, buffer, strlen(buffer));
			if(n<0)
				error("ERROR writing to socket");
			bzero(buffer, 1024);
			n = read(sockfd, buffer, 1024);
			if(buffer[0] == 'A'){
				logined = true;
				if(!serv_s){
					serv_s = true;
					p2p(createport);
				}
			}
			if(n<0)
				error("ERROR reading from socket");
			printf("%s", buffer);
		}
		if(exit_s){
			printf("\n");
			close(sockfd);
			break;
		}
	}

	return 0;
}
Exemplo n.º 10
0
int main()
{
    G4double rot2 = 0*deg;

    Target tar;

    G4ThreeVector p0n( tar.GetLength()/2.0, tar.GetWidth()/2.0, -tar.GetThickness()/2.0);
    G4ThreeVector p1n( tar.GetLength()/2.0,-tar.GetWidth()/2.0, -tar.GetThickness()/2.0);
    G4ThreeVector p2n(-tar.GetLength()/2.0,-tar.GetWidth()/2.0, -tar.GetThickness()/2.0);
    G4ThreeVector p3n(-tar.GetLength()/2.0, tar.GetWidth()/2.0, -tar.GetThickness()/2.0);

    G4ThreeVector p0p( tar.GetLength()/2.0, tar.GetWidth()/2.0, tar.GetThickness()/2.0);
    G4ThreeVector p1p( tar.GetLength()/2.0,-tar.GetWidth()/2.0, tar.GetThickness()/2.0);
    G4ThreeVector p2p(-tar.GetLength()/2.0,-tar.GetWidth()/2.0, tar.GetThickness()/2.0);
    G4ThreeVector p3p(-tar.GetLength()/2.0, tar.GetWidth()/2.0, tar.GetThickness()/2.0);

    G4RotationMatrix rMatrix;
    G4ThreeVector a1(1,0,0);
    G4ThreeVector a2(0,1,0);
    G4ThreeVector a3(-1,0,1);
    G4RotationMatrix rM1; rM1.set(a1, 90.0*deg);
    G4RotationMatrix rM2; rM2.set(a2, 45.0*deg);
    G4RotationMatrix rM3; rM3.set(a3,-45.0*deg + rot2);
    rMatrix = rM1*rM2*rM3;


    //    rMatrix.print(std::cout);

    G4RotationMatrix rotMatrix = rMatrix.inverse();
    rotMatrix.print(std::cout);
    std::cout << "phi=" << rotMatrix.getPhi()/deg << std::endl;
    std::cout << "theta=" << rotMatrix.getTheta()/deg << std::endl;
    std::cout << "psi=" << rotMatrix.getPsi()/deg << std::endl;
    
    G4ThreeVector p0np = rotMatrix*p0n;
    G4ThreeVector p1np = rotMatrix*p1n;
    G4ThreeVector p2np = rotMatrix*p2n;
    G4ThreeVector p3np = rotMatrix*p3n;

    G4ThreeVector p0pp = rotMatrix*p0p;
    G4ThreeVector p1pp = rotMatrix*p1p;
    G4ThreeVector p2pp = rotMatrix*p2p;
    G4ThreeVector p3pp = rotMatrix*p3p;

    std::cout << "p0n: " << p0n << " --> " << p0np << std::endl;
    std::cout << "p1n: " << p1n << " --> " << p1np << std::endl;
    std::cout << "p2n: " << p2n << " --> " << p2np << std::endl;
    std::cout << "p3n: " << p3n << " --> " << p3np << std::endl;

    std::cout << '\n' << std::endl;

    std::cout << "p0p: " << p0p << " --> " << p0pp << std::endl;
    std::cout << "p1p: " << p1p << " --> " << p1pp << std::endl;
    std::cout << "p2p: " << p2p << " --> " << p2pp << std::endl;
    std::cout << "p3p: " << p3p << " --> " << p3pp << std::endl;

    std::cout << "\nCenter of the bottom of the target" << std::endl;
    G4ThreeVector tar_bottom_center = 0.5*(p2np+p3np);
    std::cout << tar_bottom_center << std::endl;

    // to compute the offsets
    // we know that the target is shifted 1.38 cm in the negative x direction
    // of the rotated coordinate system. This was computed in the Notes/TargetOffsetCalcs.ods
    // file through the measurement of images of the target in the mount.

    G4double tar_offset = 1.38*cm;
    G4ThreeVector xp = rotMatrix.colX();
    xp *= -1.0*tar_offset;
    std::cout << "The target is actually offset from the base"
            << "\nof the mount slit. The base of the slit then should be"
            << "\ndisplaced by the following vector" << std::endl;
    std::cout << xp << " (mm)" << std::endl;

    std::cout << "\nThe displacement of the target from the is defined in the FragSimDetConstruction class."
            << "\nThe mount is positioned relative to the position of the target. An absolute"
            << "\nposition is acquired by adding the recently computed offset to the bottom center"
            << "\nof the target." << std::endl;
    std::cout << "\nCenter of mount slit = " << tar_bottom_center+xp << " (mm)" << std::endl;

    G4double tar_overhang = 0.25*cm;     //<-- Calculated in TargetOffsetCalcs.ods
                                         // this is the average value of two methods
    G4double mount_slit_width = 2.54*cm;
    std::cout << "\nThe target overhangs the edge of the mount as well. To account for this overhang"
            << "\nthe mount and sh metal plates are shifted in the +y' direction of the rotated coord"
            << "\nsystem."
            << std::endl;
    G4double yp_shift =-1.0*(0.5*(mount_slit_width - tar.GetWidth()) + tar_overhang);
    G4ThreeVector yp = yp_shift*rotMatrix.colY();
    std::cout << "\nOverhang   = " << tar_overhang/cm << " cm";
    std::cout << "\nShift in yp= " << yp_shift/cm << " cm" << std::endl;

    std::cout << "\nAlso we know that the target is offset by the thickness of the sheet metal"
            << "\nin the new z direction. Therefore, there must be a shift downwards"
            << "\nin the mount along the new z-direction by 0.127 cm."
            << std::endl;

    G4double sh_thickness = 0.127*cm;
    G4ThreeVector zp = rotMatrix.colZ();
    zp *= -1.0*sh_thickness;

    // The following measurements were computed using the 232Th_Inventor_Model_measurements.ods file
    // in the Ubuntu\ One/AnalysisLog folder.
    G4double target_x          =  -0.44*cm;
    G4double target_y          =  -0.01*cm;
    G4double target_z          =  -1.67*cm;

    G4ThreeVector targetPos(target_x, target_y, target_z);
    G4ThreeVector mount_transl = targetPos + tar_bottom_center + xp + yp + zp;
    std::cout << "\n\nThe target offset was " << targetPos << " (mm)" << std::endl;
    std::cout << "\n\nSlit center should then be at the following location: "
            << mount_transl << " (mm)" << std::endl;


    std::cout << "\n\nThe sheet metal inserts used to clamp the target in "
            <<  "\nplace are positioned with the same rotation matrix as "
            <<  "\nthe target but with the following translations"
            << std::endl;

    G4double sh_length = 2.54*cm;
    // The way to compute this is by determining the offset from the center of the
    // target to align the bottom of the insert with the bottom of the target.
    //  These are only aligned in for the 238U data.

    // Prior to rotation and translation, the centers of both the target and the
    // sheet metal will be aligned. The difference can then be computed as :
    G4double sh_shift = 0.5*(tar.GetLength()-sh_length);

    ///////////////////////////////////////////////////////////////////////////////
    // ---------------------------------------------------------------------------- 
    // Compute shift for the top plat
    //
    // The shift will be in the rotated x direction
    G4ThreeVector sh_bot_shift_xp = -1.0*(sh_shift + tar_offset) * rotMatrix.colX();
    G4double bsheet_shift_offset = 0*cm;
    G4double bsheet_shift = 0.47*cm + bsheet_shift_offset;
    sh_bot_shift_xp += bsheet_shift*rotMatrix.colX();
    
    // the next is the actual offset of the sheet metal plate from the bottom of the slit
    // the calculation is found in TargetOffSetCalcs.ods
    G4ThreeVector sh_bot_shift_yp = 0.0*cm * rotMatrix.colY();//    sh_bot_shift += -0.5*yp;

    G4ThreeVector sh_bot_shift_zp = -0.5*(tar.GetThickness()+sh_thickness)*rotMatrix.colZ();

    G4ThreeVector sh_bot_shift = sh_bot_shift_xp + sh_bot_shift_yp + sh_bot_shift_zp;


    ///////////////////////////////////////////////////////////////////////////////
    // ----------------------------------------------------------------------------
    // Compute shift for the bottom plate
    //
    G4ThreeVector sh_top_shift_xp = -1.0*(sh_shift+tar_offset)*rotMatrix.colX();
    // the next is the actual offset of the sheet metal plate from the bottom of the slit
    // the calculation is found in TargetOffSetCalcs.ods
    sh_top_shift_xp += 0.3*cm*rotMatrix.colX();

	G4ThreeVector sh_top_shift_yp = 0.0*cm * rotMatrix.colY();  //    G4ThreeVector  sh_top_shift_yp = 0.5*yp;
    G4ThreeVector sh_top_shift_zp = 0.5*(tar.GetThickness()+sh_thickness)*rotMatrix.colZ();
    G4ThreeVector sh_top_shift = sh_top_shift_xp + sh_top_shift_yp + sh_top_shift_zp;
  

    /////////////////////////////////////////////////////////////////////////////////
    // ------------------------------------------------------------------------------
    // Print results
    //  
    std::cout << "\nRotation (rot2): " << rot2/deg << " degrees" 
              << "\nBot. sh. shift): " << bsheet_shift_offset/cm << " (cm)"
              << "\n--------------------------------------------" << std::endl;
    std::cout << "\nmount_transl   : " << mount_transl << " (mm)" << std::endl;
    std::cout << "\nins_bot_transl : " << sh_bot_shift + targetPos << " (mm)" << std::endl;
    std::cout << "\nins_top_transl : " << sh_top_shift + targetPos << " (mm)" << std::endl;


    return 0;
}