Extracting Solution Vector
To extract the solution vector with the function mphgetu, enter:
U = mphgetu(model)
where U is an N-by-1 double array, where N is the number of degrees of freedom of the COMSOL Multiphysics model.
This section includes information about Specifying the Solution and the Output Format.
You can refer to the function mphxmeshinfo to receive the DOF name or the node coordinates in the solution vector; see Retrieving Xmesh Information.
Specifying the Solution
Change the solver node to extract the solution vector with the property solname:
U = mphgetu(model, 'soltag', <soltag>)
where <soltag> is the tag of the solver node.
For solver settings that compute for several inner solutions, select the inner solution to use with the solnum property:
U = mphgetu(model, 'solnum', <solnum>)
where <solnum> a positive integer vector that corresponds to the solution number to use to extract the solution vector. For time-dependent and continuation analyses, the default value for the solnum property is the last solution number. For an eigenvalue analysis, it is the first solution number.
A model can contain different types of solution vectors — the solution of the problem, the reaction forces vector, the adjoint solution vector, the functional sensitivity vector, or the forward sensitivity. In mphgetu, you can specify the type of solution vector to extract with the type property:
U = mphgetu(model, 'type', type)
where type is one of the strings 'sol', 'reacf', 'adj', or 'sens' used to extract the solution vector, reaction forces, functional sensitivity, or forward sensitivity, respectively.
Output Format
mphgetu returns the default the solution vector. Get the time derivative of the solution vector Udot by adding a second output variable:
[U, Udot] = mphgetu(model)
In case the property solnum is set as a 1-by-M array and the solver node only uses one mesh to create the solution, the default output is an N-by-M array, where N is the number of degrees of freedom of the model. Otherwise, the output U is a cell array that contains each solution vector. If you prefer to have the output in a cell array format, set the property matrix to off:
U = mphgetu(model, 'solnum', <solnum>, 'matrix', 'off')