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.

use modulo for periodic step function

Please login with a confirmed email address before reporting spam

Hi!

I want to create a periodic step function to control the input concentration of a contaminant in an aquifer. I want the concentration to be 1 for 3 months and 0 for the rest 9 months.

I have created a rect function with upper limit=0, lower limit=3*24*30*3600 (months in sec), and a rise time=0.5*24*30*3600 (1/2 month for smoothing).

Then I use as a dirichlet boundary condition that C=1 * rect1(mod(t,12*24*30*3600)).

This should work, no? Is there a way to plot the input function before runing the model? (the model is very big with many meshes and it takes a long time to solve).

When I try to run it I get an error at time=1 year (12*24*30*3600). It says that solver can not converge to a solution. Any idea why I get this? I thought that it could be the sharp step increase.. however it worked ok at t=3months where there was a step decrease... I have also used a 1/2 month smoothing which should be ok.. I have set the solver to take "free" time steps while solving it, so I was hoping that it will take smaller time steps around the concentration changes.

thank you so much!

4 Replies Last Post Sep 11, 2012, 3:57 a.m. EDT
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 Sep 6, 2012, 11:48 a.m. EDT
Hi

in some of the functions of COMSOL you can add a tick to get it repeat (see bottom of function GUI)

Then you must use a stepping scheme so that COMSOL understands that it must shorten the steps around your sharp transitions, as in "automatic" mode COMSOL assumes an exponential decay behaviour, by default (solver time stepping): intermediate or Strict and manually defined steps (at least 3 per steep slope region

--
Good luck
Ivar
Hi in some of the functions of COMSOL you can add a tick to get it repeat (see bottom of function GUI) Then you must use a stepping scheme so that COMSOL understands that it must shorten the steps around your sharp transitions, as in "automatic" mode COMSOL assumes an exponential decay behaviour, by default (solver time stepping): intermediate or Strict and manually defined steps (at least 3 per steep slope region -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 7, 2012, 8:39 a.m. EDT
Hi Ivar,

Thank you for your reply.After your email I changed my model:
1) I defined a rectangular function, with lower limit=0 and upper limit=3 months, and a transition zone=0.5 months.
2) then I defined an analytic function, with expression= rect1(t), argument=t, and ticked the period box with lower limit=0 and upper limit=12 months. Then in the plot parameters box I ploted t, with lower limit=0 and upper limit=100 years.

The function looks good.

When I run it I get an error "solver may have reached a singularity at t=1 year. Last time step is not converged".
Probably its because the solver does not take many steps in the slope region, as you also suggested.

I have used "steps taken by the solver=free" because I thought that the solver will know when there is a slope and would take more steps... Does the solver assume an exponential decay behaviour in all the steps options (strict, free and intermediate)?.
What other option do I have to define smaller steps in the slope regions? do I have to define them manually in the "time dependent solver-user defined-time" window? so in the time window write: range(0month, 1month, 100 years). In such a way the solver will take steps of 1 months. is there any other way?

thank you so much for your help!
Angelina
Hi Ivar, Thank you for your reply.After your email I changed my model: 1) I defined a rectangular function, with lower limit=0 and upper limit=3 months, and a transition zone=0.5 months. 2) then I defined an analytic function, with expression= rect1(t), argument=t, and ticked the period box with lower limit=0 and upper limit=12 months. Then in the plot parameters box I ploted t, with lower limit=0 and upper limit=100 years. The function looks good. When I run it I get an error "solver may have reached a singularity at t=1 year. Last time step is not converged". Probably its because the solver does not take many steps in the slope region, as you also suggested. I have used "steps taken by the solver=free" because I thought that the solver will know when there is a slope and would take more steps... Does the solver assume an exponential decay behaviour in all the steps options (strict, free and intermediate)?. What other option do I have to define smaller steps in the slope regions? do I have to define them manually in the "time dependent solver-user defined-time" window? so in the time window write: range(0month, 1month, 100 years). In such a way the solver will take steps of 1 months. is there any other way? thank you so much for your help! Angelina

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 Sep 7, 2012, 10:25 a.m. EDT
Hi

My experience is that "free" or "automatic" stepping is based primarly on a diffusion type studies so COMSOL espect some exponentail decays, when you have repeating BC signals you must choose "strict" or "intermediate" stepping, and in the time solver node (time ranges) you must combine several calls to range() such as

{range(1,1,9) range(9.1,0.1,11) range (12,1,19)}

for a signal with a slope change around 10, and rather flat response from 1 to 9 and 11 to 19)
Now use at least 3 points over the slope, 5 or more are better, but it takes time ...

Today there is no "easy" way to tell COMSOl to create such a sequence, you must use your engineering sens, but at least that means we are still in control ;)

Hope you catch my explanations

--
Good luck
Ivar
Hi My experience is that "free" or "automatic" stepping is based primarly on a diffusion type studies so COMSOL espect some exponentail decays, when you have repeating BC signals you must choose "strict" or "intermediate" stepping, and in the time solver node (time ranges) you must combine several calls to range() such as {range(1,1,9) range(9.1,0.1,11) range (12,1,19)} for a signal with a slope change around 10, and rather flat response from 1 to 9 and 11 to 19) Now use at least 3 points over the slope, 5 or more are better, but it takes time ... Today there is no "easy" way to tell COMSOl to create such a sequence, you must use your engineering sens, but at least that means we are still in control ;) Hope you catch my explanations -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 11, 2012, 3:57 a.m. EDT
Hi Ivar,

Thank you!! it works now! thank you!
Hi Ivar, Thank you!! it works now! thank you!

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.