.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/RunModel/abaqus_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_RunModel_abaqus_example.py: Third-party - Abaqus ================================== .. GENERATED FROM PYTHON SOURCE LINES 8-9 Import the necessary libraries. .. GENERATED FROM PYTHON SOURCE LINES 12-24 .. code-block:: default import glob import pickle import time import os from UQpy.distributions import Normal, Uniform from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel from UQpy.sampling import MonteCarloSampling calling_directory = os.getcwd() t = time.time() .. GENERATED FROM PYTHON SOURCE LINES 25-27 Building the model There are two probabilistic input variables, the fire load density and the yield strength. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default var_names = ['qtd', 'fy'] .. GENERATED FROM PYTHON SOURCE LINES 34-35 Create the model object .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: default m = ThirdPartyModel(model_script='abaqus_fire_analysis.py', input_template='abaqus_input.py', output_script='extract_abaqus_output.py', var_names=var_names, model_dir='SFE_MCS', ) abaqus_sfe_model = RunModel(cores_per_task=1, ntasks=24, model=m) print('Example: Created the model object.') .. GENERATED FROM PYTHON SOURCE LINES 46-52 Towards defining the sampling scheme The fire load density is assumed to be uniformly distributed between 50 :math:`MJ/m^2` and 450 :math:`MJ/m^2`. The yield strength is assumed to be normally distributed, with the parameters being: mean = 250 :math:`MPa` and coefficient of variation of :math:`7%`. Creating samples using MCS. .. GENERATED FROM PYTHON SOURCE LINES 55-60 .. code-block:: default d_n = Normal(loc=50, scale=400) d_u = Uniform(location=2.50e8, scale=1.75e7) x_mcs = MonteCarloSampling(distributions=[d_n, d_u], samples_number=100, random_state=987979) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Running simulations using the previously defined model object and samples .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: default sample_points = x_mcs.samples abaqus_sfe_model.run(samples=sample_points) .. GENERATED FROM PYTHON SOURCE LINES 70-71 The outputs from the analysis are the values of the performance function. .. GENERATED FROM PYTHON SOURCE LINES 74-78 .. code-block:: default qois = abaqus_sfe_model.qoi_list .. GENERATED FROM PYTHON SOURCE LINES 79-80 Save the samples and the qois in a dictionary called results with keys 'inputs' and 'outputs'. .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: default results = {'inputs': sample_points, 'outputs': qois} .. GENERATED FROM PYTHON SOURCE LINES 86-87 Pickle the results dictionary in the current directory. The basename and extension of the desired pickle file: .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: default res_basename = 'MCS_results' res_extension = '.pkl' .. GENERATED FROM PYTHON SOURCE LINES 94-96 Create a new results file with a larger index than any existing results files with the same name in the current directory. .. GENERATED FROM PYTHON SOURCE LINES 99-107 .. code-block:: default res_file_list = glob.glob(res_basename + '_???' + res_extension) if len(res_file_list) == 0: res_file_name = res_basename + '_000' + res_extension else: max_number = max(res_file_list).split('.')[0].split('_')[-1] res_file_name = res_basename + '_%03d' % (int(max_number) + 1) + res_extension res_file_name = os.path.join(calling_directory, res_file_name) .. GENERATED FROM PYTHON SOURCE LINES 108-110 Create a new results file with a larger index than any existing results files with the same name in the current directory. .. GENERATED FROM PYTHON SOURCE LINES 113-120 .. code-block:: default with open(res_file_name, 'wb') as f: pickle.dump(results, f) print('Saved the results to ' + res_file_name) print('Example: Done!') print('Time elapsed: %.2f minutes' % float((time.time() - t) / 60.0)) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_RunModel_abaqus_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/RunModel/abaqus_example.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: abaqus_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: abaqus_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_