[petsc-dev] New Object and Function Development
Jed Brown
jed at jedbrown.org
Thu Jan 19 12:34:47 CST 2023
Brandon Denton <bldenton at buffalo.edu> writes:
> Good Morning,
>
> For the past few years, I have been working to integrate CAD into PETSc.
> Over this time, I've worked with Dr. Knepley to enable PETSc to open and
> utilize STEP, IGES, EGADS and EGADSlite files. We've also worked to expose
> the geometry's parameters (Control Points, Weights) as well as their
> gradients for direct manipulation through PETSc allowing numerical
> optimization of the geometry underpinning the domain's discretization
> (mesh).
>
> I'm currently trying to make this functionality usable through PETSc only
> functions (wrapper functions) so users don't have to learn the underlying
> CAD library. To achieve this, I need to do the following things in PETSc.
>
> 1. Create a new PETSc object which is typedef of the underlying
> library's object. Where/what file should I include this typedef?
> - I currently defined it in the petscsystypes.h with the following
> code.
>
> #if defined(PETSC_HAVE_EGADS)
>
> #include <egads.h>
>
> #include <egads_lite.h>
>
> typedef ego PetscGeom;
>
> #endif
I think there should be a new header petscgeom.h or petscdmgeom.h for these features, and corresponding include/petsc/private/dmgeomimpl.h. There should be a struct containing the handle in the private header and only a "pointer to incomplete type" typedef (as with all the PETSc objects) in the public header.
> - This appears to work but I know it is not a final solution because on
> updating PETSc I get warnings saying that a few defined variables are being
> redefined by other header files. How do I properly incorporate this into
> PETSc as part of an optional capability?
>
> 2. Create wrapper functions where I need to return information back to the
> main code? I currently have defined the wrapper function signatures in
> plexdmplex.h as:
>
>
> - PETSC_EXTERN PetscErrorCode DMPlexGetGeomModelBodies(DM, PetscGeom *,
> PetscInt); // EGADS
>
> In my main code, I use the following. After completion, I would
> like DMPlexGetGeomModelBodies() to return the PetscGeom object which is
> usually an array of 'ego' objects and the number of objects in the array of
> the 'ego' objects.
>
> PetscGeom *newBodies = NULL;
>
> PetscInt numBodies = 0;
>
> PetscCall(DMPlexGetGeomModelBodies(dmNozzle, &newBodies, numBodies));
>
> PetscCall(PetscPrintf(PETSC_COMM_SELF, " Nb = %d || numBodies = %d
> \n", Nb, numBodies));
>
>
> I'm fairly certain I'm getting tripped up on how to properly pass these
> objects between my main code and the new PETSc functions I'm trying to
> develop. Any assistance/direction/insights you could provide is greatly
> appreciated.
I'd suggest making a draft merge request so you can ask questions in the context of the code. From the code snippet, you're missing stars on the output args (they need to accept a pointer to the thing, not the output thing itself).
More information about the petsc-dev
mailing list