Update Condition notation & domains import in tutorials
This commit is contained in:
26
tutorials/tutorial7/tutorial.ipynb
vendored
26
tutorials/tutorial7/tutorial.ipynb
vendored
@@ -50,7 +50,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"id": "00d1027d-13f2-4619-9ff7-a740568f13ff",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -78,7 +78,7 @@
|
||||
"from pina.equation import Equation, FixedValue\n",
|
||||
"from pina import Condition, Trainer\n",
|
||||
"from pina.solvers import PINN\n",
|
||||
"from pina.geometry import CartesianDomain"
|
||||
"from pina.domain import CartesianDomain"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -155,7 +155,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"id": "8ec0d95d-72c2-40a4-a310-21c3d6fe17d2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -188,19 +188,19 @@
|
||||
"\n",
|
||||
" # define the conditions for the loss (boundary conditions, equation, data)\n",
|
||||
" conditions = {\n",
|
||||
" 'gamma1': Condition(location=CartesianDomain({'x': [x_min, x_max],\n",
|
||||
" 'bound_cond1': Condition(domain=CartesianDomain({'x': [x_min, x_max],\n",
|
||||
" 'y': y_max}),\n",
|
||||
" equation=FixedValue(0.0, components=['u'])),\n",
|
||||
" 'gamma2': Condition(location=CartesianDomain({'x': [x_min, x_max], 'y': y_min\n",
|
||||
" 'bound_cond2': Condition(domain=CartesianDomain({'x': [x_min, x_max], 'y': y_min\n",
|
||||
" }),\n",
|
||||
" equation=FixedValue(0.0, components=['u'])),\n",
|
||||
" 'gamma3': Condition(location=CartesianDomain({'x': x_max, 'y': [y_min, y_max]\n",
|
||||
" 'bound_cond3': Condition(domain=CartesianDomain({'x': x_max, 'y': [y_min, y_max]\n",
|
||||
" }),\n",
|
||||
" equation=FixedValue(0.0, components=['u'])),\n",
|
||||
" 'gamma4': Condition(location=CartesianDomain({'x': x_min, 'y': [y_min, y_max]\n",
|
||||
" 'bound_cond4': Condition(domain=CartesianDomain({'x': x_min, 'y': [y_min, y_max]\n",
|
||||
" }),\n",
|
||||
" equation=FixedValue(0.0, components=['u'])),\n",
|
||||
" 'D': Condition(location=CartesianDomain({'x': [x_min, x_max], 'y': [y_min, y_max]\n",
|
||||
" 'phys_cond': Condition(domain=CartesianDomain({'x': [x_min, x_max], 'y': [y_min, y_max]\n",
|
||||
" }),\n",
|
||||
" equation=Equation(laplace_equation)),\n",
|
||||
" 'data': Condition(input_points=data_input.extract(['x', 'y']), output_points=data_output)\n",
|
||||
@@ -242,14 +242,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"id": "e3e0ae40-d8c6-4c08-81e8-85adc60a94e6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"problem.discretise_domain(20, 'grid', locations=['D'], variables=['x', 'y'])\n",
|
||||
"problem.discretise_domain(1000, 'random', locations=['gamma1', 'gamma2',\n",
|
||||
" 'gamma3', 'gamma4'], variables=['x', 'y'])"
|
||||
"problem.discretise_domain(20, 'grid', locations=['phys_cond'], variables=['x', 'y'])\n",
|
||||
"problem.discretise_domain(1000, 'random', locations=['bound_cond1', 'bound_cond2',\n",
|
||||
" 'bound_cond3', 'bound_cond4'], variables=['x', 'y'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -368,7 +368,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.8"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
22
tutorials/tutorial7/tutorial.py
vendored
22
tutorials/tutorial7/tutorial.py
vendored
@@ -25,7 +25,7 @@
|
||||
|
||||
# Let's start with useful imports.
|
||||
|
||||
# In[1]:
|
||||
# In[ ]:
|
||||
|
||||
|
||||
## routine needed to run the notebook on Google Colab
|
||||
@@ -81,7 +81,7 @@ plt.show()
|
||||
|
||||
# Then, we initialize the Poisson problem, that is inherited from the `SpatialProblem` and from the `InverseProblem` classes. We here have to define all the variables, and the domain where our unknown parameters ($\mu_1$, $\mu_2$) belong. Notice that the Laplace equation takes as inputs also the unknown variables, that will be treated as parameters that the neural network optimizes during the training process.
|
||||
|
||||
# In[4]:
|
||||
# In[ ]:
|
||||
|
||||
|
||||
### Define ranges of variables
|
||||
@@ -112,19 +112,19 @@ class Poisson(SpatialProblem, InverseProblem):
|
||||
|
||||
# define the conditions for the loss (boundary conditions, equation, data)
|
||||
conditions = {
|
||||
'gamma1': Condition(location=CartesianDomain({'x': [x_min, x_max],
|
||||
'bound_cond1': Condition(domain=CartesianDomain({'x': [x_min, x_max],
|
||||
'y': y_max}),
|
||||
equation=FixedValue(0.0, components=['u'])),
|
||||
'gamma2': Condition(location=CartesianDomain({'x': [x_min, x_max], 'y': y_min
|
||||
'bound_cond2': Condition(domain=CartesianDomain({'x': [x_min, x_max], 'y': y_min
|
||||
}),
|
||||
equation=FixedValue(0.0, components=['u'])),
|
||||
'gamma3': Condition(location=CartesianDomain({'x': x_max, 'y': [y_min, y_max]
|
||||
'bound_cond3': Condition(domain=CartesianDomain({'x': x_max, 'y': [y_min, y_max]
|
||||
}),
|
||||
equation=FixedValue(0.0, components=['u'])),
|
||||
'gamma4': Condition(location=CartesianDomain({'x': x_min, 'y': [y_min, y_max]
|
||||
'bound_cond4': Condition(domain=CartesianDomain({'x': x_min, 'y': [y_min, y_max]
|
||||
}),
|
||||
equation=FixedValue(0.0, components=['u'])),
|
||||
'D': Condition(location=CartesianDomain({'x': [x_min, x_max], 'y': [y_min, y_max]
|
||||
'phys_cond': Condition(domain=CartesianDomain({'x': [x_min, x_max], 'y': [y_min, y_max]
|
||||
}),
|
||||
equation=Equation(laplace_equation)),
|
||||
'data': Condition(input_points=data_input.extract(['x', 'y']), output_points=data_output)
|
||||
@@ -148,12 +148,12 @@ model = FeedForward(
|
||||
|
||||
# After that, we discretize the spatial domain.
|
||||
|
||||
# In[6]:
|
||||
# In[ ]:
|
||||
|
||||
|
||||
problem.discretise_domain(20, 'grid', locations=['D'], variables=['x', 'y'])
|
||||
problem.discretise_domain(1000, 'random', locations=['gamma1', 'gamma2',
|
||||
'gamma3', 'gamma4'], variables=['x', 'y'])
|
||||
problem.discretise_domain(20, 'grid', locations=['phys_cond'], variables=['x', 'y'])
|
||||
problem.discretise_domain(1000, 'random', locations=['bound_cond1', 'bound_cond2',
|
||||
'bound_cond3', 'bound_cond4'], variables=['x', 'y'])
|
||||
|
||||
|
||||
# Here, we define a simple callback for the trainer. We use this callback to save the parameters predicted by the neural network during the training. The parameters are saved every 100 epochs as `torch` tensors in a specified directory (`tmp_dir` in our case).
|
||||
|
||||
Reference in New Issue
Block a user