diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d2aeb1a..f5e63790 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,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) -add_executable(sciantix ${SOURCES}) -if (UNIX) - set(CMAKE_EXECUTABLE_SUFFIX ".x") +# Add executable sciantix.x (or .exe) or create static library +if(COUPLING_TU) + dd_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/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). diff --git a/include/coupling/TUSrcCoupling.h b/include/coupling/TUSrcCoupling.h new file mode 100644 index 00000000..c97a4409 --- /dev/null +++ b/include/coupling/TUSrcCoupling.h @@ -0,0 +1,42 @@ +////////////////////////////////////////////////////////////////////////////////////// +// _______. ______ __ ___ .__ __. .___________. __ ___ ___ // +// / | / || | / \ | \ | | | || | \ \ / / // +// | (----`| ,----'| | / ^ \ | \| | `---| |----`| | \ V / // +// \ \ | | | | / /_\ \ | . ` | | | | | > < // +// .----) | | `----.| | / _____ \ | |\ | | | | | / . \ // +// |_______/ \______||__| /__/ \__\ |__| \__| |__| |__| /__/ \__\ // +// // +// Originally developed by D. Pizzocri & T. Barani // +// // +// Version: 2.1 // +// Year: 2024 // +// Authors: D. Pizzocri, G. Zullo. // +// // +////////////////////////////////////////////////////////////////////////////////////// + +/** + * @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 072335e4..42859f1d 100644 --- a/include/file_manager/InputReading.h +++ b/include/file_manager/InputReading.h @@ -25,30 +25,30 @@ /** * @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, 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[]); +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 8ba0e44b..b3a2e1e9 100644 --- a/src/classes/Simulation.C +++ b/src/classes/Simulation.C @@ -31,21 +31,20 @@ 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, - Sciantix_diffusion_modes + Sciantix_options, + Sciantix_history, + Sciantix_variables, + Sciantix_scaling_factors, + Sciantix_diffusion_modes ); - setGas(); setMatrix(); setSystem(); @@ -54,35 +53,37 @@ void Simulation::initialize( void Simulation::execute() { - Burnup(); + #if !defined(COUPLING_TU) + Burnup(); - EffectiveBurnup(); + 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 new file mode 100644 index 00000000..2f770ef5 --- /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: D. Pizzocri, G. Zullo. // +// // +////////////////////////////////////////////////////////////////////////////////////// + +#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 fcba62ad..5f83b332 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[] ) { @@ -76,12 +76,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]; } }