Re: [petsc-users] Storing Values using a Triplet for using later

2023-11-09 Thread Brandon Denton via petsc-users
Good Morning,

Thank you Matt, Jed, and Barry. I will looking into each of these suggestions a 
report back.

-Brandon

From: Matthew Knepley 
Sent: Wednesday, November 8, 2023 4:18 PM
To: Brandon Denton 
Cc: petsc-users@mcs.anl.gov 
Subject: Re: [petsc-users] Storing Values using a Triplet for using later

On Wed, Nov 8, 2023 at 2:40 PM Brandon Denton via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Good Afternoon,

Is there a structure within PETSc that allows storage of a value using a triple 
similar to PetscHMapIJSet with the key using a struct{PetscScalar i, j, k;}?

I'm trying to access mesh information (the shape function coefficients I will 
calculate prior to their use) who's values I want to store in the auxiliary 
array available in the Residual Functions of PETSc's FEM infrastructure. After 
some trial and error work, I've come to the realization that the coordinates 
(x[]) available in the auxiliary functions is the centroid of the cell/element 
currently being evaluated. This triplet is unique for each cell/element for a 
valid mesh so I think it's reasonable to use this triplet as a key for looking 
up stored values unique to each cell/element. My plan is to attached the map to 
the Application Context, also available to Auxiliary Functions, to enable these 
calculations.

Does such a map infrastructure exist within PETSc? If so, could you point me to 
a reference for it? If not, does anyone have any suggestions on how to solve 
this problem?

As Jed says, this is a spatial hash. I have a primitive spatial hash now. You 
can use DMLocatePoints() to find the cell containing a point (like the 
centroid). Let me know if this does not work or if I misunderstand the problem.

  Thanks!

Matt

Thank you in advance for your time.
Brandon Denton



--
What most experimenters take for granted before they begin their experiments is 
infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/<http://www.cse.buffalo.edu/~knepley/>


Re: [petsc-users] Storing Values using a Triplet for using later

2023-11-08 Thread Matthew Knepley
On Wed, Nov 8, 2023 at 2:40 PM Brandon Denton via petsc-users <
petsc-users@mcs.anl.gov> wrote:

> Good Afternoon,
>
> Is there a structure within PETSc that allows storage of a value using a
> triple similar to PetscHMapIJSet with the key using a struct{PetscScalar i,
> j, k;}?
>
> I'm trying to access mesh information (the shape function coefficients I
> will calculate prior to their use) who's values I want to store in the
> auxiliary array available in the Residual Functions of PETSc's FEM
> infrastructure. After some trial and error work, I've come to the
> realization that the coordinates (x[]) available in the auxiliary functions
> is the centroid of the cell/element currently being evaluated. This triplet
> is unique for each cell/element for a valid mesh so I think it's reasonable
> to use this triplet as a key for looking up stored values unique to each
> cell/element. My plan is to attached the map to the Application Context,
> also available to Auxiliary Functions, to enable these calculations.
>
> Does such a map infrastructure exist within PETSc? If so, could you point
> me to a reference for it? If not, does anyone have any suggestions on how
> to solve this problem?
>

As Jed says, this is a spatial hash. I have a primitive spatial hash now.
You can use DMLocatePoints() to find the cell containing a point (like the
centroid). Let me know if this does not work or if I misunderstand the
problem.

  Thanks!

Matt


> Thank you in advance for your time.
> Brandon Denton
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Storing Values using a Triplet for using later

2023-11-08 Thread Barry Smith


   PETSc hashing is done by leveraging the great package khash. Take a look at 
include/petsc/private/hashtable.h and hashijkey.h for how we use kash to 
automatically generate the code for a particular key. Just make your tolerance 
smaller than the smallest diameters of your cells.


   Barry


> On Nov 8, 2023, at 2:47 PM, Jed Brown  wrote:
> 
> I don't think you want to hash floating point values, but I've had a number 
> of reasons to want spatial hashing for near-neighbor queries in PETSc and 
> that would be a great contribution. (Spatial hashes have a length scale and 
> compute integer bins.)
> 
> Brandon Denton via petsc-users  writes:
> 
>> Good Afternoon,
>> 
>> Is there a structure within PETSc that allows storage of a value using a 
>> triple similar to PetscHMapIJSet with the key using a struct{PetscScalar i, 
>> j, k;}?
>> 
>> I'm trying to access mesh information (the shape function coefficients I 
>> will calculate prior to their use) who's values I want to store in the 
>> auxiliary array available in the Residual Functions of PETSc's FEM 
>> infrastructure. After some trial and error work, I've come to the 
>> realization that the coordinates (x[]) available in the auxiliary functions 
>> is the centroid of the cell/element currently being evaluated. This triplet 
>> is unique for each cell/element for a valid mesh so I think it's reasonable 
>> to use this triplet as a key for looking up stored values unique to each 
>> cell/element. My plan is to attached the map to the Application Context, 
>> also available to Auxiliary Functions, to enable these calculations.
>> 
>> Does such a map infrastructure exist within PETSc? If so, could you point me 
>> to a reference for it? If not, does anyone have any suggestions on how to 
>> solve this problem?
>> 
>> Thank you in advance for your time.
>> Brandon Denton



Re: [petsc-users] Storing Values using a Triplet for using later

2023-11-08 Thread Jed Brown
I don't think you want to hash floating point values, but I've had a number of 
reasons to want spatial hashing for near-neighbor queries in PETSc and that 
would be a great contribution. (Spatial hashes have a length scale and compute 
integer bins.)

Brandon Denton via petsc-users  writes:

> Good Afternoon,
>
> Is there a structure within PETSc that allows storage of a value using a 
> triple similar to PetscHMapIJSet with the key using a struct{PetscScalar i, 
> j, k;}?
>
> I'm trying to access mesh information (the shape function coefficients I will 
> calculate prior to their use) who's values I want to store in the auxiliary 
> array available in the Residual Functions of PETSc's FEM infrastructure. 
> After some trial and error work, I've come to the realization that the 
> coordinates (x[]) available in the auxiliary functions is the centroid of the 
> cell/element currently being evaluated. This triplet is unique for each 
> cell/element for a valid mesh so I think it's reasonable to use this triplet 
> as a key for looking up stored values unique to each cell/element. My plan is 
> to attached the map to the Application Context, also available to Auxiliary 
> Functions, to enable these calculations.
>
> Does such a map infrastructure exist within PETSc? If so, could you point me 
> to a reference for it? If not, does anyone have any suggestions on how to 
> solve this problem?
>
> Thank you in advance for your time.
> Brandon Denton


[petsc-users] Storing Values using a Triplet for using later

2023-11-08 Thread Brandon Denton via petsc-users
Good Afternoon,

Is there a structure within PETSc that allows storage of a value using a triple 
similar to PetscHMapIJSet with the key using a struct{PetscScalar i, j, k;}?

I'm trying to access mesh information (the shape function coefficients I will 
calculate prior to their use) who's values I want to store in the auxiliary 
array available in the Residual Functions of PETSc's FEM infrastructure. After 
some trial and error work, I've come to the realization that the coordinates 
(x[]) available in the auxiliary functions is the centroid of the cell/element 
currently being evaluated. This triplet is unique for each cell/element for a 
valid mesh so I think it's reasonable to use this triplet as a key for looking 
up stored values unique to each cell/element. My plan is to attached the map to 
the Application Context, also available to Auxiliary Functions, to enable these 
calculations.

Does such a map infrastructure exist within PETSc? If so, could you point me to 
a reference for it? If not, does anyone have any suggestions on how to solve 
this problem?

Thank you in advance for your time.
Brandon Denton