Define the "withsol" function to consider all time instants resulting from a previous study

Marianna Di Pietrantonio

Please login with a confirmed email address before reporting spam

Hi,

I have two time dependent studies in my simulation. In the first, solved with a time interval defined as "range(0,1/f/100,1/f), I obtain the time variation of the variable "J" and solve the physics "cb" and "mf". Then I would like to set the J(t) results from study 1 as an input parameter in study 2 where I solve only for "mf2".

To do this I tried to impose the function "withsol('sol1',J)tTape" (tTape is a thickness) as visible in the figure but with this definition Comsol does not take into account the temporal variability of J; it is as if Comsol took J's solution in a single instant of time.

How can I define the "withsol" function so that I can take the values of J at all time instants and use them in study 2?

For consistency in both study 1 and study 2 I defined the same time interval and the same timesteps.



3 Replies Last Post Mar 26, 2024, 1:05 p.m. EDT
Robert Koslover Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 1 month ago Mar 26, 2024, 11:52 a.m. EDT
Updated: 1 month ago Mar 26, 2024, 11:52 a.m. EDT

I think this information from the Help system, about using setind and/or setval with withsol might work for you: "setind and setval

setind and setval can only be used within withsol or withparam. The following text explains the syntax using withsol, but it is the same for withparam.

Use setind to specify a parameter index and setval to specify a parameter value in connection with the withsol operator (see withsol). For parametric sweeps over several parameters, say p and q, setval and setind can be used in any combination for the two parameters — for example, withsol('sol1',expr,setind(p,2,q,3)) or withsol('sol1',expr,setind(p,2),setval(q,5)).

Negative indices in setind are counted from the end. For example, in a time-dependent solver, withsol('sol1',expr,setind(t,-2)) evaluates expr at the second last time step. An alternative notation for the first and last indices is setind(p,'first') and setind(p,'last').

You can use setind and setval with more than two arguments to make the syntax more compact. For example, withsol('sol1',expr,setval(p,1,q,2)) is equivalent to withsol('sol1',expr,setval(p,1),setval(q,2))."

-------------------
Scientific Applications & Research Associates (SARA) Inc.
www.comsol.com/partners-consultants/certified-consultants/sara
I think this information from the Help system, about using *setind* and/or *setval* with *withsol* might work for you: "setind and setval setind and setval can only be used within withsol or withparam. The following text explains the syntax using withsol, but it is the same for withparam. Use setind to specify a parameter index and setval to specify a parameter value in connection with the withsol operator (see withsol). For parametric sweeps over several parameters, say p and q, setval and setind can be used in any combination for the two parameters — for example, withsol('sol1',expr,setind(p,2,q,3)) or withsol('sol1',expr,setind(p,2),setval(q,5)). Negative indices in setind are counted from the end. For example, in a time-dependent solver, withsol('sol1',expr,setind(t,-2)) evaluates expr at the second last time step. An alternative notation for the first and last indices is setind(p,'first') and setind(p,'last'). You can use setind and setval with more than two arguments to make the syntax more compact. For example, withsol('sol1',expr,setval(p,1,q,2)) is equivalent to withsol('sol1',expr,setval(p,1),setval(q,2))."

Marianna Di Pietrantonio

Please login with a confirmed email address before reporting spam

Posted: 1 month ago Mar 26, 2024, 12:22 p.m. EDT

Thanks for the reply!

I had already seen these functions (setind and setval) but from what I understood, as you also reported, they allow you to define the withsol function only at certain moments of time or for certain values. For example withsol('sol1',expr,setind(p,2)) refers to the second time instant, right?

What I would like to do is something like ('sol1',expr,setind(p,All_timestep)) where the values of p at each time step are taken into consideration. Is it possible to do this and how should I write the withsol function?

Thanks for the reply! I had already seen these functions (setind and setval) but from what I understood, as you also reported, they allow you to define the withsol function only at certain moments of time or for certain values. For example withsol('sol1',expr,setind(p,2)) refers to the second time instant, right? What I would like to do is something like ('sol1',expr,setind(p,All_timestep)) where the values of p at each time step are taken into consideration. Is it possible to do this and how should I write the withsol function?

Robert Koslover Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 1 month ago Mar 26, 2024, 1:05 p.m. EDT
Updated: 1 month ago Mar 26, 2024, 1:12 p.m. EDT

Ah. If neither setind or setval work satisfactorily in this context, you may need to set up some kind of separate interpolation operation. (Note: According to the Help system, the use of setval in the withsol operation will support interpolation.) But I'm not sure if you might be having some kind of time-variable-naming issue. In principle, you could export the results (for J vs, time) of one run and then import those results into an interpolation function to use with your boundary condition in a subsequent run, but I suspect a less cumbersome approach exists. Perhaps another user, or Comsol employee, can suggest a more elegant solution?

-------------------
Scientific Applications & Research Associates (SARA) Inc.
www.comsol.com/partners-consultants/certified-consultants/sara
Ah. If neither *setind* or *setval* work satisfactorily in this context, you may need to set up some kind of separate interpolation operation. (Note: According to the Help system, the use of *setval* in the *withsol* operation will support interpolation.) But I'm not sure if you might be having some kind of time-variable-naming issue. In principle, you could export the results (for J vs, time) of one run and then import those results into an interpolation function to use with your boundary condition in a subsequent run, but I suspect a less cumbersome approach exists. Perhaps another user, or Comsol employee, can suggest a more elegant solution?

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.