Access Stiffness Matrix for each Parameter Sweep Value

Please login with a confirmed email address before reporting spam

Hi all,

I am trying to read stiffness matrix through Java. Currently, I am mostly following codes given in COMSOL Programming Reference Manual, which is: (1) create Assemble under my Solution 1 and (2) getSparseMatrixVal('K'), which gives me the global stiffness matrix.

This method works perfectly for Static problem, when I am using Stationary step with Stationary solver. However, if I include parametric sweep, I can only access to the stiffness matrix produced by the last parameter sweep.

For example: imagine a parameter p with values 1, 2, and 3. There is a Parametric attribute added under the Stationary Solver, which changes the parameter value through 1, 2 and 3. Let's assume, that Young's modulus depends on parameter p. Hence, the stiffness matrix of the element will change as the parameter p changes. However, I can only access the stiffness matrix for the last parameter p value, that is p = 3.

Does anyone know how can I access and read stiffness matrices for all of the parameter values? Unfortunately, I could not find any information in the manual.

Sincerely, Irakli


1 Reply Last Post Mar 15, 2024, 5:53 a.m. EDT
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 month ago Mar 15, 2024, 5:53 a.m. EDT
Updated: 1 month ago Mar 15, 2024, 8:34 a.m. EDT

Dear Irakli,

the Assemble feature uses the current solution as linearization point to assemble the system matrices and only the current assembled latest sysrtem matrices are store in the feature.

If you want to get the matrices for different parameters (and so different solutions) you need to create a second study, which uses the solution vector (from the first study) as initial value. In this second study place the Assemble feature just after the Variable feature ( You can find attached a demo model that shows how to proceed).

Then you only need to select which parameter to use (Step 1: Stationary > Values of Dependent Variables > Parameter value ) and run the solver configuration up to the Assemble feature (use Compute to Selected in the Assemble settings window). Finally extract the matrices component useing getSparseMatrixVal().

Dear Irakli, the Assemble feature uses the current solution as linearization point to assemble the system matrices and only the current assembled latest sysrtem matrices are store in the feature. If you want to get the matrices for different parameters (and so different solutions) you need to create a second study, which uses the solution vector (from the first study) as initial value. In this second study place the Assemble feature just after the Variable feature ( You can find attached a demo model that shows how to proceed). Then you only need to select which parameter to use (**Step 1: Stationary** > **Values of Dependent Variables** > **Parameter value** ) and run the solver configuration up to the Assemble feature (use **Compute to Selected** in the Assemble settings window). Finally extract the matrices component useing getSparseMatrixVal().

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.