mdolab / pygeo

pyGeo provides geometric design variables and constraints suitable for gradient-based optimization.
https://mdolab-pygeo.readthedocs-hosted.com/en/latest/?badge=latest
Apache License 2.0
122 stars 54 forks source link

Discussion: Get the derivative of the dXpt/dDV and the DVConstraint. #216

Closed KapilKhanal closed 12 months ago

KapilKhanal commented 12 months ago

Hi, I am new to pygeo. The provided jacobian from pygeo is in CSR format for TACS. How can I just get the jacobian matrices for each of the pointset and the DVs and DVconstraint. The tutorial for this is lacking compared to others.

Context: To pass the DXpt/dDV to openMDAO in the compute_partial method.

marcomangano commented 12 months ago

Hello Kapil, It looks like you have already taken a look at the computeTotalJacobian function. That method returns exactly the derivative you need. You can pass the desired pointset as input. CSR is just the sparse matrix format used internally to not store and perform operations on a dense matrix.

If you need to convert that matrix to dense format, you could try with this Scipy function. Since you need to use this Jacobian in OM, you might rather want to convert the Jacobian in a dictionary format. We have a function for that that you could use as a reference here. That however works specifically on the output of TotalSensitivity (which multiplies (DXpt/dDV)^T by another Jacobian matrix) so it will NOT return the Jacobian you need. You could write a similar function that converts the output of computeTotalJacobian into a dictionary by sorting the columns into respective DV entries.

I hope this helps and does not make you more confused. Tagging @hajdik since she has worked on the MPhys wrapper - which as far as I understand does not explicitly return DXpt/dDV for forward-mode calculations.