/**
 * 1D crystal
 * Randomize the on-site energies to be between 0 an 1
 * Fix the hopping terms to be 1 for the nearest neighbours and decaying as 1/r^3
 * Fix the dynamical terms to be 1 for the nearest neighbours and decaying as 1/r^3
 *
 * calculate
 * 1/two_particle_localization_length
 * = - lim_{|n-m|--> infty} << ln|<m, m+a|G(z)|n, n+a>| >> / |n-m|
 * where << ... >> represents the average over different configurations of disorder
 *
 * In the current case, we let a = 1 and
 * we want z.real to be at the center of the band
 */
TEST(LocalizationTest, RandomOnSiteEnergy) {
	LatticeShape lattice1D(1);
	int xmax;
	READ_INPUT("input.txt", "int", xmax);


	lattice1D.setXmax(xmax); //xsite = xmax + 1
	int initialSeperation=1; //default value is 1

	/* set up interaction data */
	double onsiteE, hop, dyn;
	bool randomOnsite, randomHop, randomDyn;
	int maxDistance;
	unsigned seed;
	bool longRangeHop, longRangeDyn;
	READ_INPUT("input.txt", "double", onsiteE);
	READ_INPUT("input.txt", "double", hop);
	READ_INPUT("input.txt", "double", dyn);
	READ_INPUT("input.txt", "bool", randomOnsite);
	READ_INPUT("input.txt", "bool", randomHop);
	READ_INPUT("input.txt", "bool", randomDyn);
	READ_INPUT("input.txt", "int", maxDistance);
	READ_INPUT("input.txt", "unsigned", seed);
	READ_INPUT("input.txt", "bool", longRangeHop);
	READ_INPUT("input.txt", "bool", longRangeDyn);
	READ_INPUT("input.txt", "int", initialSeperation);

	int n = xmax/2;
	int nPlusa = n + initialSeperation;
	Basis initialSites(n, nPlusa);

	InteractionData interactionData = { onsiteE, hop, dyn,
			                            randomOnsite, randomHop, randomDyn,
			                            maxDistance, seed,
	                                    longRangeHop, longRangeDyn};

	setUpIndexInteractions(lattice1D, interactionData);

	std::vector< dcomplex > zList;

	double E;
	READ_INPUT("input.txt", "double", E);


	double eta;
	READ_INPUT("input.txt", "double", eta);


	zList.push_back(dcomplex(E, eta));

	std::vector<std::string> fileList;
	//fileList.push_back("GF.txt");
	fileList.push_back("GF.bin");

	calculateAllGreenFunc(lattice1D,  initialSites,
			              interactionData, zList,
	                       fileList);
	// extract Green's function from the file
	CDMatrix gf;
	loadMatrix(fileList[0], gf);

	std::ofstream myFile;
	std::string output = "a_" + itos(initialSeperation)+".txt";

	myFile.open(output.c_str());
	for (int m=n; m<=xmax-initialSeperation; ++m ) {
		dcomplex element = gf(m, m+initialSeperation);
		double G_n_m = std::log( std::abs( element ) );
		myFile << (m-n) << "\t"<< G_n_m << std::endl;
	}
	myFile.close();

	EXPECT_TRUE(true);
}
예제 #2
0
static void* command_thread(void* unused)
{
	lList words;
	lInit(&words, NULL);
	
	(void)unused;

	INIT_INPUT;

	while(1)
	{
		char* command;
		void* remember;
		char* newline;

		INPUT_DECLARE;

		lDestroy(&words, free);

		if(READ_INPUT("Enter a command: ") == NULL)
			break;
		
		if((newline = strchr(input, '\n')) != NULL)
			*newline = '\0';
		
		getWords(&words, input);
		command = (char*)lGet(&words, FIRST, &remember);
		//LOG_DEBUG("Command: %s\n", command);

		if(!strcmp(command, ".") || !strcmp(command, "quit") 
		|| !strcmp(command, "q") || !strcmp(command, "exit"))
		{
			//LOG("\n");
			break;
		}
		/* 
		 * Command: send (client) (filename) 
		 */
		else if(!strcmp(command, "send") || !strcmp(command, "snd")) /* Send a file directly to a client */
		{
			ERROR_ENOUGH_ARGUMENTS(3);

			char* who = NEXT_WORD;
			char* filename = NEXT_WORD;
		
			nlServerSendFile(who, filename);
			
			WARN_TOO_MUCH_ARGUMENTS(3);
		}
		else if(!strcmp(command, "wget")) /* Tell a client to download a file at the given URL */
		{
			ERROR_ENOUGH_ARGUMENTS(4);
			
			                           /* Example: */
			char* who = NEXT_WORD;     /*   who: Client */
			char* address = NEXT_WORD; /*   address: http://some_site.org/some_file.tar.gz */
			char* where = NEXT_WORD;   /*   where: pouet.tgz */

			nlServerSendMessage(who, "W %s$%s", address, where);

			WARN_TOO_MUCH_ARGUMENTS(4);
		}
		else if(!strcmp(command, "ip")) /* Get our ip */
		{
			LOG("LAN IP: %s on port %d.", UPnPgetLanAddr(), getServerPort());
//			LOG("External IP: %s.", UPnPgetExternalAddress());
		}
		else if(!strcmp(command, "list") || !strcmp(command, "ls")) /* List all connected clients */
		{
			nlServerList();
		}
		else if(!strcmp(command, "register")) /* Register on the main server. */
		{
			if(!nlServerStartRegister())
				LOG("Unable to reach the register.");
			else
				LOG("Registered.");
		}
		else if(!strcmp(command, "h")
		     || !strcmp(command, "help"))
		{
			LOG("Non exaustive list of commands:\n"
				"\tls:\tList connected players.\n"
				"\tip:\tPrint local IP address with bound port.\n"
				"\tsend:\tSend to the given client the given file.\n"
				"\tquit:\tExit program.");
		}
		else
			LOG("Sorry, unimplemented command: %s.", cmd);	

		AFTER_INPUT;
	}
	
	lFree(&words);
	signalHandler(0);
	
	UNINIT_INPUT;

#ifndef DISABLE_PHYSICS

	thread_exit();

#else

	quit();
	return NULL;

#endif
}