@@ -32,45 +32,40 @@ class ParametricEllipticOptimalControl(SpatialProblem, ParametricProblem):
|
|||||||
x_range = [xmin, xmax]
|
x_range = [xmin, xmax]
|
||||||
y_range = [ymin, ymax]
|
y_range = [ymin, ymax]
|
||||||
# setting parameters range
|
# setting parameters range
|
||||||
amin, amax = 0.0001, 1
|
amin, amax = 0.01, 1
|
||||||
mumin, mumax = 0.5, 3
|
mumin, mumax = 0.5, 3
|
||||||
mu_range = [mumin, mumax]
|
mu_range = [mumin, mumax]
|
||||||
a_range = [amin, amax]
|
a_range = [amin, amax]
|
||||||
# setting field variables
|
# setting field variables
|
||||||
output_variables = ['u', 'p', 'y']
|
output_variables = ['u', 'y', 'z']
|
||||||
# setting spatial and parameter domain
|
# setting spatial and parameter domain
|
||||||
spatial_domain = CartesianDomain({'x1': x_range, 'x2': y_range})
|
spatial_domain = CartesianDomain({'x1': x_range, 'x2': y_range})
|
||||||
parameter_domain = CartesianDomain({'mu': mu_range, 'alpha': a_range})
|
parameter_domain = CartesianDomain({'mu': mu_range, 'alpha': a_range})
|
||||||
|
|
||||||
# equation terms as in https://arxiv.org/pdf/2110.13530.pdf
|
# equation terms as in https://arxiv.org/pdf/2110.13530.pdf
|
||||||
def term1(input_, output_):
|
def term1(input_, output_):
|
||||||
laplace_p = laplacian(output_, input_, components=['p'], d=['x1', 'x2'])
|
laplace_z = laplacian(output_, input_, components=['z'], d=['x1', 'x2'])
|
||||||
return output_.extract(['y']) - input_.extract(['mu']) - laplace_p
|
return output_.extract(['y']) - input_.extract(['mu']) - laplace_z
|
||||||
|
|
||||||
def term2(input_, output_):
|
def term2(input_, output_):
|
||||||
laplace_y = laplacian(output_, input_, components=['y'], d=['x1', 'x2'])
|
laplace_y = laplacian(output_, input_, components=['y'], d=['x1', 'x2'])
|
||||||
return - laplace_y - output_.extract(['u'])
|
return - laplace_y - output_.extract(['u'])
|
||||||
|
|
||||||
def fixed_y(input_, output_):
|
|
||||||
return output_.extract(['y'])
|
|
||||||
|
|
||||||
def fixed_p(input_, output_):
|
|
||||||
return output_.extract(['p'])
|
|
||||||
|
|
||||||
# setting problem condition formulation
|
# setting problem condition formulation
|
||||||
conditions = {
|
conditions = {
|
||||||
'gamma1': Condition(
|
'gamma1': Condition(
|
||||||
location=CartesianDomain({'x1': x_range, 'x2': 1, 'mu': mu_range, 'alpha': a_range}),
|
location=CartesianDomain({'x1': x_range, 'x2': 1, 'mu': mu_range, 'alpha': a_range}),
|
||||||
equation=SystemEquation([fixed_y, fixed_p])),
|
equation=FixedValue(0, ['y',])),
|
||||||
'gamma2': Condition(
|
'gamma2': Condition(
|
||||||
location=CartesianDomain({'x1': x_range, 'x2': -1, 'mu': mu_range, 'alpha': a_range}),
|
location=CartesianDomain({'x1': x_range, 'x2': -1, 'mu': mu_range, 'alpha': a_range}),
|
||||||
equation=SystemEquation([fixed_y, fixed_p])),
|
equation=FixedValue(0, ['y', 'z'])),
|
||||||
'gamma3': Condition(
|
'gamma3': Condition(
|
||||||
location=CartesianDomain({'x1': 1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
location=CartesianDomain({'x1': 1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
||||||
equation=SystemEquation([fixed_y, fixed_p])),
|
equation=FixedValue(0, ['y', 'z'])),
|
||||||
'gamma4': Condition(
|
'gamma4': Condition(
|
||||||
location=CartesianDomain({'x1': -1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
location=CartesianDomain({'x1': -1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
||||||
equation=SystemEquation([fixed_y, fixed_p])),
|
equation=FixedValue(0, ['y', 'z'])),
|
||||||
'D': Condition(
|
'D': Condition(
|
||||||
location=CartesianDomain(
|
location=CartesianDomain(
|
||||||
{'x1': x_range, 'x2': y_range,
|
{'x1': x_range, 'x2': y_range,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from torch.nn import Softplus
|
|||||||
|
|
||||||
from pina import LabelTensor
|
from pina import LabelTensor
|
||||||
from pina.solvers import PINN
|
from pina.solvers import PINN
|
||||||
from pina.model import MultiFeedForward
|
from pina.model import MultiFeedForward, FeedForward
|
||||||
from pina.plotter import Plotter
|
from pina.plotter import Plotter
|
||||||
from pina.trainer import Trainer
|
from pina.trainer import Trainer
|
||||||
from problems.parametric_elliptic_optimal_control import (
|
from problems.parametric_elliptic_optimal_control import (
|
||||||
@@ -25,18 +25,17 @@ class myFeature(torch.nn.Module):
|
|||||||
return LabelTensor(t, ['k0'])
|
return LabelTensor(t, ['k0'])
|
||||||
|
|
||||||
|
|
||||||
class CustomMultiDFF(MultiFeedForward):
|
class PIArch(MultiFeedForward):
|
||||||
|
|
||||||
def __init__(self, dff_dict):
|
def __init__(self, dff_dict):
|
||||||
super().__init__(dff_dict)
|
super().__init__(dff_dict)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
out = self.uu(x)
|
out = self.uy(x)
|
||||||
out.labels = ['u', 'y']
|
out.labels = ['u', 'y']
|
||||||
p = LabelTensor(
|
z = LabelTensor(
|
||||||
(out.extract(['u']) * x.extract(['alpha'])), ['p'])
|
(out.extract(['u']) * x.extract(['alpha'])), ['z'])
|
||||||
return out.append(p)
|
return out.append(z)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
@@ -55,15 +54,15 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# create problem and discretise domain
|
# create problem and discretise domain
|
||||||
opc = ParametricEllipticOptimalControl()
|
opc = ParametricEllipticOptimalControl()
|
||||||
opc.discretise_domain(n= 100, mode='random', variables=['x1', 'x2'], locations=['D'])
|
opc.discretise_domain(n= 900, mode='random', variables=['x1', 'x2'], locations=['D'])
|
||||||
opc.discretise_domain(n= 5, mode='random', variables=['mu', 'alpha'], locations=['D'])
|
opc.discretise_domain(n= 5, mode='random', variables=['mu', 'alpha'], locations=['D'])
|
||||||
opc.discretise_domain(n= 20, mode='random', variables=['x1', 'x2'], locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
opc.discretise_domain(n= 200, mode='random', variables=['x1', 'x2'], locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||||
opc.discretise_domain(n= 5, mode='random', variables=['mu', 'alpha'], locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
opc.discretise_domain(n= 5, mode='random', variables=['mu', 'alpha'], locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||||
|
|
||||||
# create model
|
# create model
|
||||||
model = CustomMultiDFF(
|
model = PIArch(
|
||||||
{
|
{
|
||||||
'uu': {
|
'uy': {
|
||||||
'input_dimensions': 4 + len(feat),
|
'input_dimensions': 4 + len(feat),
|
||||||
'output_dimensions': 2,
|
'output_dimensions': 2,
|
||||||
'layers': [40, 40, 20],
|
'layers': [40, 40, 20],
|
||||||
@@ -83,6 +82,8 @@ if __name__ == "__main__":
|
|||||||
if args.load:
|
if args.load:
|
||||||
pinn = PINN.load_from_checkpoint(checkpoint_path=args.load, problem=opc, model=model, extra_features=feat)
|
pinn = PINN.load_from_checkpoint(checkpoint_path=args.load, problem=opc, model=model, extra_features=feat)
|
||||||
plotter = Plotter()
|
plotter = Plotter()
|
||||||
plotter.plot(pinn, fixed_variables={'mu' : 1 , 'alpha' : 0.001}, components='y')
|
plotter.plot(pinn, fixed_variables={'mu' : 3 , 'alpha' : 1}, components='u')
|
||||||
|
plotter.plot(pinn, fixed_variables={'mu' : 3 , 'alpha' : 1}, components='z')
|
||||||
|
plotter.plot(pinn, fixed_variables={'mu' : 3 , 'alpha' : 1}, components='y')
|
||||||
else:
|
else:
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|||||||
Reference in New Issue
Block a user