diff --git a/SFEM/README.md b/SFEM/README.md index 4328e1195dcb71787a9279d6e364de4aeda3441c..7ed382652c9ce8e74faaea5bb40dc2e31e3831c2 100644 --- a/SFEM/README.md +++ b/SFEM/README.md @@ -67,13 +67,13 @@ Instructions for Debian/Ubuntu based workstations are as follows. * Nsim =10 * The Random fields will be generated at the spatial points defined in terms of their coordinates. * The script tries to read a file in ```mechDir+'/GPData'```, where ```mechDir``` is the working directory, describing the list of spatial points. One example of points coordinates can be found in [rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv](./rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv) stored following 3 coordinates, point number and point volume (for a FE simulation). - * The random field number ```X``` is saved in the file ```mechDir+'/randomFields/RandField_X.csv'```, where ```mechDir``` is the working directory. The number of columns is the dimension of the random variable and the number of lines the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_0.csv](./rnnRF/randomFields/RandField_0.csv). - * The random field number ```X``` along with the spatial points coordinates is saved in the file ```mechDir+'/randomFields/RandField_And_GP_X.csv'```, where ```mechDir``` is the working directory. The number of columns is the dimension of the random variable plus the 3 spatial coordinates and the number of lines the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_And_GP_0.csv](./rnnRF/randomFields/RandField_And_GP_0.csv). + * The random field number ```X``` is saved in the file ```mechDir+'/randomFields/RandField_X.csv'```, where ```mechDir``` is the working directory. The number of columns is the dimension of the random vector and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_0.csv](./rnnRF/randomFields/RandField_0.csv). + * The random field number ```X``` along with the spatial points coordinates is saved in the file ```mechDir+'/randomFields/RandField_And_GP_X.csv'```, where ```mechDir``` is the working directory. The number of columns is the dimension of the random vector plus the 3 spatial coordinates and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_And_GP_0.csv](./rnnRF/randomFields/RandField_And_GP_0.csv). * The variable ```recomputePDF=True``` forces the evaluation of the spectral density matrix, which will be saved in ```mechDir+'/randomFields/H_pdf.dat'```. * The variable ```recomputePDF=False``` reads the spectral density matrix already saved in ```mechDir+'/randomFields/H_pdf.dat'``` -* [plotRF.py](./generateRF/plotRF.py): file used to vizualize the distribution of the random variables. +* [plotRF.py](./generateRF/plotRF.py): file used to vizualize the distribution of the random vector. * Reads the ```N``` random fields of type ```'RandField_X.csv'``` found in ```mechDir+'/randomFields/'```, where ```mechDir``` is the working directory. Examples of generated 2-dimension RFs can be found in [rnnRF/randomFields/](./rnnRF/randomFields/). - * Plot the distribution of the random variables. + * Plot the distribution of the random vector. * [vizualizeRF.py](./generateRF/vizualizeRF.py): file used to generate a gmsh (www.gmsh.info) compatible file to vizualize the random fields * Reads the ```N``` random fields of type ```'RandField_And_GP_X.csv'``` found in ```mechDir+'/randomFields/'```, where ```mechDir``` is the working directory. Examples of generated 2-dimension RFs can be found in [rnnRF/randomFields/](./rnnRF/randomFields/). * Uses the mesh structure of the considered application. The script tries to read stress file in ```mechDir+'/GPData'```, where ```mechDir``` is the working directory, describing the elements structure. One example of stress file can be found in [rnnRF/GPData/stress_step1.msh](./rnnRF/GPData/stress_step1.msh). @@ -108,9 +108,9 @@ Instructions for Debian/Ubuntu based workstations are as follows. In this example, we consider a multiscale lattice simulation in which the lattice cell response is substituted by a [MOAMMM stochastic neural network](https://gitlab.uliege.be/moammm/moammmPublic/syntheticdata/sveresponses) acting as a surrogate. To this end we generate 10 random fields of correlated cell length and struts radius. MC siulations can then be conducting. -### Generate the Gauss-point list and mesh structures for the random field generator +### Generate the Gauss-points list and mesh structure for the random field generator -Form the [rnnRF](./rnnRF/) directory, run +From the [rnnRF](./rnnRF/) directory, run ``` bash python3 generateGPInfo.py @@ -118,192 +118,19 @@ python3 generateGPInfo.py After execution the ouput files are store in ```'rnnRF/GPData'```: * The script write the Gauss points coordinates in the directory ```'rnnRF/GPData'```. One example of points coordinates can be found in [rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv](./rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv) stored following 3 coordinates, point number and point volume (for a FE simulation). - * The script write the mesh structure in the directory ```'rnnRF/GPData'```. One example of stress file can be found in [rnnRF/GPData/stress_step1.msh](./rnnRF/GPData/stress_step1.msh). - -### Thread creation - -Threads are folders that contain the randomly generated SVE's alongside their intended loading paths, whose parameters are defined inside the [driver.py](./Scripts/driver.py) script. Executing a thread, generates the data by simulating the SVE response on the load paths. - -Thread creation is done by executing the driver script with the ```thread``` argument. - -```bash -python3 driver.py thread -``` - -The number of threads created per each ```load_type``` equals to the variable ```n_split``` - -Thread are created inside the ```Cell<cell_type>/DataPaths``` directory per the following **naming scheme**: - -```G<cell_type>Y<cell_num>L<size>Rad<radius><mat>_<load_path>``` - -### Thread execution - -Threads created in the last step can be simulated using the dG3D Finite element solver available opensource (GPL) under the cm3Libraries. For access visit [MOAMMM Developed software](https://www.moammm.eu/index.php/developed-code/) - -To execute threads, run the following inside in the directory where threads are generated with thread numbers as arguments. - -For example, execting the following will run thread 5 , 7 and 10. - -```bash -./run.sh 5 7 10 -``` - -## Database and Visualization - -Data and load paths are stored under their respective Cell names as per the naming convention detailed in [thread creation](#thread-creation) and [load path generation](#load-path-generation). - -### Load Path Visualization - -Histograms, path reports and visual representation of randomly selected paths are computed automatically at generation time, and can be found inside the ```pathReports``` folder under the unique load path storage folder. - -Chosen load paths can be visualized by specifying the unique folder and paths inside the driver scripts. - -| Parameter | Type | Description | -|:----------------|:---------------:|:----------------------------------------------| -| vis_load_folder | String | Name of the unique load folder folder | -| vis_load_paths | List of strings | Names of the selected paths inside the folder | - -Executing the driver script with the ```vload``` argument, will generate and save the plots under the ```vis_load_folder```. - -A set of paths are specified in the example driver.py script and can be generated as follows. - -```bash -python3 driver.py vload -``` - -> :blue_book: Info -> ```vis_load_folder``` only needs the name of the parent folder. -> No need to append ```load_dir```. Absolute path is determined automatically. - -### Data Path Visualization - -Selected data paths can be visualized by specifying the unique folder and paths inside the driver scripts. - -| Parameter | Type | Description | -|:----------------|:---------------:|:----------------------------------------------| -| vis_data_folder | String | Name of the unique data folder folder | -| vis_data_paths | List of strings | Names of the selected paths inside the folder | - -Executing the driver script with the ```vdata``` argument, will generate and save the plots under the ```vis_data_folder```. - -A set of paths are specified in the example driver.py script and can be generated as follows. - -```bash -python3 driver.py vdata -``` - -> :blue_book: Info -> ```vis_data_folder``` only needs the name of the parent folder. -> No need to append ```data_dir```. Absolute path is determined automatically. - -### Alternate Method - -This method requires appending, location of```driver.py``` in your ```$PATH``` enviroment variable. - -Executing driver.py with the ```v``` argument followed by the names of (load or data) paths (seperated with spaces) at the stored location will generate the visualizations and save them at (one level above the parent folder) under Plots. +* The script write the mesh structure in the directory ```'rnnRF/GPData'```. One example of stress file can be found in [rnnRF/GPData/stress_step1.msh](./rnnRF/GPData/stress_step1.msh). -For example executing the following at stored location will visualize the 4 specified loadpaths +### Generate Random Fields -```bash -driver.py v strainPath80001.csv strainPath80002.csv strainPath80003.csv strainPath80004.csv -``` - -This method can be used to quickly visualize paths withoutchanging the driver.py script. - -### Histograms for Generated Data - -Spread of generated data can be visualized by executing the driver script with the ```collect``` argument. +From the [generateRF](./generateRF/) directory, select ```testNb=1``` for ```'rnnRF'``` in the file [generateRF.py](./generateRF/generateRF.py) and then run ```bash -python3 driver.py collect +python3 generateRF.py ``` -By default this will generate histograms all data paths for the specified ```cell_type``` contained in the ```DataPaths``` and store them in the ```CollectedData``` folder - -## Surrogate Modelling - -### RNN Parameters - -Parameters for Recurrent neural network are defined inside the [driver.py](Scripts/driver.py), categorized as: - -| Parameter | Type | Description | -|:----------------|:--------------:|:-----------------------------------------------------------------------------------------------------| -| Datatype | String Literal | IO (Conjugate) Pair. "GS" for Green Lagrange Strain, Second Piola Kirchoff Stress | -| n_pad | Int | Padding for Normalized Data | -| input_dim | Int | Width of FF Layers | -| hidden_dim | Int | RNN hidden variables | -| forward_layers0 | Int | Depth of FF Output Layers | -| forward_layers | Int | Depth of FF Input Layers | -| default | flag | Choice of device for training/testing: "cpu", "cuda" or True (for default) | -| ratio | float | Training / Testing Ratio | -| Nt | Int | Batch iterations for training | -| mini_batch | float | Batch size of testing_data specified as a ratio: 1.0 selects all testing data, 0.25 selects quarter. | -| n_epochs1 | Int | Epoch Training per batch | -| n_epochs2 | Int | Epoch Training per batch ( Optional) | -| n_epochs3 | Int | Epoch Training per batch ( Optional) | -| lr | float | learning rate | -| decay_factor | float | learning rate decay factor to to applied at the end of batch epoch (Optional) | -| Pn | Int | Print training status per epoch | -| Testn | Int | Print testing status per epoch | -| Sn | Int | Save model per epoch | - -## Surrogate Training - -### Data collection - -First the data for training needs to be collected for the surrogate to start training. This entails running the driver.py script with the collect argument. - -```bash -python3 driver.py collect -``` - -By default this will collect all the data availible under the DataPaths subfolder for a specified cell defined in the driver.py script, and store it as a OrigG_S.dat inside the CollectedData folder. This will also generate a Bounds.dat File that will store the upper and lower bounds of the generated data. - -### Training - -Invoking the driver.py script with arguments ```train cold``` starts the training process (from scratch), per the RNN parameters definied in the last section. - -```bash -python3 driver.py train cold -``` -Setting the parameter `default` to `TRUE` will automatically use GPU if (CUDA compatible) is available, -however it can also be set manually by setting its value to "cpu" or "cuda". - -If memory becomes a bottleneck, a mini batch of data which gets randomly shuffled per batch iteration -can be used for training. The size of mini batch is given as a ratio to original size in the parameter `mini_batch`, where -each mini_batch gets `n_epochs` after which a new shuffled mini_batch is sampled. This goes on `Nt` batch iterations. - -### Warm start - -Invoking the driver.py script with arguments ```train warm``` resumes the training process from a previous saved state. - -```bash -python3 driver.py train warm -``` - -## Surrogate Testing - -Inside the RNNSurrogate folder training and testing error plots are generated whose update frequency is dictated by the variable ```Pn```. Intermediate state for warm start is saved per the frequency defined as ```Sn``` using the folllowing naming convention. - -```ModelGRU_GS_0f<forward_layers0>_<input_dim>_f<forward_layers>_<hidden_dim>``` - -### Visualization - -#### Training Plots - -Executing the driver.py script with arguments ```pred``` and ```train``` followed by the index of the training paths will plot its stress-strain response alongside the surrogate prediction. e.g. executing the following will populate the comparison of data path 5, 8 and 32 in the training data set with its predicted values. - -```bash -python3 driver.py pred train 5 8 32 -``` - -#### Testing Plots - -Executing the driver.py script with arguments ```pred``` and ```test``` followed by the index of the testing paths will plot its stress-strain response alongside the surrogate prediction. e.g. executing the following will populate the comparison of data path 2, 4 and 9 in the testing data set with its predicted values. - -```bash -python3 driver.py pred test 2 4 9 -``` +After execution the ouput files are store in ```'rnnRF/randomFields'```: +* The random field number ```X``` is saved in the file ```'rnnRF/randomFields/RandField_X.csv'```. The number of columns is the dimension (2) of the random vector and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_0.csv](./rnnRF/randomFields/RandField_0.csv). +* The random field number ```X``` along with the spatial points coordinates is saved in the file ```'rnnRF/randomFields/RandField_And_GP_X.csv'```. The number of columns is the dimension (2) of the random vector plus the 3 spatial coordinates and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in [rnnRF/randomFields/RandField_And_GP_0.csv](./rnnRF/randomFields/RandField_And_GP_0.csv). ## Disclaimer