Note! The next release of FEATool Multiphysics will have a utility function seteqncoef that simplifies (and performs the below steps) in one function call/command.Equation coefficients for a physics mode are stored in the
fea.phys.(mode_tag).eqn.coef cell array.
The columns contain the coefficient tag/name, display label, description, and coefficient values, respectively. The coefficient values in the last column are themselves stored as a cell array, with one entry for each applicable subdomain.
For example, to set the source coefficient
f:
% Get equation/subdomain coefficients.
eqn_coef = fea.phys.(mode_tag).eqn.coef;
% Find the source-term coefficient.
f_tag = ['f_', mode_tag];
f_row = find(strcmp(f_tag, eqn_coef(:,1)));
% Set the value.
eqn_coef{f_row,4} = {f};
% Store the modified coefficients back in the physics fea.phys.(mode_tag).
fea.phys.(mode_tag).eqn.coef = eqn_coef;
Here
mode_tag is the tag of the physics fea.phys.(mode_tag). FEATool generates coefficient tags by combining the coefficient name with the physics-mode tag, so the source coefficient will typically have a tag such as
f_<mode_tag>
For example, if
mode_tag = 'ht'; % Default mode tag for Heat-transfer physics mode
the corresponding source coefficient tag is
f_ht
The important detail is that column 4 contains
one coefficient value per subdomain. For a physics mode defined together with a geometry that has
a single subdomain
eqn_coef{f_row, 4} = {f};
is sufficient. If the mode applies to several subdomains, the entries can be specified separately. For example:
eqn_coef{f_row, 4} = {1, 'x+y', 2.5};
would assign different source values/expressions to three subdomains. It can also be useful to inspect the coefficient table directly:
eqn_coef = fea.phys.(mode_tag).eqn.coef;
eqn_coef(:, 1:3)
This shows the available coefficient tags, labels, and descriptions and avoids relying on the row number of a particular coefficient. A more defensive version can check that the requested coefficient exists
eqn_coef = fea.phys.(mode_tag).eqn.coef;
f_tag = ['f_', mode_tag];
f_row = find(strcmp(f_tag, eqn_coef(:, 1)), 1);
if isempty(f_row)
error('Coefficient "%s" was not found.', f_tag);
end
eqn_coef{f_row, 4} = {f};
fea.phys.(mode_tag).eqn.coef = eqn_coef;
The same approach can be used for other equation coefficients: inspect
fea.phys.(mode_tag).eqn.coef(:,1) for the corresponding coefficient tag, locate that row, and update its fourth-column value.