Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to implement different boundary condition on different geometry part #22

Closed
sumantkrsoni opened this issue Mar 27, 2020 · 45 comments
Closed

Comments

@sumantkrsoni
Copy link

kindly help me in implementing the different boundary condition in the different geometry of the problem,

Like. in unit square two sides have Dirichlet BC and Two sides have Neumann BC.

@lululxvi
Copy link
Owner

You can define a seperate a BC for each part. Here is an example to define left and right BC in 1D: https://github.com/lululxvi/deepxde/blob/master/examples/Poisson_Neumann_1d.py. You can do similar thing in 2D.

@sumantkrsoni
Copy link
Author

Thanks Lu,
Thanks for your prompt reply. I am trying to implement the drichlet condition on edge joining coordinates [0,0] and [1,0]. I am trying to compile this code ,,,,,is it ok.

kindly help me lu.

geom = dde.geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1]])
def boundary_l(x, on_boundary):
return on_boundary and np.isclose(x[0], [0,0] ) and np.isclose(x[0],[0,1])

@lululxvi
Copy link
Owner

def boundary_bottom(x, on_boundary):
    return on_boundary and np.isclose(x[1], 0)  # y coordinate x[1] is 0

@sumantkrsoni
Copy link
Author

Hello Lu,
First of all thanks for your support. I have written one code that is given below but I am getting errors. Kindly suggest, where I am making mistakes.

my code=====================================================

from future import absolute_import
from future import division
from future import print_function

import numpy as np
import tensorflow as tf

import deepxde as dde

def main():
def pde(x, y):
phio = 0.1003
kts = 2.49
ktf = 0.6
kt = (1-phio)kts + phio ktf
dy_x = tf.gradients(y, x)[0]
dy_x, dy_y = dy_x[:, 0:1], dy_x[:, 1:]
dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
dy_yy = tf.gradients(dy_y, x)[0][:, 1:]
return kt * (dy_xx + dy_yy)

def func(x):
    return np.zeros([len(x), 1])

geom = dde.geometry.Rectangle([0,0],[20,20])

def boundary_l(x, on_boundary):
   
    return on_boundary and np.isclose(x[1], 0 ) 

def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[1],20)

bc_l = dde.DirichletBC(geom, func, boundary_l)     
bc_2 = dde.DirichletBC(geom, func, boundary_u)     

data = dde.data.PDE(geom, 1, pde, [bc_l,bc_2], 16, 2, func=func, num_test=100)


layer_size = [1] + [50] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)

if name == "main":
main()

error is==========
ValueError Traceback (most recent call last)
in ()
56
57 if name == "main":
---> 58 main()

5 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1154 'Cannot feed value of shape %r for Tensor %r, '
1155 'which has shape %r' %
-> 1156 (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
1157 if not self.graph.is_feedable(subfeed_t):
1158 raise ValueError('Tensor %s may not be fed.' % subfeed_t)

ValueError: Cannot feed value of shape (24, 2) for Tensor 'Placeholder_3:0', which has shape '(?, 1)'

@lululxvi
Copy link
Owner

The network input is 2D, i.e., the first layer should have two neurons:

layer_size = [2] + [50] * 3 + [1]

@sumantkrsoni
Copy link
Author

Lu, you are really cooperative, finally, It runs.
I want your suggestion.
I am very new in Tensorflow, so could you tell me the way that I can gain the prominent knowledge in this field.
I am currently looking for the solution of pde or system of pde with the help of DEEP learning (deep collocation method).

Kindly comment, so that I can improve my programming skills.

Thanks Lu

@lululxvi
Copy link
Owner

If you use DeepXDE, actually you don't need to learn tensorflow, unless you want to modify the source code. You only need to learn some basic knowledge of deep learning.

@sumantkrsoni
Copy link
Author

sumantkrsoni commented Mar 29, 2020 via email

@lululxvi
Copy link
Owner

lululxvi commented Mar 29, 2020

After the training, the data is saved in loss.dat, train.dat, and test.dat in plain text mode. You can use whatever tool you like for plotting, like Matlab, Python, Gnuplot, etc. DeepXDE is not a tool designed for visualization.

@sumantkrsoni
Copy link
Author

sumantkrsoni commented Mar 30, 2020 via email

@sumantkrsoni
Copy link
Author

Hii Lu,
I have written a code but it shows some error for normal boundary error.
Kindly suggest me, how to fix it.

code is as ==================

%tensorflow_version 1.x

from future import absolute_import
from future import division
from future import print_function

import numpy as np
import tensorflow as tf

import deepxde as dde

def main():
def pde(x, y):
phio = 0.1003
rhos = 2910.2
cvs = 1000
rhof = 1000
cvf = 4200
kts = 2.49
ktf = 0.6

    rhocv = (1-phio)*rhos*cvs + rhos* rhof*cvf
    kt = (1-phio)*kts + phio*ktf
    dy_x = tf.gradients(y, x)[0]
    dy_x, dy_y, dy_t = dy_x[:, 0:1], dy_x[:, 1:2], dy_x[:,2:]
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
    dy_yy = tf.gradients(dy_y, x)[0][:, 1:2]
    dy_t = tf.gradients(dy_x,x)[0][:,2:3]
 
    return (    -ktf* (dy_xx + dy_yy)+ rhocv * dy_t   ) 
       
def func(x):
    return 473.15*np.ones((len(x),1),dtype = np.float32)
 
def func1(x):
    return 473.15* np.ones((len(x),1),dtype = np.float64) - 10 * x[:,2:]
    #return np.sin(np.pi * x[:, 0:1]) * np.exp(-x[:, 1:])
def func_n(x):
    return np.zeros((len(x),1), dtype= np.float64)
  

geom = dde.geometry.Polygon([[0,0],[20,0],[20,20], [0,20]])

timedomain = dde.geometry.TimeDomain(0, 5)

geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary_l(x, on_boundary):
   
    return on_boundary and np.isclose(x[1], 0 ) 

def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[1],20)
def boundary_ln(x, on_boundary):
    return on_boundary and np.isclose(x[0], 0)

def boundary_rn(x, on_boundary):
    return on_boundary and np.isclose(x[0], 20)  

bc_l = dde.DirichletBC(geomtime, func, boundary_l)
bc_r = dde.DirichletBC(geomtime, func1,  boundary_u )
bc_nu = dde.NeumannBC(geomtime , func_n ,  boundary_ln)
bc_nl = dde.NeumannBC(geomtime , func_n , boundary_rn)
ic = dde.IC(geomtime, func, lambda _, on_initial: on_initial)

data = dde.data.TimePDE(
    geomtime,
    2,
    pde,
    [bc_l,bc_r,bc_nu,bc_nl, ic],
    num_domain=1000,
    num_boundary=100,
    num_initial=50,
    func=None,
    num_test=10000,
)

layer_size = [3] + [30] * 2 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)

model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)

if name == "main":
main()

==========================error is==============

/usr/local/lib/python3.6/dist-packages/deepxde/geometry/geometry.py in boundary_normal(self, x)
38 def boundary_normal(self, x):
39 raise NotImplementedError(
---> 40 "{}.boundary_normal to be implemented".format(self.idstr)
41 )
42

NotImplementedError: Polygon.boundary_normal to be implemented

@lululxvi
Copy link
Owner

Instead of dde.geometry.Polygon, use dde.geometry.Rectangle for rectangle

@sumantkrsoni
Copy link
Author

after replacing Polygon to Rectangle.
I have given the value num_test = 1000 on compiling there is dimensionality error.

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 289 and the array at index 1 has size 282

how to get rid of it?
Also, am I doing the right neural network set up for input?
I have given [3] for the input variable for (x,y,t). is it ok?

Also, if you have more example in 2d and 3d except than github example, then, please
help me. So, that I can explore more feature on DEEPXDE.
Thanks

@lululxvi
Copy link
Owner

  • There is only one unknown, and thus
data = dde.data.TimePDE(geomtime, 1, ...)
  • Inputs are (x, y, t).
  • I will provide more examples later.

@sumantkrsoni
Copy link
Author

Hii Lu,
First of all , I would like to thank you and this small information about inputs are helping me to dive more into deepxde. I have read all the supporting documents of deepxde that is mentioned at the deepxde page but still a complete and detailed documents will be more helpful to go through it (just like FREEFEM++).

Also, I have recompile it and the same error is showing some inequal dimensional point. error and complete code is given below.

Kindly help me !!!

==================code====================

%tensorflow_version 1.x

from future import absolute_import
from future import division
from future import print_function

import numpy as np
import tensorflow as tf

import deepxde as dde

def main():
def pde(x, y):
phio = 0.1003
rhos = 2910.2
cvs = 1000
rhof = 1000
cvf = 4200
kts = 2.49
ktf = 0.6

    rhocv = (1-phio)*rhos*cvs + rhos* rhof*cvf
    kt = (1-phio)*kts + phio*ktf
    dy_x = tf.gradients(y, x)[0]
    dy_x, dy_y, dy_t = dy_x[:, 0:1], dy_x[:, 1:2], dy_x[:,2:3]
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
    dy_yy = tf.gradients(dy_y, x)[0][:, 1:2]
    dy_t = tf.gradients(dy_x,x)[0][:,2:3]
 
    return (    -ktf* (dy_xx + dy_yy)+ rhocv * dy_t   ) 
       
def func(x):
    return 473.15*np.ones((len(x),1),dtype = np.float32)
 
def func1(x):
    return 473.15* np.ones((len(x),1),dtype = np.float64) - 10 * x[:,2:]
    #return np.sin(np.pi * x[:, 0:1]) * np.exp(-x[:, 1:])
def func_n(x):
    return np.zeros((len(x),1), dtype= np.float64)
  

geom = dde.geometry.Rectangle([0,0],[20,20])

timedomain = dde.geometry.TimeDomain(0, 5)

geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary_l(x, on_boundary):
   
    return on_boundary and np.isclose(x[1], 0 ) 

def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[1],20)
def boundary_ln(x, on_boundary):
    return on_boundary and np.isclose(x[0], 0)

def boundary_rn(x, on_boundary):
    return on_boundary and np.isclose(x[0], 20)  

bc_l = dde.DirichletBC(geomtime, func, boundary_l)
bc_r = dde.DirichletBC(geomtime, func1,  boundary_u )
bc_nu = dde.NeumannBC(geomtime , func_n ,  boundary_ln)
bc_nl = dde.NeumannBC(geomtime , func_n , boundary_rn)
ic = dde.IC(geomtime, func, lambda _, on_initial: on_initial)

data = dde.data.TimePDE(
    geomtime,
    1,
    pde,
    [bc_l,bc_r,bc_nu,bc_nl, ic],
    num_domain=1000,
    num_boundary=100,
    num_initial=100,
    func=None,
    num_test=1000,
)

layer_size = [3] + [30] * 2 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)

model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)

if name == "main":
main()

==================================error============

ValueError Traceback (most recent call last)
in ()
95
96 if name == "main":
---> 97 main()
98
99

7 frames
<array_function internals> in hstack(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in hstack(tup)
343 return _nx.concatenate(arrs, 0)
344 else:
--> 345 return _nx.concatenate(arrs, 1)
346
347

<array_function internals> in concatenate(*args, **kwargs)

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 289 and the array at index 1 has size 282

=======================================================

@lululxvi
Copy link
Owner

lululxvi commented Apr 1, 2020

  • dy_t = tf.gradients(dy_x,x)[0][:,2:3] should be dy_xt = tf.gradients(dy_x,x)[0][:,2:3]?
  • model.compile("adam", lr=0.001) since there is no reference solution
  • Unfortunately it is a small bug ... I will fix this bug and release a new version soon. You can remove num_test=1000, and then the training and test will be the same points.

@sumantkrsoni
Copy link
Author

Thanks, Lu, after removing num_test = 1000 the above code has run. will it affects the result after removing this num_test value? what is the significant role of this value?

Few things I would like clarify.
as per I got from deepXDE.
the dependent variable and independent variables are assigned to different tensors(column-wise).
i.e, x[o] stands for x & x[1] stands for y variable.
can I extend it for z variable in 3D model by assigning x[2] as z?

Also, in data line of code ....commented after

data = dde.data.TimePDE(
geomtime,
1, #--------------------> stands for output
pde,
[bc_l,bc_r,bc_nu,bc_nl, ic],
num_domain=1000, #-----------> number of collocation point on domain (rectangle)
num_boundary=100, #----------> collocation point on boundary of domain( rectangle)
num_initial=100, #-----------> collocation point on time domain (t)
func=None,

)

I am don't know about "num_test" and "func" appears in data, what is the role of these terms.

also, if I am not wrong the predicted value of the governing equation i.e. variable value (y) has been saved in Test.txt file. that can be further plotted with various plotting tools.

kindly clarify it.

@lululxvi
Copy link
Owner

lululxvi commented Apr 1, 2020

  • num_test is used to specific how many points used for testing the error. For example, . If you do not set num_test, then the test points are the same as train points, otherwise, it will use another set of points for test. This will not have any effect on the result.
  • Yes, in 3D it is (x, y, z, t). In general the inputs are (x_1, x_2, x_3, ..., t).
  • func is used to specific the reference solution if known, so that the other error like L2 error can be computed.
  • Yes, the prediction is saved in test.dat in plain text mode. Then you can plot whatever you like.

@lululxvi
Copy link
Owner

lululxvi commented Apr 2, 2020

The issue of num_test is fixed in v0.5.1.

@sumantkrsoni
Copy link
Author

bc

Hello Lu,
my coding is running well.
Sorry, for asking many doubts but I really want to learn it.

I am trying to solve the governing equation for the porous medium given in the paper.

"A deep collocation method for heat transfer in porous media: Verification
from the finite element method, d
Juan Lina,b, Shuwei Zhou⁎,c,d, Hongwei Guo"

I have written my coding for transient heat transfer problem in porous media as: ( Already given in the previous comment).

There are a few things I am not getting:
a) the time discretization is only for initial (t = 0) and end time (t=5) has been done through the simulation (according to the output file 'test.dat' file )

b) the predicted output is not matching from the result value (y_exact= 458.0535817 )

c) why with the time increment the predicted value(y) is not changing.

kindly suggest something.

================================================

%tensorflow_version 1.x

from future import absolute_import
from future import division
from future import print_function

import numpy as np
import tensorflow as tf

import deepxde as dde

def main():
def pde(x, y):
phio = 0.1003
rhos = 2910.2
cvs = 1000
rhof = 1000
cvf = 4200
kts = 2.49
ktf = 0.6

    rhocv = (1-phio)*rhos*cvs + rhos* rhof*cvf
    kt = (1-phio)*kts + phio*ktf
    dy_x = tf.gradients(y, x)[0]
    dy_x, dy_y, dy_t = dy_x[:, 0:1], dy_x[:, 1:2], dy_x[:,2:3]
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
    dy_yy = tf.gradients(dy_y, x)[0][:, 1:2]
    dy_xt = tf.gradients(dy_x,x)[0][:,2:3]
 
    return (    -ktf* (dy_xx + dy_yy)+ rhocv * dy_xt   ) 

def functest(x):
    return 458.0535817 * np.ones((len(x),1), dtype = np.float32)          
def func(x):
    return 473.15*np.ones((len(x),1),dtype = np.float32)
 
def func1(x):
    return 473.15* np.ones((len(x),1),dtype = np.float64) - 10 * x[:,2:]
    #return np.sin(np.pi * x[:, 0:1]) * np.exp(-x[:, 1:])
def func_n(x):
    return np.zeros((len(x),1), dtype= np.float32)
  

geom = dde.geometry.Rectangle([0,0],[20,20])

timedomain = dde.geometry.TimeDomain(0,5)

geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary_l(x, on_boundary):
   
    return on_boundary and np.isclose(x[0], 0 ) 

def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[0],20)
def boundary_ln(x, on_boundary):
    return on_boundary and np.isclose(x[1], 0)

def boundary_rn(x, on_boundary):
    return on_boundary and np.isclose(x[1], 20)  

bc_l = dde.DirichletBC(geomtime, func, boundary_l)
bc_r = dde.DirichletBC(geomtime, func1,  boundary_u )
bc_nu = dde.NeumannBC(geomtime , func_n ,  boundary_ln)
bc_nl = dde.NeumannBC(geomtime , func_n , boundary_rn)
ic = dde.IC(geomtime, func, lambda _, on_initial: on_initial)

data = dde.data.TimePDE(
    geomtime,
    1,
    pde,
    [bc_l,bc_r,bc_nu,bc_nl, ic],
    num_domain=1000,
    num_boundary=200,
    num_initial=10,
    func=functest,
    num_test=150
    
)

layer_size = [3] + [30] * 2 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)

model.compile("adam", lr=0.001)
losshistory, train_state = model.train(epochs=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)

if name == "main":
main()

=========================================

@lululxvi
Copy link
Owner

lululxvi commented Apr 2, 2020

  • Are you sure that in the PDE it is dy_xt not dy_t?
  • Use more points for testing like num_test=1000
  • Which direction is x, and which is y?

BTW, the code you posted has wired format...

@sumantkrsoni
Copy link
Author

  • Yes, Lu, you are right there was dy_t .

  • I have changed the governing eq.

  • x[0] , x[1] and x[2] has been chosen for x, y and t axis respectively.

  • I would like to explain my coding according to the conditions.

Governing equation is :------------

governing equation

subject to the domain and boundary conditions are :-----------------

Boundary_and BC

where, kt and rho*cv value is:-------------------

kt

rhocv

Parameter value is:-------------------------

parameter value

since qf and qs value is 0 that's why I have excluded that term from coding part.
==================Code=================

`

%tensorflow_version 1.x

from future import absolute_import
from future import division
from future import print_function

import numpy as np
import tensorflow as tf

import deepxde as dde

def main():
def pde(x, y):
phio = 0.1003
rhos = 2910.2
cvs = 1000
rhof = 1000
cvf = 4200
kts = 2.49
ktf = 0.6

    rhocv = (1-phio)*rhos*cvs + rhos* rhof*cvf
    kt = (1-phio) * kts + phio * ktf


    dy_x = tf.gradients(y, x)[0]
    dy_x, dy_y, dy_t = dy_x[:, 0:1], dy_x[:, 1:2], dy_x[:,2:3]
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
    dy_yy = tf.gradients(dy_y, x)[0][:, 1:2]

   #dy_t = tf.gradients(y,t)[0]
 
    return (    -kt* (dy_xx + dy_yy)+ rhocv * dy_t   ) 

def functest(x):
    return 458.0535817 * np.ones((len(x),1), dtype = np.float32)          
def func(x):
    return 473.15*np.ones((len(x),1),dtype = np.float32)
 
def func1(x):
    return 473.15* np.ones((len(x),1),dtype = np.float32) - 10 * x[:,2:3]

def func_n(x):
    return np.zeros((len(x),1), dtype= np.float32)
  

geom = dde.geometry.Rectangle([-10,-10],[10,10])

timedomain = dde.geometry.TimeDomain(0,5)

geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary_l(x, on_boundary):
   
    return on_boundary and np.isclose(x[0], -10 ) 

def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[0],10)
def boundary_ln(x, on_boundary):
    return on_boundary and np.isclose(x[1], -10)

def boundary_rn(x, on_boundary):
    return on_boundary and np.isclose(x[1], 10)  

bc_l = dde.DirichletBC(geomtime, func, boundary_l)
bc_r = dde.DirichletBC(geomtime, func1,  boundary_u )
bc_nu = dde.NeumannBC(geomtime , func_n ,  boundary_ln)
bc_nl = dde.NeumannBC(geomtime , func_n , boundary_rn)
ic = dde.IC(geomtime, func, lambda _, on_initial: on_initial)

data = dde.data.TimePDE(
    geomtime,
    1,
    pde,
    [bc_l,bc_r,bc_nu,bc_nl, ic],
    num_domain=1000,
    num_boundary=200,
    num_initial=10,
    func=functest,
    num_test=1500
    
)

layer_size = [3] + [30] * 2 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)

model.compile("adam", lr=0.001)
losshistory, train_state = model.train(epochs=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)

if name == "main":
main()

`

  • I have used
    dy_x = tf.gradients(y, x)[0]
    dy_x = dy_x[:, 0:1] -------------------------------->for diff of variable T wrt x
    dy_y = dy_x[:, 1:2] --------------------------------> for diff of variable T wrt y
    dy_t = dy_x[:,2:3] ---------------------------------> for diff of variable T wrt t
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1] --------------------> for twice diff of variable T wrt x
    dy_yy = tf.gradients(dy_y, x)[0][:, 1:2] ----------------------> twice diff of variable T wrt y

  • Boundary condition used for the square domain whose left end at (-10,-10) and top right end at (10,10)

    def boundary_l(x, on_boundary):
    return on_boundary and np.isclose(x[0], -10 ) -----------------> x is close to x=-10 axis

    def boundary_u(x, on_boundary):
    return on_boundary and np.isclose(x[0],10) --------------------> x is close to x=10
    def boundary_ln(x, on_boundary):
    return on_boundary and np.isclose(x[1], -10) ---------------------> y is close to y =-10

    def boundary_rn(x, on_boundary):
    return on_boundary and np.isclose(x[1], 10) --------------------> y is close to y =10

-the Actual value obtained from FEM is 458.0535817

but after running my code I am getting the value near 9~10 only.

Kindly help me,
Waiting for your suggestion.

@lululxvi
Copy link
Owner

lululxvi commented Apr 5, 2020

The scale of the solution is 100, which is hard to train the network. Try one of the following

  • Re-scale your problem such that the solution is of scale 1;
  • Scale the network output by 100
net = dde.maps.FNN(...)
net.outputs_modify(lambda x, y: y * 100)

Your domain is large, and then try more training points, e.g.,

dx = 0.5
dt = 0.5
N1 = 20 // dx
N2 = 5 / dt
data = dde.data.TimePDE(..., num_domain=N1**2 * N2, num_boundary=N1*N2 * 4, num_initial=N1**2
)

@sumantkrsoni
Copy link
Author

  • Thanks, Lu, finally I could solve a simple problem using DEEPXDE.
    now, the predicted y value matching with y value output from FreeFem++

  • Still, I am wondering about the implementation of extra options according to the problem
    I mean, How can we familiar with extra options provided in your module.

like , net.outputs_modify(.....)

I have been using only the terms and methods used during tutorial examples.

  • so, I would request you to kindly publish documentation, so that each term can be used accordingly.

I would ask further if I'll get any confusion in DeepXde. :)

@lululxvi
Copy link
Owner

lululxvi commented Apr 5, 2020

Document is on the plan, but it will take some time. Currently the best way to understand a method is reading the API https://deepxde.readthedocs.io/en/latest/modules/modules.html

@sumantkrsoni
Copy link
Author

  • How did you get the scale of the solution?

  • how did you get that the scale of the solution is 100?

@lululxvi
Copy link
Owner

lululxvi commented Apr 6, 2020

It is a diffusion equation. You can know it from physics.

@sumantkrsoni
Copy link
Author

  • please suggest me about accessing the output value at a particular point on the domain.
    like the value of y at point (0,0).

  • Also, can we perform an iteration until the desired loss value?

@lululxvi
Copy link
Owner

lululxvi commented Apr 12, 2020

@sumantkrsoni
Copy link
Author

sumantkrsoni commented Apr 12, 2020 via email

@sumantkrsoni
Copy link
Author

  • Why such error occurring after running the well-set code that has been run already.

==================================================
TypeError: init() got multiple values for argument 'num_domain'

==================================================

@lululxvi
Copy link
Owner

Since the version 0.6.0, the API of PDE and TimePDE changed a little bit. Check the current examples if you are using version 0.6.0.

@sumantkrsoni
Copy link
Author

Yes, I got it, Thanks

@lululxvi lululxvi closed this as completed May 6, 2020
@lacrymose
Copy link

The scale of the solution is 100, which is hard to train the network. Try one of the following

  • Re-scale your problem such that the solution is of scale 1;
  • Scale the network output by 100
net = dde.maps.FNN(...)
net.outputs_modify(lambda x, y: y * 100)

Your domain is large, and then try more training points, e.g.,

dx = 0.5
dt = 0.5
N1 = 20 // dx
N2 = 5 / dt
data = dde.data.TimePDE(..., num_domain=N1**2 * N2, num_boundary=N1*N2 * 4, num_initial=N1**2
)

I cannot find net.outputs_modify(...). Could you inform where this function is, please?

@sumantkrsoni
Copy link
Author

@lacrymose
Try to insert the code as:

Note: According to the scale of the model you may change the numeric value (100).

net = dde.maps.FNN(layer_size, activation, initializer)
net.outputs_modify(lambda x, y: y * 100)

model = dde.Model(data, net)

model.compile("adam", lr=0.001)

Hope it may help you.

@lacrymose
Copy link

Thanks for you reply, but I still cannot find the function outputs_modify. I ran the code involving net.outputs_modify(lambda x, y: y * 100). It turns out that there is no outputs_modify in DeepXDE. Could you help me find this function?

@lacrymose
Copy link

BTW,I am using DeepXDE-0.8.3. I searched the upzipped folder in and out, but sadly no function named outputs_modify popped out.

@sumantkrsoni
Copy link
Author

@lacrymose

DeepXDE-0.8.3 has modified its module slightly.
Different types of maps functionality can be found on the link
Maps Module

your answer to the question is on the link below:
output modified link

Hope, it may help you.

@lacrymose
Copy link

Thanks for you replay!! It works!!!
One more questions. My network has 3 outputs. How to scale the 3 outputs with different factors? For example, let y be the outputs and scale y[:,0:1] with 100, y[:,1:2] with 200, y[:,2:3] with 300.

@lacrymose
Copy link

Is net.apply_output_transform(lambda x, y: y * 100) correct, to call the function apply_output_transform?

@sumantkrsoni
Copy link
Author

@lacrymose
I am not using DeepXDE Version 0.8.3,
Also, I think your code will work accordingly.

further, @lululxvi may clarify it correctly.

If you need anything further then I can help you.

@lacrymose
Copy link

lacrymose commented Jul 23, 2020

@sanjusoni Many thanks!!!
@lululxvi During the training, how and where is the function apply_output_transform called? My network has 3 outputs. I tried to scale the outputs with the code:
net.apply_output_transform(lambda x, y: y * np.array([100,100,1]))
I am not sure this correctly works as I want.

@lacrymose
Copy link

lacrymose commented Jul 23, 2020

@lululxvi
Here below is a system of PDEs I want to solve:
dne_t - ke0dE_xne + vedne_x - DL0dne_xx - Stf.cast(tf.abs(E),dtype=tf.float32)tf.exp(K/tf.abs(E))ne=0
dnpi_t + kpi0
dE_x
npi + vpi
dnpi_x=0
dV_xx + (npi - ne) = 0
whre ne, npi and V are underdetermined unkowns and E= -dV_x, dE_x = -dV_xx. The initial conditions for ne and npi are:
2e+2*np.exp(-x[:, 0:1]^2/0.025^2)
and the boundary conditions for ne, npi are zero NeumannBC in the interval [0, 1], while that for V are
V(0) = -1, V(1) = 0.
The network I used is
net = dde.maps.FNN([2] + [100] * 6 + [3], "tanh", "Glorot normal")
Sadly, even with the scaling strategy
net.apply_output_transform(lambda x, y: y * np.array([100,100,1])),
I cannot get a fairly good solution. Could you give me some guidances, please?

@lululxvi
Copy link
Owner

lululxvi commented Jul 23, 2020

@lacrymose net.apply_output_transform(lambda x, y: y * np.array([100,100,1])) is correct.

Is your train loss small enough? If not, there are many possible reason. One possible thing is that one loss is dominant. Make sure the initial loss are balanced, i.e., different loss terms have similar magnitude. This can be done by setting different weights for different losses. Search loss_weights in issues for "Q: I failed to train the network or get the right solution, e.g., the training loss is large." You can also see an example here https://github.com/alirezayazdani1/SBINNs/blob/master/glucose_insulin.py

@lacrymose
Copy link

@lululxvi Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants