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.

How to use the Mod() Function?

Please login with a confirmed email address before reporting spam

I have searched all over and all I can find in the documentation is simply - Mod (x,y)

Awesome, that doesn't tell me how to use it or what it is for (i'm seeing a pattern here). In addition It's been suggested on this forum many times but I can't find out how to PROPERLY use the function. Am I missing some document somewhere? I have the user and reference guides in PDF form, but it doesn't say how to use these functions.

I'm simply trying to repeat an interpolated function over and over again. I have tried all the following and other random permutations I can't recall:

Flow_Int(mod(t[1/s],1))
Flow_Int(mod(t,1))
Flow_Int(mod(t[1/s],0.5))
Flow_Int(mod(t,0.5))

Whenever it hit the point I defined such as 1 or 0.5 it tells me there is a "singularity" whatever that means... I have even tried simply sin(mod(t,1)) as my inlet and this still won't work.

*NOTE* Trying to use this on "laminar" inflow, won't work. However when I tried it in Velocity it does?!?!

1 Reply Last Post 2012年8月2日 GMT-4 15:18
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2012年8月2日 GMT-4 15:18
Hi

first, the mod(t,my_time) is a standard "mod" function repeating each time t >= N*my_time.

By default "t" has units [s] in COMSOL and operators, such as mod() requires unitless values, therefore a t[1/s] idsformally more correct as the resulting variable sent to the operator is a scalar without units.

But for you model, I beleive the issue is not the mod() operator, but the fact that such a "square" function is not "physical" at the transition points, COMSOL asks for functions that can be derived at least once (this is classical for PDE theory the assumption of continuous functions is inherent and often even forgotten in the math or physics courses ;)
I would suggest to use a step or rect function of COMSOL V4 (or a combination with a heavyside function in v3.5) to make your function smooth, then you need toplay with the time steps you propose, and the time steppng solver settings to strict or intermediate (BUT NOT the default "automatic"). You can make your function repetitive, either by combining it with an analytical function, or with the mod() operator

--
Good luck
Ivar
Hi first, the mod(t,my_time) is a standard "mod" function repeating each time t >= N*my_time. By default "t" has units [s] in COMSOL and operators, such as mod() requires unitless values, therefore a t[1/s] idsformally more correct as the resulting variable sent to the operator is a scalar without units. But for you model, I beleive the issue is not the mod() operator, but the fact that such a "square" function is not "physical" at the transition points, COMSOL asks for functions that can be derived at least once (this is classical for PDE theory the assumption of continuous functions is inherent and often even forgotten in the math or physics courses ;) I would suggest to use a step or rect function of COMSOL V4 (or a combination with a heavyside function in v3.5) to make your function smooth, then you need toplay with the time steps you propose, and the time steppng solver settings to strict or intermediate (BUT NOT the default "automatic"). You can make your function repetitive, either by combining it with an analytical function, or with the mod() operator -- Good luck Ivar

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.