diff --git a/docs/arduino/img/equation-1-2.png b/docs/arduino/img/equation-1-2.png new file mode 100644 index 00000000..4734aac2 Binary files /dev/null and b/docs/arduino/img/equation-1-2.png differ diff --git a/docs/arduino/img/equation-3.png b/docs/arduino/img/equation-3.png new file mode 100644 index 00000000..f0b62dc3 Binary files /dev/null and b/docs/arduino/img/equation-3.png differ diff --git a/docs/arduino/img/equation-4.png b/docs/arduino/img/equation-4.png new file mode 100644 index 00000000..db5dd592 Binary files /dev/null and b/docs/arduino/img/equation-4.png differ diff --git a/docs/arduino/usecase.md b/docs/arduino/usecase.md index 223ed441..3c31f067 100644 --- a/docs/arduino/usecase.md +++ b/docs/arduino/usecase.md @@ -1,280 +1,74 @@ # From constitutive parameter calibration to site response analysis -**Pedro Arduino - University of Washington** -A collection of educational notebooks to introduce model parameter calibration and site response analysis using OpenSees in DesignSafe-CI. The example makes use of the following DesignSafe resources: +## A collection of educational notebooks to introduce model parameter calibration and site response analysis using OpenSees in DesignSafe-CI. -[Simulation on DS - OpenSees](https://www.designsafe-ci.org/rw/workspace/#!/OpenSees::Simulation){target=_blank}
-[Jupyter notebooks on DS Juypterhub](https://www.designsafe-ci.org/rw/workspace/#!/Jupyter::Analysis){target=_blank}
+**Pedro Arduino - University of Washington**
+**Sang-Ri Yi - SimCenter, UC Berkeley**
+**Aakash Bangalore Satish - SimCenter, UC Berkeley** -## Background -### Citation and Licensing +*key Words: quoFEM, OpenSees, Tapis, Python* -* Please cite [Chen, L. et al. (2021)](https://peer.berkeley.edu/sites/default/files/2021_chen_final.pdf){target=_blank} to acknowledge the use of resources from this use case. - -* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246){target=_blank} to acknowledge the use of DesignSafe resources. - -* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html){target=_blank}. - -## Description -Site response analysis for liquefiable soils is fundamental in the estimation of demands on civil infrastructure including buildings and lifelines. Current state of the art in numerical methods in geotechnical engineering require the use of advance constitutive models and fully couple nonlinear finite element (FEM) tools. Advanced constitutive models require calibration of material parameters based on experimental tests. These parameters include uncertainties that in turn propagate to uncertenties in the estimation of demands. The products included in this use-case provide simple examples showing how to achieve site response analysis including parameter identification and uncertainty quantification using SimCenter tools and the DesignSafe cyber infrastructure. - -

-Propagation of vertical waves in site response analysis -

-

Fig.1 - Site response problem

- -This document presents a suite of Jupyter Notebooks published in DesignSafe that navigate the process of constitutive model parameter calibration and site response analysis for a simple liquefaction case. They also introduce methods useful when using DesignSafe infrastructure in TACC. All notebooks leverage existing SimCenter backend functionality (e.g. Dakota, OpenSees, etc) implemented in quoFEM and run locally and in TACC through DesignSafe. Three notebooks are included for this purpose: - -1. **Site response workflow notebook**: This notebook introduces typical steps used in geotechnical numerical analysis workflows taking advantage of Jupyter and DesignSafe. - -2. **Parameter calibration notebook**: This notebook is customized for the PM4Sand model and presents the estimation of its main parameters that best fit experimental data as well as their uncertainty. - -3. **Propagation of parameter undertainty in site response analysis notebook**: This notebook introduces methods to propagate material parameter uncertainties in site reponse analysis. +## Resources -This first version of this use-case page includes details on the site response workflow notebook. The parameter calibration and propagation of uncertainties notebooks will be updated in a second version. +The example makes use of the following DesignSafe resources: +[DesignSafe - Jupyter notebooks on DS Juypterhub](https://www.designsafe-ci.org/rw/workspace/#!/Jupyter::Analysis)
+[SimCenter - quoFEM](https://simcenter.designsafe-ci.org/research-tools/quofem-application)
+[OPenSees - Simulation on DS](https://www.designsafe-ci.org/rw/workspace/#!/OpenSees::Simulation)
-## Site response workflow notebook -The *site response workflow notebook* introduces typical steps used in the evaluation of the surface response for a site with liquefiable soil. -The notebook takes advantage of the site response problem to introduce a general numerical analysis workflow shown in Figure 2 that includes: - -1. running OpenSees using a **TAPIS** APP, -2. postprocessing results using python, -3. generating authomatic reports using rst2pdf or latex, and -4. Creating animated plots using visualization widgets. +and the following Jupyter notebooks are available to facilitate the analysis of each case. You can access and run them directly from the DesignSafe community folder.

- OpenSees numericla simulation workflow -

-

Fig.2 - OpenSees numerical simulation workflow

+| Site Response | Notebook | +| :-------: | :---------: | +| FreeField Response | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb) | -The soil profile shown in Figure 3 includes a 5.0m loose sand underlain by a 1.0 m dense soil.The loose sand is modeled using the PM4Sand constitutive model for liquefiable soils available in OpenSees. The dense sand is considered linear elastic. The groundwter table is assumed at 2.0 m making the lower 3.0 m of the loose sand susceptible to liquefaction. The soil profile is subject to a dynamic excitation at its base. The site response of interest includes (i) the surface acceleration, (ii) profiles of lateral displacement, horizontal acceleration, maximum shear strain, and cyclic stress ratio and (iii) stress strain and pore pressure plots for a point in the middle of the soil profile. The opensees model definition, analysis steps, and recorders are contained in the [N10_T3.tcl](FreeField-JupyterNB/N10_T3.tcl) file, and the input signal is in [velocity.input](FreeField-JupyterNB/velocity.input). The model can be run using OpenSees in any OS framework. + quoFEM | Notebook | +| :-------: | :---------: | +| Sensitivity analysis | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/GlobalSensitivity/quoFEM-Sensitivity.ipynb)| +| Bayessian calibration | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/BayesianCalibration/quoFEM-Bayesian.ipynb)| +| Forward propagation | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/ForwardPropagation/quoFEM-Propagation.ipynb)| -

-N10_T3 soil profile with liquefiable layer

-

Fig.3 - N10_T3 soil profile with liquefiable layer

- -The notebook, and required scripts, are available in the [DesignSafe/community](https://www.designsafe-ci.org/data/browser/public/designsafe.storage.community/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand){target=_blank} folder and can be executed without any modification. -Users are invited to try this notebook and use any parts of it. -The notebook can be broken down into four main components: -
    -
  1. Setup TAPIS/AGAVE APP and run OpenSees job
  2. -
  3. Post process results
  4. -
  5. Generate report
  6. -
  7. Generate interactive plots
  8. -
- -It is emphasize that the main motivation of this notebook is to take advantage of DesignSafe resources. -Therefore, relevant details for each component as it pertains to access to DesignSafe-CI resources are described here. - -### Setup tapis/agave app and run OpenSees job - -The notebook can be executed launching *Jupyter Lab* in Designsafe. This opens a user *docker container* in DesignSafe that includes all the functionality required to execute jupyter commands. This gives immediate access to the **agavepy** module from which it is possible to run any **TAPIS** APP. - -#### Setup job description - -A few commands are required to setup a TAPIS OpenSees job in DesignSafe. This requires definition of the TAPIS APP to use, control variables, parameters and inputs. The control variables define the infrastructre resources requested to TACC. The parameters define the executable (opensees), version (current), and opensees input file to run. For the site response case the *OpenseesSp-3.3.0u1* app is selected. The main steps required to setup an agave job are: - - -1. importing agave/tapis, -2. getting the specific app of interest, -3. defining control variables, parameters and inputs, and -4. encapsulating all data in a job_description array - -The python code shown below exemplifies these steps. The complete set of commands is available in the notebook. The job_description array includes all the information required to submit the job. - -```python -# Import Agave -from agavepy.agave import Agave -ag = Agave.restore() - -# Get Agave app of interest -app_id = 'OpenseesSp-3.3.0u1' -app = ag.apps.get(appId=app_id) - -# Define control tapis-app variables -control_batchQueue = 'small' -control_jobname = 'Jup_OP_Tapis' -control_nodenumber = '1' -control_processorsnumber = '8' -control_memorypernode = '1' -control_maxRunTime = '00:1:00' - -# Define inputs -# Identify folder with input file in DesignSafe -cur_dir = os.getcwd() -if ('jupyter/MyData' in cur_dir ): - cur_dir = cur_dir.split('MyData').pop() - storage_id = 'designsafe.storage.default' - input_dir = ag.profiles.get()['username']+ cur_dir - input_uri = 'agave://{}/{}'.format(storage_id,input_dir) - input_uri = input_uri.replace(" ","%20") -... -... -inputs = {"inputDirectory": [ input_uri ]} - -# Define parameters -parameter_executable = 'opensees' -parameter_version = 'current' -input_filename = 'N10_T3.tcl' -parameters = {} -parameters["executable"] = parameter_executable -parameters["version"] = parameter_version -parameters["inputScript"] = input_filename - - -# Set job_description array -job_description = {} -job_description["appId"] = (app_id) -... -job_description["inputs"] = inputs -job_description["parameters"] = parameters -``` - -#### Run OpenSees Job - -Submitting a job using DesignSafe HPC resources requires the use of agave job.submit(); and passing the job_description array as argument. Checking the status of a job can be done using jobs.getStatus(). The python code shown below exemplifies these commands. When submitting a job, agave copies all the files present in the input folder to a temporary location that is used during execution. After completion agave copies all the results to an archived folder. - -```python -import time -job = ag.jobs.submit(body=job_description) -print(" Job launched. Status provided below") -print(" Can also check in DedignSafe portal under - Workspace > Tools & Application > Job Status") - -status = ag.jobs.getStatus(jobId=job["id"])["status"] -while status != "FINISHED": - status = ag.jobs.getStatus(jobId=job["id"])["status"] - print(f"Status: {status}") - time.sleep(60) -``` - -### Postprocess Results - -Postprocessing requires identification of the location of the archived files. This is done interrogating a particular agave job and evaluating the correct folder location. The python code lines shown below exemplifly the steps required for this purpose. - -#### Identify job, archived location and user - -``` python -jobinfo = ag.jobs.get(jobId=job.id) -jobinfo.archivePath -user = jobinfo.archivePath.split('/', 1)[0] - -import os -%cd .. -cur_dir_name = cur_dir.split('/').pop() -os.chdir(jobinfo.archivePath.replace(user,'/home/jupyter/MyData')) -if not os.path.exists(cur_dir_name): - os.makedirs(cur_dir_name) -os.chdir(cur_dir_name) -``` -#### Plot Results - -Once in the archived folder (cur_dir_name), postprocessing can be done using python scripts that operate on output files. For the particualar case of the site response analysis used in this notebook three scripts are used to evaluate: -1. surface acceleration time history and its response spectrum, -2. profiles of maximum displacement, peak horizontal acceleration (PHA), peak shear strain, and cyclic stress ratio, and -3. Stress-strain and excess pore water pressure at the middle of the liquefiable layer. - -The python code and figures shown below exemplify these steps. All python scripts are available in the notebook community folder. - -Plot acceleration time hisotory and response spectra on log-linear scale -``` python -from plotAcc import plot_acc -plot_acc() -``` - -

-Surface acceleration -Response spectrum -

-

Fig.4 - Surface acceleratio and response spectrum

- - -Plot profiles -``` python -from plotProfile import plot_profile -plot_profile() -``` +## Description -

-Profiles -

-

Fig.5 - Profiles of max displacement, PHA, Max shear strain and cyclic stress ratio

+Seismic site response refers to the way the ground responds to seismic waves during an earthquake. This response can vary based on the soil and rock properties of the site, as well as the characteristics of the earthquake itself. -Plot excess pore water pressure -``` python -from plotPorepressure import plot_porepressure -plot_porepressure() -``` +Site response analysis for liquefiable soils is fundamental in the estimation of demands on civil infrastructure including buildings and lifelines. For this purpose, current state of the art in numerical methods in geotechnical engineering require the use of advance constitutive models and fully couple nonlinear finite element (FEM) tools. Advanced constitutive models require calibration of material parameters based on experimental tests. These parameters include uncertainties that in turn propagate to uncertenties in the estimation of demands. The products included in this use-case provide simple examples showing how to achieve site response analysis including parameter identification and uncertainty quantification using SimCenter tools and the DesignSafe cyber infrastructure.

-Stress strain -Pore pressure +Propagation of vertical waves in site response analysis

-

Fig.6 - stress strain and pore pressure in the middle of liquefiable layer

- +

Fig.1 - Site response problem

-#### Generate report +## Implementation -Generating a summary report is a convenient way to present results from lengthy simulations prcesses. In jupyter this can be done invoking any posprocessor available in the docker container image. Among them rst2pdf is commonly distributed with python. For the site response notebook a simple ShortReport.rst file is included that collects the results and plots generated in a simple pdf file. The python code shown below, exemplifies this process and include: -1. Running rst2pdf on [ShortReport.rst](FreeField-JupyterNB/ShortReport.rst) -2. Posting the resulting pdf file in the jupyter notebook. For this it is convenient to define the PDF function shown below that specifies the format of the file in the screen. +This use-case introduces a suite of Jupyter Notebooks published in DesignSafe that navigate the process of constitutive model parameter calibration and site response analysis for a simple liquefaction case. They also introduce methods useful when using DesignSafe infrastructure in TACC. All notebooks leverage existing SimCenter backend functionality (e.g. Dakota, OpenSees, etc) implemented in quoFEM and run locally and in TACC through DesignSafe. The following two pages address these aspects, including: -Run rst2pdf, assign to pdf_fn, and call PDF show function -``` python -import sys -!{sys.executable} -m pip install rst2pdf -os.system('rst2pdf ShortReport.rst ShortReport.pdf') +1. [**Site response workflow notebook**](./usecase_siteResponse.md): This notebook introduces typical steps used a seismic site response analysis workflow taking advantage of Jupyter, OpenSees, and DesignSafe-CI. -pdf_fn = jobinfo.archivePath.replace(user, '/user/' + user + '/files/MyData') -pdf_fn += '/' -pdf_fn += cur_dir.split('/')[-1] -pdf_fn += '/ShortReport.pdf' -print pdf_fn +2. [**quoFEM Notebooks**](./usecase_quoFEM.md): These notebooks provide an introduction to uncertainty quantification (UQ) methods using *quoFEM* to address sensitivity, Bayesian calibration, and forward propagation specifically in the context of seismic site response. Three different analysis are discussed including: -PDF(pdf_fn , (750,600)) -``` + a. **Global sensitivity analysis** This notebook provides insight into which model parameters are critical for estimating triggering of liquefaction. -PDF function -``` python -class PDF(object): - def __init__(self, pdf, size=(200,200)): - self.pdf = pdf - self.size = size + b. **Parameter calibration notebook**: This notebook is customized for the PM4Sand model and presents the estimation of its main parameters that best fit experimental data as well as their uncertainty. - def _repr_html_(self): - return ''.format(self.pdf, self.size) + c. **Propagation of parameter undertainty in site response analysis notebook**: This notebook introduces methods to propagate material parameter uncertainties in site reponse analysis. - def _repr_latex_(self): - return r'\includegraphics[width=1.0\textwidth]{{{0}}}'.format(self.pdf) -``` -#### Create Interactive Plots +## Citation and Licensing -Finally, jupyter notebooks offer flexibility to invoke GUI widgets that can help present results in a dynamic and interactive manner. The python scripts shown below create interactive plots for pore water pressure and soil profile lateral displacements. The horizontal bars allow users interrogate each plot for results at any particular time. Complete pyhon scripts are included in the [interactiveplot.py](FreeField-JupyterNB/interactiveplot.py) available in community. +* Please cite [Aakash B. Satish et al. (2022)](https://doi.org/10.1007/978-3-031-11898-2_152){target=_blank} to acknowledge the use of resources from this use case.
-#### Pore water pressure +* Please cite [Sang-Ri Yi et al. (2022)](https://doi.org/10.1007/978-3-031-30125-4_6){target=_blank} to acknowledge the use of resources from this use case.
-``` python -from interactiveplot import createpwpplot, createDispplot -createpwpplot() -``` -

-Pore pressure interatvie plot -

-

Fig.7 - Pore pressure interactive plot

+* Please cite [Chen, L. et al. (2021)](https://peer.berkeley.edu/sites/default/files/2021_chen_final.pdf){target=_blank} to acknowledge the use of resources from this use case. -#### Displacement +* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246){target=_blank} to acknowledge the use of DesignSafe resources. -``` python -createDispplot() -``` +* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html){target=_blank}. -

-Displacement profile interatvie plot -

-

Fig.8 - Displacement proficle interactive plot

diff --git a/docs/arduino/usecase_matlab.md b/docs/arduino/usecase_matlab.md index be7dfeea..29e9659c 100644 --- a/docs/arduino/usecase_matlab.md +++ b/docs/arduino/usecase_matlab.md @@ -1,43 +1,40 @@ -# Launching a Matlab script from a Jupyter notebook +# Launching a Matlab script in Jupyter -**Pedro Arduino - University of Washington** +## Launching a Matlab Script from DesignSafe Jupyter Hub using a dedicated Tapis app -This document presents a Jupyter Notebook published in DesignSafe that navigate the process of launching a matlab script from jupyter using a DesignSafe matlab Tapis app. It also exemplifies how to combine matlab and python events in a single notebook. The example makes use of the following DesignSafe resources: +**Pedro Arduino - University of Washington** -[Jupyter notebooks on DS Juypterhub](https://www.designsafe-ci.org/rw/workspace/#!/Jupyter::Analysis){target=_blank}
+*key Words: Matlab, Tapis, Python* - +## Resources -## Background -### Citation and Licensing +This example makes use of the following DesignSafe resources: -* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246){target=_blank} to acknowledge the use of DesignSafe resources. +[![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/MatlabBatch/matlabBatch-VM.ipynb) -* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html){target=_blank}. +The notebook, and required scripts, are available in the Community Data folder and can be executed without any modification. Users are invited to try this notebook and use any parts of it. ## Description -The notebook utilizes a MATLAB Tapis app (*MATLAB-2022a-VM-1.0.0*) to launch any MATLAB script. For this instance, a simple MATLAB script serves as a example to showcase how to effectively use the app. The matlab script begins by reading acceleration time histories and performing two integrations to produce velocity and displacement time histories. The script then calculates the response spectra for each motion and generates a sequence of plots, while also saving numerical data in ASCII files. +This document presents a Jupyter Notebook published in DesignSafe that navigates the process of launching a matlab script from jupyter using a DesignSafe matlab Tapis app. It also exemplifies how to combine matlab and python events in a single notebook. + +The notebook utilizes a MATLAB Tapis app (*MATLAB-2022a-VM-1.0.0*) to launch any MATLAB script. In this example, a simple MATLAB script (*plotMotions.m*) serves as a example to showcase how to effectively use the app. The matlab script begins by reading acceleration time histories and performing two integrations to produce velocity and displacement time histories. The script then calculates the response spectra for each motion saving numerical data in ASCII files. In a second step, the output files generated by the MATLAB are utilized by Python to generate simple plots. These plots provide an easy-to-understand visualization of the data and enable users to quickly comprehend the results. By combining the capabilities of MATLAB and Python in a single Jupyter notebook, users can develop powerful analysis workflows that can handle complex data sets and generate insightful visualizations. FInally a simple report is generated using rst2pdf. + + A schematic workflow for this example is presented in Fig. 1

-Schematic of Matlab workflow +Schematic of Matlab workflow

Fig.1 - Schematic of Matlab workflow

- -The notebook, and required scripts, are available in the Community Data folder and can be executed without any modification. -Users are invited to try this notebook and use any parts of it. -[matlabBatch-VM.ipynb](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/MatlabBatch/matlabBatch-VM.ipynb) - +## Implementation The notebook can be broken down into three main components: @@ -128,10 +125,9 @@ job_description["notifications"] = [ ] ``` - #### Run Matlab script -Submitting a job using DesignSafe HPC resources requires the use of agave job.submit(); and passing the job_description array as argument. Checking the status of a job can be done using jobs.getStatus(). The python code shown below exemplifies these commands. In the notebook a simple python function is included in *DS_GenFunctions.py* that encapsulates the GetStatus process. When submitting a job, agave copies all the files present in the input folder to a temporary location that is used during execution. After completion agave copies all the results to an archived folder. +Submitting a job using DesignSafe HPC resources requires the use of agave/tapis job.submit(); and passing the job_description array as argument. Checking the status of a job can be done using jobs.getStatus(). The python code shown below exemplifies these commands. In the notebook a simple python function is included in *DS_GenFunctions.py* that encapsulates the GetStatus process. When submitting a job, agave/tapis copies all the files present in the input folder to a temporary location that is used during execution. After completion agave/tapis copies all the results to an archived folder. ```python import time @@ -149,7 +145,7 @@ while status != "FINISHED": ### Postprocess Results using Python -With JupyterHub, post-processing can be efficiently carried out using Python, R, or Julia through DesignSafe. Independent of scripting language, postprocessing requires identification of the location of the archived files. This is done interrogating a particular agave job and evaluating the correct folder location. The python code lines shown below exemplifly the steps required for this purpose. +With JupyterHub, post-processing can be efficiently carried out using Python, R, or Julia through DesignSafe. Independent of scripting language, postprocessing requires identification of the location of the archived files. This is done interrogating a particular agave/tapis job and evaluating the correct folder location. The python code lines shown below exemplifly the steps required for this purpose. #### Identify job, archived location and user @@ -213,7 +209,7 @@ for ii in range(3): ```

-Time histories +Time histories

Fig.2 - Displacement, velocity and acceleration time history for selected motion

@@ -245,7 +241,7 @@ axs2[0].grid(True) ```

-Response spectra +Response spectra

Fig.3 - Response spectra

@@ -285,5 +281,10 @@ class PDF(object): return r'\includegraphics[width=1.0\textwidth]{{{0}}}'.format(self.pdf) ``` +## Citation and Licensing + +* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246){target=_blank} to acknowledge the use of DesignSafe resources. + +* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html){target=_blank}. diff --git a/docs/arduino/usecase_quoFEM.md b/docs/arduino/usecase_quoFEM.md index 0a914d68..6c324c5f 100644 --- a/docs/arduino/usecase_quoFEM.md +++ b/docs/arduino/usecase_quoFEM.md @@ -1,27 +1,32 @@ # Sensitivity Analysis, Bayesian Calibration and Forward Propagation of Uncertainties Using quoFEM + + + + **Pedro Arduino - University of Washington**
-**Sang-Ri Yi and**
+**Sang-Ri Yi - SimCenter, UC Berkeley and**
**Aakash Bangalore Satish - SimCenter, UC Berkeley** -This use-case outlines a Bayesian updating framework that integrates probabilistic calibration of a soil constitutive model and probabilistic prediction of lateral spreading due to seismic liquefaction. To accomplish this, the SimCenter **quoFEM** tool and SimCenter UQ backend applications are utilized alongside a collection of jupyter notebooks that enhance the functionality of quoFEM within the DesignSafe infrastructure [1]. +*key Words: quoFEM, OpenSees, Tapis, Python* -[SimCenter - quoFEM](https://simcenter.designsafe-ci.org/research-tools/quofem-application)
-[Simulation on DS - OpenSees](https://www.designsafe-ci.org/rw/workspace/#!/OpenSees::Simulation)
-[Jupyter notebooks on DS Juypterhub](https://www.designsafe-ci.org/rw/workspace/#!/Jupyter::Analysis)
+## Resources -## Background -### Citation and Licensing +This example makes use of the following DesignSafe resources: -* Please cite [Aakash B. Satish et al. (2022)](https://doi.org/10.1007/978-3-031-11898-2_152) to acknowledge the use of resources from this use case.
+

-* Please cite [Sang-Ri Yi et al. (2022)](https://doi.org/10.1007/978-3-031-30125-4_6) to acknowledge the use of resources from this use case.
+| Step | Notebook | +| :-------: | :---------: | +| Sensitivity analysis | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/GlobalSensitivity/quoFEM-Sensitivity.ipynb)| +| Bayessian calibration | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/BayesianCalibration/quoFEM-Bayesian.ipynb)| +| Forward propagation | [![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/ForwardPropagation/quoFEM-Propagation.ipynb)| -* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246) to acknowledge the use of DesignSafe resources.
+

-* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html). +The notebooks, and required scripts, are available in the Community Data folder and can be executed without any modification. Users are invited to try this notebook and use any parts of it. -## Problem Description +## Description This illustrative use_case demonstrates several UQ techniques using the parameters of the PM4Sand constitutive model, a liquefaction-capable soil model in OpenSees. This complex material model is often calibrated using a small number of experimental results which yields imperfect information about its parameters. This leads to uncertain model predictions. Quantifying such uncertainties and inspecting the uncertainty bounds of model predictions can provide more information about the importance of each model parameter. Recognizing these uncertainties can incentivize more sophisticated modeling and calibration techniques that can better utilize the available data from experiments to reduce these bounds and provide more robust and higher fidelity simulations. @@ -35,12 +40,13 @@ In this use case, the amount of reduction in the uncertainty in PM4Sand paramete

-Probabilistic calibration +Probabilistic calibration

Fig.1 - Probabilistic calibration of soil model (step 2) with sensitivity analysis (step 1) and prediction of uncertainty in estimation of lateral sperading (step 3)

+## Implementation -## Uncertainty Quantification Using quoFEM +### Uncertainty Quantification Using quoFEM Accurate quantification of uncertainty requires well-established workflows that incorporate sophisticated UQ techniques with advanced simulation models and frameworks. The SimCenter quoFEM tool streamlines this process by offering comprehensive workflows in a single tool, which can be accessed locally or remotely through a web browser using the DCV client on DesignSafe. Furthermore, users can utilize the Jupyter Hub environment on DesignSafe to manage the same, or additional, runs via Python scripts, defining job variables and submitting jobs through the Tapis system. This allows for seamless collaboration and efficient job management, resulting in faster and more effective UQ analysis. @@ -49,7 +55,7 @@ In this context, the notebooks included in this use-case complement input genera To connect SimCenter applications and Jupyter notebooks in DesignSafe, it's essential to ensure that all required tools are accessible from both frameworks. The SimCenter's vision is well-aligned with this concept and offers all of the necessary functionality through backend applications installed in DesignSafe that can be accessed via Tapis apps. This is schematically shown in Fig 2. Additionally, all SimCenter workflows are stored in JSON files that represent all steps in a workflow. This file is readily accesible using a JSON parser.

-quoFEm in DesignSafe +quoFEm in DesignSafe

Fig.2 - Running quoFEM analysis using remote computing resources at DesignSafe

@@ -62,7 +68,7 @@ In order to facilitate the discussion of each notebook, it is helpful to first i 3. Run Tapis job 4. Post-process results -Instructions for (1) setting up and (2) running Tapis jobs can be found [here](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb). These steps are generally applicable for launching any Tapis app from a Jupyter notebook in DesignSafe. The most significant step in this process is determining the appropriate Tapis app to utilize. To perform uncertainty quantification within SimCenter backend applications, the following Tapis app is used: +Instructions for (1) setting up and (2) running Tapis jobs can be found [here](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb). These steps are generally applicable for launching any Tapis app from a Jupyter notebook in DesignSafe. The most significant step in this process is determining the appropriate Tapis app to utilize. To perform uncertainty quantification within SimCenter backend applications, the following Tapis app is used: ``` python #Select tapis-app @@ -74,12 +80,12 @@ storage_id = 'designsafe.storage.default' app = ag.apps.get(appId=app_id) ``` -Post-processing of results is specific to the problem being solved and can be achieved using Python to access output data stored in archived files. For this purpose it is important to identify the location of data files. This is explained [here](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb). +Post-processing of results is specific to the problem being solved and can be achieved using Python to access output data stored in archived files. For this purpose it is important to identify the location of data files. This is explained [here](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb). Displaying a quoFEM job workflow is useful for understanding the data and steps followed in the workflow. These include: simulation tools, input variables, UQ methods used, and remote directories/folders. An schematic of a typical quoFEM workflow is shown in Fig. 3.

-quoFEM workflow +quoFEM workflow

Fig.3 - Elements of quoFEM workflow (only relevant elements for launching notebook from JupyterHub)

@@ -97,9 +103,9 @@ IPython.display.JSON(jsonInfo) To modify the workflow, the user can either manually change the workflow files within the tmp.SimCenter folder or regenerate the workflow using quoFEM. Regenerating the workflow using quoFEM is the preferred approach, as the quoFEM desktop is specifically designed to facilitate workflow creation. On the other hand, Jupyter notebooks offer more flexibility in terms of post-processing, generating plots, and manipulating data. -## Step 1 – Global Sensitivity Analysis +### Step 1 – Global Sensitivity Analysis - [quoFEM-Sensitivity.ipynb](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/GlobalSensitivity/quoFEM-Sensitivity.ipynb). +[![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/GlobalSensitivity/quoFEM-Sensitivity.ipynb) The PM4Sand constitutive model has 24 parameters. Among them, apparent relative density $D_r$, shear modulus coefficient $G_o$, and contraction rate parameter $h_{po}$, are known to be important for predicting liquefaction responses [2]. Therefore, these three parameters $\theta = \{D_r,G_o,h_{po}\}$ are considered in the UQ analyses and their prior distributions are assumed to be uniform distributions with the ranges shown in Table 1. These prior distributions shall capture a plausible wide range that includes all possible parameter values for the target soils. The experimental data will be used to constrain this wide range to the domain that best describes the behavior exhibited by the specimen during the experiments. @@ -120,17 +126,17 @@ The sensitivity analysis is performed for a simulation model that reproduces the -$$ + + +

+Eqn 1 2 +

+

where $\theta_i$ is the parameter of interest (i.e., one of the $\{D_r,G_o,h_{po}\}$ ) , $\boldsymbol{\theta}_{\sim i}$ denotes the other two parameters, $\mathbb{E}_{\boldsymbol{X}}[.]$ and $\operatorname{Var}_{\boldsymbol{X}}[.]$ denote mean and variance of function over $\boldsymbol{X}$, respectively, and the vertical bar denotes ‘conditional on’. The former index, called the main-effect index, quantifies how much of the variance of $Y$ is attributed to the parameter $\theta_i$, while the latter index, called the total-effect index, also considers the joint contributions of $\theta_i$ and other parameters [3].

-OpenSees models +OpenSees models

Fig.4 - Single element FE model used in sensitivity analysis and Bayesian calibration

-OpenSees models +OpenSees models

Fig.5 - (a) simulated cyclic stress-strain curve; (b)stress path during the simulated cyclic direct simple shear test; (c) evolution of pore water pressure ratio during the simulated CyDSS test

The sensitivity analysis is performed using the algorithm in Weirs et al. (2012) through the Dakota engine that interfaces with quoFEM [3]. 2500 simulations were performed using the prior distributions in Table 1. The resulting sensitivity is shown in Fig. 6(a) which indicates that $D_r$ is the dominating parameter for the response $Y$. This is also confirmed by inspecting the scatter plot of Fig. 6(b): $D_r$ (horizontal axis) demonstrates a stronger influence on the output (vertical axis) compared to the influence of the other parameters shown in (c) and (d). Based on this, we can expect that the CyDSS observations will help constrain the uncertainty in $D_r$, while the reduction of uncertainty in $h_{po}$ and $G_o$ will be relatively limited. Additionally, different types of experiments would be needed to better characterize those other parameters.

-Probabilistic calibration +Probabilistic calibration

Fig.6 - (a) Sensitivity analysis results for the critical number of cycles given CSR = 0.172; (b)– (d) Individual input-output scatter plots

-## Step 2 – Bayesian Parameter Calibration +### Step 2 – Bayesian Parameter Calibration + +[![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/BayesianCalibration/quoFEM-Bayesian.ipynb) -[quoFEM-Bayesian.ipynb](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/BayesianCalibration/quoFEM-Bayesian.ipynb) Consider now the observations of the CyDSS experiment in Table 2, that are publicly available on the DesignSafe data depot [4]. We assume that the observed count of cycles at different CSR values, denoted as $Y_i^m$ $(i = 1,…,6)$, is given by the simulation model predictions and an added Gaussian noise. The latter captures various inaccuracies such as inherent uncertainty in the phenomenon, the imperfection of our simulation model, and measurement error. Given the above assumptions, we can denote the relationship between the data and model prediction, $Y_i(\theta)$, as -$$ + + +

+Eqn 1 2 +

+

where noise $\epsilon_i$ is assumed to have zero-mean and unknown variance $\sigma^2_{\epsilon,i}$. Given the six measurement values, we can use a Bayesian approach to evaluate the posterior distribution of the parameters of PM4Sand and the unknown noise variances: -$$ + + +

+Eqn 1 2 +

+

where $p(∙)$ denotes the (joint) probability distribution, and $c$ is the normalization constant that ensures the area under the posterior distribution is one. From Eq. (3), @@ -214,20 +236,20 @@ test experimental data

-Calibrated predictions +Calibrated predictions

Fig.7 - Comparison of calibrated model predictions and experimental data

Figure 7 compares the experimental data with the calibrated model predictions of the load-cycle counts, while Fig. 8 shows the calibrated parameter sample from the joint posterior distribution. Figure 8 shows that uncertainty in all variables is reduced by calibrating to the observed data, but the reduction was most apparent in $D_r$. This is in line with our expectations from the earlier sensitivity analysis. The results also highlight a strong dependency between $D_r$ and $h_{po}$, indicating that multiple combinations of $D_r$ and $h_{po}$ produce near-optimal solutions. None of these features are captured by a deterministic estimator that results from a conventional error-minimizing optimization approach (e.g., red diamond marker shown in the same figure). It is also important to recognize that a non-negligible amount of uncertainty remains in the parameter estimates, and this produces substantial uncertainty in the model predictions. The dark blue bounds in Fig. 7 show the level of uncertainty in the estimated number of cycles to liquefaction, but this simulation model was prepared to reproduce the experimental setup. When the calibrated constitutive model is applied in another simulation, the responses can exhibit different scales of uncertainties.

-Forward propagation +Forward propagation

Fig.8 - PM4Sand model parameters sampled from the joint posterior distribution

-## Step 3 – Forward Propagation +### Step 3 – Forward Propagation -[quoFEM-Propagation.ipynb](https://jupyter.designsafe-ci.org/user/name/lab/workspaces/auto-J/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/ForwardPropagation/quoFEM-Propagation.ipynb) +[![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/quoFEM_Example1/ForwardPropagation/quoFEM-Propagation.ipynb) A forward propagation analysis is helpful to characterize uncertainties in a simulation model. For this purpose it is good practice to run such an analysis and characterize the effect of uncertainties on application-specific quantities of interest before practically applying these parameter values in a simulation for decision making. @@ -235,7 +257,7 @@ The obtained samples of the soil parameters in Fig. 8 are used to predict the un

-Forward propagation +Forward propagation

Fig.9 - Schematic of 1D soil layer with liquefiable soil used in the forward propagation analysis.

@@ -243,14 +265,13 @@ The results of 500 simulations are shown in Fig. 10. The mean and standard devia

-Forward propagation +Forward propagation

Fig.10 - Predicted earthquake response of soil column

- -## References +### References 1. McKenna, F., et al.: NHERI-SimCenter/quoFEM: Version 3.0.0. Zenodo (2022). @@ -265,3 +286,13 @@ https://doi.org/10.17603/ds2-eahz-9466. Accessed 28 June 2021. 5. Ching, J., Chen, Y.C.: Transitional Markov chain Monte Carlo method for Bayesian model updating, model class selection, and model averaging. J. Eng. Mech. 133(7), 816–832 (2007). 6. Carlin, J.B., Vehtari, A., Stern, H.S., Rubin, D.B., Gelman, A., Dunson, D.B.: Bayesian Data Analysis, 3rd edn. Taylor & Francis, United Kingdom (2014). + +## Citation and Licensing + +* Please cite [Aakash B. Satish et al. (2022)](https://doi.org/10.1007/978-3-031-11898-2_152) to acknowledge the use of resources from this use case.
+ +* Please cite [Sang-Ri Yi et al. (2022)](https://doi.org/10.1007/978-3-031-30125-4_6) to acknowledge the use of resources from this use case.
+ +* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246) to acknowledge the use of DesignSafe resources.
+ +* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html). diff --git a/docs/arduino/usecase_siteResponse.md b/docs/arduino/usecase_siteResponse.md new file mode 100644 index 00000000..856adb6c --- /dev/null +++ b/docs/arduino/usecase_siteResponse.md @@ -0,0 +1,268 @@ +# Performing site response analysis in Jupyter + +#### Simple jupyter notebook to introduce site response analysis using OpenSees in DesignSafe-CI. + +**Pedro Arduino - University of Washington** + +## Resources + +This example makes use of the following DesignSafe resources: + +[![Open In DesignSafe](https://raw.githubusercontent.com/geoelements/LearnMPM/main/DesignSafe-Badge.svg)](https://jupyter.designsafe-ci.org/hub/user-redirect/lab/tree/CommunityData/Jupyter%20Notebooks%20for%20Civil%20Engineering%20Courses/University_of_Washington/freeFieldJupyterPM4Sand/freeFieldJupyterPM4Sand_Community.ipynb) + +The notebook, and required scripts, are available in the Community Data folder and can be executed without any modification. Users are invited to try this notebook and use any parts of it. + +## Description + +The *site response workflow notebook* introduces typical steps used in the evaluation of the surface response for a site with liquefiable soil. +The notebook takes advantage of the site response problem to introduce the general numerical analysis workflow shown in Figure 2 that includes: + +1. running OpenSees using a **TAPIS** APP, +2. postprocessing results using python, +3. generating authomatic reports using rst2pdf or latex, and +4. Creating animated plots using visualization widgets. + + +

+ OpenSees numericla simulation workflow +

+

Fig.2 - OpenSees numerical simulation workflow

+ + +The soil profile shown in Figure 3 includes a 5.0m loose sand underlain by a 1.0 m dense soil.The loose sand is modeled using the PM4Sand constitutive model for liquefiable soils available in OpenSees. The dense sand is considered linear elastic. The groundwter table is assumed at 2.0 m making the lower 3.0 m of the loose sand susceptible to liquefaction. The soil profile is subject to a dynamic excitation at its base. The site response of interest includes (i) the surface acceleration, (ii) profiles of lateral displacement, horizontal acceleration, maximum shear strain, and cyclic stress ratio and (iii) stress strain and pore pressure plots for a point in the middle of the soil profile. The opensees model definition, analysis steps, and recorders are contained in the [N10_T3.tcl](FreeField-JupyterNB/N10_T3.tcl) file, and the input signal is in [velocity.input](FreeField-JupyterNB/velocity.input). The model can be run using OpenSees in any OS framework. + +

+N10_T3 soil profile with liquefiable layer +

+

Fig.3 - N10_T3 soil profile with liquefiable layer

+ + +## Implementation + +The notebook can be broken down into four main components: + +
    +
  1. Setup TAPIS/AGAVE APP and run OpenSees job
  2. +
  3. Post process results
  4. +
  5. Generate report
  6. +
  7. Generate interactive plots
  8. +
+ +It is emphasize that the main motivation of this notebook is to take advantage of DesignSafe resources. +Therefore, relevant details for each component as it pertains to access to DesignSafe-CI resources are described here. + +### Setup tapis/agave app and run OpenSees job + +The notebook can be executed launching *Jupyter Lab* in Designsafe. This opens a user *docker container* in DesignSafe that includes all the functionality required to execute jupyter commands. This gives immediate access to the **agavepy** module from which it is possible to run any **TAPIS** APP. + +#### Setup job description + +A few commands are required to setup a TAPIS OpenSees job in DesignSafe. This requires definition of the TAPIS APP to use, control variables, parameters and inputs. The control variables define the infrastructre resources requested to TACC. The parameters define the executable (opensees), version (current), and opensees input file to run. For the site response case the *OpenseesSp-3.3.0u1* app is selected. The main steps required to setup an agave job are: + + +1. importing agave/tapis, +2. getting the specific app of interest, +3. defining control variables, parameters and inputs, and +4. encapsulating all data in a job_description array + +The python code shown below exemplifies these steps. The complete set of commands is available in the notebook. The job_description array includes all the information required to submit the job. + +```python +# Import Agave +from agavepy.agave import Agave +ag = Agave.restore() + +# Get Agave app of interest +app_id = 'OpenseesSp-3.3.0u1' +app = ag.apps.get(appId=app_id) + +# Define control tapis-app variables +control_batchQueue = 'small' +control_jobname = 'Jup_OP_Tapis' +control_nodenumber = '1' +control_processorsnumber = '8' +control_memorypernode = '1' +control_maxRunTime = '00:1:00' + +# Define inputs +# Identify folder with input file in DesignSafe +cur_dir = os.getcwd() +if ('jupyter/MyData' in cur_dir ): + cur_dir = cur_dir.split('MyData').pop() + storage_id = 'designsafe.storage.default' + input_dir = ag.profiles.get()['username']+ cur_dir + input_uri = 'agave://{}/{}'.format(storage_id,input_dir) + input_uri = input_uri.replace(" ","%20") +... +... +inputs = {"inputDirectory": [ input_uri ]} + +# Define parameters +parameter_executable = 'opensees' +parameter_version = 'current' +input_filename = 'N10_T3.tcl' +parameters = {} +parameters["executable"] = parameter_executable +parameters["version"] = parameter_version +parameters["inputScript"] = input_filename + + +# Set job_description array +job_description = {} +job_description["appId"] = (app_id) +... +job_description["inputs"] = inputs +job_description["parameters"] = parameters +``` + +#### Run OpenSees Job + +Submitting a job using DesignSafe HPC resources requires the use of agave job.submit(); and passing the job_description array as argument. Checking the status of a job can be done using jobs.getStatus(). The python code shown below exemplifies these commands. When submitting a job, agave copies all the files present in the input folder to a temporary location that is used during execution. After completion agave copies all the results to an archived folder. + +```python +import time +job = ag.jobs.submit(body=job_description) +print(" Job launched. Status provided below") +print(" Can also check in DedignSafe portal under - Workspace > Tools & Application > Job Status") + +status = ag.jobs.getStatus(jobId=job["id"])["status"] +while status != "FINISHED": + status = ag.jobs.getStatus(jobId=job["id"])["status"] + print(f"Status: {status}") + time.sleep(60) +``` + +### Postprocess Results + +Postprocessing requires identification of the location of the archived files. This is done interrogating a particular agave job and evaluating the correct folder location. The python code lines shown below exemplifly the steps required for this purpose. + +#### Identify job, archived location and user + +``` python +jobinfo = ag.jobs.get(jobId=job.id) +jobinfo.archivePath +user = jobinfo.archivePath.split('/', 1)[0] + +import os +%cd .. +cur_dir_name = cur_dir.split('/').pop() +os.chdir(jobinfo.archivePath.replace(user,'/home/jupyter/MyData')) +if not os.path.exists(cur_dir_name): + os.makedirs(cur_dir_name) +os.chdir(cur_dir_name) +``` +#### Plot Results + +Once in the archived folder (cur_dir_name), postprocessing can be done using python scripts that operate on output files. For the particualar case of the site response analysis used in this notebook three scripts are used to evaluate: +1. surface acceleration time history and its response spectrum, +2. profiles of maximum displacement, peak horizontal acceleration (PHA), peak shear strain, and cyclic stress ratio, and +3. Stress-strain and excess pore water pressure at the middle of the liquefiable layer. + +The python code and figures shown below exemplify these steps. All python scripts are available in the notebook community folder. + +Plot acceleration time hisotory and response spectra on log-linear scale +``` python +from plotAcc import plot_acc +plot_acc() +``` + +

+Surface acceleration +Response spectrum +

+

Fig.4 - Surface acceleratio and response spectrum

+ + +Plot profiles +``` python +from plotProfile import plot_profile +plot_profile() +``` + +

+Profiles +

+

Fig.5 - Profiles of max displacement, PHA, Max shear strain and cyclic stress ratio

+ +Plot excess pore water pressure +``` python +from plotPorepressure import plot_porepressure +plot_porepressure() +``` + +

+Stress strain +Pore pressure +

+

Fig.6 - stress strain and pore pressure in the middle of liquefiable layer

+ + +#### Generate report + +Generating a summary report is a convenient way to present results from lengthy simulations prcesses. In jupyter this can be done invoking any posprocessor available in the docker container image. Among them rst2pdf is commonly distributed with python. For the site response notebook a simple ShortReport.rst file is included that collects the results and plots generated in a simple pdf file. The python code shown below, exemplifies this process and include: +1. Running rst2pdf on [ShortReport.rst](FreeField-JupyterNB/ShortReport.rst) +2. Posting the resulting pdf file in the jupyter notebook. For this it is convenient to define the PDF function shown below that specifies the format of the file in the screen. + +Run rst2pdf, assign to pdf_fn, and call PDF show function +``` python +import sys +!{sys.executable} -m pip install rst2pdf +os.system('rst2pdf ShortReport.rst ShortReport.pdf') + +pdf_fn = jobinfo.archivePath.replace(user, '/user/' + user + '/files/MyData') +pdf_fn += '/' +pdf_fn += cur_dir.split('/')[-1] +pdf_fn += '/ShortReport.pdf' +print pdf_fn + +PDF(pdf_fn , (750,600)) +``` + +PDF function +``` python +class PDF(object): + def __init__(self, pdf, size=(200,200)): + self.pdf = pdf + self.size = size + + def _repr_html_(self): + return ''.format(self.pdf, self.size) + + def _repr_latex_(self): + return r'\includegraphics[width=1.0\textwidth]{{{0}}}'.format(self.pdf) +``` + +#### Create Interactive Plots + +Finally, jupyter notebooks offer flexibility to invoke GUI widgets that can help present results in a dynamic and interactive manner. The python scripts shown below create interactive plots for pore water pressure and soil profile lateral displacements. The horizontal bars allow users interrogate each plot for results at any particular time. Complete pyhon scripts are included in the [interactiveplot.py](FreeField-JupyterNB/interactiveplot.py) available in community. + +#### Pore water pressure + +``` python +from interactiveplot import createpwpplot, createDispplot +createpwpplot() +``` +

+Pore pressure interatvie plot +

+

Fig.7 - Pore pressure interactive plot

+ +#### Displacement + +``` python +createDispplot() +``` + +

+Displacement profile interatvie plot +

+

Fig.8 - Displacement proficle interactive plot

+ +## Citation and Licensing + +* Please cite [Chen, L. et al. (2021)](https://peer.berkeley.edu/sites/default/files/2021_chen_final.pdf){target=_blank} to acknowledge the use of resources from this use case. + +* Please cite [Rathje et al. (2017)](https://doi.org/10.1061/(ASCE)NH.1527-6996.0000246){target=_blank} to acknowledge the use of DesignSafe resources. + +* This software is distributed under the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.html){target=_blank}. +