Skip to content

Commit

Permalink
feat: TemperatureSchedule module (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
trisyoungs committed May 14, 2024
1 parent d572e8c commit 205b28d
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 1 deletion.
120 changes: 120 additions & 0 deletions src/gui/icons/modules/TemperatureSchedule.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/gui/main.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<file>icons/modules/NeutronSQ.svg</file>
<file>icons/modules/GeometryOptimisation.svg</file>
<file>icons/modules/Compare.svg</file>
<file>icons/modules/TemperatureSchedule.svg</file>
</qresource>
<qresource prefix="general">
<file>icons/ff.svg</file>
Expand Down
1 change: 1 addition & 0 deletions src/module/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ EnumOptions<ModuleTypes::ModuleType> moduleTypes_("ModuleType", {{ModuleTypes::A
{ModuleTypes::SDF, "SDF"},
{ModuleTypes::SiteRDF, "SiteRDF"},
{ModuleTypes::SQ, "SQ"},
{ModuleTypes::TemperatureSchedule, "TemperatureSchedule"},
{ModuleTypes::Test, "Test"},
{ModuleTypes::XRaySQ, "XRaySQ"}});

Expand Down
1 change: 1 addition & 0 deletions src/module/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum ModuleType
SiteRDF,
Skeleton,
SQ,
TemperatureSchedule,
Test,
XRaySQ
};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/energy/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Module::ExecutionResult EnergyModule::process(ModuleContext &moduleContext)

// Print parameter summary
if (test_)
Messenger::print("Energy: Production energies will be tested against analytical equivaltnes.\n");
Messenger::print("Energy: Production energies will be tested against analytical equivalents.\n");

Messenger::print("\n");

Expand Down
3 changes: 3 additions & 0 deletions src/modules/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "modules/sdf/sdf.h"
#include "modules/siteRDF/siteRDF.h"
#include "modules/sq/sq.h"
#include "modules/temperatureSchedule/temperatureSchedule.h"
#include "modules/test/test.h"
#include "modules/xRaySQ/xRaySQ.h"

Expand Down Expand Up @@ -88,6 +89,8 @@ ModuleRegistry::ModuleRegistry()
registerProducer<SDFModule>(ModuleTypes::SDF, "Calculate spatial density functions around oriented sites", "Analysis");
registerProducer<SiteRDFModule>(ModuleTypes::SiteRDF, "Calculate radial distribution functions between sites", "Analysis");
registerProducer<SQModule>(ModuleTypes::SQ, "Transform g(r) into unweighted S(Q)", "Correlation Functions");
registerProducer<TemperatureScheduleModule>(ModuleTypes::TemperatureSchedule,
"Adjust the temperature of a configuration during a simulation", "Evolution");
registerProducer<TestModule>(ModuleTypes::Test, "Development Module");
registerProducer<XRaySQModule>(ModuleTypes::XRaySQ, "Calculate x-ray-weighted S(Q)", "Correlation Functions");
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/temperatureSchedule/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dissolve_add_module(temperatureSchedule.h temperatureSchedule)
32 changes: 32 additions & 0 deletions src/modules/temperatureSchedule/process.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors

#include "classes/configuration.h"
#include "modules/temperatureSchedule/temperatureSchedule.h"

// Run main processing
Module::ExecutionResult TemperatureScheduleModule::process(ModuleContext &moduleContext)
{
// Check for zero Configuration targets
if (!targetConfiguration_)
{
Messenger::error("No configuration target set for module '{}'.\n", name());
return ExecutionResult::Failed;
}

// Get the current configuration temperature
auto currentT = targetConfiguration_->temperature();

// Get difference with tergat temperature
auto diffT = targetTemperature_ - currentT;

// Get move amount
auto deltaT = DissolveMath::sgn(diffT) * std::min(fabs(diffT), rate_);

Messenger::print("Difference between current and target temperatures is {} K.\n", fabs(diffT));
Messenger::print("New temperature will be {} K (rate max = {} K / iteration).\n", currentT + deltaT, rate_);

targetConfiguration_->setTemperature(currentT + deltaT);

return ExecutionResult::Success;
}
17 changes: 17 additions & 0 deletions src/modules/temperatureSchedule/temperatureSchedule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors

#include "modules/temperatureSchedule/temperatureSchedule.h"
#include "keywords/configuration.h"
#include "keywords/double.h"

TemperatureScheduleModule::TemperatureScheduleModule() : Module(ModuleTypes::TemperatureSchedule)
{
keywords_.addTarget<ConfigurationKeyword>("Configuration", "Set target configuration for the module", targetConfiguration_);

keywords_.setOrganisation("Options", "Schedule", "Control rate of temperature change on the target configuration.");
keywords_.add<DoubleKeyword>("TargetTemperature", "Target temperature, in Kelvin, to move towards", targetTemperature_,
0.0);
keywords_.add<DoubleKeyword>(
"Rate", "Rate of temperature change, in Kelvin per iteration, to move towards target temperature", rate_, 0.0);
}
32 changes: 32 additions & 0 deletions src/modules/temperatureSchedule/temperatureSchedule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors

#pragma once

#include "module/module.h"

// TemperatureSchedule Module
class TemperatureScheduleModule : public Module
{
public:
TemperatureScheduleModule();
~TemperatureScheduleModule() override = default;

/*
* Definition
*/
private:
// Target configuration
Configuration *targetConfiguration_{nullptr};
// Target temperature
double targetTemperature_{300.0};
// Rate of change, Kelvin per iteration
double rate_{1.0};

/*
* Processing
*/
private:
// Run main processing
Module::ExecutionResult process(ModuleContext &moduleContext) override;
};
23 changes: 23 additions & 0 deletions web/docs/userguide/modules/evolution/temperatureschedule/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: TemperatureSchedule (Module)
linkTitle: TemperatureSchedule
description: Control the temperature of a configuration
---

## Overview

The `TemperatureSchedule` module gives the ability to control the temperature of a configuration, adjusting its towards some target temperature at a predefined maximum rate per iteration of the module.

### Targets

|Keyword|Arguments|Default|Description|
|:------|:--:|:-----:|-----------|
|`Configuration`|`Configuration`|--|{{< required-label >}}Target configuration on which to operate.|

### Schedule

|Keyword|Arguments|Default|Description|
|:------|:--:|:-----:|-----------|
|`Rate`|`double`|`1.0`|Maximal absolute change to add or subtract from the configuration's current temperature each time the module runs in order to move it towards the target temperature. If the difference between the target and current temperatures is less than the defined rate, the configuration temperature is set to the target temperature.|
|`TargetTemperature`|`double`|`300.0`|Target temperature for the configuration.|

0 comments on commit 205b28d

Please sign in to comment.