Exemple #1
0
// Setup all simulation data, checking it as we go
bool DUQ::setupSimulation()
{
	/* Check each defined Species */
	Messenger::print("*** Checking Species definitions...\n");
	for (Species* sp = species_.first(); sp != NULL; sp = sp->next)
	{
		Messenger::print("--- Species '%s'...\n", sp->name());
		if (!sp->checkSetup(atomTypes_)) return false;
	}

	Messenger::print("\n");
	Messenger::print("*** Setting up Configurations...\n");
	int index = 0;
	for (Configuration* cfg = configurations_.first(); cfg != NULL; cfg = cfg->next, ++index)
	{
		Messenger::print("*** Configuration %2i: '%s'\n", index, cfg->name());

		if (!cfg->setup(worldPool_, atomTypes_, pairPotentialRange_, boxNormalisationPoints_)) return false;
	}

	/* Pair Potentials */
	/* We expect a PairPotential to have been defined for every combination of AtomType used in the system */
	Messenger::print("\n");
	Messenger::print("*** Checking PairPotential definitions....\n");
	int nMissingPots = 0;
	for (AtomType* at1 = atomTypes_.first(); at1 != NULL; at1 = at1->next)
	{
		for (AtomType* at2 = at1; at2 != NULL; at2 = at2->next)
		{
			PairPotential* pot = hasPairPotential(at1, at2);
			if (pot == NULL)
			{
				Messenger::error("A PairPotential between AtomTypes '%s' and '%s' is required, but has not been defined.\n", at1->name(), at2->name());
				++nMissingPots;
			}
		}
	}
	if (nMissingPots > 0) return false;

	/* Finalise AtomTypes */

	// Assign indices to atom types
	Messenger::print("--> Assigning indices to master AtomTypes...\n");
	int id = 0;
	for (AtomType* at = atomTypes_.first(); at != NULL; at = at->next) at->setIndex(id++);

	// Set global AtomType indices in all Configurations
	Messenger::print("--> Setting global AtomType indices in Configurations...\n");
	for (Configuration* cfg = configurations_.first(); cfg != NULL; cfg = cfg->next) cfg->setGlobalAtomTypeIndices(atomTypes_);

	// Create PairPotential matrix
	Messenger::print("--> Creating PairPotential matrix (%ix%i)...\n", atomTypes_.nItems(), atomTypes_.nItems());
	if (!potentialMap_.initialise(atomTypes_, pairPotentials_, pairPotentialRange_)) return false;

	/* Construct Pre/Post-Process Lists */

	Messenger::print("--> Creating Pre/Post-Processing task list...\n");
	// Loop over configurations
	for (Configuration* cfg = configurations_.first(); cfg != NULL; cfg = cfg->next)
	{
		// Loop over Modules, checking for those that have pre- or post-processing steps
		RefListIterator<Module,bool> moduleIterator(cfg->modules());
		while (Module* module = moduleIterator.iterate())
		{
			// Pre-Processing
			if (module->hasPreProcessing())
			{
				// If the Module's instance type is UniqueInstance, check that it is not already in the list
				if (module->instanceType() == Module::UniqueInstance)
				{
					Module* oldModule = findPreProcessingTask(module->name());
					if (!oldModule) preProcessingTasks_.add(module);
				}
				else preProcessingTasks_.add(module);
			}

			// Post-Processing
			if (module->hasPostProcessing())
			{
				// If the Module's instance type is UniqueInstance, check that it is not already in the list
				if (module->instanceType() == Module::UniqueInstance)
				{
					Module* oldModule = findPostProcessingTask(module->name());
					if (!oldModule) postProcessingTasks_.add(module);
				}
				else postProcessingTasks_.add(module);
			}
		}
	}

	if (preProcessingTasks_.nItems() == 0) Messenger::print("--> No pre-processing tasks found.\n");
	else Messenger::print("--> %i pre-processing %s found.\n", preProcessingTasks_.nItems(), preProcessingTasks_.nItems() == 1 ? "task" : "tasks");
	RefListIterator<Module,bool> preProcessingIterator(preProcessingTasks_);
	while (Module* module = preProcessingIterator.iterate())
	{
		Messenger::print("    %s:\n", module->name());
		if (module->nConfigurationTargets() == 0) Messenger::print("      No Configuration targets.\n");
		else
		{
			Messenger::print("      %i Configuration %s:\n", module->nConfigurationTargets(), module->nConfigurationTargets() == 1 ? "target" : "targets");
			RefListIterator<Configuration,bool> configIterator(module->targetConfigurations());
			while (Configuration* cfg = configIterator.iterate()) Messenger::print("      --> %s\n", cfg->name());
		}
		if (module->nSampleTargets() == 0) Messenger::print("      No Sample targets.\n");
		else
		{
			Messenger::print("      %i Sample %s:\n", module->nSampleTargets(), module->nSampleTargets() == 1 ? "target" : "targets");
			RefListIterator<Sample,bool> sampleIterator(module->targetSamples());
			while (Sample* sample = sampleIterator.iterate()) Messenger::print("      --> %s\n", sample->name());
		}
	}

	if (postProcessingTasks_.nItems() == 0) Messenger::print("--> No post-processing tasks found.\n");
	else Messenger::print("--> %i post-processing %s found.\n", postProcessingTasks_.nItems(), postProcessingTasks_.nItems() == 1 ? "task" : "tasks");
	RefListIterator<Module,bool> postProcessingIterator(postProcessingTasks_);
	while (Module* module = postProcessingIterator.iterate())
	{
		Messenger::print("    %s:\n", module->name());
		if (module->nConfigurationTargets() == 0) Messenger::print("      No Configuration targets.\n");
		else
		{
			Messenger::print("      %i Configuration %s:\n", module->nConfigurationTargets(), module->nConfigurationTargets() == 1 ? "target" : "targets");
			RefListIterator<Configuration,bool> configIterator(module->targetConfigurations());
			while (Configuration* cfg = configIterator.iterate()) Messenger::print("      --> %s\n", cfg->name());
		}
		if (module->nSampleTargets() == 0) Messenger::print("      No Sample targets.\n");
		else
		{
			Messenger::print("      %i Sample %s:\n", module->nSampleTargets(), module->nSampleTargets() == 1 ? "target" : "targets");
			RefListIterator<Sample,bool> sampleIterator(module->targetSamples());
			while (Sample* sample = sampleIterator.iterate()) Messenger::print("      --> %s\n", sample->name());
		}
	}

	return true;
}
Exemple #2
0
// Search for Species by name
Species* DUQ::findSpecies(const char* name) const
{
	for (Species* sp = species_.first(); sp != NULL; sp = sp->next) if (strcmp(name,sp->name()) == 0) return sp;
	return NULL;
}