Skip to content

Commit

Permalink
Merge pull request #25970 from dschwen/tc_thread_25969
Browse files Browse the repository at this point in the history
Enable threaded calculations with thermochimica
  • Loading branch information
dschwen authored Dec 9, 2023
2 parents 4b3cebd + 7070a8b commit a95084c
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This UserObject is designed for use with thermochemistry library Thermochimica.
[`ThermochimicaElementData`](ThermochimicaElementData.md) performs Thermochimica calculations on elements.

!alert note
This object can only be set up using teh [ChemicalComposition](ChemicalCompositionAction.md) action
This object can only be set up using the [ChemicalComposition](ChemicalCompositionAction.md) action

Thermochimica is called by this object at every execute (please see the Thermochimica user manual
for more details), and the data required to re-initialize Thermochimica calculations is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,14 @@ This UserObject is designed for use with thermochemistry library Thermochimica.
## Description

[`ThermochimicaNodalData`](ThermochimicaNodalData.md) performs Thermochimica calculations at nodes.
In this UserObject, the masses of elements included in the vector variable [!param](/UserObjects/ThermochimicaNodalData/elements) are input
to the Fortan 90 module Thermochimica, along with the temperature and pressure. Optionally, the
user may disable Thermochimica calculation re-initialization by setting [!param](/UserObjects/ThermochimicaNodalData/reinit_type) to `none`.
This may reduce memory use in the calculation, but will likely greatly increase the length of each
call to Thermochimica.

!alert note
Currently this object is designed to only work with constant monomial type variables (one DOF per element)!
This object can only be set up using the [ChemicalComposition](ChemicalCompositionAction.md) action

Thermochimica is called by this object at every execute (please see the Thermochimica user manual
for more details), and the data required to re-initialize Thermochimica calculations is
saved/loaded if re-initialization is enabled.

If the optional variable [!param](/UserObjects/ThermochimicaNodalData/output_phases) is set to a non-empty list of phase names, then concentration
data corresponding to these phases will be output. These phase names must exactly match those specified
in the datafile used for Thermochimica calculations. Similarly, if [!param](/UserObjects/ThermochimicaNodalData/output_species) is a non-empty list
of `phase:species` pairs, these will be parsed and the specified species in the specified phases will be
located in Thermochimica output and stored for later output via an AuxKernel.

If [!param](/UserObjects/ThermochimicaNodalData/output_element_potentials) is a non-empty list formatted as `any_string:element_name`, then the chemical
potentials of the elements in the list are output to the variables specified in the list.

## Example Input Syntax

!syntax parameters /UserObjects/ThermochimicaNodalData
Expand Down
28 changes: 26 additions & 2 deletions modules/chemical_reactions/include/userobjects/ThermochimicaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ThermochimicaDataBase : public ThermochimicaDataBaseParent<is_nodal>
public:
static InputParameters validParams();
ThermochimicaDataBase(const InputParameters & parameters);
~ThermochimicaDataBase();

virtual void initialize() override;
virtual void execute() override;
Expand Down Expand Up @@ -70,8 +71,16 @@ class ThermochimicaDataBase : public ThermochimicaDataBaseParent<is_nodal>
const Data & getData(dof_id_type id) const;

protected:
// get current node or element ID
auto currentID();
// child process routine to dispatch thermochimica calculations
void server();

// helper to wait on a socket read
template <typename T>
void expect(T expect_msg);

// send message to socket
template <typename T>
void notify(T send_msg);

const VariableValue & _pressure;
const VariableValue & _temperature;
Expand Down Expand Up @@ -124,6 +133,21 @@ class ThermochimicaDataBase : public ThermochimicaDataBaseParent<is_nodal>
/// Mass unit for output species
const enum class OutputMassUnit { MOLES, FRACTION } _output_mass_unit;

/// communication socket
int _socket;

/// child PID
pid_t _pid;

/// shared memory pointer for dof_id_type values
dof_id_type * _shared_dofid_mem;

/// shared memory pointer for Real values
Real * _shared_real_mem;

// current node or element ID
dof_id_type _current_id;

using ThermochimicaDataBaseParent<is_nodal>::isCoupled;
using ThermochimicaDataBaseParent<is_nodal>::isParamValid;
using ThermochimicaDataBaseParent<is_nodal>::coupledValue;
Expand Down
Loading

0 comments on commit a95084c

Please sign in to comment.