Пример #1
0
// [[Rcpp::export]]
double distance(std::string start, std::string end, std::string units) {
  const double pie = std::atan(1)*4;
  const double degrees2radians = pie / 180;
  std::string coordinates1 = get_coords(start);
  std::string coordinates2 = get_coords(end);

  auto c1 = json::parse(coordinates1);
  auto c2 = json::parse(coordinates2);
  double c10 = std::stod(c1[0].dump());
  double c11 = std::stod(c1[1].dump());
  double c20 = std::stod(c2[0].dump());
  double c21 = std::stod(c2[1].dump());

  const double dLat = degrees2radians * (c21 - c11);
  const double dLon = degrees2radians * (c20 - c10);
  const double lat1 = degrees2radians * c11;
  const double lat2 = degrees2radians * c21;

  const double a = pow(sin(dLat / 2), 2) +
    pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);

  const double dist = radiansToDistance(2 * atan2(sqrt(a), sqrt(1 - a)), units);

  return dist;
}
Пример #2
0
int find_displacement(struct cars *car1, struct cars *car2, float *rx, float *ry)
{
        if (car1 == NULL || car2 == NULL || car1 == car2) {
                return -1;
        }

        float x, y, w, h;
        x = car1->my_car.car_x - (car1->my_car.car->w/2) - (car2->my_car.car_x + (car2->my_car.car->w/2));
        y = car1->my_car.car_y - (car1->my_car.car->h/2) - (car2->my_car.car_y + (car2->my_car.car->h/2));
        w = car1->my_car.car->w + car2->my_car.car->w;
        h = car1->my_car.car->h + car2->my_car.car->h;
        
        struct points *p1 = NULL;
        struct points *p2 = NULL;
        p1 = get_coords(&car1->my_car);
        p2 = get_coords(&car2->my_car);
        struct points *diff = NULL;
        diff = minkowski_difference(p1, p2);
        
        struct points *hull = NULL;
        hull = convex_hull(diff);

        mk_minimum_displacement(hull, rx, ry);

        free_points(&p1);
        free_points(&p2);
        free_points(&diff);
        free_points(&hull);
        
        return 0;
}
Пример #3
0
//------------------------------------------------------------------------------
    int main( int argc, char* argv[])
//------------------------------------------------------------------------------
{
 int i,k;
 point_t points[NP];
 double a,b,c,s; 
 
 if( argc != 2*NP+1 ){    
    printf("\nUsage: $square x1 y1 ... x%d y%d\n\n", NP, NP);  
    if( NP==4){    
        points[0].x=0;    points[0].y=0; 
        points[1].x=1.5;  points[1].y=1.5; 
        points[2].x=0;    points[2].y=1.5; 
        points[3].x=1.5;  points[3].y=0;
    }
    else return(1);    
       
 }
 else{
     if( get_coords( NP, &argv[1], points) == false ){     puts("Input error");    return(1);    }
 }    
      
 
 for( i=0; i< NP; i++)  printf("(%16.8g, %16.8g)\n", points[i].x, points[i].y);
 
 if( isSquare( NP, points) ) puts("Square\n"); else puts("Not a square\n");
 
 return(0);

}
Пример #4
0
void parse_lumpy(std::string lumpy_bede, std::vector<strvcfentry> & entries,
		int min_number_supporting, double max_eval) {
	size_t buffer_size = 2000000;
	char*buffer = new char[buffer_size];
	std::ifstream myfile;
	myfile.open(lumpy_bede.c_str(), std::ifstream::in);
	if (!myfile.good()) {
		std::cout << "Lumpy Parser: could not open file: " << lumpy_bede.c_str()
				<< std::endl;
		exit(0);
	}
	int call_id=entries.size();
	myfile.getline(buffer, buffer_size);
	while (!myfile.eof()) {
		int count = 0;
		short type = -1;
		double eval = 99;

		strregion region;
		int support = 0;
		for (size_t i = 0;
				i < buffer_size && buffer[i] != '\0' && buffer[i] != '\n';
				i++) {
			if (count == 7 && buffer[i - 1] == '\t') {
				eval = atof(&buffer[i]);
			}

			if (count >9 && strncmp(&buffer[i], "TYPE:", 5) == 0) {
				//get type;
				type = get_type(&buffer[i + 5]);
			}

			if (count > 10 && strncmp(&buffer[i], "STRANDS", 7) == 0) {
				//get support val;
				support = get_support(&buffer[i + 7]);
			}

			if (count > 10 && strncmp(&buffer[i], "MAX:", 4) == 0) {
				//get positions;
				region = get_coords(&buffer[i + 4]);
			}

			if (buffer[i] == '\t') {
				count++;
			}
		}

		//filter the parsed SV:
		if (support > min_number_supporting && eval < max_eval) {
			//std::cout<<eval<<" "<<type<<" "<<region.start.pos<<" "<<region.stop.pos<<std::endl;
			//detect overlap with delly:
			//if no overlap construct vcf entry for Lumpy:
			entries.push_back(create_entry(region,eval,support,type,call_id));
			call_id++;
		}
		myfile.getline(buffer, buffer_size);
	}

	myfile.close();
}
Пример #5
0
void TMouse::doClip(COORD start_coords, COORD end_coords) {
	// COORD screen_start = {0, 0};
	COORD first_coords, last_coords;
	DWORD Result;

	get_coords(&start_coords, &end_coords, &first_coords, &last_coords);

	// Allocate the minimal size buffer
	int data_size = 3 + ConsoleInfo.dwSize.X *
		(last_coords.Y - first_coords.Y) + (last_coords.X - first_coords.X);
	HGLOBAL clipboard_data = GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE,
		data_size);
	LPVOID mem_ptr = GlobalLock(clipboard_data);

	// Reset data_size so we can count the actual data size
	data_size = 0;

	// Read the console, put carriage returns at the end of each line if
	// reading more than one line (Paul Brannan 9/17/98)
	for(int j = first_coords.Y; j <= last_coords.Y; j++) {

		// Read line at (0,j)
		COORD coords;
		coords.X = 0;
		coords.Y = j;
		int length = ConsoleInfo.dwSize.X;

		if(j == first_coords.Y) {
			coords.X = first_coords.X;
			length = ConsoleInfo.dwSize.X - first_coords.X;
		} else {
			// Add a carriage return to the end of the previous line
			*((char *)mem_ptr + data_size++) = '\r';
			*((char *)mem_ptr + data_size++) = '\n';
		}

		if(j == last_coords.Y) {
			length -= (ConsoleInfo.dwSize.X - last_coords.X);
		}

		// Read the next line
		ReadConsoleOutputCharacter(hStdout, (LPTSTR)((char *)mem_ptr +
			data_size), length, coords, &Result);
		data_size += Result;

		// Strip the spaces at the end of the line
		if((j != last_coords.Y) && (first_coords.Y != last_coords.Y))
			while(*((char *)mem_ptr + data_size - 1) == ' ') data_size--;
	}
	if(first_coords.Y != last_coords.Y) {
		// Add a carriage return to the end of the last line
		*((char *)mem_ptr + data_size++) = '\r';
		*((char *)mem_ptr + data_size++) = '\n';
	}

	*((char *)mem_ptr + data_size) = 0;
	GlobalUnlock(clipboard_data);

	Clipboard.Copy(clipboard_data);
}
Пример #6
0
void	GSMS::Source::generate_G4(G4GeneralParticleSource*	dst, G4double	dAngle) {

    if (!dst) return;
    for(int i=0; i<m_gamma.size(); i++) {
        G4float	ene = m_gamma[i].first;
        G4float	act = m_gamma[i].second;

        dst->AddaSource(act);
        dst->SetParticleDefinition(G4Gamma::Gamma());
        G4SingleParticleSource*	src = dst->GetCurrentSource();
        src->GetEneDist()->SetMonoEnergy(ene);

        src->GetAngDist()->SetAngDistType("iso");
        src->GetPosDist()->SetPosDisType("Point");
        src->GetEneDist()->SetEnergyDisType("Mono");

        //src->GetPosDist()->SetCentreCoords(get_coords());
        //src->GetPosDist()->SetCentreCoords(G4ThreeVector(1., 0., 0.));
        src->GetPosDist()->SetCentreCoords(G4ThreeVector(m_x, m_y, m_z));

        G4double	basePhi = 0.0;
        m_x != 0.0 ? basePhi = std::atan(m_y/m_x) :
                               m_y > 0 ? basePhi = pi/2 : basePhi = -pi/2;

        if(m_x < 0.0 ) basePhi = -pi + basePhi;

        std::cerr << "X: " << m_x << " Y: " << m_y << " Phi: " << basePhi << std::endl;


        G4double	dPhi = GSMS::get_hull().get_delta_phi(get_coords());
        G4double	baseTheta = pi/2;//TODO

        G4double	dTheta = GSMS::get_hull().get_delta_theta(get_coords());
        std::cerr << "dPhi: " << dPhi*360/2/pi << "; dTheta" << dTheta*360/2/pi << std::endl;

        //dPhi = 3*pi/2/180;//2*pi/2/180;
        //dTheta = 16*pi/2/180;//6*pi/2/180;

        src->GetAngDist()->SetMinPhi(basePhi - dPhi);
        src->GetAngDist()->SetMaxPhi(basePhi + dPhi);
        src->GetAngDist()->SetMinTheta(baseTheta - dTheta);
        src->GetAngDist()->SetMaxTheta(baseTheta + dTheta);
        std::cerr << ene << std::endl;
        std::cerr << act << std::endl;
    }
}
Пример #7
0
void qio_get_coords(int x[], int node, int index){
  /* For this node we have a table */
  if(node == this_node){
    x[0] = lattice[index].x;
    x[1] = lattice[index].y;
    x[2] = lattice[index].z;
    x[3] = lattice[index].t;
  }
  /* For other nodes we require the layout function */
  else
    get_coords( x, node, index );
}
Пример #8
0
void TMouse::move_mouse(COORD start_coords, COORD end_coords) {
	COORD screen_start = {0, 0};
	COORD first_coords, last_coords;
	DWORD Result;

	FillConsoleOutputAttribute(hStdout, normal,
		ConsoleInfo.dwSize.X * ConsoleInfo.dwSize.Y, screen_start, &Result);
					
	get_coords(&start_coords, &end_coords, &first_coords, &last_coords);
	FillConsoleOutputAttribute(hStdout, inverse, ConsoleInfo.dwSize.X * 
		(last_coords.Y - first_coords.Y) + (last_coords.X - first_coords.X),
		first_coords, &Result);
}
Пример #9
0
static int
find_move(char *board)
{
    char *piece;
    int x, y;

    if ((piece = strpbrk(board, "prnbqk")) == NULL)
        return EXIT_FAILURE;

    get_coords(board, piece, &x, &y);

    switch(*piece) {
    case 'p':
        move_pawn(board, x, y);
        break;
    case 'r':
        move_rook(board, x, y);
        break;
    case 'n':
        move_knight(board, x, y);
        break;
    case 'b':
        move_bishop(board, x, y);
        break;
    case 'q':
        move_queen(board, x, y);
        break;
    case 'k':
        move_king(board, x, y);
        break;
    default:
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Пример #10
0
int
verify_solution(const simple_mesh_description<typename VectorType::GlobalOrdinalType>& mesh,
                const VectorType& x, double tolerance, bool verify_whole_domain = false)
{
  typedef typename VectorType::GlobalOrdinalType GlobalOrdinal;
  typedef typename VectorType::ScalarType Scalar;

  int global_nodes_x = mesh.global_box[0][1]+1;
  int global_nodes_y = mesh.global_box[1][1]+1;
  int global_nodes_z = mesh.global_box[2][1]+1;
  Box box;
  copy_box(mesh.local_box, box);

  //num-owned-nodes in each dimension is num-elems+1
  //only if num-elems > 0 in that dimension *and*
  //we are at the high end of the global range in that dimension:
  if (box[0][1] > box[0][0] && box[0][1] == mesh.global_box[0][1]) ++box[0][1];
  if (box[1][1] > box[1][0] && box[1][1] == mesh.global_box[1][1]) ++box[1][1];
  if (box[2][1] > box[2][0] && box[2][1] == mesh.global_box[2][1]) ++box[2][1];

  std::vector<GlobalOrdinal> rows;
  std::vector<Scalar> row_coords;

  int roffset = 0;
  for(int iz=box[2][0]; iz<box[2][1]; ++iz) {
   for(int iy=box[1][0]; iy<box[1][1]; ++iy) {
    for(int ix=box[0][0]; ix<box[0][1]; ++ix) {
      GlobalOrdinal row_id =
          get_id<GlobalOrdinal>(global_nodes_x, global_nodes_y, global_nodes_z,
                                ix, iy, iz);
      Scalar x, y, z;
      get_coords(row_id, global_nodes_x, global_nodes_y, global_nodes_z, x, y, z);

      bool verify_this_point = false;
      if (verify_whole_domain) verify_this_point = true;
      else if (std::abs(x - 0.5) < 0.05 && std::abs(y - 0.5) < 0.05 && std::abs(z - 0.5) < 0.05) {
        verify_this_point = true;
      }

      if (verify_this_point) {
        rows.push_back(roffset);
        row_coords.push_back(x);
        row_coords.push_back(y);
        row_coords.push_back(z);
      }

      ++roffset;
    }
   }
  }

  int return_code = 0;

  const int num_terms = 300;

  err_info<Scalar> max_error;
  max_error.err = 0.0;

  for(size_t i=0; i<rows.size(); ++i) {
    Scalar computed_soln = x.coefs[rows[i]];
    Scalar x = row_coords[i*3];
    Scalar y = row_coords[i*3+1];
    Scalar z = row_coords[i*3+2];
    Scalar analytic_soln = 0.0;
    //set exact boundary-conditions:
    if (x == 1.0) {
      //x==1 is first, we want soln to be 1 even around the edges
      //of the x==1 plane where y and/or z may be 0 or 1...
      analytic_soln = 1;
    }
    else if (x == 0.0 || y == 0.0 || z == 0.0) {
      analytic_soln = 0;
    }
    else if (y == 1.0 || z == 1.0) {
      analytic_soln = 0;
    }
    else {
      analytic_soln = soln(x, y, z, num_terms, num_terms);
    }

#ifdef MINIFE_DEBUG_VERBOSE
std::cout<<"("<<x<<","<<y<<","<<z<<") row "<<rows[i]<<": computed: "<<computed_soln<<",  analytic: "<<analytic_soln<<std::endl;
#endif
    Scalar err = std::abs(analytic_soln - computed_soln);
    if (err > max_error.err) {
      max_error.err = err;
      max_error.computed = computed_soln;
      max_error.analytic = analytic_soln;
      max_error.coords[0] = x;
      max_error.coords[1] = y;
      max_error.coords[2] = z;
    }
  }

  Scalar local_max_err = max_error.err;
  Scalar global_max_err = 0;
#ifdef HAVE_MPI
  MPI_Allreduce(&local_max_err, &global_max_err, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
#else
  global_max_err = local_max_err;
#endif

  if (local_max_err == global_max_err) {
    if (max_error.err > tolerance) {
      std::cout << "max absolute error is "<<max_error.err<<":"<<std::endl;
      std::cout << "   at position ("<<max_error.coords[0]<<","<<max_error.coords[1]<<","<<max_error.coords[2]<<"), "<<std::endl;
      std::cout << "   computed solution: "<<max_error.computed<<",  analytic solution: "<<max_error.analytic<<std::endl;
    }
    else {
      std::cout << "solution matches analytic solution to within "<<tolerance<<" or better."<<std::endl;
    }
  }

  if (global_max_err > tolerance) {
    return_code = 1;
  }

  return return_code;
}
Пример #11
0
/*------------------------------------------------------------------*/
static void milc_get_coords(int coords[], int node, int index, 
			    int dirp[], int squaresize[], int nsquares[]){
  get_coords(coords, node, index); 
}
Пример #12
0
int main( int argc, char *argv[] )
{
    /* loop counters                */
    int i, j,n;

    /* time variables               */
    double starttime, all_starttime, all_ps_time_l, all_ps_time_g, endtime;
    double delta_t, delta_x;
    struct timing data = { 0, 0, 0, 0, 0, 0 };
    
    /* error variable               */
    int ierr;
    
    /* iteration counter            */
    int max_iter, num_iter;

    /* variables for the input file */
    int **grid;
    int mem_fac, msg_fac, cpt_fac;
    double accuracy, tstep_fac, c_fact;
    double min[3], max[3];
    
    /* variables needed for setting */
    /* up the correct topology      */
    int numprocs, myid, oldmyid, ndim, dimlist[3];
    int reorder, periods[3], coords[3], tcoords[3];
/* MIR */
    int ncoords[3];
/* MIR */
    MPI_Comm newcomm;
    int nodenum;
    
    /* variables for the pack/unpack */
    /* routines                      */
    int position, numvars, buffsize;
    
    /* variables for the get_domain  */
    /* routine                       */
    int ppnode[3];
    double lmin[3], lmax[3]; 
    
    /* variables for get_mesh_mem    */
    struct point **setlist;
    
    /* variable for get_time_mem     */
    struct tstep solution;
    
    /* array for the neighbor process ranks */
    int neighbor[6];
    
    /* variables to account for the modified */
    /* domain.                               */
    int start[3], end[3];
    int num_bfaces, num_ifaces;
    int num_bcnodes, max_bcnodes;
    int *bcnode = NULL;
    int nb_of_problems;
    /* Filename for output file      */
    char filename[]="parheat.dat";
    
    /* this is necessary for getting the timing */
    /* information to the root process          */
    double tsend[6] = { 0, 0, 0, 0, 0, 0 };
    double *trecv;
    
    for( i=0 ; i<6 ; i++ ) 
    {
	neighbor[i] = MPI_PROC_NULL;
    }    
    if( ierr=MPI_Init( &argc, &argv ) != 0 )
    {
	printf( "MPI_Init failed with code %d.\n", ierr );
	exit( ierr );
    }
    ADCL_Init();
    MPI_Comm_size( MPI_COMM_WORLD, &numprocs );
    MPI_Comm_rank( MPI_COMM_WORLD, &oldmyid );
    
    get_dimlist( numprocs, &ndim, dimlist );
    
    periods[0] = 0;
    periods[1] = 0;
    periods[2] = 0;
    reorder = 1;
    
    /* take care of unused dimensions */
    for( i=0 ; i<3 ; i++ ) {
        coords[i] = 0;
    }
    if( ierr=MPI_Cart_create( MPI_COMM_WORLD, ndim, dimlist, periods, 
			      reorder, &newcomm ) != 0 ) {
        printf( "MPI_Cart_create failed with code %d.\n", ierr );
        MPI_Abort ( MPI_COMM_WORLD, ierr );
    }
    
    MPI_Comm_rank( newcomm, &myid );
    MPI_Cart_coords( newcomm, myid, ndim, coords );
    
    if( myid == 0  ) {
	printf( "There are %d processes.\n", numprocs );
    }
    
    if ( 0 > read_input( &nb_of_problems, &grid, &mem_fac, &msg_fac, &cpt_fac, \
                         &accuracy, &tstep_fac, &c_fact, min, max, &max_iter  ) ) {
        printf("Error in memory allocation\n");
        return 0;
    }

    /* Start time for solving all pb sizes */
    for( i=0 ; i<ndim ; i++ ) {
        if( ierr = MPI_Cart_shift( newcomm, i, 1, &neighbor[i], &neighbor[i+3] ) != 0 ) {
            printf( "MPI_Cart_shift failed with code %d.\n" , ierr );
            MPI_Abort ( MPI_COMM_WORLD, ierr );
        }
    }
    all_starttime = MPI_Wtime();
    /* Looping for all problem sizes */
    for ( n=0; n<nb_of_problems; n++ ) {
        /* Start time for solving the current pb size */
        starttime = MPI_Wtime();
        /* MIR */
        delta_x = 1.0/(grid[n][1]-1);
        delta_t = tstep_fac * delta_x *delta_x/6.0;
        /* MIR */

        if( get_domain( grid[n], coords, dimlist, ndim,		\
                        min, max, ppnode, lmin, lmax ) != 0 ) {
            printf( "Error in get_domain.\n" );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }

        /* find out the right properties for */
        /* my particular domain.             */
        num_bfaces = 0;
        num_ifaces = 0;
        for( i=0 ; i<3 ; i++ ) {
            if( neighbor[i] != MPI_PROC_NULL ) {
                ppnode[i]++;
                start[i] = 1;
                num_ifaces++;
            }
            else {
                start[i] = 0;
                num_bfaces++;
            }
            if( neighbor[i+3] != MPI_PROC_NULL ) {
                ppnode[i]++;
                end[i] = ppnode[i] - 2;
                num_ifaces++;
            }
            else {
                end[i] = ppnode[i] - 1;
                num_bfaces++;
            }
        }
        
        if( ierr=get_mesh_mem( mem_fac, ppnode, &setlist ) != 0 ) {
            printf( "process %d: get_mesh_mem failed with code %d.\n", 
		myid, ierr );
        }
        if( ierr=get_coords( ppnode, start, end,        \
            lmin, lmax, *setlist ) != 0 ) {
            printf( "parheat: get_coords failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
    
        if( ierr=get_time_mem( ppnode, &solution ) != 0 ) {
            printf( "parheat: get_time_mem failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
        /* compute the maximal possible number   */
        /* of boundary nodes.                    */
        max_bcnodes = 0;
        for( i=0 ; i<6 ; i++ ) {
            if( neighbor[i] == MPI_PROC_NULL ) {
                max_bcnodes += ppnode[ (i+1)%3 ] * ppnode[ (i+2)%3 ];
            }
        }
        if( NULL != bcnode ) {
            free(bcnode);
        }
        if( ierr=get_bcnode_mem( max_bcnodes, &bcnode ) != 0 ) {
            printf( "parheat: get_bcnode_mem failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
    
        if( ierr=find_bcnodes( ppnode, start, end, neighbor,	\
                               bcnode, &num_bcnodes ) != 0 ) {
            printf( "parheat: find_bcnodes failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
    
        if( ierr=set_initial( ppnode, solution.old ) != 0 ) {
            printf( "parheat: set_initial failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
    
        if( ierr=apply_bc( num_bcnodes, *setlist, solution.old,	\
                           bcnode ) != 0 ) {
            printf( "parheat: apply_bc failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
    
        if( ierr=apply_bc( num_bcnodes, *setlist, solution.neu,	\
                           bcnode ) != 0 ) {
            printf( "parheat: apply_bc failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, 1 );
        }
        /* Initialazation of data timing struct */
        data.comp = 0;
        data.comm_start = 0;
        data.recv_end = 0;
        data.send_end = 0;
        data.sync = 0;
        data.total = 0;
        /* Here comes the actual computation ! */
        if( ierr=update_solution( c_fact, delta_t, delta_x, ppnode,   
                                  start, end, neighbor, tstep_fac, accuracy,
                                  msg_fac, cpt_fac, max_iter, &num_iter,
                                  *setlist, &data, &solution, newcomm ) != 0 ) {
            printf( "update_ solution failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, ierr );
        }
   
        endtime = MPI_Wtime();
        data.total = endtime - starttime;
        tsend[0] = data.comp;
        tsend[1] = data.comm_start;
        tsend[2] = data.recv_end;
        tsend[3] = data.send_end;
        tsend[4] = data.sync;
        tsend[5] = data.total;

        if( myid == 0 ) {
            trecv = (double *)malloc( 6*numprocs*sizeof(double) );
        }
        if( ierr = MPI_Gather( (void *)&tsend, 6, MPI_DOUBLE, (void *)trecv, 6,
                               MPI_DOUBLE, 0, newcomm ) != 0 ) {
            printf( "MPI_Gather failed with code %d.\n", ierr );
            MPI_Abort ( MPI_COMM_WORLD, ierr );
        }

        if( myid == 0 ) {
            printf( "grid: %dx%dx%d\n", grid[n][0], grid[n][1], grid[n][2] );
            printf( "mem_fac=%d, msg_fac=%d, cpt_fac=%d\n", mem_fac, msg_fac, cpt_fac );
            printf( "accuracy=%le\n", accuracy );
            printf( "Number of iterations: %d.\n", num_iter );
            
            printf( "\ttime[sec]\t\tcomputation\tcomm_start  \trecv_end" );
            printf( "\tsend_end\tsync\ttotal\n" );
            for( i=0 ; i<numprocs*6 ; i+=6 ) {
                nodenum = i/6;
                MPI_Cart_coords( newcomm, nodenum, ndim, tcoords );
                
                printf( "node %4d coords=", nodenum );
                for( j=0 ; j<3 ; j++ ) {
                    printf( "%3d ", tcoords[j] );
                }
                printf( ":" );
                for( j=0 ; j<6 ; j++ ) {
                    printf( "\t%lf ", trecv[i+j] );
                }
                printf( "\n" );
            }
	
            if( ierr=write_step( ppnode, *setlist, solution.old, filename ) != 0 ) {
                printf( "process %d: write_step failed with code %d.\n", myid, ierr );
                MPI_Abort ( MPI_COMM_WORLD, 1 );
            }
        }
        /* Freeing allocated memory */
        for( i=0; i<mem_fac; i++ ) {
            free(setlist[i]);
        }
        free(setlist);
        free(solution.start);

    }
    /* End of the timer for solving all pb sizes */
    all_ps_time_l = MPI_Wtime() - all_starttime;
    MPI_Reduce ( &all_ps_time_l, &all_ps_time_g, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
    if( 0 == myid ) {
        printf("The overall execution time of all problem sizes is: %f\n", all_ps_time_g );
    }

    ADCL_Finalize();
    MPI_Finalize();
    return 0;
}
Пример #13
0
int mk_oh_solv(LinusProtein *p, int start, int end, Atom3d * acp, Atom3d *sp, Atom3d *tp, 
                int *numvirt, int tryall, FILE *watpdb, int watpdb_write,double ext_rad, double *wat_coord)
{
   
   
    
    //coords of the first parent, second and third   
    double coordsfp[3];
    get_coords(acp,coordsfp);
        
    double coordssp[3];
    get_coords(sp,coordssp);
        
    double coordstp[3];
    get_coords(tp,coordstp);
    
     
    // define the distance, angle, and torsion for the "lower side" sol2
    double ozmvalu1[3]={2.95,130.0,90.0};
    
    double owat1_crds[3];
    _ztox(coordsfp,coordssp,coordstp,ozmvalu1,owat1_crds);
        
    int i;
    int ctr =0; // keep count of water coords
    int isbump = 0;
    int gotone = 0;
    double scale = 0.9;
    double hsd;
    for(i=0;i<p->num_atoms;i++)
    {
        if( strcmp(p->res_names[p->atoms[i].resnum],"NME") && strcmp(p->res_names[p->atoms[i].resnum],"ACE"))
        {
            double atm_crds[3];
            get_coords(&p->atoms[i],atm_crds);
            double atm_rad = scale * p->atoms[i].radius;
            if(!strcmp(p->atoms[i].name, " H  "))
            {
                hsd = 1.94;
            }
            else
            {
                hsd = (ext_rad + atm_rad);
            }
            if(_close(owat1_crds,atm_crds,hsd))
            {
                isbump = 1;
                break;
            }
        
        }
    
    }
    
    // if no bump write out virtual water
    if(!isbump)
    {
        *numvirt += 1;
        
        if(watpdb_write && (tryall || !gotone))
        {
            fprintf(watpdb,"ATOM    900  O   HOH   922    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat1_crds[0],owat1_crds[1],owat1_crds[2],0.0,50.0);
        }
        if(gotone == 0)
        {
           // printf("0 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat1_crds[0];
            //printf("1 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat1_crds[1];
            //printf("2 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat1_crds[2];
           // printf("3 Ctr %d\n",ctr);
            gotone =1;
        }
    }
    else if(watpdb_write && tryall)
    {
                fprintf(watpdb,"ATOM    900  O   HOH   922    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat1_crds[0],owat1_crds[1],owat1_crds[2],0.0,0.0);
    }
    
      // define the distance, angle, and torsion for the "upper side" sol3
    double ozmvalu2[3]={2.95,130.0,-90.0};
    
    double owat3_crds[3];
    _ztox(coordsfp,coordssp,coordstp,ozmvalu2,owat3_crds);
        
    isbump =0;
    for(i=0;i<p->num_atoms;i++)
    {
        if( strcmp(p->res_names[p->atoms[i].resnum],"NME") && strcmp(p->res_names[p->atoms[i].resnum],"ACE"))
        {
            double atm_crds[3];
            get_coords(&p->atoms[i],atm_crds);
            double atm_rad = scale * p->atoms[i].radius;
            if(!strcmp(p->atoms[i].name, " H  "))
            {
                hsd = 1.94;
            }
            else
            {
                hsd = (ext_rad + atm_rad);
            }
            if(_close(owat3_crds,atm_crds,hsd))
            {
                isbump = 1;
                break;
            }
        
        }
    
    }
    
    // if no bump write out virtual water
    if(!isbump)
    {
        *numvirt += 1;
        
        if(watpdb_write && (tryall || !gotone))
        {
            fprintf(watpdb,"ATOM    900  O   HOH   923    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat3_crds[0],owat3_crds[1],owat3_crds[2],0.0,50.0);
        }
        if(gotone == 0)
        {
            //printf("0 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat3_crds[0];
           // printf("1 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat3_crds[1];
           // printf("2 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat3_crds[2];
           // printf("3 Ctr %d\n",ctr);
            gotone =1;
        }
    }
    else if(watpdb_write && tryall)
    {
                fprintf(watpdb,"ATOM    900  O   HOH   923    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat3_crds[0],owat3_crds[1],owat3_crds[2],0.0,0.0);
    }
    
      // define the distance, angle, and torsion for the "near lone pair" sol4
    double ozmvalu3[3]={2.95,130.0,0.0};
    
    double owat4_crds[3];
    _ztox(coordsfp,coordssp,coordstp,ozmvalu3,owat4_crds);
        
    isbump =0;
    for(i=0;i<p->num_atoms;i++)
    {
        if( strcmp(p->res_names[p->atoms[i].resnum],"NME") && strcmp(p->res_names[p->atoms[i].resnum],"ACE"))
        {
            double atm_crds[3];
            get_coords(&p->atoms[i],atm_crds);
            double atm_rad = scale * p->atoms[i].radius;
            if(!strcmp(p->atoms[i].name, " H  "))
            {
                hsd = 1.94;
            }
            else
            {
                hsd = (ext_rad + atm_rad);
            }
            if(_close(owat4_crds,atm_crds,hsd))
            {
                isbump = 1;
                break;
            }
        
        }
    
    }
    
    // if no bump write out virtual water
    if(!isbump)
    {
        *numvirt += 1;
        
        if(watpdb_write && (tryall || !gotone))
        {
            fprintf(watpdb,"ATOM    900  O   HOH   924    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat4_crds[0],owat4_crds[1],owat4_crds[2],0.0,50.0);
        }
        if(gotone == 0)
        {
            //printf("0 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat4_crds[0];
            //printf("1 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat4_crds[1];
           // printf("2 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat4_crds[2];
           // printf("3 Ctr %d\n",ctr);
            gotone =1;
        }
    }
    else if(watpdb_write && tryall)
    {
                fprintf(watpdb,"ATOM    900  O   HOH   924    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat4_crds[0],owat4_crds[1],owat4_crds[2],0.0,0.0);
    }
    
         // define the distance, angle, and torsion for the "far lone pair" sol5
    double ozmvalu4[3]={2.95,-130.0,0.0};
    
    double owat5_crds[3];
    _ztox(coordsfp,coordssp,coordstp,ozmvalu4,owat5_crds);
       
    isbump =0;
    for(i=0;i<p->num_atoms;i++)
    {
        if( strcmp(p->res_names[p->atoms[i].resnum],"NME") && strcmp(p->res_names[p->atoms[i].resnum],"ACE"))
        {
            double atm_crds[3];
            get_coords(&p->atoms[i],atm_crds);
            double atm_rad = scale * p->atoms[i].radius;
            if(!strcmp(p->atoms[i].name, " H  "))
            {
                hsd = 1.94;
            }
            else
            {
                hsd = (ext_rad + atm_rad);
            }
            if(_close(owat5_crds,atm_crds,hsd))
            {
                isbump = 1;
                break;
            }
        
        }
    
    }
    
    // if no bump write out virtual water
    if(!isbump)
    {
        *numvirt += 1;
        
        if(watpdb_write && (tryall || !gotone))
        {
            fprintf(watpdb,"ATOM    900  O   HOH   925    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat5_crds[0],owat5_crds[1],owat5_crds[2],0.0,50.0);
        }
        if(gotone == 0)
        {
            //printf("0 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat5_crds[0];
            //printf("1 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat5_crds[1];
            //printf("2 Ctr %d\n",ctr);
            wat_coord[ctr++]=owat5_crds[2];
            //printf("3 Ctr %d\n",ctr);
            gotone =1;
        }
    }
    else if(watpdb_write && tryall)
    {
                fprintf(watpdb,"ATOM    900  O   HOH   925    %8.3f%8.3f%8.3f%6.2f%6.2f\n",owat5_crds[0],owat5_crds[1],owat5_crds[2],0.0,0.0);
    }
    
    return ctr;
}