From 8d0180c3858e9dea87848811ef3c580116d6bafd Mon Sep 17 00:00:00 2001 From: Daniel Schwen Date: Thu, 8 Dec 2022 06:58:19 -0700 Subject: [PATCH 1/9] Remove unused variables --- src/Thermochimica-cxx.C | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Thermochimica-cxx.C b/src/Thermochimica-cxx.C index def145e2..c3aba8b1 100644 --- a/src/Thermochimica-cxx.C +++ b/src/Thermochimica-cxx.C @@ -113,7 +113,7 @@ namespace Thermochimica std::vector getMolesPhase() { - auto [elements, species] = getReinitDataSizes(); + auto elements = getReinitDataSizes().first; std::vector molesPhase(elements); TCAPI_getMolesPhase(molesPhase.data()); return molesPhase; @@ -121,7 +121,7 @@ namespace Thermochimica std::vector getAssemblage() { - auto [elements, species] = getReinitDataSizes(); + auto elements = getReinitDataSizes().first; std::vector assemblage(elements); TCAPI_getAssemblage(assemblage.data()); return assemblage; @@ -140,7 +140,7 @@ namespace Thermochimica std::vector getAllElementPotential() { - auto [elements, species] = getReinitDataSizes(); + auto elements = getReinitDataSizes().first; std::vector potential(elements); TCAPI_getAllElementPotential(potential.data()); return potential; From bec5c0ee880e2487e26703b25ff7ea5071864029 Mon Sep 17 00:00:00 2001 From: maxposchmann Date: Thu, 22 Dec 2022 11:07:02 -0500 Subject: [PATCH 2/9] Change default in CompMolFraction: phase models don't need to be listed --- src/gem/CompMolFraction.f90 | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/gem/CompMolFraction.f90 b/src/gem/CompMolFraction.f90 index 9cc9f4b3..ecb441e2 100755 --- a/src/gem/CompMolFraction.f90 +++ b/src/gem/CompMolFraction.f90 @@ -117,17 +117,8 @@ subroutine CompMolFraction(k) ! Compute the mole fraction depending on the type of solution phase: select case (cSolnPhaseType(k)) - - ! Leave this for now until I improve the estimator: - - case ('QKTO','RKMP','RKMPM','SUBL','SUBLM','SUBG','SUBQ') - - ! Perform subminimization: - call Subminimization(k,lPhasePass) - - case default - - ! The default case assumes an ideal solution phase. + case ('IDMX') + ! Ideal solution phase. dSum = 0D0 do i = m, n dTemp = 0D0 @@ -155,6 +146,10 @@ subroutine CompMolFraction(k) (dStdGibbsEnergy(i) + DLOG(DMAX1(dMolFraction(i)/dSum, 1D-75)) - dTemp) end do + case default + ! All other phase models use subminimization: + call Subminimization(k,lPhasePass) + end select From 19416a456e3990c8cf4de4d4efad12214f25f5e5 Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Tue, 17 Jan 2023 16:44:01 -0500 Subject: [PATCH 3/9] Update phaseDiagramGUI doco phaseDiagramGUI has been renamed as binaryPhaseDiagramGUI. Updating the doco to reflect the change. --- ....png => binaryPhaseDiagramGUI-default.png} | Bin ...> binaryPhaseDiagramGUI-example-setup.png} | Bin doc/phaseDiagramGUI.md | 117 ++++++++++-------- 3 files changed, 68 insertions(+), 49 deletions(-) rename doc/images/{phaseDiagramGUI-default.png => binaryPhaseDiagramGUI-default.png} (100%) rename doc/images/{phaseDiagramGUI-example-setup.png => binaryPhaseDiagramGUI-example-setup.png} (100%) diff --git a/doc/images/phaseDiagramGUI-default.png b/doc/images/binaryPhaseDiagramGUI-default.png similarity index 100% rename from doc/images/phaseDiagramGUI-default.png rename to doc/images/binaryPhaseDiagramGUI-default.png diff --git a/doc/images/phaseDiagramGUI-example-setup.png b/doc/images/binaryPhaseDiagramGUI-example-setup.png similarity index 100% rename from doc/images/phaseDiagramGUI-example-setup.png rename to doc/images/binaryPhaseDiagramGUI-example-setup.png diff --git a/doc/phaseDiagramGUI.md b/doc/phaseDiagramGUI.md index afa697cd..10136a30 100644 --- a/doc/phaseDiagramGUI.md +++ b/doc/phaseDiagramGUI.md @@ -1,7 +1,9 @@ -# `phaseDiagramGUI` +# `binaryPhaseDiagramGUI` + This interface is used to generate **binary** phase diagrams. It includes the following functions: -- [set up](#calculation-setup), -- [refinement](#diagram-refinement), + +- [set up](#calculation-setup), +- [refinement](#diagram-refinement), - [labelling](#labels), - [undo](#undo), - [plot settings](#plot-settings), @@ -14,14 +16,15 @@ This interface is used to generate **binary** phase diagrams. It includes the fo It can be launched by using the following command: ```bash -./scripts/phaseDiagramGUI.sh +./scripts/binaryPhaseDiagramGUI.sh ``` -The `phaseDiagramGUI` window is shown below. +The `binaryPhaseDiagramGUI` window is shown below. -![`phaseDiagramGUI` default window](/doc/images/phaseDiagramGUI-default.png) +![`binaryPhaseDiagramGUI` default window](/doc/images/binaryPhaseDiagramGUI-default.png) ## Calculation Setup + The `Element 1` and `Element 2` dropdown menus are used to select the endmembers of the binary phase diagram. In this GUI, these must be pure elements. The input boxes labelled `Minimum Temperature` and `Maximum Temperature` are used to set the limits of the diagram. If left blank, the default values for are 300 and 1000. The dropdown menu below is used to select the `Temperature unit`. Similarly, the `Pressure` input box can be used to set the pressure for which the diagram is calculated, with a default value of 1, and unit selected from the `Pressure unit` dropdown. @@ -34,124 +37,138 @@ Once `Run` is pressed, the settings described above will be loaded, the initial An example configuration for the Pd - Ru phase diagram using the [`Kaye_NobleMetals.dat`](/data/Kaye_NobleMetals.dat) database is shown below, followed by the resulting initial phase diagram. -![`phaseDiagramGUI` example setup](/doc/images/phaseDiagramGUI-example-setup.png) +![`binaryPhaseDiagramGUI` example setup](/doc/images/binaryPhaseDiagramGUI-example-setup.png) -![`phaseDiagramGUI` example initial diagram](/doc/images/pd-ru-phaseDiagram-setup.png) +![`binaryPhaseDiagramGUI` example initial diagram](/doc/images/pd-ru-phaseDiagram-setup.png) ## Diagram Refinement + The initial phase diagram will likely be quite sparsely populated, with rough phase boundary edges and missing regions. Three functions are available to improve the phase diagram: (manual) `Refine`, `Auto Refine` and `Auto Smoothen`. Each performs new Thermochimica calculations with the aim of adding more points to the phase diagram, and thereby increasing the coverage of the phase diagram and smoothness of the phase boundaries. ### `Refine` + The first option is to manually refine the phase diagram by selecting regions in which to perform additional calculations. The window shown below is used for entry of the limits of this region. The input mirrors that used to set up the calculation, except different numbers of grid points along the two axes may be supplied. -![`phaseDiagramGUI` `Refine` window](/doc/images/phaseDiagramGUI-refine.png) +![`binaryPhaseDiagramGUI` `Refine` window](/doc/images/phaseDiagramGUI-refine.png) `Refine` has largely been superceded by the automated routines `Auto Refine` and `Auto Smoothen`. It is recommended for use when these routines fail to resolve some area or feature of a phase diagram. An example refinement and the resulting improved phase diagram are shown below. -![`phaseDiagramGUI` example setup](/doc/images/phaseDiagramGUI-example-refine.png) +![`binaryPhaseDiagramGUI` example setup](/doc/images/phaseDiagramGUI-example-refine.png) -![`phaseDiagramGUI` example refined diagram](/doc/images/pd-ru-phaseDiagram-refine.png) +![`binaryPhaseDiagramGUI` example refined diagram](/doc/images/pd-ru-phaseDiagram-refine.png) ### `Auto Refine` + The suggested first step to improve a rough phase diagram is to use `Auto Refine`. This routine uses a geometric analysis of the existing regions of the phase diagram to determine where the diagram is missing phase information, and efficiently deploys calculations in those areas. The density of the refinement grid is set by an internal parameter, which is increased with each use of `Auto Refine`. Thus, successive calls to `Auto Refine` will continue to improve the resolution of the phase diagram. Some phase regions may be skipped and the terminal output should indicate this. The example phase diagram is shown after one call to `Auto Refine` below. -![`phaseDiagramGUI` example auto-refined diagram](/doc/images/pd-ru-phaseDiagram-autorefine.png) +![`binaryPhaseDiagramGUI` example auto-refined diagram](/doc/images/pd-ru-phaseDiagram-autorefine.png) ### `Auto Smoothen` + `Auto Smoothen` is similar in operation to `Auto Refine`: it also automatically determines where calculations should be performed, and uses a ratcheting internal parameter to progressively increase the diagram resolution. However, whereas `Auto Refine` searches for regions of missing phase information to populate, `Auto Smoothen` increases the smoothness of phase boundaries by performing calculations within known two-phase regions. The example phase diagram is shown after one call to `Auto Smoothen` below. -![`phaseDiagramGUI` example auto-smoothened diagram](/doc/images/pd-ru-phaseDiagram-autosmoothen.png) +![`binaryPhaseDiagramGUI` example auto-smoothened diagram](/doc/images/pd-ru-phaseDiagram-autosmoothen.png) `Auto Smoothen` also performs a second function, which is to detect overlapping phase regions. This is required in the somewhat uncommon case of a two-phase region existing at low temperature, disappears, and then reappears as temperature is increased. Consider the following Mo - Ru phase diagram, again using the [`Kaye_NobleMetals.dat`](/data/Kaye_NobleMetals.dat) database. After `Auto Refine`, it has multiple overlapping two-phase regions. -![`phaseDiagramGUI` example phase diagram with overlapping two-phase regions](/doc/images/mo-ru-phaseDiagram-overlap.png) +![`binaryPhaseDiagramGUI` example phase diagram with overlapping two-phase regions](/doc/images/mo-ru-phaseDiagram-overlap.png) After calling `Auto Smoothen`, this issue is resolved as shown below. -![`phaseDiagramGUI` example phase diagram with resolved two-phase regions](/doc/images/mo-ru-phaseDiagram-resolved.png) +![`binaryPhaseDiagramGUI` example phase diagram with resolved two-phase regions](/doc/images/mo-ru-phaseDiagram-resolved.png) This detection of overlapping regions is done by using heuristic analysis of the spacing between consecutive points on a phase boundary line. This analysis fails if phase boundaries are sparsely populated, which is why it is not performed until `Auto Smoothen` is called. ## Labels + Labels of phase regions can be added and removed manually, as well as automatically generated. ### `Add Label` + Pressing the `Add Label` button opens a very simple dialogue box, as shown below, which requests the location at which a label will be added. Pressing the `Add Label` button in this dialogue performs a new Thermochimica calculation at the specified point, adds phase boundary data corresponding to that point to the existing phase diagram, and adds text corresponding to the equilibrium phases determined at that point. -![`phaseDiagramGUI` `Add Label` window](/doc/images/phaseDiagramGUI-addlabel.png) +![`binaryPhaseDiagramGUI` `Add Label` window](/doc/images/phaseDiagramGUI-addlabel.png) An example label point and the result on the phase diagram are shown below. -![`phaseDiagramGUI` example add label](/doc/images/phaseDiagramGUI-example-addlabel.png) +![`binaryPhaseDiagramGUI` example add label](/doc/images/phaseDiagramGUI-example-addlabel.png) -![`phaseDiagramGUI` example diagram with label](/doc/images/pd-ru-phaseDiagram-label.png) +![`binaryPhaseDiagramGUI` example diagram with label](/doc/images/pd-ru-phaseDiagram-label.png) ### `Auto Label` -`Auto Label` attempts to create one label per phase region on the phase diagram. This routine is different from `Add Label` in that it does not run any new Thermochimica calculations, so no new phase region data is added to the diagram. Instead, the geometric analysis used for [`Auto Refine`](#auto-refine) is used to detect the regions. The algorithm also attempts to determine the midpoints of the regions, so that the labels are placed in convenient positions. + +`Auto Label` attempts to create one label per phase region on the phase diagram. This routine is different from `Add Label` in that it does not run any new Thermochimica calculations, so no new phase region data is added to the diagram. Instead, the geometric analysis used for [`Auto Refine`](#auto-refine) is used to detect the regions. The algorithm also attempts to determine the midpoints of the regions, so that the labels are placed in convenient positions. As with `Auto Refine`, some phase regions may be skipped and the terminal output should indicate this. The example phase diagram with automatically-generated labels is shown below. -![`phaseDiagramGUI` example diagram with automatic labels](/doc/images/pd-ru-phaseDiagram-autolabel.png) +![`binaryPhaseDiagramGUI` example diagram with automatic labels](/doc/images/pd-ru-phaseDiagram-autolabel.png) ### `Remove Label` + When there are labels on the current phase diagram, pressing `Remove Label` opens a dialogue box with a list of the labels. The label text as well as the concentration (of element 2) and temperature coordinates are displayed. Under the `Remove Label?` heading, a checkbox is present corresponding to each label. When `Remove Label(s)` is pressed, all the labels for which the box is checked are removed, and the dialogue window closed automatically. An example dialogue window for the Pd - Ru phase diagram with automatically generated labels is shown below. -![`phaseDiagramGUI` example remove label](/doc/images/phaseDiagramGUI-example-removelabel.png) +![`binaryPhaseDiagramGUI` example remove label](/doc/images/phaseDiagramGUI-example-removelabel.png) ## `Undo` + The most recent `Refine`, `Auto Refine`, `Auto Smoothen`, `Label`, `Auto Label`, or `Remove Label` operation can be undone by pressing `Undo`. Note that only one level of history is stored at this time, so subsequent `Undo` operations are not possible. ## `Plot Settings` + When `Plot Settings` is pressed, the following settings window is opened. -![`phaseDiagramGUI` plot settings window](/doc/images/phaseDiagramGUI-plotsettings.png) +![`binaryPhaseDiagramGUI` plot settings window](/doc/images/phaseDiagramGUI-plotsettings.png) A few plot options are available: -- `Marker Style`: - - `Lines`: display only lines connecting data points - - `Points`: display only closed circles (•) at data points - - `Both`: display both lines and closed circles + +- `Marker Style`: + - `Lines`: display only lines connecting data points + - `Points`: display only closed circles (•) at data points + - `Both`: display both lines and closed circles - `Plot Colors`: - - `Colorful`: the color for the outline of each two-phase region is determined by taking equal intervals in the `rainbow` colorspace - - `Black`: all lines are set to black + - `Colorful`: the color for the outline of each two-phase region is determined by taking equal intervals in the `rainbow` colorspace + - `Black`: all lines are set to black - `Experimental Data Colors`: - - `Colorful`: the color for each loaded experimental data series is determined by taking equal intervals in the `rainbow` colorspace - - `Black`: all loaded experimental data series are set to black + - `Colorful`: the color for each loaded experimental data series is determined by taking equal intervals in the `rainbow` colorspace + - `Black`: all loaded experimental data series are set to black - `Show`: - - `Experimental Data`: toggles whether loaded experimental data is displayed - - `Loaded Diagram`: toggles whether a loaded phase diagram is displayed + - `Experimental Data`: toggles whether loaded experimental data is displayed + - `Loaded Diagram`: toggles whether a loaded phase diagram is displayed `Auto-Label Settings` presents two toggles for the [`Auto Label`](#auto-label) feature, which determine whether single-phase regions and two-phase regions given labels when using `Auto Label`. Note that these only apply to subsequent uses of `Auto Label` and will not alter existing labels. The following settings are available to configure exported figures: + - `Export Filename`: name of exported figure (default is `thermochimicaPhaseDiagram`), which will be saved to the `outputs` directory (note that the extension corresponding to the format selected in `Export Format` will be appended) - `Export Format`: image file format may be selected from the following: - - `png`: portable network graphic - - `pdf`: portable document format - - `ps`: postscript image - - `eps`: encapsulated postscript - - `svg`: scalable vector graphic + - `png`: portable network graphic + - `pdf`: portable document format + - `ps`: postscript image + - `eps`: encapsulated postscript + - `svg`: scalable vector graphic - `Export DPI`: set resolution in dots per inch (default is 300) ## `Export Plot` + Press `Export Plot` to save the current phase diagram to the location specified using `Export Filename` in the settings menu. ## `Inspect` + The `Inspect` feature allows a user to examine the underlying equilibrium calculations used to construct the phase diagram. This can be useful for debugging purposes, and also allows spurious calculations to be suppressed from a phase diagram. An example of the inspection window corresponding to the Pd - Ru phase diagram is shown below. -![`phaseDiagramGUI` `Inspect` window example for Pd - Ru system](/doc/images/phaseDiagramGUI-example-inspect.png) +![`binaryPhaseDiagramGUI` `Inspect` window example for Pd - Ru system](/doc/images/phaseDiagramGUI-example-inspect.png) The column on the left-hand side lists all equilibrium calculations used in the phase diagram. These are listed with an index, followed by the temperature and concentrations of `Element 2` in the two phases present. When selected, information and options for a calculation are displayed on the right-hand side of the `Inspect` window. @@ -167,42 +184,44 @@ There is also a dropdown to filter by active or suppressed status. When this men An example of filtered data is shown below. -![`phaseDiagramGUI` `Inspect` window example with filter for Pd - Ru system](/doc/images/phaseDiagramGUI-example-inspect-filtered.png) - +![`binaryPhaseDiagramGUI` `Inspect` window example with filter for Pd - Ru system](/doc/images/phaseDiagramGUI-example-inspect-filtered.png) ## Overlaying Diagrams + Once a phase diagram has been created, the data corresponding to that diagram can be saved by pressing `Export Diagram Data`. A dialogue window (shown below) will open to ask for a name for the file to which the data will be saved. The default name is `savedDiagram`. The extension is `pkl`, as the saved file is a [`pickle`](https://docs.python.org/3/library/pickle.html). The file will be saved to the `outputs` directory. -![`phaseDiagramGUI` `Export Diagram Data` window](/doc/images/phaseDiagramGUI-exportdiagramdata.png) +![`binaryPhaseDiagramGUI` `Export Diagram Data` window](/doc/images/phaseDiagramGUI-exportdiagramdata.png) A diagram saved by this method can be loaded with the `Load Diagram` button. This opens a file selection window (opened by default in the `outputs` directory) that lists all `pkl` files. When a file is selected, the diagram saved in that file will be added as an overlay to the current phase diagram. For example, consider a case in which the example Pd - Ru phase diagram was saved after the initial diagram setup to a file `pd-ru-example.pkl`. The `Load Diagram` window will appear as the below. -![`phaseDiagramGUI` example `Load Diagram` window](/doc/images/phaseDiagramGUI-example-loaddata.png) +![`binaryPhaseDiagramGUI` example `Load Diagram` window](/doc/images/phaseDiagramGUI-example-loaddata.png) Once `Auto Refine` and `Auto Smoothen` have been applied to the current phase diagram (as described in [Diagram Refinement](#diagram-refinement)), the resulting phase diagram with overlay will look like the figure below. -![`phaseDiagramGUI` example diagram with overlay](/doc/images/pd-ru-phaseDiagram-overlay.png) +![`binaryPhaseDiagramGUI` example diagram with overlay](/doc/images/pd-ru-phaseDiagram-overlay.png) ## Experimental Data + Experimental data points may be added to the phase diagram for the purposes of comparing the computed diagram to experimental data. Experimental data is expected in a simple two-column CSV format, with concentration of `Element 2` in the first column, and temperature in the second column. [An example CSV file is available here](/doc/examples/pd-ru-example_experiment1.csv). When the `Add Data` button is pressed, a file selection window is opened, which lists `csv` files. An example file selection window is shown below. As with the other file selection windows, `Browse` can be pressed to change directory. In the file selection column, multiple files can be selected simultaneously using `Ctrl` or `Shift` + click. When `Add Data` is pressed, the data in the selected files will be added to the phase diagram. -![`phaseDiagramGUI` example `Add Data` window](/doc/images/phaseDiagramGUI-example-experimental.png) +![`binaryPhaseDiagramGUI` example `Add Data` window](/doc/images/phaseDiagramGUI-example-experimental.png) An example of the Pd - Ru phase diagram with two (fictitious) settings of experimental data added is shown below. -![`phaseDiagramGUI` example diagram with experiment](/doc/images/pd-ru-phaseDiagram-experiment.png) +![`binaryPhaseDiagramGUI` example diagram with experiment](/doc/images/pd-ru-phaseDiagram-experiment.png) ## Macros -While a phase diagram is being generated, refined, and labelled, the button and settings used are automatically logged to a macro, i.e. a collection of commands. By pressing `Export Macro`, the logged commands can be saved to a file. This file will be placed in the `python` directory, and is actually a full-fledged python script, which means it can be run outside of the `phaseDiagramGUI` environment. Macros can also be edited to add or remove commands as necessary. This makes them an effective way to 'save' your work when using the `phaseDiagramGUI`. -Pressing `Macro Settings` opens a window (shown below) with a file browser and a field for entering `Macro File Save Name`. The file browser and file selection column are used to select a previously-saved macro. This selection is confirmed by pressing `Select Macro`. The `Macro File Save Name` input box is used to set the file name for the macro saved when `Export Macro` is pressed in the main `phaseDiagramGUI` window. This setting is confirmed by pressing `Set Save Name`. Note that the file will always have extension `py`, and the default name is `macroPhaseDiagram`. +While a phase diagram is being generated, refined, and labelled, the button and settings used are automatically logged to a macro, i.e. a collection of commands. By pressing `Export Macro`, the logged commands can be saved to a file. This file will be placed in the `python` directory, and is actually a full-fledged python script, which means it can be run outside of the `binaryPhaseDiagramGUI` environment. Macros can also be edited to add or remove commands as necessary. This makes them an effective way to 'save' your work when using the `binaryPhaseDiagramGUI`. + +Pressing `Macro Settings` opens a window (shown below) with a file browser and a field for entering `Macro File Save Name`. The file browser and file selection column are used to select a previously-saved macro. This selection is confirmed by pressing `Select Macro`. The `Macro File Save Name` input box is used to set the file name for the macro saved when `Export Macro` is pressed in the main `binaryPhaseDiagramGUI` window. This setting is confirmed by pressing `Set Save Name`. Note that the file will always have extension `py`, and the default name is `macroPhaseDiagram`. -![`phaseDiagramGUI` example `Macro Settings` window](/doc/images/phaseDiagramGUI-example-macrosettings.png) +![`binaryPhaseDiagramGUI` example `Macro Settings` window](/doc/images/phaseDiagramGUI-example-macrosettings.png) When `Run Macro` is pressed, the macro selected in the `Macro Settings` window is run. Further `Refine`, `Label`, etc., operations will be applied to the diagram generated. -`Clear Macro` can be used to erase the commands in the currect macro log. \ No newline at end of file +`Clear Macro` can be used to erase the commands in the currect macro log. From 8d5e16fd0f63c1c2a47bd006713e2b814e06f9df Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Mon, 30 Jan 2023 20:50:32 -0500 Subject: [PATCH 4/9] Fix missing presetElementMass function Closes #128 --- src/Thermochimica-cxx.C | 5 +++++ src/Thermochimica-cxx.h | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Thermochimica-cxx.C b/src/Thermochimica-cxx.C index c3aba8b1..fb47f014 100644 --- a/src/Thermochimica-cxx.C +++ b/src/Thermochimica-cxx.C @@ -56,6 +56,11 @@ namespace Thermochimica TCAPI_setTemperaturePressure(&temperature, &pressure); } + void presetElementMass(int element, double mass) + { + TCAPI_presetElementMass(&element, &mass); + } + void setElementMass(int element, double mass) { TCAPI_setElementMass(&element, &mass); diff --git a/src/Thermochimica-cxx.h b/src/Thermochimica-cxx.h index 9b5e5431..54ce8dd9 100644 --- a/src/Thermochimica-cxx.h +++ b/src/Thermochimica-cxx.h @@ -17,6 +17,7 @@ namespace Thermochimica void setStandardUnits(); void setModelicaUnits(); void setTemperaturePressure(double temperature, double pressure); + void presetElementMass(int element, double mass); void setElementMass(int element, double mass); int checkInfoThermo(); void parseThermoFile(); @@ -69,7 +70,8 @@ namespace Thermochimica getMqmqaConstituentFraction(const std::string &phaseName, int sublattice, const std::string &constituent); // Reinitialization data - struct reinitData { + struct reinitData + { std::vector assemblage; std::vector molesPhase; std::vector elementPotential; From b123123e6ebe4641f0ab416dfcc8d1f27b36bcaf Mon Sep 17 00:00:00 2001 From: "Samuel A. Walker" Date: Fri, 7 Apr 2023 16:30:44 -0600 Subject: [PATCH 5/9] Changing Subroutine name for BlueCrab Integration --- src/Thermochimica.f90 | 2 +- src/postprocess/{PostProcess.f90 => PostProcessThermo.f90} | 6 +++--- src/postprocess/RetryCalculationFirstPhase.f90 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/postprocess/{PostProcess.f90 => PostProcessThermo.f90} (95%) diff --git a/src/Thermochimica.f90 b/src/Thermochimica.f90 index 81ab3548..cbf6fce5 100755 --- a/src/Thermochimica.f90 +++ b/src/Thermochimica.f90 @@ -467,7 +467,7 @@ subroutine Thermochimica ! Attempt a retry by re-initializing with first phase only call RetryCalculationFirstPhase ! Perform post-processing calculations of results: - if (INFOThermo == 0 .OR. INFOThermo == 12) call PostProcess + if (INFOThermo == 0 .OR. INFOThermo == 12) call PostProcessThermo end if if (lHeatCapacityEntropyEnthalpy .AND. .NOT. lHeatCapacityCurrent) call HeatCapacity diff --git a/src/postprocess/PostProcess.f90 b/src/postprocess/PostProcessThermo.f90 similarity index 95% rename from src/postprocess/PostProcess.f90 rename to src/postprocess/PostProcessThermo.f90 index da194a76..efeaa84c 100755 --- a/src/postprocess/PostProcess.f90 +++ b/src/postprocess/PostProcessThermo.f90 @@ -1,7 +1,7 @@ !------------------------------------------------------------------------------------------------------------- ! - !> \file PostProcess.f90 + !> \file PostProcessThermo.f90 !> \brief Perform post-processing of results. !> \author M.H.A. Piro !> \date January 14, 2013 @@ -28,7 +28,7 @@ !------------------------------------------------------------------------------------------------------------- -subroutine PostProcess +subroutine PostProcessThermo USE ModuleThermo USE ModuleThermoIO @@ -73,4 +73,4 @@ subroutine PostProcess dNormalizeInput = 1D0 / dNormalizeInput return -end subroutine PostProcess +end subroutine PostProcessThermo diff --git a/src/postprocess/RetryCalculationFirstPhase.f90 b/src/postprocess/RetryCalculationFirstPhase.f90 index fcfc0a50..fbc021f1 100644 --- a/src/postprocess/RetryCalculationFirstPhase.f90 +++ b/src/postprocess/RetryCalculationFirstPhase.f90 @@ -14,7 +14,7 @@ subroutine RetryCalculationFirstPhase if (nSpeciesPhase(1) > 0) then INFOThermo = 0 lReinitRequested = .TRUE. - call PostProcess + call PostProcessThermo nSolnPhases = 1 call SaveReinitData if (lReinitAvailable) then From 870725b49a4373b75f6dcd20e8db3d65d11e273d Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Fri, 14 Apr 2023 11:26:14 -0600 Subject: [PATCH 6/9] Increase supported filepath length --- src/parser/ParseCSDataFile.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/ParseCSDataFile.f90 b/src/parser/ParseCSDataFile.f90 index bb7c5d4e..b64efa59 100644 --- a/src/parser/ParseCSDataFile.f90 +++ b/src/parser/ParseCSDataFile.f90 @@ -117,9 +117,9 @@ subroutine ParseCSDataFile(cFileName) implicit none character(*):: cFileName - character(120) :: cFileNameLen + character(1024) :: cFileNameLen - cFileNameLen = cFileName(1:min(120,len(cFileName))) + cFileNameLen = cFileName(1:min(1024,len(cFileName))) ! Initialize variables: From aabef5641ce8c818b5c4e21145a3acb379e1943c Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Fri, 28 Apr 2023 15:29:23 -0600 Subject: [PATCH 7/9] Add FFPE_TRAPS flag --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bac7e2d9..bc52df0e 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ AR = ar FC = gfortran CC = g++ -FCFLAGS = -Wall -O2 -fno-automatic -fbounds-check -ffpe-trap=zero -cpp -D"DATA_DIRECTORY='$(DATA_DIR)'" +FFPE_TRAPS ?= zero +FCFLAGS = -Wall -O2 -fno-automatic -fbounds-check -ffpe-trap=$(FFPE_TRAPS) -cpp -D"DATA_DIRECTORY='$(DATA_DIR)'" CCFLAGS = -std=gnu++17 UNAME_S := $(shell uname -s) @@ -88,7 +89,7 @@ SHARED_LIB = $(OBJ_DIR)/$(TC_LIB) ## C interface library: ## ================= C_SRC = Thermochimica-c.C Thermochimica-cxx.C -C_OBJ = $(C_SRC:.C=.o) +C_OBJ = $(C_SRC:.C=.o) C_LNK = $(addprefix $(OBJ_DIR)/,$(C_OBJ)) TC-C_LIB = libthermoc.a C_LIB = $(OBJ_DIR)/$(TC-C_LIB) @@ -234,6 +235,6 @@ test: all dailytest ## DEBUG: ## =========== setdebug: - $(eval FCFLAGS = -Wall -O0 -g -fno-automatic -fbounds-check -ffpe-trap=zero -D"DATA_DIRECTORY='$(DATA_DIR)'") + $(eval FCFLAGS = -Wall -O0 -g -fno-automatic -fbounds-check -ffpe-trap=$(FFPE_TRAPS) -D"DATA_DIRECTORY='$(DATA_DIR)'") debug: setdebug all dailytest From 1f524bdb9c820817b9d49c052c03cc275118df13 Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Thu, 4 May 2023 14:33:35 -0600 Subject: [PATCH 8/9] New phase/species name API (#137) --- src/Thermochimica-cxx.C | 74 +++++++++++++++++++ src/Thermochimica-cxx.h | 8 ++ src/api/CouplingUtilities.f90 | 27 +++++++ src/api/CouplingUtilitiesISO_C.f90 | 114 ++++++++++++++++++++++++----- src/module/ModuleParseCS.f90 | 4 +- 5 files changed, 205 insertions(+), 22 deletions(-) diff --git a/src/Thermochimica-cxx.C b/src/Thermochimica-cxx.C index fb47f014..008d970e 100644 --- a/src/Thermochimica-cxx.C +++ b/src/Thermochimica-cxx.C @@ -103,6 +103,80 @@ namespace Thermochimica TCAPI_resetThermoAll(); } + // utilitiy functions for consistency check / database record + std::pair getNumberPhasesDatabase() + { + int solution, condensed; + TCAPI_getNumberPhasesDatabase(&solution, &condensed); + return {(std::size_t)solution, (std::size_t)condensed}; + } + + std::vector getPhaseNamesDatabase() + { + auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase(); + auto n_phases = n_soln_phases + n_cond_phases; + + std::vector phase_names(n_phases); + + for (std::size_t i = 0; i < n_phases; ++i) + phase_names[i] = getPhaseNameAtIndex(i); + + return phase_names; + } + + std::vector getNumberSpeciesDatabase() + { + auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase(); + (void)n_cond_phases; + std::vector n_sp(n_soln_phases); + std::vector n_species(n_soln_phases); + TCAPI_getNumberSpeciesDatabase(n_sp.data()); + for (std::size_t i = 0; i < n_soln_phases; ++i) + n_species[i] = (std::size_t)n_sp[i]; + + return n_species; + } + + std::string getPhaseNameAtIndex(int phase_index) + { + int length; + auto index = phase_index + 1; // Fortran indexing starts at 1 instead of 0 + + char *buffer = TCAPI_getPhaseNameAtIndex(&index, &length); + + return std::string(buffer, buffer + length); + } + + std::vector> getSpeciesDatabase() + { + auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase(); + (void)n_cond_phases; + std::vector> species(n_soln_phases); + + for (std::size_t i = 0; i < n_soln_phases; ++i) + species[i] = getSpeciesInPhaseDatabase(i); + + return species; + } + + std::vector getSpeciesInPhaseDatabase(int phase_index) + { + int length, index; + auto n_species = getNumberSpeciesDatabase(); + auto n_species_phase = phase_index == 0 ? n_species[phase_index] : n_species[phase_index] - n_species[phase_index - 1]; + + std::vector species(n_species_phase); + + for (std::size_t i = 0; i < n_species_phase; ++i) + { + index = phase_index == 0 ? i + 1 : n_species[phase_index - 1] + i + 1; + char *buffer = TCAPI_getSpeciesAtIndex(&index, &length); + species[i] = std::string(buffer, buffer + length); + } + + return species; + } + // re-initialization-related functions void saveReinitData() { diff --git a/src/Thermochimica-cxx.h b/src/Thermochimica-cxx.h index 54ce8dd9..bf08576b 100644 --- a/src/Thermochimica-cxx.h +++ b/src/Thermochimica-cxx.h @@ -27,6 +27,14 @@ namespace Thermochimica void resetThermo(); void resetThermoAll(); + // utilitiy functions for consistency check / database record + std::pair getNumberPhasesDatabase(); + std::vector getPhaseNamesDatabase(); + std::string getPhaseNameAtIndex(int phase_index); + std::vector getNumberSpeciesDatabase(); + std::vector getSpeciesInPhaseDatabase(int phase_index); + std::vector> getSpeciesDatabase(); + // re-initialization-related functions void saveReinitData(); std::pair getReinitDataSizes(); diff --git a/src/api/CouplingUtilities.f90 b/src/api/CouplingUtilities.f90 index 766dd177..b77c3e39 100644 --- a/src/api/CouplingUtilities.f90 +++ b/src/api/CouplingUtilities.f90 @@ -202,6 +202,33 @@ subroutine SetElementMass(iAtom, dMass) end subroutine SetElementMass +subroutine GetNumberPhasesDatabase(iNumSolnPhases, iNumConPhases) + + USE ModuleParseCS, ONLY: nSpeciesCS, nSpeciesPhaseCS, nSolnPhasesSysCS + + implicit none + + integer, intent(out):: iNumSolnPhases, iNumConPhases + + iNumConPhases = nSpeciesCS - MAXVAL(nSpeciesPhaseCS) + iNumSolnPhases = nSolnPhasesSysCS + + return + +end subroutine GetNumberPhasesDatabase + +subroutine GetNumberSpeciesDatabase(nSpeciesDB) + USE ModuleParseCS, ONLY: nSolnPhasesSysCS, nSpeciesPhaseCS + implicit none + + integer, intent(out), dimension(nSolnPhasesSysCS) :: nSpeciesDB + + nSpeciesDB = nSpeciesPhaseCS(1:size(nSpeciesDB)) + + return + +end subroutine GetNumberSpeciesDatabase + subroutine GetElementMass(iAtom, dMass) USE ModuleThermoIO, ONLY: dElementMass diff --git a/src/api/CouplingUtilitiesISO_C.f90 b/src/api/CouplingUtilitiesISO_C.f90 index 15c900d4..54215acb 100644 --- a/src/api/CouplingUtilitiesISO_C.f90 +++ b/src/api/CouplingUtilitiesISO_C.f90 @@ -10,7 +10,7 @@ subroutine SetThermoFileNameISO(cFileName, lcFileName) & character(kind=c_char,len=lcFileName), pointer :: fFileName call c_f_pointer(cptr=c_loc(cFileName), fptr=fFileName) - + call SetThermoFileName(fFileName) return @@ -174,7 +174,7 @@ subroutine SetElementMassISO(iAtom, dMass) & implicit none integer(C_INT), intent(in) :: iAtom real(C_DOUBLE), intent(in) :: dMass - + call SetElementMass(iAtom, dMass) return @@ -251,6 +251,80 @@ subroutine ResetThermoAllISO() & end subroutine ResetThermoAllISO +subroutine GetNumberPhasesDatabaseISO(iSolnPhases, iConPhases) & + bind(C, name="TCAPI_getNumberPhasesDatabase") + + USE,INTRINSIC :: ISO_C_BINDING + + implicit none + + integer(C_INT), intent(out):: iSolnPhases, iConPhases + + call GetNumberPhasesDatabase(iSolnPhases, iConPhases) + + return + +end subroutine GetNumberPhasesDatabaseISO + +function GetPhaseNameAtIndexISO(phase_index, phase_name_len) & + bind(C, name='TCAPI_getPhaseNameAtIndex') + + USE, INTRINSIC :: ISO_C_BINDING + USE ModuleParseCS + + implicit none + + integer(c_int), intent(in) :: phase_index + integer(c_int), intent(out) :: phase_name_len + type(c_ptr) :: GetPhaseNameAtIndexISO + + if (phase_index <= nSolnPhasesSysCS) then + GetPhaseNameAtIndexISO = c_loc(cSolnPhaseNameCS(phase_index)) + phase_name_len = len_trim(cSolnPhaseNameCS(phase_index)) + else + GetPhaseNameAtIndexISO = c_loc(cSpeciesNameCS(phase_index - nSolnPhasesSysCS)) + phase_name_len = len_trim(cSpeciesNameCS(phase_index - nSolnPhasesSysCS)) + end if + + return + +end function GetPhaseNameAtIndexISO + +subroutine GetNumberSpeciesDatabaseISO(nSpeciesDB) & + bind(C, name='TCAPI_getNumberSpeciesDatabase') + + USE, INTRINSIC :: ISO_C_BINDING + USE ModuleParseCS, ONLY: nSolnPhasesSysCS + + implicit none + + integer(c_int), intent(out), dimension(nSolnPhasesSysCS) :: nSpeciesDB + + call GetNumberSpeciesDatabase(nSpeciesDB) + + return + +end subroutine GetNumberSpeciesDatabaseISO + +function GetSpeciesAtIndexISO(index, len) & + bind(C, name='TCAPI_getSpeciesAtIndex') + + USE, INTRINSIC :: ISO_C_BINDING + USE ModuleParseCS + + implicit none + + integer(c_int), intent(in) :: index + integer(c_int), intent(out) :: len + type(c_ptr) :: GetSpeciesAtIndexISO + + GetSpeciesAtIndexISO = c_loc(cSpeciesNameCS(index)) + len = len_trim(cSpeciesNameCS(index)) + + return + +end function GetSpeciesAtIndexISO + subroutine ThermoDebugISO() & bind(C, name="TCAPI_thermoDebug") @@ -312,7 +386,7 @@ subroutine SolPhaseParseISO(iElem, dMolSum) & integer(C_INT), intent(in) :: iElem real(C_DOUBLE), intent(out) :: dMolSum - + call SolPhaseParse(iElem, dMolSum) return @@ -432,7 +506,7 @@ subroutine getReinitDataISO(mAssemblage,mMolesPhase,mElementPotential, & bind(C, name="TCAPI_getReinitData") USE,INTRINSIC :: ISO_C_BINDING - + USE ModuleThermo, ONLY: nElements, nSpecies implicit none @@ -454,7 +528,7 @@ subroutine setReinitDataISO(mElements,mSpecies,mAssemblage,mMolesPhase, & bind(C, name="TCAPI_setReinitData") USE,INTRINSIC :: ISO_C_BINDING - + implicit none integer(C_INT), intent(in) :: mElements, mSpecies @@ -541,9 +615,9 @@ subroutine PrintStateISO() & USE,INTRINSIC :: ISO_C_BINDING implicit none - + call PrintState - + end subroutine PrintStateISO subroutine GetElementMoleFractionInPhaseISO(cElement, lcElement, cPhase, lcPhase, dMolesOut, INFO) & @@ -799,7 +873,7 @@ subroutine GetMqmqaMolesPairsISO(cPhaseName, lcPhaseName, dMolesPairsOut, INFO) call c_f_pointer(cptr=c_loc(cPhaseName), fptr=fPhaseName) - call GetMqmqaMolesPairs(fPhaseName, dMolesPairsOut, INFO) + call GetMqmqaMolesPairs(fPhaseName, dMolesPairsOut, INFO) return @@ -907,37 +981,37 @@ subroutine SetFuzzyStoichISO(lFuzzyStoichIn) & bind(C, name="TCAPI_setFuzzyStoich") USE,INTRINSIC :: ISO_C_BINDING - + implicit none logical(C_BOOL), intent(in) :: lFuzzyStoichIn - + call SetFuzzyStoich(lFuzzyStoichIn) - + return end subroutine SetFuzzyStoichISO - + subroutine SetFuzzyMagnitudeISO(dFuzzMagIn) & bind(C, name="TCAPI_setFuzzyMagnitude") USE,INTRINSIC :: ISO_C_BINDING - + implicit none real(C_DOUBLE), intent(in) :: dFuzzMagIn - + call SetFuzzyMagnitude(dFuzzMagIn) - + return end subroutine SetFuzzyMagnitudeISO - + subroutine SetGibbsMinCheckISO(lGibbsMinCheckIn) & bind(C, name="TCAPI_setGibbsMinCheck") USE,INTRINSIC :: ISO_C_BINDING - + implicit none logical(C_BOOL), intent(in) :: lGibbsMinCheckIn - + call SetGibbsMinCheck(lGibbsMinCheckIn) - + return - end subroutine SetGibbsMinCheckISO \ No newline at end of file + end subroutine SetGibbsMinCheckISO diff --git a/src/module/ModuleParseCS.f90 b/src/module/ModuleParseCS.f90 index a3b417af..c83aa627 100755 --- a/src/module/ModuleParseCS.f90 +++ b/src/module/ModuleParseCS.f90 @@ -97,8 +97,8 @@ module ModuleParseCS character(3), dimension(:), allocatable :: cElementNameCS character(8), dimension(:), allocatable :: cSolnPhaseTypeCS - character(25), dimension(:), allocatable :: cSolnPhaseNameCS - character(25), dimension(:), allocatable :: cSpeciesNameCS + character(25), dimension(:), allocatable, target :: cSolnPhaseNameCS + character(25), dimension(:), allocatable, target :: cSpeciesNameCS character(30), dimension(:,:), allocatable :: cPairNameCS character(8), dimension(:,:,:), allocatable :: cConstituentNameSUBCS character, dimension(:), allocatable :: cRegularParamCS From 59e1453e09cab4acd7b824945048164d1b580738 Mon Sep 17 00:00:00 2001 From: Parikshit Bajpai Date: Thu, 4 May 2023 14:54:02 -0600 Subject: [PATCH 9/9] Add TCAPI functions to new API (#137) --- src/Thermochimica.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Thermochimica.h b/src/Thermochimica.h index 09197ab8..238593b5 100644 --- a/src/Thermochimica.h +++ b/src/Thermochimica.h @@ -46,6 +46,11 @@ extern "C" void TCAPI_printResults(); void TCAPI_printState(); + void TCAPI_getNumberPhasesDatabase(int *, int *); + char *TCAPI_getPhaseNameAtIndex(int *, int *); + void TCAPI_getNumberSpeciesDatabase(int *); + char *TCAPI_getSpeciesAtIndex(int *, int *); + void TCAPI_resetInfoThermo(); void TCAPI_resetThermo(); void TCAPI_resetThermoAll();