fix old codes
This commit is contained in:
@@ -14,13 +14,12 @@ class Burgers1D(TimeDependentProblem, SpatialProblem):
|
||||
domain = Span({'x': [-1, 1], 't': [0, 1]})
|
||||
|
||||
def burger_equation(input_, output_):
|
||||
grad_u = grad(output_.extract(['u']), input_)
|
||||
grad_x = grad_u.extract(['x'])
|
||||
grad_t = grad_u.extract(['t'])
|
||||
gradgrad_u_x = grad(grad_u.extract(['x']), input_)
|
||||
du = grad(output_, input_)
|
||||
ddu = grad(du, input_, components=['dudx'])
|
||||
return (
|
||||
grad_u.extract(['t']) + output_.extract(['u'])*grad_u.extract(['x']) -
|
||||
(0.01/torch.pi)*gradgrad_u_x.extract(['x'])
|
||||
du.extract(['dudt']) +
|
||||
output_.extract(['u'])*du.extract(['dudx']) -
|
||||
(0.01/torch.pi)*ddu.extract(['ddudxdx'])
|
||||
)
|
||||
|
||||
def nil_dirichlet(input_, output_):
|
||||
|
||||
@@ -1,52 +1,59 @@
|
||||
import numpy as np
|
||||
import torch
|
||||
from pina.problem import Problem
|
||||
from pina.segment import Segment
|
||||
from pina.cube import Cube
|
||||
from pina.problem2d import Problem2D
|
||||
|
||||
xmin, xmax, ymin, ymax = -1, 1, -1, 1
|
||||
|
||||
class ParametricEllipticOptimalControl(Problem2D):
|
||||
|
||||
def __init__(self, alpha=1):
|
||||
|
||||
def term1(input_, param_, output_):
|
||||
grad_p = self.grad(output_['p'], input_)
|
||||
gradgrad_p_x1 = self.grad(grad_p['x1'], input_)
|
||||
gradgrad_p_x2 = self.grad(grad_p['x2'], input_)
|
||||
#print('mu', input_['mu'])
|
||||
return output_['y'] - input_['mu'] - (gradgrad_p_x1['x1'] + gradgrad_p_x2['x2'])
|
||||
|
||||
def term2(input_, param_, output_):
|
||||
grad_y = self.grad(output_['y'], input_)
|
||||
gradgrad_y_x1 = self.grad(grad_y['x1'], input_)
|
||||
gradgrad_y_x2 = self.grad(grad_y['x2'], input_)
|
||||
return - (gradgrad_y_x1['x1'] + gradgrad_y_x2['x2']) - output_['u_param']
|
||||
|
||||
def term3(input_, param_, output_):
|
||||
#print('a', input_['alpha'], output_['p'], output_['u_param'])
|
||||
return output_['p'] - output_['u_param']*input_['alpha']
|
||||
from pina import Span, Condition
|
||||
from pina.problem import SpatialProblem, ParametricProblem
|
||||
from pina.operators import grad, nabla
|
||||
|
||||
|
||||
def nil_dirichlet(input_, param_, output_):
|
||||
y_value = 0.0
|
||||
p_value = 0.0
|
||||
return torch.abs(output_['y'] - y_value) + torch.abs(output_['p'] - p_value)
|
||||
class ParametricEllipticOptimalControl(SpatialProblem, ParametricProblem):
|
||||
|
||||
self.conditions = {
|
||||
'gamma1': {'location': Segment((xmin, ymin), (xmax, ymin)), 'func': nil_dirichlet},
|
||||
'gamma2': {'location': Segment((xmax, ymin), (xmax, ymax)), 'func': nil_dirichlet},
|
||||
'gamma3': {'location': Segment((xmax, ymax), (xmin, ymax)), 'func': nil_dirichlet},
|
||||
'gamma4': {'location': Segment((xmin, ymax), (xmin, ymin)), 'func': nil_dirichlet},
|
||||
'D1': {'location': Cube([[xmin, xmax], [ymin, ymax]]), 'func': [term1, term2]},
|
||||
#'D2': {'location': Cube([[0, 1], [0, 1]]), 'func': term2},
|
||||
#'D3': {'location': Cube([[0, 1], [0, 1]]), 'func': term3}
|
||||
}
|
||||
xmin, xmax, ymin, ymax = -1, 1, -1, 1
|
||||
amin, amax = 0.0001, 1
|
||||
mumin, mumax = 0.5, 3
|
||||
mu_range = [mumin, mumax]
|
||||
a_range = [amin, amax]
|
||||
x_range = [xmin, xmax]
|
||||
y_range = [ymin, ymax]
|
||||
|
||||
self.input_variables = ['x1', 'x2']
|
||||
self.output_variables = ['u', 'p', 'y']
|
||||
self.parameters = ['mu', 'alpha']
|
||||
self.spatial_domain = Cube([[xmin, xmax], [xmin, xmax]])
|
||||
self.parameter_domain = np.array([[0.5, 3], [0.0001, 1]])
|
||||
spatial_variables = ['x1', 'x2']
|
||||
parameters = ['mu', 'alpha']
|
||||
output_variables = ['u', 'p', 'y']
|
||||
domain = Span({
|
||||
'x1': x_range, 'x2': y_range, 'mu': mu_range, 'alpha': a_range})
|
||||
|
||||
|
||||
def term1(input_, output_):
|
||||
laplace_p = nabla(output_, input_, components=['p'], d=['x1', 'x2'])
|
||||
return output_.extract(['y']) - input_.extract(['mu']) - laplace_p
|
||||
|
||||
def term2(input_, output_):
|
||||
laplace_y = nabla(output_, input_, components=['y'], d=['x1', 'x2'])
|
||||
return - laplace_y - output_.extract(['u_param'])
|
||||
|
||||
def state_dirichlet(input_, output_):
|
||||
y_exp = 0.0
|
||||
return output_.extract(['y']) - y_exp
|
||||
|
||||
def adj_dirichlet(input_, output_):
|
||||
p_exp = 0.0
|
||||
return output_.extract(['p']) - p_exp
|
||||
|
||||
conditions = {
|
||||
'gamma1': Condition(
|
||||
Span({'x1': x_range, 'x2': 1, 'mu': mu_range, 'alpha': a_range}),
|
||||
[state_dirichlet, adj_dirichlet]),
|
||||
'gamma2': Condition(
|
||||
Span({'x1': x_range, 'x2': -1, 'mu': mu_range, 'alpha': a_range}),
|
||||
[state_dirichlet, adj_dirichlet]),
|
||||
'gamma3': Condition(
|
||||
Span({'x1': 1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
||||
[state_dirichlet, adj_dirichlet]),
|
||||
'gamma4': Condition(
|
||||
Span({'x1': -1, 'x2': y_range, 'mu': mu_range, 'alpha': a_range}),
|
||||
[state_dirichlet, adj_dirichlet]),
|
||||
'D': Condition(
|
||||
Span({'x1': x_range, 'x2': y_range,
|
||||
'mu': mu_range, 'alpha': a_range}),
|
||||
[term1, term2]),
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ class ParametricPoisson(SpatialProblem, ParametricProblem):
|
||||
|
||||
def laplace_equation(input_, output_):
|
||||
force_term = torch.exp(
|
||||
- 2*(input_.extract(['x']) - input_.extract(['mu1']))**2 - 2*(input_.extract(['y']) -
|
||||
input_.extract(['mu2']))**2)
|
||||
- 2*(input_.extract(['x']) - input_.extract(['mu1']))**2
|
||||
- 2*(input_.extract(['y']) - input_.extract(['mu2']))**2)
|
||||
return nabla(output_.extract(['u']), input_) - force_term
|
||||
|
||||
def nil_dirichlet(input_, output_):
|
||||
|
||||
@@ -23,11 +23,11 @@ class Poisson(SpatialProblem):
|
||||
return output_.extract(['u']) - value
|
||||
|
||||
conditions = {
|
||||
'gamma1': Condition(Span({'x': [-1, 1], 'y': 1}), nil_dirichlet),
|
||||
'gamma2': Condition(Span({'x': [-1, 1], 'y': -1}), nil_dirichlet),
|
||||
'gamma3': Condition(Span({'x': 1, 'y': [-1, 1]}), nil_dirichlet),
|
||||
'gamma4': Condition(Span({'x': -1, 'y': [-1, 1]}), nil_dirichlet),
|
||||
'D': Condition(Span({'x': [-1, 1], 'y': [-1, 1]}), laplace_equation),
|
||||
'gamma1': Condition(Span({'x': [0, 1], 'y': 1}), nil_dirichlet),
|
||||
'gamma2': Condition(Span({'x': [0, 1], 'y': 0}), nil_dirichlet),
|
||||
'gamma3': Condition(Span({'x': 1, 'y': [0, 1]}), nil_dirichlet),
|
||||
'gamma4': Condition(Span({'x': 0, 'y': [0, 1]}), nil_dirichlet),
|
||||
'D': Condition(Span({'x': [0, 1], 'y': [0, 1]}), laplace_equation),
|
||||
}
|
||||
|
||||
def poisson_sol(self, x, y):
|
||||
|
||||
@@ -2,9 +2,9 @@ import argparse
|
||||
import torch
|
||||
from torch.nn import Softplus
|
||||
|
||||
from pina import PINN, Plotter
|
||||
from pina import PINN, Plotter, LabelTensor
|
||||
from pina.model import FeedForward
|
||||
from problems.burgers import Burgers1D
|
||||
from burger2 import Burgers1D
|
||||
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
@@ -16,7 +16,7 @@ class myFeature(torch.nn.Module):
|
||||
self.idx = idx
|
||||
|
||||
def forward(self, x):
|
||||
return torch.sin(torch.pi * x[:, self.idx])
|
||||
return LabelTensor(torch.sin(torch.pi * x.extract(['x'])), ['sin(x)'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -45,12 +45,14 @@ if __name__ == "__main__":
|
||||
model,
|
||||
lr=0.006,
|
||||
error_norm='mse',
|
||||
regularizer=0,
|
||||
lr_accelerate=None)
|
||||
regularizer=0)
|
||||
|
||||
if args.s:
|
||||
pinn.span_pts(2000, 'latin', ['D'])
|
||||
pinn.span_pts(150, 'random', ['gamma1', 'gamma2', 't0'])
|
||||
pinn.span_pts(
|
||||
{'n': 200, 'mode': 'random', 'variables': 't'},
|
||||
{'n': 20, 'mode': 'random', 'variables': 'x'},
|
||||
locations=['D'])
|
||||
pinn.span_pts(150, 'random', location=['gamma1', 'gamma2', 't0'])
|
||||
pinn.train(5000, 100)
|
||||
pinn.save_state('pina.burger.{}.{}'.format(args.id_run, args.features))
|
||||
else:
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import argparse
|
||||
import numpy as np
|
||||
import torch
|
||||
import argparse
|
||||
from pina.pinn import PINN
|
||||
from pina.ppinn import ParametricPINN as pPINN
|
||||
from pina.label_tensor import LabelTensor
|
||||
from torch.nn import ReLU, Tanh, Softplus
|
||||
from pina.adaptive_functions.adaptive_softplus import AdaptiveSoftplus
|
||||
from problems.parametric_elliptic_optimal_control_alpha_variable import ParametricEllipticOptimalControl
|
||||
from pina.multi_deep_feed_forward import MultiDeepFeedForward
|
||||
from pina.deep_feed_forward import DeepFeedForward
|
||||
|
||||
alpha = 1
|
||||
from pina import PINN, LabelTensor
|
||||
from parametric_elliptic_optimal_control_alpha_variable2 import ParametricEllipticOptimalControl
|
||||
from pina.model import MultiFeedForward, FeedForward
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
"""
|
||||
@@ -21,46 +16,21 @@ class myFeature(torch.nn.Module):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return (-x[:, 0]**2+1) * (-x[:, 1]**2+1)
|
||||
t = (-x.extract(['x1'])**2+1) * (-x.extract(['x2'])**2+1)
|
||||
return LabelTensor(t, ['k0'])
|
||||
|
||||
|
||||
class CustomMultiDFF(MultiDeepFeedForward):
|
||||
class CustomMultiDFF(MultiFeedForward):
|
||||
|
||||
def __init__(self, dff_dict):
|
||||
super().__init__(dff_dict)
|
||||
|
||||
def forward(self, x):
|
||||
out = self.uu(x)
|
||||
p = LabelTensor((out['u_param'] * x[:, 3]).reshape(-1, 1), ['p'])
|
||||
a = LabelTensor.hstack([out, p])
|
||||
return a
|
||||
|
||||
model = CustomMultiDFF(
|
||||
{
|
||||
'uu': {
|
||||
'input_variables': ['x1', 'x2', 'mu', 'alpha'],
|
||||
'output_variables': ['u_param', 'y'],
|
||||
'layers': [40, 40, 20],
|
||||
'func': Softplus,
|
||||
'extra_features': [myFeature()],
|
||||
},
|
||||
# 'u_param': {
|
||||
# 'input_variables': ['u', 'mu'],
|
||||
# 'output_variables': ['u_param'],
|
||||
# 'layers': [],
|
||||
# 'func': None
|
||||
# },
|
||||
# 'p': {
|
||||
# 'input_variables': ['u'],
|
||||
# 'output_variables': ['p'],
|
||||
# 'layers': [10],
|
||||
# 'func': None
|
||||
# },
|
||||
}
|
||||
)
|
||||
p = LabelTensor((out.extract(['u_param']) * x.extract(['alpha'])), ['p'])
|
||||
return out.append(p)
|
||||
|
||||
|
||||
opc = ParametricEllipticOptimalControl(alpha)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -70,138 +40,39 @@ if __name__ == "__main__":
|
||||
group.add_argument("-l", "-load", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
# model = DeepFeedForward(
|
||||
# layers=[40, 40, 20],
|
||||
# output_variables=['u_param', 'y', 'p'],
|
||||
# input_variables=opc.input_variables+['mu', 'alpha'],
|
||||
# func=Softplus,
|
||||
# extra_features=[myFeature()]
|
||||
# )
|
||||
opc = ParametricEllipticOptimalControl()
|
||||
model = CustomMultiDFF(
|
||||
{
|
||||
'uu': {
|
||||
'input_variables': ['x1', 'x2', 'mu', 'alpha'],
|
||||
'output_variables': ['u_param', 'y'],
|
||||
'layers': [40, 40, 20],
|
||||
'func': Softplus,
|
||||
'extra_features': [myFeature()],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
pinn = pPINN(
|
||||
pinn = PINN(
|
||||
opc,
|
||||
model,
|
||||
lr=0.002,
|
||||
error_norm='mse',
|
||||
regularizer=1e-8,
|
||||
lr_accelerate=None)
|
||||
regularizer=1e-8)
|
||||
|
||||
if args.s:
|
||||
|
||||
pinn.span_pts(30, 'grid', ['D1'])
|
||||
pinn.span_pts(50, 'grid', ['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
pinn.train(10000, 20)
|
||||
# with open('ocp_wrong_history.txt', 'w') as file_:
|
||||
# for i, losses in enumerate(pinn.history):
|
||||
# file_.write('{} {}\n'.format(i, sum(losses).item()))
|
||||
pinn.span_pts(
|
||||
{'variables': ['x1', 'x2'], 'mode': 'random', 'n': 100},
|
||||
{'variables': ['mu', 'alpha'], 'mode': 'grid', 'n': 5},
|
||||
locations=['D'])
|
||||
pinn.span_pts(
|
||||
{'variables': ['x1', 'x2'], 'mode': 'grid', 'n': 20},
|
||||
{'variables': ['mu', 'alpha'], 'mode': 'grid', 'n': 5},
|
||||
locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
|
||||
pinn.train(10000, 20)
|
||||
pinn.save_state('pina.ocp')
|
||||
|
||||
else:
|
||||
pinn.load_state('working.pina.ocp')
|
||||
pinn.load_state('pina.ocp')
|
||||
|
||||
import matplotlib
|
||||
matplotlib.use('GTK3Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# res = 64
|
||||
# param = torch.tensor([[3., 1]])
|
||||
# pts_container = []
|
||||
# for mn, mx in [[-1, 1], [-1, 1]]:
|
||||
# pts_container.append(np.linspace(mn, mx, res))
|
||||
# grids_container = np.meshgrid(*pts_container)
|
||||
# unrolled_pts = torch.tensor([t.flatten() for t in grids_container]).T
|
||||
# unrolled_pts = torch.cat([unrolled_pts, param.double().repeat(unrolled_pts.shape[0], 1).reshape(-1, 2)], axis=1)
|
||||
|
||||
# unrolled_pts = LabelTensor(unrolled_pts, ['x1', 'x2', 'mu', 'alpha'])
|
||||
# Z_pred = pinn.model(unrolled_pts.tensor)
|
||||
# print(Z_pred.tensor.shape)
|
||||
|
||||
# plt.subplot(2, 3, 1)
|
||||
# plt.pcolor(Z_pred['y'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
# plt.subplot(2, 3, 2)
|
||||
# plt.pcolor(Z_pred['u_param'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
# plt.subplot(2, 3, 3)
|
||||
# plt.pcolor(Z_pred['p'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
# with open('ocp_mu3_a1_plot.txt', 'w') as f_:
|
||||
# f_.write('x y u p ys\n')
|
||||
# for (x, y), tru, pre, e in zip(unrolled_pts[:, :2],
|
||||
# Z_pred['u_param'].reshape(-1, 1),
|
||||
# Z_pred['p'].reshape(-1, 1),
|
||||
# Z_pred['y'].reshape(-1, 1),
|
||||
# ):
|
||||
# f_.write('{} {} {} {} {}\n'.format(x.item(), y.item(), tru.item(), pre.item(), e.item()))
|
||||
|
||||
|
||||
# param = torch.tensor([[3.0, 0.01]])
|
||||
# unrolled_pts = torch.tensor([t.flatten() for t in grids_container]).T
|
||||
# unrolled_pts = torch.cat([unrolled_pts, param.double().repeat(unrolled_pts.shape[0], 1).reshape(-1, 2)], axis=1)
|
||||
# unrolled_pts = LabelTensor(unrolled_pts, ['x1', 'x2', 'mu', 'alpha'])
|
||||
# Z_pred = pinn.model(unrolled_pts.tensor)
|
||||
|
||||
# plt.subplot(2, 3, 4)
|
||||
# plt.pcolor(Z_pred['y'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
# plt.subplot(2, 3, 5)
|
||||
# plt.pcolor(Z_pred['u_param'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
# plt.subplot(2, 3, 6)
|
||||
# plt.pcolor(Z_pred['p'].reshape(res, res).detach())
|
||||
# plt.colorbar()
|
||||
|
||||
# plt.show()
|
||||
# with open('ocp_mu3_a0.01_plot.txt', 'w') as f_:
|
||||
# f_.write('x y u p ys\n')
|
||||
# for (x, y), tru, pre, e in zip(unrolled_pts[:, :2],
|
||||
# Z_pred['u_param'].reshape(-1, 1),
|
||||
# Z_pred['p'].reshape(-1, 1),
|
||||
# Z_pred['y'].reshape(-1, 1),
|
||||
# ):
|
||||
# f_.write('{} {} {} {} {}\n'.format(x.item(), y.item(), tru.item(), pre.item(), e.item()))
|
||||
|
||||
|
||||
|
||||
|
||||
y = {}
|
||||
u = {}
|
||||
for alpha in [0.01, 0.1, 1]:
|
||||
y[alpha] = []
|
||||
u[alpha] = []
|
||||
for p in np.linspace(0.5, 3, 32):
|
||||
a = pinn.model(LabelTensor(torch.tensor([[0, 0, p, alpha]]).double(), ['x1', 'x2', 'mu', 'alpha']).tensor)
|
||||
y[alpha].append(a['y'].detach().numpy()[0])
|
||||
u[alpha].append(a['u_param'].detach().numpy()[0])
|
||||
|
||||
|
||||
|
||||
plt.plot(np.linspace(0.5, 3, 32), u[1], label='u')
|
||||
plt.plot(np.linspace(0.5, 3, 32), u[0.01], label='u')
|
||||
plt.plot(np.linspace(0.5, 3, 32), u[0.1], label='u')
|
||||
plt.plot([1, 2, 3], [0.28, 0.56, 0.85], 'o', label='Truth values')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
print(y[1])
|
||||
print(y[0.1])
|
||||
print(y[0.01])
|
||||
with open('elliptic_param_y.txt', 'w') as f_:
|
||||
f_.write('mu 1 01 001\n')
|
||||
for mu, y1, y01, y001 in zip(np.linspace(0.5, 3, 32), y[1], y[0.1], y[0.01]):
|
||||
f_.write('{} {} {} {}\n'.format(mu, y1, y01, y001))
|
||||
|
||||
with open('elliptic_param_u.txt', 'w') as f_:
|
||||
f_.write('mu 1 01 001\n')
|
||||
for mu, y1, y01, y001 in zip(np.linspace(0.5, 3, 32), u[1], u[0.1], u[0.01]):
|
||||
f_.write('{} {} {} {}\n'.format(mu, y1, y01, y001))
|
||||
|
||||
|
||||
plt.plot(np.linspace(0.5, 3, 32), y, label='y')
|
||||
plt.plot([1, 2, 3], [0.062, 0.12, 0.19], 'o', label='Truth values')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import torch
|
||||
from torch.nn import Softplus
|
||||
from pina import Plotter
|
||||
from pina import PINN as pPINN
|
||||
from problems.parametric_poisson import ParametricPoisson
|
||||
from pina import Plotter, LabelTensor, PINN
|
||||
from parametric_poisson2 import ParametricPoisson
|
||||
from pina.model import FeedForward
|
||||
|
||||
|
||||
@@ -14,7 +13,13 @@ class myFeature(torch.nn.Module):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return torch.exp(- 2*(x.extract(['x']) - x.extract(['mu1']))**2 - 2*(x.extract(['y']) - x.extract(['mu2']))**2)
|
||||
t = (
|
||||
torch.exp(
|
||||
- 2*(x.extract(['x']) - x.extract(['mu1']))**2
|
||||
- 2*(x.extract(['y']) - x.extract(['mu2']))**2
|
||||
)
|
||||
)
|
||||
return LabelTensor(t, ['k0'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -38,21 +43,23 @@ if __name__ == "__main__":
|
||||
extra_features=feat
|
||||
)
|
||||
|
||||
pinn = pPINN(
|
||||
pinn = PINN(
|
||||
poisson_problem,
|
||||
model,
|
||||
lr=0.0006,
|
||||
lr=0.006,
|
||||
regularizer=1e-6)
|
||||
|
||||
if args.s:
|
||||
|
||||
pinn.span_pts(500, n_params=10, mode_spatial='random', locations=['D'])
|
||||
pinn.span_pts(200, n_params=10, mode_spatial='random', locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
pinn.plot_pts()
|
||||
pinn.span_pts(
|
||||
{'variables': ['x', 'y'], 'mode': 'random', 'n': 100},
|
||||
{'variables': ['mu1', 'mu2'], 'mode': 'grid', 'n': 5},
|
||||
locations=['D'])
|
||||
pinn.span_pts(
|
||||
{'variables': ['x', 'y'], 'mode': 'grid', 'n': 20},
|
||||
{'variables': ['mu1', 'mu2'], 'mode': 'grid', 'n': 5},
|
||||
locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
pinn.train(10000, 100)
|
||||
with open('param_poisson_history_{}_{}.txt'.format(args.id_run, args.features), 'w') as file_:
|
||||
for i, losses in enumerate(pinn.history):
|
||||
file_.write('{} {}\n'.format(i, sum(losses)))
|
||||
pinn.save_state('pina.poisson_param')
|
||||
|
||||
else:
|
||||
|
||||
@@ -7,7 +7,7 @@ from torch.nn import ReLU, Tanh, Softplus
|
||||
from pina import PINN, LabelTensor, Plotter
|
||||
from pina.model import FeedForward
|
||||
from pina.adaptive_functions import AdaptiveSin, AdaptiveCos, AdaptiveTanh
|
||||
from problems.poisson import Poisson
|
||||
from poisson2 import Poisson
|
||||
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
@@ -19,7 +19,9 @@ class myFeature(torch.nn.Module):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return torch.sin(x[:, 0]*torch.pi) * torch.sin(x[:, 1]*torch.pi)
|
||||
t = (torch.sin(x.extract(['x'])*torch.pi) *
|
||||
torch.sin(x.extract(['y'])*torch.pi))
|
||||
return LabelTensor(t, ['sin(x)sin(y)'])
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -51,14 +53,9 @@ if __name__ == "__main__":
|
||||
|
||||
if args.s:
|
||||
|
||||
print(pinn)
|
||||
pinn.span_pts(20, mode_spatial='grid', locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
pinn.span_pts(20, mode_spatial='grid', locations=['D'])
|
||||
pinn.plot_pts()
|
||||
pinn.span_pts(20, 'grid', locations=['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
pinn.span_pts(20, 'grid', locations=['D'])
|
||||
pinn.train(5000, 100)
|
||||
with open('poisson_history_{}_{}.txt'.format(args.id_run, args.features), 'w') as file_:
|
||||
for i, losses in enumerate(pinn.history):
|
||||
file_.write('{} {}\n'.format(i, sum(losses)))
|
||||
pinn.save_state('pina.poisson')
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user