Skip to content

Commit

Permalink
Merge branch 'master' into subminimizationPerformance
Browse files Browse the repository at this point in the history
  • Loading branch information
parikshitbajpai committed Jun 1, 2023
2 parents 85254b1 + c9d054d commit 61d2af5
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 96 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
File renamed without changes
117 changes: 68 additions & 49 deletions doc/phaseDiagramGUI.md

Large diffs are not rendered by default.

85 changes: 82 additions & 3 deletions src/Thermochimica-cxx.C
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -98,6 +103,80 @@ namespace Thermochimica
TCAPI_resetThermoAll();
}

// utilitiy functions for consistency check / database record
std::pair<std::size_t, std::size_t> getNumberPhasesDatabase()
{
int solution, condensed;
TCAPI_getNumberPhasesDatabase(&solution, &condensed);
return {(std::size_t)solution, (std::size_t)condensed};
}

std::vector<std::string> getPhaseNamesDatabase()
{
auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase();
auto n_phases = n_soln_phases + n_cond_phases;

std::vector<std::string> phase_names(n_phases);

for (std::size_t i = 0; i < n_phases; ++i)
phase_names[i] = getPhaseNameAtIndex(i);

return phase_names;
}

std::vector<std::size_t> getNumberSpeciesDatabase()
{
auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase();
(void)n_cond_phases;
std::vector<int> n_sp(n_soln_phases);
std::vector<std::size_t> 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<std::vector<std::string>> getSpeciesDatabase()
{
auto [n_soln_phases, n_cond_phases] = getNumberPhasesDatabase();
(void)n_cond_phases;
std::vector<std::vector<std::string>> species(n_soln_phases);

for (std::size_t i = 0; i < n_soln_phases; ++i)
species[i] = getSpeciesInPhaseDatabase(i);

return species;
}

std::vector<std::string> 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<std::string> 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()
{
Expand All @@ -113,15 +192,15 @@ namespace Thermochimica

std::vector<double> getMolesPhase()
{
auto [elements, species] = getReinitDataSizes();
auto elements = getReinitDataSizes().first;
std::vector<double> molesPhase(elements);
TCAPI_getMolesPhase(molesPhase.data());
return molesPhase;
}

std::vector<int> getAssemblage()
{
auto [elements, species] = getReinitDataSizes();
auto elements = getReinitDataSizes().first;
std::vector<int> assemblage(elements);
TCAPI_getAssemblage(assemblage.data());
return assemblage;
Expand All @@ -140,7 +219,7 @@ namespace Thermochimica

std::vector<double> getAllElementPotential()
{
auto [elements, species] = getReinitDataSizes();
auto elements = getReinitDataSizes().first;
std::vector<double> potential(elements);
TCAPI_getAllElementPotential(potential.data());
return potential;
Expand Down
12 changes: 11 additions & 1 deletion src/Thermochimica-cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -26,6 +27,14 @@ namespace Thermochimica
void resetThermo();
void resetThermoAll();

// utilitiy functions for consistency check / database record
std::pair<std::size_t, std::size_t> getNumberPhasesDatabase();
std::vector<std::string> getPhaseNamesDatabase();
std::string getPhaseNameAtIndex(int phase_index);
std::vector<std::size_t> getNumberSpeciesDatabase();
std::vector<std::string> getSpeciesInPhaseDatabase(int phase_index);
std::vector<std::vector<std::string>> getSpeciesDatabase();

// re-initialization-related functions
void saveReinitData();
std::pair<int, int> getReinitDataSizes();
Expand Down Expand Up @@ -69,7 +78,8 @@ namespace Thermochimica
getMqmqaConstituentFraction(const std::string &phaseName, int sublattice, const std::string &constituent);

// Reinitialization data
struct reinitData {
struct reinitData
{
std::vector<int> assemblage;
std::vector<double> molesPhase;
std::vector<double> elementPotential;
Expand Down
2 changes: 1 addition & 1 deletion src/Thermochimica.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Thermochimica.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 27 additions & 0 deletions src/api/CouplingUtilities.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 61d2af5

Please sign in to comment.