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.

Best practice for conditionaly switched boundary condition (simulations with multiple steps)

Please login with a confirmed email address before reporting spam

Hello!

I am trying to model the coupled heat and mass transfer of a refrigeration cycle. The model includes distinct steps with different boundary conditions. Switching times cannot be fixed but depend on physical quantities (e.g. pressure at a certain point). Now, I am wondering what is the best practice to implement these conditional switches in the boundary conditions. I tryed different approaches documented in the forum, knowledge base or conference paper that all have drawbacks. I feel like this topic has not been fully discussed, especially for version 4.2 (see www.comsol.com/community/forums/general/thread/6746/).

The simplest approach would be hard switching (BC1*(p<p1) + BC2*(p>=p1)). This leads to long solving times due to unsteadiness of the BC or (in my case) to infinity switching back and forth (negative feedback between BC and switch condition).
This approach can be further refined with a) smoothed step functions (www.comsol.com/support/knowledgebase/905/) or b) a complicated procedure that uses a sub domain to get "one-way-only" step by integrating a positive pulse of a switch variable defined by a differential equation (www.comsol.com/conference2011/usa/abstract/id/10337/lam_abstract.pdf).
Nevertheless, even with all these laborious refinements a well converging model needs manual adjustment (smoothening etc.) when ever parameters of the model are changed. This disqualifies the approach for parametric sweep, hence this is exactly what I want to use the model for. Furthermore, solving times are long, as the solver wants to calculate the moment of switching with all precision, though these moments are not interesting for me. (Simply spoken: the approach seems improvised, a bit von-hinten-durch-die-Brust-ins-Auge)

A second approach, that has sparsely been mentioned in some threats in this forum (first link above): a "save solution" in between the steps and a (automatic?) restart (of a second solver?) with the new BC and the solutions from the end of the step before as new initial values. I still have not found how to implement this in 4.2 (neither by searching here nor by trying on my own). This seems promising and more straight forward. However, I am not sure if post-processing becomes a issue (haven't yet been able to try;).

A third approach includes a matlab frame, calling the model with different BC for each step. The problem: no matlab available. (I remember some one writing that matlab is not necessary anymore with Comsol 4 ...)

Is there a way to implement approach 2 in 4.2, or are there even better solutions to this, I guess, not unusual problem?

Thank you!

6 Replies Last Post 2012年9月15日 GMT-4 05:21

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年11月29日 GMT-5 04:53
no one?
no one?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年11月29日 GMT-5 04:53
No one?
No one?

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 2011年11月30日 GMT-5 11:36
Hi Eric

I'm probably the one writing that I do (hardly) not use Matlab anymore in V4. For certain applications and for your case, it's still useful. THen perhaps you can use an api programming ? Not sure, havent tried.

Last resort, some manual teawing: you have two "Parametric Sweeps" approaches, the specific (outer) parametric seep and the solver "continuation sweep". Both uses a parameter as argument, that can drive different boolean operations, or proportional variables. But these two have a different behaviour on the "restat conditions". The solver continuation sweep does NOT loop around the geoemtry and the mesh (these are newer updated) but uses the last results as initial conditions for next solving step. While the external parametric sweep loop does go around the geoemtry and mesh (hence updates both if required) and then ALWAYS restarts with the original initial conditions.

Conclusions, when using the external loop to switch the BC's you know from which state you start, when using the internal one you can ramp up a variable to start from a known state and get to a desired value, that might have a sign controlled by the odd/even parameter from the external loop

It's perhaps a tortuous way, but I believe it should work, again all depends on your model (and it's wthout matlab) Apart from that, Matlab is a great programme, I have used it from about v1, it's just that I can survive with i.e. SciLab for the numerics, but I cannot survive without COMSOL ;)

--
Good luck.
Ivar
Hi Eric I'm probably the one writing that I do (hardly) not use Matlab anymore in V4. For certain applications and for your case, it's still useful. THen perhaps you can use an api programming ? Not sure, havent tried. Last resort, some manual teawing: you have two "Parametric Sweeps" approaches, the specific (outer) parametric seep and the solver "continuation sweep". Both uses a parameter as argument, that can drive different boolean operations, or proportional variables. But these two have a different behaviour on the "restat conditions". The solver continuation sweep does NOT loop around the geoemtry and the mesh (these are newer updated) but uses the last results as initial conditions for next solving step. While the external parametric sweep loop does go around the geoemtry and mesh (hence updates both if required) and then ALWAYS restarts with the original initial conditions. Conclusions, when using the external loop to switch the BC's you know from which state you start, when using the internal one you can ramp up a variable to start from a known state and get to a desired value, that might have a sign controlled by the odd/even parameter from the external loop It's perhaps a tortuous way, but I believe it should work, again all depends on your model (and it's wthout matlab) Apart from that, Matlab is a great programme, I have used it from about v1, it's just that I can survive with i.e. SciLab for the numerics, but I cannot survive without COMSOL ;) -- Good luck. Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年12月1日 GMT-5 08:52
Hello Ivar,

thanks for your response. However, I still cannot see how to implement conditional BC switching using solver internal Parametric Sweep.

Let's say I implement the different BC as a parameter to be changed by the Solver Parametric Sweep. This would lead to a continuous cycle as the next step would initialised with the final values of the preceding parameter value. But, how can I stop each solver sweep (and initialise the next one) when certain conditions are reached (in my example a pressure threshold at a certain position), while the time when this condition will be reached is unknown?

Kind regards

Eric
Hello Ivar, thanks for your response. However, I still cannot see how to implement conditional BC switching using solver internal Parametric Sweep. Let's say I implement the different BC as a parameter to be changed by the Solver Parametric Sweep. This would lead to a continuous cycle as the next step would initialised with the final values of the preceding parameter value. But, how can I stop each solver sweep (and initialise the next one) when certain conditions are reached (in my example a pressure threshold at a certain position), while the time when this condition will be reached is unknown? Kind regards Eric

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2012年9月13日 GMT-4 06:28
Hi Ivar,

I was wondering if it possible to integrate Scilab with COMSOL?

Thanks,
Ashwini


Hi Eric

I'm probably the one writing that I do (hardly) not use Matlab anymore in V4. For certain applications and for your case, it's still useful. THen perhaps you can use an api programming ? Not sure, havent tried.

Last resort, some manual teawing: you have two "Parametric Sweeps" approaches, the specific (outer) parametric seep and the solver "continuation sweep". Both uses a parameter as argument, that can drive different boolean operations, or proportional variables. But these two have a different behaviour on the "restat conditions". The solver continuation sweep does NOT loop around the geoemtry and the mesh (these are newer updated) but uses the last results as initial conditions for next solving step. While the external parametric sweep loop does go around the geoemtry and mesh (hence updates both if required) and then ALWAYS restarts with the original initial conditions.

Conclusions, when using the external loop to switch the BC's you know from which state you start, when using the internal one you can ramp up a variable to start from a known state and get to a desired value, that might have a sign controlled by the odd/even parameter from the external loop

It's perhaps a tortuous way, but I believe it should work, again all depends on your model (and it's wthout matlab) Apart from that, Matlab is a great programme, I have used it from about v1, it's just that I can survive with i.e. SciLab for the numerics, but I cannot survive without COMSOL ;)

--
Good luck.
Ivar


Hi Ivar, I was wondering if it possible to integrate Scilab with COMSOL? Thanks, Ashwini [QUOTE] Hi Eric I'm probably the one writing that I do (hardly) not use Matlab anymore in V4. For certain applications and for your case, it's still useful. THen perhaps you can use an api programming ? Not sure, havent tried. Last resort, some manual teawing: you have two "Parametric Sweeps" approaches, the specific (outer) parametric seep and the solver "continuation sweep". Both uses a parameter as argument, that can drive different boolean operations, or proportional variables. But these two have a different behaviour on the "restat conditions". The solver continuation sweep does NOT loop around the geoemtry and the mesh (these are newer updated) but uses the last results as initial conditions for next solving step. While the external parametric sweep loop does go around the geoemtry and mesh (hence updates both if required) and then ALWAYS restarts with the original initial conditions. Conclusions, when using the external loop to switch the BC's you know from which state you start, when using the internal one you can ramp up a variable to start from a known state and get to a desired value, that might have a sign controlled by the odd/even parameter from the external loop It's perhaps a tortuous way, but I believe it should work, again all depends on your model (and it's wthout matlab) Apart from that, Matlab is a great programme, I have used it from about v1, it's just that I can survive with i.e. SciLab for the numerics, but I cannot survive without COMSOL ;) -- Good luck. Ivar [/QUOTE]

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年9月15日 GMT-4 05:21
Hi

not that I know about, he link trough matlab goes through some dll I believe so you must probably rewrite these, perhaps someone could do it, with the java api

But are you sure yu cannot solve everything within COMSOL ? or via Java, if you do not have the matlab link ?

--
Good luck
Ivar
Hi not that I know about, he link trough matlab goes through some dll I believe so you must probably rewrite these, perhaps someone could do it, with the java api But are you sure yu cannot solve everything within COMSOL ? or via Java, if you do not have the matlab link ? -- 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.