tmp commit - toward 0.0.1
This commit is contained in:
115
examples/run_burgers.py
Normal file
115
examples/run_burgers.py
Normal file
@@ -0,0 +1,115 @@
|
||||
import sys
|
||||
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 problems.burgers import Burgers1D
|
||||
from pina.deep_feed_forward import DeepFeedForward
|
||||
|
||||
from pina.adaptive_functions import AdaptiveSin, AdaptiveCos, AdaptiveTanh
|
||||
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
"""
|
||||
Feature: sin(x)
|
||||
"""
|
||||
|
||||
def __init__(self, idx):
|
||||
|
||||
super(myFeature, self).__init__()
|
||||
self.idx = idx
|
||||
|
||||
def forward(self, x):
|
||||
|
||||
return torch.sin(torch.pi * x[:, self.idx])
|
||||
|
||||
class myExp(torch.nn.Module):
|
||||
def __init__(self, idx):
|
||||
|
||||
super().__init__()
|
||||
self.idx = idx
|
||||
|
||||
def forward(self, x):
|
||||
|
||||
return torch.exp(x[:, self.idx])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run PINA")
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("-s", "-save", action="store_true")
|
||||
group.add_argument("-l", "-load", action="store_true")
|
||||
parser.add_argument("id_run", help="number of run", type=int)
|
||||
parser.add_argument("features", help="extra features", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
feat = [myFeature(0)] if args.features else []
|
||||
|
||||
burgers_problem = Burgers1D()
|
||||
model = DeepFeedForward(
|
||||
layers=[20, 10, 5],
|
||||
#layers=[8, 4, 2],
|
||||
#layers=[16, 8, 4, 4],
|
||||
#layers=[20, 4, 4, 4],
|
||||
output_variables=burgers_problem.output_variables,
|
||||
input_variables=burgers_problem.input_variables,
|
||||
func=Tanh,
|
||||
extra_features=feat
|
||||
)
|
||||
|
||||
pinn = PINN(
|
||||
burgers_problem,
|
||||
model,
|
||||
lr=0.006,
|
||||
error_norm='mse',
|
||||
regularizer=0,
|
||||
lr_accelerate=None)
|
||||
|
||||
if args.s:
|
||||
|
||||
pinn.span_pts(8000, 'latin', ['D'])
|
||||
pinn.span_pts(50, 'random', ['gamma1', 'gamma2', 'initia'])
|
||||
#pinn.plot_pts()
|
||||
pinn.train(10000, 1000)
|
||||
#with open('burgers_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).item()))
|
||||
pinn.save_state('pina.burger.{}.{}'.format(args.id_run, args.features))
|
||||
|
||||
else:
|
||||
pinn.load_state('pina.burger.{}.{}'.format(args.id_run, args.features))
|
||||
#pinn.plot(256,filename='pina.burger.{}.{}.jpg'.format(args.id_run, args.features))
|
||||
|
||||
|
||||
print(pinn.history)
|
||||
with open('burgers_history_{}_{}.txt'.format(args.id_run, args.features), 'w') as file_:
|
||||
for i, losses in enumerate(pinn.history):
|
||||
print(losses)
|
||||
file_.write('{} {}\n'.format(i, sum(losses)))
|
||||
import scipy
|
||||
data = scipy.io.loadmat('Data/burgers_shock.mat')
|
||||
data_solution = {'grid': np.meshgrid(data['x'], data['t']), 'grid_solution': data['usol'].T}
|
||||
import matplotlib
|
||||
matplotlib.use('Qt5Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
t =75
|
||||
for t in [25, 50, 75]:
|
||||
input = torch.cat([
|
||||
torch.linspace(-1, 1, 256).reshape(-1, 1),
|
||||
torch.ones(size=(256, 1)) * t /100],
|
||||
axis=1).double()
|
||||
output = pinn.model(input)
|
||||
fout = 'pina.burgers.{}.{}.t{}.dat'.format(args.id_run, args.features, t)
|
||||
with open(fout, 'w') as f_:
|
||||
f_.write('x utruth upinn\n')
|
||||
for x, utruth, upinn in zip(data['x'], data['usol'][:, t], output.tensor.detach()):
|
||||
f_.write('{} {} {}\n'.format(x[0], utruth, upinn.item()))
|
||||
plt.plot(data['usol'][:, t], label='truth')
|
||||
plt.plot(output.tensor.detach(), 'x', label='pinn')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
207
examples/run_parametric_elliptic_optimal_control_alpha.py
Normal file
207
examples/run_parametric_elliptic_optimal_control_alpha.py
Normal file
@@ -0,0 +1,207 @@
|
||||
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
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
"""
|
||||
Feature: sin(x)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return (-x[:, 0]**2+1) * (-x[:, 1]**2+1)
|
||||
|
||||
|
||||
class CustomMultiDFF(MultiDeepFeedForward):
|
||||
|
||||
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
|
||||
# },
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
opc = ParametricEllipticOptimalControl(alpha)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run PINA")
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("-s", "-save", action="store_true")
|
||||
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()]
|
||||
# )
|
||||
|
||||
|
||||
pinn = pPINN(
|
||||
opc,
|
||||
model,
|
||||
lr=0.002,
|
||||
error_norm='mse',
|
||||
regularizer=1e-8,
|
||||
lr_accelerate=None)
|
||||
|
||||
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.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()
|
||||
|
||||
|
||||
157
examples/run_parametric_poisson.py
Normal file
157
examples/run_parametric_poisson.py
Normal file
@@ -0,0 +1,157 @@
|
||||
import sys
|
||||
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 problems.parametric_poisson import ParametricPoisson2DProblem as Poisson2D
|
||||
from pina.deep_feed_forward import DeepFeedForward
|
||||
|
||||
from pina.adaptive_functions import AdaptiveSin, AdaptiveCos, AdaptiveTanh
|
||||
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
"""
|
||||
Feature: sin(x)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return torch.exp(- 2*(x[:, 0] - x[:, 2])**2 - 2*(x[:, 1] - x[:, 3])**2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run PINA")
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("-s", "-save", action="store_true")
|
||||
group.add_argument("-l", "-load", action="store_true")
|
||||
parser.add_argument("id_run", help="number of run", type=int)
|
||||
parser.add_argument("features", help="extra features", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
feat = [myFeature()] if args.features else []
|
||||
|
||||
poisson_problem = Poisson2D()
|
||||
model = DeepFeedForward(
|
||||
layers=[200, 40, 10],
|
||||
output_variables=poisson_problem.output_variables,
|
||||
input_variables=poisson_problem.input_variables+['mu1', 'mu2'],
|
||||
func=Softplus,
|
||||
extra_features=feat
|
||||
)
|
||||
|
||||
pinn = pPINN(
|
||||
poisson_problem,
|
||||
model,
|
||||
lr=0.0006,
|
||||
regularizer=1e-6,
|
||||
lr_accelerate=None)
|
||||
|
||||
if args.s:
|
||||
|
||||
pinn.span_pts(30, 'chebyshev', ['D'])
|
||||
pinn.span_pts(50, 'grid', ['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
#pinn.plot_pts()
|
||||
pinn.train(10000, 10)
|
||||
pinn.save_state('pina.poisson_param')
|
||||
|
||||
else:
|
||||
pinn.load_state('pina.poisson_param')
|
||||
#pinn.plot(40, torch.tensor([-0.8, -0.8]))
|
||||
#pinn.plot(40, torch.tensor([ 0.8, 0.8]))
|
||||
|
||||
from smithers.io import VTUHandler
|
||||
from scipy.interpolate import griddata
|
||||
import matplotlib
|
||||
matplotlib.use('GTK3Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
res = 64
|
||||
fname_minus = 'Poisson_param_08minus000000.vtu'
|
||||
param = torch.tensor([-0.8, -0.8])
|
||||
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]).reshape(-1, 2)], axis=1)
|
||||
|
||||
#unrolled_pts.to(dtype=self.dtype)
|
||||
unrolled_pts = LabelTensor(unrolled_pts, ['x1', 'x2', 'mu1', 'mu2'])
|
||||
|
||||
Z_pred = pinn.model(unrolled_pts.tensor)
|
||||
data = VTUHandler.read(fname_minus)
|
||||
|
||||
|
||||
print(data['points'][:, :2].shape)
|
||||
print(data['point_data']['f_16'].shape)
|
||||
print(grids_container[0].shape)
|
||||
print(grids_container[1].shape)
|
||||
Z_truth = griddata(data['points'][:, :2], data['point_data']['f_16'], (grids_container[0], grids_container[1]))
|
||||
|
||||
|
||||
err = np.abs(Z_truth + Z_pred.tensor.reshape(res, res).detach().numpy())
|
||||
|
||||
plt.subplot(1, 3, 1)
|
||||
plt.pcolor(-Z_pred.tensor.reshape(res, res).detach())
|
||||
plt.colorbar()
|
||||
plt.subplot(1, 3, 2)
|
||||
plt.pcolor(Z_truth)
|
||||
plt.colorbar()
|
||||
plt.subplot(1, 3, 3)
|
||||
plt.pcolor(err, vmin=0, vmax=0.009)
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
|
||||
print(unrolled_pts.tensor.shape)
|
||||
with open('parpoisson_minus_plot.txt', 'w') as f_:
|
||||
f_.write('x y truth pred e\n')
|
||||
for (x, y), tru, pre, e in zip(unrolled_pts[:, :2], Z_truth.reshape(-1, 1), -Z_pred.tensor.reshape(-1, 1), err.reshape(-1, 1)):
|
||||
f_.write('{} {} {} {} {}\n'.format(x.item(), y.item(), tru.item(), pre.item(), e.item()))
|
||||
|
||||
fname_plus = 'Poisson_param_08plus000000.vtu'
|
||||
param = torch.tensor([0.8, 0.8])
|
||||
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]).reshape(-1, 2)], axis=1)
|
||||
|
||||
#unrolled_pts.to(dtype=self.dtype)
|
||||
unrolled_pts = LabelTensor(unrolled_pts, ['x1', 'x2', 'mu1', 'mu2'])
|
||||
|
||||
Z_pred = pinn.model(unrolled_pts.tensor)
|
||||
data = VTUHandler.read(fname_plus)
|
||||
|
||||
|
||||
print(data['points'][:, :2].shape)
|
||||
print(data['point_data']['f_16'].shape)
|
||||
print(grids_container[0].shape)
|
||||
print(grids_container[1].shape)
|
||||
Z_truth = griddata(data['points'][:, :2], data['point_data']['f_16'], (grids_container[0], grids_container[1]))
|
||||
|
||||
|
||||
err = np.abs(Z_truth + Z_pred.tensor.reshape(res, res).detach().numpy())
|
||||
|
||||
plt.subplot(1, 3, 1)
|
||||
plt.pcolor(-Z_pred.tensor.reshape(res, res).detach())
|
||||
plt.colorbar()
|
||||
plt.subplot(1, 3, 2)
|
||||
plt.pcolor(Z_truth)
|
||||
plt.colorbar()
|
||||
plt.subplot(1, 3, 3)
|
||||
print('gggggg')
|
||||
plt.pcolor(err, vmin=0, vmax=0.001)
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
with open('parpoisson_plus_plot.txt', 'w') as f_:
|
||||
f_.write('x y truth pred e\n')
|
||||
for (x, y), tru, pre, e in zip(unrolled_pts[:, :2], Z_truth.reshape(-1, 1), -Z_pred.tensor.reshape(-1, 1), err.reshape(-1, 1)):
|
||||
f_.write('{} {} {} {} {}\n'.format(x.item(), y.item(), tru.item(), pre.item(), e.item()))
|
||||
|
||||
|
||||
70
examples/run_poisson.py
Normal file
70
examples/run_poisson.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import sys
|
||||
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 problems.poisson2D import Poisson2DProblem as Poisson2D
|
||||
from pina.deep_feed_forward import DeepFeedForward
|
||||
|
||||
from pina.adaptive_functions import AdaptiveSin, AdaptiveCos, AdaptiveTanh
|
||||
|
||||
|
||||
class myFeature(torch.nn.Module):
|
||||
"""
|
||||
Feature: sin(x)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(myFeature, self).__init__()
|
||||
|
||||
def forward(self, x):
|
||||
return torch.sin(x[:, 0]*torch.pi) * torch.sin(x[:, 1]*torch.pi)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description="Run PINA")
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("-s", "-save", action="store_true")
|
||||
group.add_argument("-l", "-load", action="store_true")
|
||||
parser.add_argument("id_run", help="number of run", type=int)
|
||||
parser.add_argument("features", help="extra features", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
feat = [myFeature()] if args.features else []
|
||||
|
||||
poisson_problem = Poisson2D()
|
||||
model = DeepFeedForward(
|
||||
layers=[10, 10],
|
||||
output_variables=poisson_problem.output_variables,
|
||||
input_variables=poisson_problem.input_variables,
|
||||
func=Softplus,
|
||||
extra_features=feat
|
||||
)
|
||||
|
||||
pinn = PINN(
|
||||
poisson_problem,
|
||||
model,
|
||||
lr=0.003,
|
||||
error_norm='mse',
|
||||
regularizer=1e-8,
|
||||
lr_accelerate=None)
|
||||
|
||||
if args.s:
|
||||
|
||||
pinn.span_pts(10, 'grid', ['D'])
|
||||
pinn.span_pts(10, 'grid', ['gamma1', 'gamma2', 'gamma3', 'gamma4'])
|
||||
#pinn.plot_pts()
|
||||
pinn.train(10000, 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).item()))
|
||||
pinn.save_state('pina.poisson')
|
||||
|
||||
else:
|
||||
pinn.load_state('pina.poisson')
|
||||
pinn.plot(40)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user