pysdic.SDICFixedParametrization#

SDICFixedParametrization class#

class SDICFixedParametrization(analysis, unknowns, *, vertices=None, components=None, sparse=True)[source]#

A parametrization of the unknowns of a SDIC problem optimizing only the displacements of selected vertices and components of the optimized frames (and all the parameters of the optimized transformations), the other unknowns keeping their value in the analysis. The pysolvegn.Parametrization to give to pysolvegn.solve is the property parametrization.

Important

pysolvegn.Parametrization is not pysdic.Parametrization, despite the same name and a close purpose:

The terms of the problem (pysdic.SDICCorrelationTerm, pysdic.SDICTemporalRegularizationTerm) keep working on the complete vector \(\vec{p} = [\vec{p}_U, \vec{p}_T]\) of unknowns. The parametrization is the affine map

\[\vec{p} = P(\vec{q}) = \vec{p}_{current} \text{ with } \vec{p}[I] = \vec{q}, \qquad \frac{\partial \vec{p}}{\partial \vec{q}} = S\]

where \(I\) are the selected indices (see pysdic.SDICAnalysis.compute_unknowns_indices()) and \(S\) the constant selection matrix. The values of the unknowns that are not selected are read from the analysis at each call (pysdic.SDICAnalysis.pack_unknowns()): after a convergence written in the analysis (reparametrized_apply()), the same parametrization can be used again for a new resolution, without building it again.

Initial vector. With a parametrization, the solver starts from the reduced vector \(\vec{q}_0\) given by reparametrized_pack(), not from analysis.pack_unknowns(unknowns) (the complete vector \(\vec{p}_0\), used without parametrization). The three methods mirror those of pysdic.SDICAnalysis on the reduced vector \(\vec{q}\):

Without parametrization (\(\vec{p}\))

With this parametrization (\(\vec{q}\))

analysis.pack_unknowns(unknowns)

reparametrized_pack()

analysis.unpack_unknowns(unknowns, p)

reparametrized_unpack() (q)

analysis.apply_unknowns(unknowns, p)

reparametrized_apply() (q)

As for the unknowns, \(\vec{q}\) holds total values (displacements from the reference mesh, parameters of the transformations), not increments.

Warning

With a parametrization, always use reparametrized_pack(), reparametrized_unpack() and reparametrized_apply() on the vectors of the solver (p0 and result.parameters are reduced vectors \(\vec{q}\)). analysis.pack_unknowns, analysis.unpack_unknowns and analysis.apply_unknowns (and pack, unpack, apply of the terms) work on the complete vector \(\vec{p}\): giving them \(\vec{q}\) raises an error (wrong size) or, worse, misplaces the values if the sizes happen to match.

q0 = parametrization.reparametrized_pack()               # NOT analysis.pack_unknowns(unknowns)
result = pysolvegn.solve(terms, q0, parametrization=parametrization.parametrization)
parametrization.reparametrized_apply(result.parameters)  # NOT analysis.apply_unknowns(unknowns, ...)

Typical uses:

  • optimize only the vertices supporting integration points (see pysdic.compute_supported_vertices()), the other ones keeping their displacement;

  • optimize only some components, e.g. the in-plane components \(x\) and \(y\).

The object is immutable: with_unknowns() and with_options() create a new parametrization.

Parameters:
  • analysis (pysdic.SDICAnalysis) – The analysis of the problem, shared with its terms.

  • unknowns (pysdic.SDICUnknowns) – The unknowns of the problem, shared with its terms (validated by the analysis).

  • vertices (Optional[ArrayLike], optional) – The vertices whose displacement is optimized: indices or a boolean mask of shape \((N_v,)\). By default, all the vertices.

  • components (Optional[Sequence[Integral]], optional) – The components of the displacement that are optimized. By default, all the components.

  • sparse (bool, optional (default: True)) – If True, the Jacobian \(S\) is a scipy.sparse.csr_matrix (recommended: the dense matrix has \(\dim(\vec{p}) \times \dim(\vec{q})\) entries).

Raises:

Examples

Measure the displacements of several frames, only for the vertices that support integration points and only for the in-plane components:

import pysolvegn
from pysdic import (SDICCorrelationTerm, SDICFixedParametrization, SDICUnknowns,
                    compute_supported_vertices)

unknowns = SDICUnknowns([1], [])
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings)
vertices = compute_supported_vertices(analysis.mesh, integration_points)
fixed = SDICFixedParametrization(analysis, unknowns, vertices=vertices, components=[0, 1])

for loop in range(3):  # The same parametrization: the fixed values are read at each call
    result = pysolvegn.solve([correlation.term], fixed.reparametrized_pack(),
                             parametrization=fixed.parametrization, max_iteration=20)
    fixed.reparametrized_apply(result.parameters)

Instantiation and new parametrizations#

A SDICFixedParametrization is created with the unknowns of the problem (the same pysdic.SDICUnknowns as its terms), the selected vertices and components. The values that are not selected are read from the analysis at each call: after a convergence written in the analysis, the same parametrization can be used again. It is immutable: the methods below create a new parametrization.

SDICFixedParametrization.with_unknowns(unknowns)

A new parametrization with other unknowns and the same selection (vertices, components).

SDICFixedParametrization.with_options(**changes)

A new parametrization with other options (vertices, components, sparse).

Reduced vector#

The solver optimizes the reduced vector \(\vec{q}\) (the selected entries of \(\vec{p}\), total values):

Warning

With a parametrization, always use SDICFixedParametrization.reparametrized_pack(), SDICFixedParametrization.reparametrized_unpack() and SDICFixedParametrization.reparametrized_apply() on the vectors of the solver. unknowns.pack, unknowns.unpack and unknowns.apply work on the complete vector \(\vec{p}\): giving them \(\vec{q}\) raises an error (wrong size) or, worse, misplaces the values if the sizes happen to match.

Without parametrization

With a parametrization

unknowns.pack()

parametrization.reparametrized_pack()

unknowns.unpack(p)

parametrization.reparametrized_unpack(q)

unknowns.apply(p)

parametrization.reparametrized_apply(q)

parametrization = SDICFixedParametrization(unknowns, vertices=vertices, components=[0, 1])
result = pysolvegn.solve([correlation.term], parametrization.reparametrized_pack(),
                         parametrization=parametrization.parametrization)
parametrization.reparametrized_apply(result.parameters)  # NOT unknowns.apply(...)

SDICFixedParametrization.reparametrized_pack()

The reduced vector \(\vec{q}\) of the current state of the analysis: the initial parameters q0 of a resolution with parametrization (analysis.pack_unknowns(unknowns) gives the complete vector, used without parametrization).

SDICFixedParametrization.reparametrized_unpack(q)

Split a reduced vector \(\vec{q}\) (e.g. result.parameters) into the complete displacements of the optimized frames and the parameters of the optimized transformations, the values not selected being those of the analysis: analysis.unpack_unknowns(unknowns, p_func(q)).

SDICFixedParametrization.reparametrized_apply(q)

Write a reduced vector \(\vec{q}\) (e.g. result.parameters) in the analysis: analysis.apply_unknowns(unknowns, p_func(q)) (the values not selected are unchanged).

SDICFixedParametrization.p_func(q)

The complete vector \(\vec{p} = P(\vec{q})\): the current values of the unknowns in the analysis, with the selected ones replaced by \(\vec{q}\).

Attributes#

SDICFixedParametrization.parametrization

The pysolvegn.Parametrization \(\vec{q} \mapsto \vec{p}\), to give to pysolvegn.solve.

SDICFixedParametrization.unknowns

The unknowns of the problem (the complete vector \(\vec{p}\)).

SDICFixedParametrization.analysis

The analysis of the problem (shared with its terms).

SDICFixedParametrization.indices

The indices \(I\) of the selected unknowns in \(\vec{p}\) (read-only).

SDICFixedParametrization.n_reparametrized

The number of optimized unknowns \(\dim(\vec{q})\).

SDICFixedParametrization.sparse

Whether the Jacobian \(S\) is sparse.