-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,300 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Welcome to ProgPy's Growth Example!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In this example, we'll be demonstrating how to use the Paris Law Crack Growth Equation for Prognostics." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The Paris Law or Paris Crack Growth Law is a seminal equation in the field of fracture mechanics. It models the growth of fatigue cracks, and is named after Paul C. Paris who first proposed it.\n", | ||
"\n", | ||
"This law predicts the rate at which an existing crack will grow as a function of the range of stress intensity factor experienced by the crack. It is given by:\n", | ||
"\n", | ||
"$$\n", | ||
"\\frac{d a}{d N}=C\\left(\\Delta K\\right)^{m}\n", | ||
"$$\n", | ||
"\n", | ||
"\n", | ||
"where \n", | ||
"$\n", | ||
"\\frac{d a}{d N}\n", | ||
"$\n", | ||
" is the crack growth per cycle, \n", | ||
"$\n", | ||
"ΔK\n", | ||
"$ is the stress intensity range, and \n", | ||
"$\n", | ||
"C$ and \n", | ||
"$m$ are material constants. In the context of prognostics, understanding and predicting crack growth is vital to estimating the remaining useful life (RUL) of a component or system. This knowledge can help prevent catastrophic failures and optimize maintenance scheduling." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### __States in the `ParisLawCrackGrowth` Class__\n", | ||
"\n", | ||
"The `ParisLawCrackGrowth` class also has one state, `c_l`, which stands for the current length of the crack. This state represents the internal state of the system being modeled, and it evolves over time based on the system inputs and the Paris Law equation." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Importing Modules" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import csv\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import os\n", | ||
"from progpy.models.experimental.paris_law import ParisLawCrackGrowth " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First, we'll define a model object." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = ParisLawCrackGrowth(process_noise = 0)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Next, we'll define the [Future Loading](https://nasa.github.io/progpy/prog_models_guide.html#future-loading) Function." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def future_loading(t, x=None):\n", | ||
" #variable (piece-wise) future loading scheme \n", | ||
" #inputs are ['k_min', 'k_max']\n", | ||
" if (t < 500):\n", | ||
" k_min = 12\n", | ||
" k_max = 24\n", | ||
" elif (t < 750):\n", | ||
" k_min = 8\n", | ||
" k_max = 32\n", | ||
" else:\n", | ||
" k_min = 0\n", | ||
" k_max = 28\n", | ||
" return m.InputContainer({'k_min': k_min, 'k_max': k_max})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### __Inputs in the `ParisLawCrackGrowth` Class__\n", | ||
"\n", | ||
"The `ParisLawCrackGrowth` class takes two inputs:\n", | ||
"\n", | ||
"1. `k_max`: This is the maximum stress intensity factor experienced by the crack.\n", | ||
"2. `k_min`: This is the minimum stress intensity factor experienced by the crack.\n", | ||
"\n", | ||
"The difference between `k_max` and `k_min` gives the range of the stress intensity factor, which is an essential part of the Paris Law equation." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In our future loading function, we are setting the growth limits to different values depending on the time relative to our model." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"One caveat of our system is that we do not know the model's parameters for this system, thus we'll need to estimate it using data collected from the system. \n", | ||
"\n", | ||
"First, we'll have to import some data from the real system." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"times = []\n", | ||
"inputs = []\n", | ||
"outputs = []\n", | ||
"csv_dir = 'growth.csv'\n", | ||
"\n", | ||
"#Reads csv file\n", | ||
"try:\n", | ||
" with open(csv_dir, newline='') as csvfile:\n", | ||
" data = csv.reader(csvfile, delimiter=',', quotechar='|' , quoting=csv.QUOTE_NONNUMERIC)\n", | ||
" for row in data:\n", | ||
" times.append(row[0])\n", | ||
" inputs.append({'k_min': row[1], 'k_max': row[2]})\n", | ||
" outputs.append({'c_l': row[3]})\n", | ||
"except FileNotFoundError:\n", | ||
" print(\"No data file found\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Next, we can use our [Parameter Estimation](https://nasa.github.io/progpy/prog_models_guide.html#parameter-estimation) feature to estimate the parameters of the model." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Estimates the model parameters\n", | ||
"keys = ['c', 'm']\n", | ||
"\n", | ||
"print('Model configuration before')\n", | ||
"for key in keys:\n", | ||
" print(\"-\", key, m.parameters[key])\n", | ||
"print(' Error: ', m.calc_error(times, inputs, outputs, dt=10))\n", | ||
"\n", | ||
"m.estimate_params([(times, inputs, outputs)], keys, dt=10)\n", | ||
"\n", | ||
"print('\\nOptimized configuration')\n", | ||
"for key in keys:\n", | ||
" print(\"-\", key, m.parameters[key])\n", | ||
"print(' Error: ', m.calc_error(times, inputs, outputs, dt=10))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now that we have some model parameters and a future loading function, we can utilize our Simulation feature to run a simulation of our model to threshold!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### __Events in the `ParisLawCrackGrowth` Class__\n", | ||
"\n", | ||
"In the `ParisLawCrackGrowth` class, there is one event defined: `CGF` or Crack Growth Fracture. This event signifies that the crack length has reached a certain limit, the `crack_limit`, beyond which the component or system is considered to have fractured or failed." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"options = {\n", | ||
" 'save_freq': 10, # Frequency at which results are saved\n", | ||
" 'dt': 10, # Timestep\n", | ||
" 'horizon': 1e5, # Horizon\n", | ||
"}\n", | ||
"\n", | ||
"(times, inputs, _, outputs, event_states) = m.simulate_to_threshold(future_loading, **options)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's plot the results of the growth model. We'll plot the inputs, the event state, and the output of our model til threshold is met!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"inputs.plot(ylabel='Stress Intensity')\n", | ||
"event_states.plot(ylabel= 'CGF')\n", | ||
"outputs.plot(ylabel= {'c_l': \"Crack Length\"}, compact= False)\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### __Outputs from the `ParisLawCrackGrowth` Class__\n", | ||
"\n", | ||
"The `ParisLawCrackGrowth` class has one output, which is `c_l` (_the model's state_), the current length of the crack. This output is updated with each cycle based on the Paris Law equation.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Conclusion" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"ProgPy users can utilize the ParisLawCrackGrowth Function to calculate the crack growth rate of a material. The user can input the stress intensity factor, the crack length, and the material properties to calculate the crack growth!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"For more information on ProgPy, please refer to our ProgPy [Documentation](https://nasa.github.io/progpy/index.html)." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Welcome to ProgPy's New Model Example!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In this example, we demonstrate how to define and use a new prognostics model!\n", | ||
"\n", | ||
"We will create a simple state-transition model of an object thrown upward into the air is defined. That model is then used in simulation under different conditions and the results are displayed in different formats." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Importing Modules" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from progpy import PrognosticsModel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.