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

BC Over a Right Angle Triangle #107

Closed
sumantkrsoni opened this issue Aug 19, 2020 · 12 comments
Closed

BC Over a Right Angle Triangle #107

sumantkrsoni opened this issue Aug 19, 2020 · 12 comments

Comments

@sumantkrsoni
Copy link

Dear @lululxvi

I have defined a right angle triangle using the geometry code as:

geom = dde.geometry.Triangle([0,0], [1,0], [0,1])

Now, I am trying to implement a BC over the inclined edge of the triangle. For that I have written as:

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

    def func_1(x):
            return np.ones((len(x), 1) )


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

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

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

My doubt is for boundary_incline
is it ok according to the problem definition.

Kindly, suggest.

@lululxvi
Copy link
Owner

Looks good.

@sumantkrsoni
Copy link
Author

Thanks @lululxvi
unfortunately, it shows some error for not implementation on geometry type.

  File "D:/deepxde-master/deepxde-master\deepxde\geometry\geometry.py", line 23, in on_boundary
    raise NotImplementedError("{}.on_boundary to be implemented".format(self.idstr))
NotImplementedError: Triangle.on_boundary to be implemented

It seems on_boundary for the module has not been implemented.

I have attached the code here. Kindly Suggest me.

triangle.zip

@lululxvi
Copy link
Owner

I have implemented them. You can download the updated code.

@sumantkrsoni
Copy link
Author

Thanks @lululxvi
It works, now I am trying to validate the result with it.

@sumantkrsoni
Copy link
Author

Dear @lululxvi
I have implemented the code for natural convection over the triangle but the DeepXDE result is not showing according to the computed result from other platforms( using the FEM method).

FYI: triangle geometry has been chosen with parameters:
Ra = 100, AspectRation(AR) = 0.5

for that, the result for streamline and isotherm contours should be like:
Ra100AR050

but the deep learning method shows the result below which is not the same from the above result:

streamlineDeepXDE

I am confused about it, that where I am going wrong.

the attachment includes code for it.

triangle.zip

It would be helpful for me if I could get a Suggestion regarding it.

Thanks.

@lululxvi
Copy link
Owner

You may check "Q: I failed to train the network or get the right solution, e.g., the training loss is large." at FAQ first.

@sumantkrsoni
Copy link
Author

Thanks @lululxvi
After increasing the no of epochs the result has improved up to some extent but still, some modifications needed. Fo that I have enforced the BC after taking the reference from FAQ.

for implementing the BC:
over right angle triangle:

S = 0 on all sides of the triangular domain.

T = 1 on y=0
T = 0 on inclined side. i.e y = 1-x

New parameters are as imposed as:

S_new = x * y * ( 1-x - y) * S

T_new = (1-x-y)* (1-y)* T

and its code is:

    net.apply_output_transform(  lambda x, y : tf.concat([
                                                        x[:,0:1]*x[:, 1:2]*(1-x[:, 0:1]-x[:, 1:2])*y[:,0:1],
                                                         (1 - x[:.0:1] - x[:,1:2])* (1-x[:,1:2]) * y[:, 1:2]
                                                         ], axis = 1 )  )

but, unfortunately I am getting an error:

Traceback (most recent call last):
  File "D:\DIAT_PhD\PhD_Content\Coding_Script\TrianglePorous\triangle.py", line 104, in <module>
    main()
  File "D:\DIAT_PhD\PhD_Content\Coding_Script\TrianglePorous\triangle.py", line 89, in main
    model.compile("adam", lr=0.002)
  File "D:/deepxde-master/deepxde-master\deepxde\utils.py", line 52, in wrapper
    result = f(*args, **kwargs)
  File "D:/deepxde-master/deepxde-master\deepxde\model.py", line 76, in compile
    self.net.build()
  File "D:/deepxde-master/deepxde-master\deepxde\utils.py", line 52, in wrapper
    result = f(*args, **kwargs)
  File "D:/deepxde-master/deepxde-master\deepxde\maps\fnn.py", line 70, in build
    self.y = self._output_transform(self.x, self.y)
  File "D:\DIAT_PhD\PhD_Content\Coding_Script\TrianglePorous\triangle.py", line 85, in <lambda>
    (1 - x[:.0:1] - x[:,1:2])* (1-x[:,1:2]) * y[:, 1:2] ], axis = 1 )  )
  File "C:\Users\SUMANT\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\ops\array_ops.py", line 841, in _slice_helper
    _check_index(s.stop)
  File "C:\Users\SUMANT\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\ops\array_ops.py", line 752, in _check_index
    raise TypeError(_SLICE_TYPE_ERROR + ", got {!r}".format(idx))
TypeError: Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf.int64 tensors are valid indices, got 0.0

Please suggest me.

@lululxvi
Copy link
Owner

Why the dot in x[:.0:1]?

@sumantkrsoni
Copy link
Author

Why the dot in x[:.0:1]?

sorry for typo error and Thanks @lululxvi
Now It's working.

@sumantkrsoni
Copy link
Author

sumantkrsoni commented Sep 19, 2020

Dear @lululxvi Sir,
The above problem, I have been trying to solve but I am getting a huge training loss without enforcing exact BC.

Under the following criteria:

  • Rayleigh No: 100

Ra = 100.0

  • PDE definition
        S, T = y[:,0:1], y[:, 1:2]
        dS_x = tf.gradients(S,x)[0]
        dT_x = tf.gradients(T,x)[0]

        dS_x, dS_y= dS_x[:,0:1], dS_x[:,1:2]
        dT_x, dT_y = dT_x[:,0:1], dT_x[:,1:2]

        dS_xx = tf.gradients(dS_x, x )[0][:,0:1]
        dS_yy = tf.gradients(dS_y, x )[0][:,1:2]

        dT_xx = tf.gradients(dT_x, x)[0][:, 0:1]
        dT_yy = tf.gradients(dT_y, x)[0][:, 1:2]


        return[ dS_xx + dS_yy + Ra * dT_x,
                dS_y*dT_x - dS_x*dT_y - dT_xx - dT_yy]
  • Data Definition

data = dde.data.PDE(geom, pde, [..........], num_domain = 8000, num_boundary = 5000, num_test = 10000)

  • Layer size and other parameters:

`
layer_size = [2] + [250]*3 + [2]
......................
model.compile("adam", lr=0.0001)
......................
losshistory, train_state = model.train(epochs = 10000, .............)

`

for cross-validating the training process I have compiled only for 10K iteration to see the training loss progress but no luck here, I have found.

training loss is:

training_loss

The similar scenario are occuring in #84 ,
If I could get any idea about dealing such issue, that would be helpful for me.

kindly comment something.

Thanks in advance

Attched File for code script is:
triangle_2a.zip

@sumantkrsoni
Copy link
Author

Dear @lululxvi Sir,

If I am not wrong, DeepXDE is based on the PINN approach.

Sir, do you have any example coded over the Penalty approach over the Feedforward neural network?

I have coded few problems over DeepXDE and want to see the comparison by the Penalty approach.

I have coded in DeepXDE for the simple first-order problem and now I am interested in solving it with a penalty approach.

I have coded it but not getting the exact solution.

  • I am stuck with the training of the data over the boundary of the domain.

If possible, suggest me, please.

first_order.zip

@lululxvi
Copy link
Owner

lululxvi commented Feb 6, 2021

What do you mean exactly by "Penalty approach"?

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

2 participants