Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Stepwise function in COMSOL

Please login with a confirmed email address before reporting spam

I am currently using COMSOL to solve the 2D Schrödinger Equation for an spherical infinite square well with a potential bottom that is deeper inside a core region sqrt(x^2 + y^2) < R1 < R, where R is the total radius of the spherical well.
To do so I use the generic expression for a 2D PDE in the eigenvalue form and identify u as the potential function (is this the best way to do it? I am quite new to COMSOL). My geometry is a circle, where I demand that the wavefunctions vanish at the boundary.
To incorporate the I therefore want to define a 2d piecewise function f(x,y) to which I equate u. For my problem I want f(x,y) = {a for sqrt(x^2 + y^2) < R1 , b for R1 < sqrt(x^2 + y^2) < R
But how can I implement this is in the setup for a piecewise function? I was able to construct a 1d piecewise function using the interval structure in the setup, but how do I implement this 2D boundary?

3 Replies Last Post 2016年4月7日 GMT-4 09:53

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2016年4月5日 GMT-4 20:00
a + (b - a) * (x^2 + y^2 > R1^2) - b * (x^2 + y^2 > R^2)

This works because the binary comparison operator ">" uses 1 for true, 0 for false.

Only issue with this is the step function doesn't interpolate well and you may want to use a continuous function (like the error function) which can be used to yield a smooth transition between 0 and 1.

a + (b - a) * (x^2 + y^2 > R1^2) - b * (x^2 + y^2 > R^2) This works because the binary comparison operator ">" uses 1 for true, 0 for false. Only issue with this is the step function doesn't interpolate well and you may want to use a continuous function (like the error function) which can be used to yield a smooth transition between 0 and 1.

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2016年4月6日 GMT-4 09:42
If I understand what you want to do and what you did in 1D correctly, you can use the same approach as in 1D, with the argument of the (interpolation or step of what-have-you) function being sqrt(x^2+y^2) instead of x, see attached file for an example: in that file the heat source in the left hand side square uses the approach I think you've used before extended to 2D.

Note that if you do not want continuity of the function, you should use a different approach and draw a disc of radius R1 in the geometry and define the function to take separate values in that disc versus the rest of the geometry. You can use a couple of Variable nodes to set this up elegantly, see the attached file again - right hand side).
Best,
Jeff
If I understand what you want to do and what you did in 1D correctly, you can use the same approach as in 1D, with the argument of the (interpolation or step of what-have-you) function being sqrt(x^2+y^2) instead of x, see attached file for an example: in that file the heat source in the left hand side square uses the approach I think you've used before extended to 2D. Note that if you do not want continuity of the function, you should use a different approach and draw a disc of radius R1 in the geometry and define the function to take separate values in that disc versus the rest of the geometry. You can use a couple of Variable nodes to set this up elegantly, see the attached file again - right hand side). Best, Jeff


Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2016年4月7日 GMT-4 09:53
I am the op, but my account was apparently suspended because I had used a file from the internet that came from a pirated version. I am therefore using my university's account now and have run the file through my comsol version, so I hope it's good now (though I have no idea how to recover my original account?).
Either way, I tried to understand how you defined the stepwise potential on different segments, but did not quite understand it? Can you elaborate? I have switched to a geometry with two hexagons of different sizes on top of each other and poly-like shape on two of the facets, which makes the approach of defining the function on the different segments necessary. Could you show me in my script how to define the function? Also I want the function to be an object that can enter in the generic PDE expression in COMSOL. Is it possible using this approach or should I add some kind of smoothing?
I am the op, but my account was apparently suspended because I had used a file from the internet that came from a pirated version. I am therefore using my university's account now and have run the file through my comsol version, so I hope it's good now (though I have no idea how to recover my original account?). Either way, I tried to understand how you defined the stepwise potential on different segments, but did not quite understand it? Can you elaborate? I have switched to a geometry with two hexagons of different sizes on top of each other and poly-like shape on two of the facets, which makes the approach of defining the function on the different segments necessary. Could you show me in my script how to define the function? Also I want the function to be an object that can enter in the generic PDE expression in COMSOL. Is it possible using this approach or should I add some kind of smoothing?

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.