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.

Conversion from Cartesian to polar coordinate to integrate polar angle in 2D

Please login with a confirmed email address before reporting spam

Hi,

I have a function that depends on Cartesian coordinates x and y obained by solving a partial differential equation. The domain is a unit disk. I would like to convert the data of into polar coordinate form so that I can do the integration .

How can I do that? Thanks in advance.

Will


5 Replies Last Post Aug 5, 2021, 4:49 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Aug 3, 2021, 12:20 a.m. EDT
Updated: 3 years ago Aug 3, 2021, 12:26 a.m. EDT

I have tried General Extrusion in nonlocal couping to transform the coordinate from Cartesian to polar. But the domain after transformation remains as unit disk instead of rectangle .

Below is the original function dependent on Cartesian coordinate.

function dependent on Cartesian coordinate

This is the general extrusion configure general extrusion configure

And the obtained function after transformation is transformed function using general extrusion

How can I obtain a transformed function with a new domain instead of the original unit disk by using General extrusion?

PS: upload of image seems not working. So I just used the image link. Excuse me for the inconvenience.

I have tried General Extrusion in nonlocal couping to transform the coordinate from Cartesian to polar. But the domain after transformation remains as unit disk instead of rectangle [0,1]\times [0, 2\pi]. Below is the original function dependent on Cartesian coordinate. [function dependent on Cartesian coordinate](https://pasteboard.co/Ke7yCkF.png) This is the general extrusion configure [general extrusion configure](https://pasteboard.co/Ke7xqVh.png) And the obtained function after transformation is [transformed function using general extrusion](https://pasteboard.co/Ke7zvzZ.png) How can I obtain a transformed function with a new domain [0,1]\times [0, 2\pi] instead of the original unit disk by using General extrusion? PS: upload of image seems not working. So I just used the image link. Excuse me for the inconvenience.

Robert Koslover Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Aug 3, 2021, 11:50 a.m. EDT
Updated: 3 years ago Aug 3, 2021, 11:51 a.m. EDT

Here's a suggestion: You may not have to convert to polar coordinates to do your integral. If you create a circle of radius r in your model, and you have the function u(x,y), then you can do a line integral of u(x,y) along the curve specified by the circle. Basically, the process would go like this: Create and execute your model (including drawing a circle in the model, along which you intend to integrate later). Then, after the solution is available, go to Results --> Derived Values --> Line Integration, and select the curve(s) (aka, circle) along which you want to evaluate u, and then make sure you add u to the expression to be integrated. Then click "Evaluate." Note that there are also some other ways (such as probes) available to you, which allow you to specify various line, surface, and volume integrals.

-------------------
Scientific Applications & Research Associates (SARA) Inc.
www.comsol.com/partners-consultants/certified-consultants/sara
Here's a suggestion: You may not have to convert to polar coordinates to do your integral. If you create a circle of radius *r* in your model, and you have the function *u(x,y)*, then you can do a *line integral* of *u(x,y)* along the curve specified by the circle. Basically, the process would go like this: Create and execute your model (including drawing a circle in the model, along which you intend to integrate later). Then, after the solution is available, go to Results --> Derived Values --> Line Integration, and select the curve(s) (aka, circle) along which you want to evaluate *u*, and then make sure you add *u* to the expression to be integrated. Then click "Evaluate." Note that there are also some other ways (such as probes) available to you, which allow you to specify various line, surface, and volume integrals.

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Aug 3, 2021, 9:42 p.m. EDT

Thank you for the reponse.

According to your suggestion, I can now obtain the line integral of a specific circle, which is a single point data. That is a nice progress. But a function depending on radius r is desired instead of single value, say w(r=0.5). So how to obtain the whole data of the radius dependent function ?

Thank you for the reponse. According to your suggestion, I can now obtain the line integral of a specific circle, which is a single point data. That is a nice progress. But a function w(r) = \int_0^{2\pi} u(r, \phi) \mathrm{d}\, \phi depending on radius r is desired instead of single value, say w(r=0.5). So how to obtain the whole data of the radius dependent function w(r)?

Robert Koslover Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 3 years ago Aug 3, 2021, 11:20 p.m. EDT
Updated: 3 years ago Aug 3, 2021, 11:22 p.m. EDT

Ok, I'll illustrate one way (but there are others) that leverages my earlier comment. See the attached file. I've defined two quantities under Component 1 --> Definitions. One is called myX and the other is myY. Then, under Results --> Datasets, I've defined a parameterized curve that is a simple circle, which I have called "My Parameterized Curve (Circle)" which you will find listed there. If you want, you can click on that and click "Plot" under the Settings tab, to see the circle. Notice how the circle has a radius of myR, which you can pass to it (I arbitrarily set myR=0.25 for this example). (You don't actually have to plot it, to use it for doing integrals.) Now, if you look under Results --> Derived Values, you will see something I called "My Line Integral." Select that. Put whatever you want to be integrated into the Expressions field, under Settings. Also under Settings, you can click "Evaluate" and then (in Table 1) you will see appear the value of the integral of whatever expression you entered, which has been evaluated around the parameterized curve (i.e., the circle). I suspect that with a little thought, you can generalize this approach into your own user-defined functions and line integrals. I hope that helps!

-------------------
Scientific Applications & Research Associates (SARA) Inc.
www.comsol.com/partners-consultants/certified-consultants/sara
Ok, I'll illustrate one way (but there are others) that leverages my earlier comment. See the attached file. I've defined two quantities under Component 1 --> Definitions. One is called *myX* and the other is *myY*. Then, under Results --> Datasets, I've defined a parameterized curve that is a simple circle, which I have called "My Parameterized Curve (Circle)" which you will find listed there. If you want, you can click on that and click "Plot" under the Settings tab, to see the circle. Notice how the circle has a radius of *myR*, which you can pass to it (I arbitrarily set *myR*=0.25 for this example). (You don't actually have to plot it, to use it for doing integrals.) Now, if you look under Results --> Derived Values, you will see something I called "My Line Integral." Select that. Put whatever you want to be integrated into the Expressions field, under Settings. Also under Settings, you can click "Evaluate" and then (in Table 1) you will see appear the value of the integral of whatever expression you entered, which has been evaluated around the parameterized curve (i.e., the circle). I suspect that with a little thought, you can generalize this approach into your own user-defined functions and line integrals. I hope that helps!


Please login with a confirmed email address before reporting spam

Posted: 3 years ago Aug 5, 2021, 4:49 a.m. EDT
Updated: 3 years ago Aug 5, 2021, 4:54 a.m. EDT

Thank you for the detailed instruction, which looks promising.

Anyway, now I can solve my original problem by using "General Projection" in "Nonlocal Coupling" (COMSOL 5.6). In case someone runs into the same kind problem. I briefly describe what I have done. I found the key to solve the problem using general projection is to understand the meaning of "source map" and "destination map" in the general projection setting.

An intermediate coordinate system is used to transform the coordinates. The source map defines the map from the source coordinate system (which is Cartesian in the above problem) to the intermediate coordiante system. And destination map from intermediate coordiante system to destination coordinate system (polar).

In the attached file, in order to integrate the polar angle, the source map is

x_intermediate = sqrt(x^2+y^2)

y_intermediate = atan2(y, x)

The destination map is

x_destination = x_intermediate

So here y_intermediate being the polar angle is integrated out with only the radius variable x_intermediate left.

A test function has been used to test the validity of the above setting.

Thank you for the detailed instruction, which looks promising. Anyway, now I can solve my original problem by using "General Projection" in "Nonlocal Coupling" (COMSOL 5.6). In case someone runs into the same kind problem. I briefly describe what I have done. I found the key to solve the problem using general projection is to understand the meaning of "source map" and "destination map" in the general projection setting. An intermediate coordinate system is used to transform the coordinates. The source map defines the map from the source coordinate system (which is Cartesian in the above problem) to the intermediate coordiante system. And destination map from intermediate coordiante system to destination coordinate system (polar). In the attached file, in order to integrate the polar angle, the source map is x_intermediate = sqrt(x^2+y^2) y_intermediate = atan2(y, x) The destination map is x_destination = x_intermediate So here y_intermediate being the polar angle is integrated out with only the radius variable x_intermediate left. A test function f = x^2 = r^2\cos^2\phi has been used to test the validity of the above setting.

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.