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.

Iterative treatment of integration couplings or other implicit constraints?

Please login with a confirmed email address before reporting spam

Hello,

My model has an integration coupling -- one of the boundary conditions for a variable depends on the integration of the same variable over that domain. Of course, this makes the problem less sparse and slows down the calculation immensely. Therefore, I want to try to solve iteratively: Calculate the integral, then hold that fixed and solve the PDE, then re-calculate the integral, then hold it fixed and solve the PDE, etc. But I can't figure out how to do that in COMSOL. Does anyone know? Thanks in advance!

(I'm just doing a stationary solution.)

UPDATE: I realized that this is not just for computational efficiency, I actually want a different answer than you would get in the non-iterative approach. Here's another example:

Solve some ODE in a 1D domain (0,1) with Dirichlet boundary conditions f(0) = f(1) = B.

The self-consistency requirement is that B is determined by the value in the center of the domain: B = f(0.5).

The "iterative method" (which I want) would solve f with B=0, then set B=f(0.5), then solve f with the new boundary condition, etc.

The "direct method" would use global equations and/or extrusion couplings to solve f and B simultaneously.

These sound equivalent, but they actually don't give the same finite-element solution, because in the direct method, there is an extra direct force on the point (0.5) from its "contact" with (0) and (1). In my tests I got kinks in f(x) (discontinuities in the first derivative) at the point (0.5). The iterative method would never give a kink at (0.5), because you're always solving the normal ODE with no extra force at any particular point.

So again the question is: How do I do the iterative approach in COMSOL and get the iterative answer?

(Also, please correct me if I'm misunderstanding anything.)

UPDATE 2: Here are some related threads I found, but they have not led me towards an answer:
www.comsol.com/community/forums/general/thread/7198/
www.comsol.com/community/forums/general/thread/8479/
www.comsol.com/community/forums/general/thread/12701/

5 Replies Last Post Nov 2, 2011, 2:17 p.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 28, 2011, 11:20 a.m. EDT
Well my simulations are working, but the solution is very kludgy!

I actually have two models where this came up, and used two different solutions.

The first model was a very fast-solving one-dimensional problem. I basically did the calculation with every possible value of the parameter, and then in postprocessing searched for the self-consistent solution. (I interpolated between simulation results to improve accuracy.)

The second model was too slow for that, so I did manual iterations. I had a "Results" node that exported to a specific text file, then a MATLAB script that read it and wrote the same data in a different file which served as input to a COMSOL Interpolation Function for the next run. (A function and not a value, because in my model I am also varying another parameter independent of the self-consistent one.) I had a little flag parameter "IsTheFirstRun", which decided whether or not to use initial conditions versus read the input file.

With that, I can run the simulation with the IsTheFirstRun flag on, click to export the results, run the MATLAB program, switch the flag off, run COMSOL again, export, run MATLAB again, run COMSOL again, etc. This is good enough for me, I actually only needed one iteration.

[Ways this could be improved if I wanted to: (1) Automate everything with the MATLAB-COMSOL interface; (2) Save the full solution of one run as an initial condition for the next for faster convergence.]

I'm still disappointed that this all seems impossible within the COMSOL GUI. I have to guess that the programmers deliberately make it hard to dynamically manipulate parameters, so that we all have to buy their Optimization Module. :-P
Well my simulations are working, but the solution is very kludgy! I actually have two models where this came up, and used two different solutions. The first model was a very fast-solving one-dimensional problem. I basically did the calculation with every possible value of the parameter, and then in postprocessing searched for the self-consistent solution. (I interpolated between simulation results to improve accuracy.) The second model was too slow for that, so I did manual iterations. I had a "Results" node that exported to a specific text file, then a MATLAB script that read it and wrote the same data in a different file which served as input to a COMSOL Interpolation Function for the next run. (A function and not a value, because in my model I am also varying another parameter independent of the self-consistent one.) I had a little flag parameter "IsTheFirstRun", which decided whether or not to use initial conditions versus read the input file. With that, I can run the simulation with the IsTheFirstRun flag on, click to export the results, run the MATLAB program, switch the flag off, run COMSOL again, export, run MATLAB again, run COMSOL again, etc. This is good enough for me, I actually only needed one iteration. [Ways this could be improved if I wanted to: (1) Automate everything with the MATLAB-COMSOL interface; (2) Save the full solution of one run as an initial condition for the next for faster convergence.] I'm still disappointed that this all seems impossible within the COMSOL GUI. I have to guess that the programmers deliberately make it hard to dynamically manipulate parameters, so that we all have to buy their Optimization Module. :-P

Daniel Smith COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 28, 2011, 1:03 p.m. EDT
Hi David, in your example in Update 1 of your first post you need to use a <b>unidirectional</b> constraint for your boundary condition at x=0 and x=1. This will then not impose an unphysical constraint force at x=0.5 and you will get the expected result. You can then solve everything simultaneously and the non-linear solver will automatically iterate to the correct solution.
Hi David, in your example in Update 1 of your first post you need to use a unidirectional constraint for your boundary condition at x=0 and x=1. This will then not impose an unphysical constraint force at x=0.5 and you will get the expected result. You can then solve everything simultaneously and the non-linear solver will automatically iterate to the correct solution.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 29, 2011, 12:24 p.m. EDT
Daniel -- Thanks, I didn't know about "unidirectional constraints".

Since my kludgy solutions (above) are working well enough, I won't spend the time to try anything else. But yes, that seems like it would solve some or all of my problems.
Daniel -- Thanks, I didn't know about "unidirectional constraints". Since my kludgy solutions (above) are working well enough, I won't spend the time to try anything else. But yes, that seems like it would solve some or all of my problems.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 21, 2011, 3:02 p.m. EDT
Hi There,

I have a very similar problem and was wondering whether anyone can help me. I am using COMSOL 4.2 and I have a 1D electrostatic model. At one boundary, I have a simple fixed potential boundary condition, which is no problem to implement. At the other boundary, I would like to define a surface charge density that depends on the potential at that same boundary. For example, it would be similar to the following equation: Q[C/m^2] = Q_0*exp(-phi/E_A). I would then like the solver to calculate the appropriate value of phi (electric potential) at the boundary and elsewhere in the model, based on the constraint between phi and the surface charge defined at the boundary (which depends on phi).

Does anyone know how I can do this? It seems there should be an easy, straightforward way to define a self-referencing boundary condition.

Thanks in advance,

George
Hi There, I have a very similar problem and was wondering whether anyone can help me. I am using COMSOL 4.2 and I have a 1D electrostatic model. At one boundary, I have a simple fixed potential boundary condition, which is no problem to implement. At the other boundary, I would like to define a surface charge density that depends on the potential at that same boundary. For example, it would be similar to the following equation: Q[C/m^2] = Q_0*exp(-phi/E_A). I would then like the solver to calculate the appropriate value of phi (electric potential) at the boundary and elsewhere in the model, based on the constraint between phi and the surface charge defined at the boundary (which depends on phi). Does anyone know how I can do this? It seems there should be an easy, straightforward way to define a self-referencing boundary condition. Thanks in advance, George

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 2, 2011, 2:17 p.m. EDT
type in Q[C/m^2] = Q_0*exp(-phi/E_A) in "expression" definition.
type in Q[C/m^2] = Q_0*exp(-phi/E_A) in "expression" definition.

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.