From 72a53de5264666e04e21326e561ade51fa00a60e Mon Sep 17 00:00:00 2001 From: Elena Travaglia Date: Mon, 23 Sep 2024 08:35:16 +0100 Subject: [PATCH 1/4] issue #19, Coupling of Sciantix with the v1m1j24 version of Transuranus --- CMakeLists.txt | 18 +++-- include/coupling/TUSrcCoupling.h | 42 +++++++++++ include/file_manager/InputReading.h | 22 ++++-- src/classes/Simulation.C | 24 ++++--- src/coupling/TUSrcCoupling.C | 106 ++++++++++++++++++++++++++++ src/operations/SetVariables.C | 18 +++-- 6 files changed, 203 insertions(+), 27 deletions(-) create mode 100644 include/coupling/TUSrcCoupling.h create mode 100644 src/coupling/TUSrcCoupling.C diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d2aeb1a..01593042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # This CMakeLists.txt file is useful when compiling SCIANTIX with the cmake tool -# +# # output: # > build directory with executable in build/sciantix.x # @@ -28,6 +28,10 @@ endfunction() # Enable C++ compiler enable_language (CXX) +# Set option for coupling with TU +option (COUPLING_TU OFF) + +# Include CTest include(CTest) enable_testing() @@ -42,10 +46,16 @@ file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.C) # Set custom object file directory (to have all object files in the obj directory) set(CMAKE_OBJECT_PATH_PREFIX ${PROJECTSOUR}/obj/) -# Add executable sciantix.x (or .exe) -add_executable(sciantix ${SOURCES}) -if (UNIX) + +# Add executable sciantix.x (or .exe) or create static library +if(COUPLING_TU) + add_library(sciantix STATIC ${SOURCES}) + set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") +else() + add_executable(sciantix ${SOURCES}) + if (UNIX) set(CMAKE_EXECUTABLE_SUFFIX ".x") + endif() endif() # Copy all object files in obj directory by using a custom command diff --git a/include/coupling/TUSrcCoupling.h b/include/coupling/TUSrcCoupling.h new file mode 100644 index 00000000..86698f61 --- /dev/null +++ b/include/coupling/TUSrcCoupling.h @@ -0,0 +1,42 @@ +////////////////////////////////////////////////////////////////////////////////////// +// _______. ______ __ ___ .__ __. .___________. __ ___ ___ // +// / | / || | / \ | \ | | | || | \ \ / / // +// | (----`| ,----'| | / ^ \ | \| | `---| |----`| | \ V / // +// \ \ | | | | / /_\ \ | . ` | | | | | > < // +// .----) | | `----.| | / _____ \ | |\ | | | | | / . \ // +// |_______/ \______||__| /__/ \__\ |__| \__| |__| |__| /__/ \__\ // +// // +// Originally developed by D. Pizzocri & T. Barani // +// // +// Version: 2.1 // +// Year: 2023 // +// Authors: E. Travaglia // +// // +////////////////////////////////////////////////////////////////////////////////////// + +/** + * @brief This is a file required for TRANSURANUS-SCIANTIX coupling. + * With this file, two functions are defined (getSciantixOptions and callSciantix) in SCIANTIX. + * These two functions are also defined in TRANSURANUS, and are essentially required to create the + * communication channel between the two codes. + * + * @author E. Travaglia + * + */ + +#ifndef TUSRCCOUPLING_H +#define TUSRCCOUPLING_H + +#ifdef __cplusplus +extern "C" +{ + #endif + void getSciantixOptions(int options[], double scaling_factors[]); + void callSciantix(int options[], double history[], double variables[], + double scaling_factors[], double diffusion_modes[]); + + #ifdef __cplusplus +} +#endif + +#endif // TUSRCCOUPLING_H \ No newline at end of file diff --git a/include/file_manager/InputReading.h b/include/file_manager/InputReading.h index d8d8e166..a205beb5 100644 --- a/include/file_manager/InputReading.h +++ b/include/file_manager/InputReading.h @@ -25,21 +25,21 @@ /** * @brief Handles all input processing for the simulation. - * It opens necessary input files, reads configuration and initial condition data, + * It opens necessary input files, reads configuration and initial condition data, * logs this data for verification, and manages any missing file errors. - * + * * @author D. Pizzocri * @author T. Barani * @author G. Zullo * @author F. Bastien - * + * */ void InputReading( - int Sciantix_options[], - double Sciantix_variables[], + int Sciantix_options[], + double Sciantix_variables[], double Sciantix_scaling_factors[], int &Input_history_points, - std::vector &Time_input, + std::vector &Time_input, std::vector &Temperature_input, std::vector &Fissionrate_input, std::vector &Hydrostaticstress_input, @@ -51,4 +51,14 @@ void InputReading( void readSettings(std::ifstream &input, std::ofstream &output, int Sciantix_options[]); void readParameters(std::ifstream &input, std::ofstream &output, double Sciantix_Array[]); +unsigned short int ReadOneSetting( + std::string variable_name, + std::ifstream& input_file, + std::ofstream& output_file); + +double ReadOneParameter( + std::string variable_name, + std::ifstream& input_file, + std::ofstream& output_file); + #endif // INPUT_READING_H diff --git a/src/classes/Simulation.C b/src/classes/Simulation.C index c9793586..7765b028 100644 --- a/src/classes/Simulation.C +++ b/src/classes/Simulation.C @@ -31,18 +31,18 @@ Simulation* Simulation::getInstance() } void Simulation::initialize( - int Sciantix_options[], - double Sciantix_history[], - double Sciantix_variables[], - double Sciantix_scaling_factors[], + int Sciantix_options[], + double Sciantix_history[], + double Sciantix_variables[], + double Sciantix_scaling_factors[], double Sciantix_diffusion_modes[] ) { - setVariables( - Sciantix_options, - Sciantix_history, - Sciantix_variables, - Sciantix_scaling_factors, + setVariables( + Sciantix_options, + Sciantix_history, + Sciantix_variables, + Sciantix_scaling_factors, Sciantix_diffusion_modes ); @@ -54,15 +54,17 @@ void Simulation::initialize( void Simulation::execute() { - Burnup(); +#if !defined(COUPLING_TU) + Burnup(); EffectiveBurnup(); +#endif GapPartialPressure(); UO2Thermochemistry(); - StoichiometryDeviation(); + StoichiometryDeviation(); HighBurnupStructureFormation(); diff --git a/src/coupling/TUSrcCoupling.C b/src/coupling/TUSrcCoupling.C new file mode 100644 index 00000000..f91e7db8 --- /dev/null +++ b/src/coupling/TUSrcCoupling.C @@ -0,0 +1,106 @@ +////////////////////////////////////////////////////////////////////////////////////// +// _______. ______ __ ___ .__ __. .___________. __ ___ ___ // +// / | / || | / \ | \ | | | || | \ \ / / // +// | (----`| ,----'| | / ^ \ | \| | `---| |----`| | \ V / // +// \ \ | | | | / /_\ \ | . ` | | | | | > < // +// .----) | | `----.| | / _____ \ | |\ | | | | | / . \ // +// |_______/ \______||__| /__/ \__\ |__| \__| |__| |__| /__/ \__\ // +// // +// Originally developed by D. Pizzocri & T. Barani // +// // +// Version: 2.1 // +// Year: 2024 // +// Authors: E. Travaglia // +// // +////////////////////////////////////////////////////////////////////////////////////// + +#include "TUSrcCoupling.h" +#include "Simulation.h" +#include "InputReading.h" +#include + +/** + * @brief This is a file required for TRANSURANUS-SCIANTIX coupling. + * With this file, two functions are defined (getSciantixOptions and callSciantix) in SCIANTIX. + * These two functions are also defined in TRANSURANUS, and are essentially required to create the + * communication channel between the two codes. + * + * @author E. Travaglia + * + */ + +void callSciantix(int options[], double history[], double variables[], double scaling_factors[], double diffusion_modes[]) +{ + Simulation* simulation = Simulation::getInstance(); + + simulation->initialize(Sciantix_options, Sciantix_history, Sciantix_variables, Sciantix_scaling_factors, Sciantix_diffusion_modes); + + simulation->execute(); + + simulation->update(Sciantix_variables, Sciantix_diffusion_modes); + +} + +void getSciantixOptions(int options[], double scaling_factors[]) +{ + std::ofstream input_check("input_check.txt", std::ios::out); + + // Abort execution if any of the input files does not exist + std::ifstream input_settings("input_settings.txt", std::ios::in); + if (!input_settings) + ErrorMessages::MissingInputFile("input_settings.txt"); + + std::ifstream input_scaling_factors(TestPath + "input_scaling_factors.txt", std::ios::in); + + Sciantix_options[0] = ReadOneSetting("iGrainGrowth", input_settings, input_check); + Sciantix_options[1] = ReadOneSetting("iFissionGasDiffusivity", input_settings, input_check); + Sciantix_options[2] = ReadOneSetting("iDiffusionSolver", input_settings, input_check); + Sciantix_options[3] = ReadOneSetting("iIntraGranularBubbleBehavior", input_settings, input_check); + Sciantix_options[4] = ReadOneSetting("iResolutionRate", input_settings, input_check); + Sciantix_options[5] = ReadOneSetting("iTrappingRate", input_settings, input_check); + Sciantix_options[6] = ReadOneSetting("iNucleationRate", input_settings, input_check); + Sciantix_options[7] = ReadOneSetting("iOutput", input_settings, input_check); + Sciantix_options[8] = ReadOneSetting("iGrainBoundaryVacancyDiffusivity", input_settings, input_check); + Sciantix_options[9] = ReadOneSetting("iGrainBoundaryBehaviour", input_settings, input_check); + Sciantix_options[10] = ReadOneSetting("iGrainBoundaryMicroCracking", input_settings, input_check); + Sciantix_options[11] = ReadOneSetting("iFuelMatrix", input_settings, input_check); + Sciantix_options[12] = ReadOneSetting("iGrainBoundaryVenting", input_settings, input_check); + Sciantix_options[13] = ReadOneSetting("iRadioactiveFissionGas", input_settings, input_check); + Sciantix_options[14] = ReadOneSetting("iHelium", input_settings, input_check); + Sciantix_options[15] = ReadOneSetting("iHeDiffusivity", input_settings, input_check); + Sciantix_options[16] = ReadOneSetting("iGrainBoundarySweeping", input_settings, input_check); + Sciantix_options[17] = ReadOneSetting("iHighBurnupStructureFormation", input_settings, input_check); + Sciantix_options[18] = ReadOneSetting("iHighBurnupStructurePorosity", input_settings, input_check); + Sciantix_options[19] = ReadOneSetting("iHeliumProductionRate", input_settings, input_check); + Sciantix_options[20] = ReadOneSetting("iStoichiometryDeviation", input_settings, input_check); + Sciantix_options[21] = ReadOneSetting("iBubbleDiffusivity",input_settings,input_check); + +if (!input_scaling_factors.fail()) + { + Sciantix_scaling_factors[0] = ReadOneParameter("sf_resolution_rate", input_scaling_factors, input_check); + Sciantix_scaling_factors[1] = ReadOneParameter("sf_trapping_rate", input_scaling_factors, input_check); + Sciantix_scaling_factors[2] = ReadOneParameter("sf_nucleation_rate", input_scaling_factors, input_check); + Sciantix_scaling_factors[3] = ReadOneParameter("sf_diffusivity", input_scaling_factors, input_check); + Sciantix_scaling_factors[4] = ReadOneParameter("sf_temperature", input_scaling_factors, input_check); + Sciantix_scaling_factors[5] = ReadOneParameter("sf_fission_rate", input_scaling_factors, input_check); + Sciantix_scaling_factors[6] = ReadOneParameter("sf_cent_parameter", input_scaling_factors, input_check); + Sciantix_scaling_factors[7] = ReadOneParameter("sf_helium_production_rate", input_scaling_factors, input_check); + Sciantix_scaling_factors[8] = ReadOneParameter("sf_dummy", input_scaling_factors, input_check); + } + else + { + Sciantix_scaling_factors[0] = 1.0; + Sciantix_scaling_factors[1] = 1.0; + Sciantix_scaling_factors[2] = 1.0; + Sciantix_scaling_factors[3] = 1.0; + Sciantix_scaling_factors[4] = 1.0; + Sciantix_scaling_factors[5] = 1.0; + Sciantix_scaling_factors[6] = 1.0; + Sciantix_scaling_factors[7] = 1.0; + Sciantix_scaling_factors[8] = 1.0; + } + + input_check.close(); + input_settings.close(); + input_scaling_factors.close(); +} diff --git a/src/operations/SetVariables.C b/src/operations/SetVariables.C index 41216b97..e2652b9c 100644 --- a/src/operations/SetVariables.C +++ b/src/operations/SetVariables.C @@ -18,10 +18,10 @@ #include "Simulation.h" void Simulation::setVariables( - int Sciantix_options[], - double Sciantix_history[], - double Sciantix_variables[], - double Sciantix_scaling_factors[], + int Sciantix_options[], + double Sciantix_history[], + double Sciantix_variables[], + double Sciantix_scaling_factors[], double Sciantix_diffusion_modes[] ) { @@ -46,7 +46,7 @@ void Simulation::setVariables( toOutputStoichiometryDeviation = input_variable["iStoichiometryDeviation"].getValue() > 0; - // Physics variable + // Physics variable physics_variable.push(SciantixVariable("Time step", "(s)", Sciantix_history[6], Sciantix_history[6], 0)); @@ -78,12 +78,18 @@ void Simulation::setVariables( sciantix_variable.push(initial_value); } +#if defined(COUPLING_TU) + + sciantix_variable["Burnup"]setInitialValue(Sciantix_history["Burnup"]); + +#endif + // Diffusion modes for (int i = 0; i < n_modes; ++i) { for (int j = 0; j <= 17; j++) { - modes_initial_conditions[j * n_modes + i] = Sciantix_diffusion_modes[j * n_modes + i]; + modes_initial_conditions[j * n_modes + i] = Sciantix_diffusion_modes[j * n_modes + i]; } } From 35f962dfb53b6207aade236394ccc2f2ec15ea2c Mon Sep 17 00:00:00 2001 From: Elena Travaglia Date: Mon, 23 Sep 2024 09:20:05 +0100 Subject: [PATCH 2/4] issue #19, Updated the README file --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 7625b529..9ce3885e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,14 @@ The validation database is available in the `regression` folder. The compiled executable, `sciantix.x`, will be located in the `build` directory. +4. **TRANSURANUS coupling:** The code can be coupled with the v1m1j24 version of TRANSURANUS software package distributed by JRC-EC Karlsruhe. + + In the build folder + - Generate the Makefile with CMake: `cmake -DCOUPLING_TU=ON ..` + - Compile the code: `make` + +The static library, `libsciantix.a`, will be located in the `build` directory. + ## Windows Installation A recommended approach for Windows users is to use the [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install). From e3dc00eb5ba6295329c906bc2e5895ff3834f60c Mon Sep 17 00:00:00 2001 From: giozu Date: Mon, 23 Sep 2024 13:27:49 +0200 Subject: [PATCH 3/4] minor header update and tabs --- CMakeLists.txt | 13 ++++---- include/coupling/TUSrcCoupling.h | 4 +-- include/file_manager/InputReading.h | 11 ++----- src/classes/Simulation.C | 49 ++++++++++++++--------------- src/coupling/TUSrcCoupling.C | 2 +- src/operations/SetVariables.C | 6 ++-- 6 files changed, 38 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01593042..f5e63790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,16 +46,15 @@ file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.C) # Set custom object file directory (to have all object files in the obj directory) set(CMAKE_OBJECT_PATH_PREFIX ${PROJECTSOUR}/obj/) - # Add executable sciantix.x (or .exe) or create static library if(COUPLING_TU) - add_library(sciantix STATIC ${SOURCES}) - set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") + dd_library(sciantix STATIC ${SOURCES}) + set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") else() - add_executable(sciantix ${SOURCES}) - if (UNIX) - set(CMAKE_EXECUTABLE_SUFFIX ".x") - endif() + add_executable(sciantix ${SOURCES}) + if (UNIX) + set(CMAKE_EXECUTABLE_SUFFIX ".x") + endif() endif() # Copy all object files in obj directory by using a custom command diff --git a/include/coupling/TUSrcCoupling.h b/include/coupling/TUSrcCoupling.h index 86698f61..c97a4409 100644 --- a/include/coupling/TUSrcCoupling.h +++ b/include/coupling/TUSrcCoupling.h @@ -9,8 +9,8 @@ // Originally developed by D. Pizzocri & T. Barani // // // // Version: 2.1 // -// Year: 2023 // -// Authors: E. Travaglia // +// Year: 2024 // +// Authors: D. Pizzocri, G. Zullo. // // // ////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/file_manager/InputReading.h b/include/file_manager/InputReading.h index a205beb5..ff136d24 100644 --- a/include/file_manager/InputReading.h +++ b/include/file_manager/InputReading.h @@ -51,14 +51,7 @@ void InputReading( void readSettings(std::ifstream &input, std::ofstream &output, int Sciantix_options[]); void readParameters(std::ifstream &input, std::ofstream &output, double Sciantix_Array[]); -unsigned short int ReadOneSetting( - std::string variable_name, - std::ifstream& input_file, - std::ofstream& output_file); - -double ReadOneParameter( - std::string variable_name, - std::ifstream& input_file, - std::ofstream& output_file); +unsigned short int ReadOneSetting(std::string variable_name, std::ifstream& input_file, std::ofstream& output_file); +double ReadOneParameter(std::string variable_name, std::ifstream& input_file, std::ofstream& output_file); #endif // INPUT_READING_H diff --git a/src/classes/Simulation.C b/src/classes/Simulation.C index 7765b028..e09a25c8 100644 --- a/src/classes/Simulation.C +++ b/src/classes/Simulation.C @@ -38,14 +38,13 @@ void Simulation::initialize( double Sciantix_diffusion_modes[] ) { - setVariables( - Sciantix_options, - Sciantix_history, - Sciantix_variables, - Sciantix_scaling_factors, - Sciantix_diffusion_modes + setVariables( + Sciantix_options, + Sciantix_history, + Sciantix_variables, + Sciantix_scaling_factors, + Sciantix_diffusion_modes ); - setGas(); setMatrix(); setSystem(); @@ -54,37 +53,37 @@ void Simulation::initialize( void Simulation::execute() { -#if !defined(COUPLING_TU) - Burnup(); + #if !defined(COUPLING_TU) + Burnup(); - EffectiveBurnup(); -#endif + EffectiveBurnup(); + #endif - GapPartialPressure(); + GapPartialPressure(); - UO2Thermochemistry(); + UO2Thermochemistry(); - StoichiometryDeviation(); + StoichiometryDeviation(); - HighBurnupStructureFormation(); + HighBurnupStructureFormation(); - HighBurnupStructurePorosity(); + HighBurnupStructurePorosity(); - GrainGrowth(); + GrainGrowth(); - GrainBoundarySweeping(); + GrainBoundarySweeping(); - GasProduction(); + GasProduction(); - GasDecay(); + GasDecay(); - IntraGranularBubbleBehavior(); + IntraGranularBubbleBehavior(); - GasDiffusion(); + GasDiffusion(); - GrainBoundaryMicroCracking(); + GrainBoundaryMicroCracking(); - GrainBoundaryVenting(); + GrainBoundaryVenting(); - InterGranularBubbleBehavior(); + InterGranularBubbleBehavior(); } \ No newline at end of file diff --git a/src/coupling/TUSrcCoupling.C b/src/coupling/TUSrcCoupling.C index f91e7db8..2f770ef5 100644 --- a/src/coupling/TUSrcCoupling.C +++ b/src/coupling/TUSrcCoupling.C @@ -10,7 +10,7 @@ // // // Version: 2.1 // // Year: 2024 // -// Authors: E. Travaglia // +// Authors: D. Pizzocri, G. Zullo. // // // ////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/operations/SetVariables.C b/src/operations/SetVariables.C index e2652b9c..e7485145 100644 --- a/src/operations/SetVariables.C +++ b/src/operations/SetVariables.C @@ -78,11 +78,11 @@ void Simulation::setVariables( sciantix_variable.push(initial_value); } -#if defined(COUPLING_TU) + #if defined(COUPLING_TU) - sciantix_variable["Burnup"]setInitialValue(Sciantix_history["Burnup"]); + sciantix_variable["Burnup"]setInitialValue(Sciantix_history["Burnup"]); -#endif + #endif // Diffusion modes for (int i = 0; i < n_modes; ++i) From 387203a2cbbb6bc3b8ee31e40743fc7b25412bbe Mon Sep 17 00:00:00 2001 From: giozu Date: Mon, 23 Sep 2024 13:33:19 +0200 Subject: [PATCH 4/4] minor fix --- include/file_manager/InputReading.h | 27 ++++++++++++--------------- src/operations/SetVariables.C | 1 - 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/file_manager/InputReading.h b/include/file_manager/InputReading.h index ff136d24..7efeefde 100644 --- a/include/file_manager/InputReading.h +++ b/include/file_manager/InputReading.h @@ -35,21 +35,18 @@ * */ void InputReading( - int Sciantix_options[], - double Sciantix_variables[], - double Sciantix_scaling_factors[], - int &Input_history_points, - std::vector &Time_input, - std::vector &Temperature_input, - std::vector &Fissionrate_input, - std::vector &Hydrostaticstress_input, - std::vector &Steampressure_input, - double &Time_end_h, - double &Time_end_s - ); - -void readSettings(std::ifstream &input, std::ofstream &output, int Sciantix_options[]); -void readParameters(std::ifstream &input, std::ofstream &output, double Sciantix_Array[]); + int Sciantix_options[], + double Sciantix_variables[], + double Sciantix_scaling_factors[], + int &Input_history_points, + std::vector &Time_input, + std::vector &Temperature_input, + std::vector &Fissionrate_input, + std::vector &Hydrostaticstress_input, + std::vector &Steampressure_input, + double &Time_end_h, + double &Time_end_s + ); unsigned short int ReadOneSetting(std::string variable_name, std::ifstream& input_file, std::ofstream& output_file); double ReadOneParameter(std::string variable_name, std::ifstream& input_file, std::ofstream& output_file); diff --git a/src/operations/SetVariables.C b/src/operations/SetVariables.C index e7485145..c1048bb2 100644 --- a/src/operations/SetVariables.C +++ b/src/operations/SetVariables.C @@ -49,7 +49,6 @@ void Simulation::setVariables( // Physics variable physics_variable.push(SciantixVariable("Time step", "(s)", Sciantix_history[6], Sciantix_history[6], 0)); - // History variable std::vector values = initializeHistoryVariable( Sciantix_history,