Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

function for distribution of discrete values (0 and 1)

Please login with a confirmed email address before reporting spam

hi all,

I am new to COMSOL. I was wondering if somebody can help me with this. I want to make a function that gives me 20% (by area) distribution of value 1 and remaining 80% area the value of zero. I could not do it using random function of COMSOL. Appreciate your help already.

best regards,


5 Replies Last Post Feb 19, 2018, 2:38 a.m. EST

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Feb 13, 2018, 8:46 a.m. EST

though i can do it in matlab using randsrc function. i can generate a matrix of any order comprising of zero and one according to a probability function. but cannot do it in comsol.

though i can do it in matlab using randsrc function. i can generate a matrix of any order comprising of zero and one according to a probability function. but cannot do it in comsol.

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Feb 15, 2018, 4:31 a.m. EST

i am still stuck on this. if somebody could help it will be really helpful.

i am still stuck on this. if somebody could help it will be really helpful.

Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Feb 15, 2018, 7:43 a.m. EST

Hi Zahid,

You do not really tell why you cannot use the built-in random function. If you just want a randomized variable over the domain to take the value 0 or 1 with an expected value of 0.2, you can write an expression like

Here rn1 is the built-in random function, but shifted so that it is uniform over the interval [0,1].

Regards,

Henrik

-------------------
Henrik Sönnerlind
COMSOL
Hi Zahid, You do not really tell why you cannot use the built-in random function. If you just want a randomized variable over the domain to take the value 0 or 1 with an expected value of 0.2, you can write an expression like rn1(X,Y)

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Feb 16, 2018, 3:32 p.m. EST

Dear Henrik.

Thanks alot for your response. I actually am working on phase field modeling for phase transformation. I want my initial domain to consist of Phase 'A' (20% of the material by area) with a value of 0 and another Phase 'B' (80% of the material by area). For this problem, I need to make a function that gives me these two discreet values randomly distributed. I hope you understood it now more clearly. I dont want to make two separate domains for both phases and assign two different functions for them.

Dear Henrik. Thanks alot for your response. I actually am working on phase field modeling for phase transformation. I want my initial domain to consist of Phase 'A' (20% of the material by area) with a value of 0 and another Phase 'B' (80% of the material by area). For this problem, I need to make a function that gives me these two discreet values randomly distributed. I hope you understood it now more clearly. I dont want to make two separate domains for both phases and assign two different functions for them.

Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago Feb 19, 2018, 2:38 a.m. EST

Hi Zahid,

The expression I wrote in my previous post does exactly that: Generates two discrete values randomly distrubuted. They will however also be randomly distributed within each element, and that may not be what you want.

If you for example want each element to have the value 1 or 0, then you have to feed the random function with the element number, rather that by the coordinates, as in my example.

If you want larger contiguous regions, then it is trickier.

Regards,

Henrik

-------------------
Henrik Sönnerlind
COMSOL
Hi Zahid, The expression I wrote in my previous post does exactly that: Generates two discrete values randomly distrubuted. They will however also be randomly distributed within each element, and that may not be what you want. If you for example want each element to have the value 1 or 0, then you have to feed the random function with the element number, rather that by the coordinates, as in my example. If you want larger contiguous regions, then it is trickier. Regards, Henrik

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.