[petsc-users] using petsc functions in structs?
John-Michael Fischer
fischej at umich.edu
Wed May 12 15:01:34 CDT 2010
you just saved me a lot of time -- thanks.
On May 12, 2010, at 4:00 PM, Jed Brown wrote:
> On Wed, 12 May 2010 15:54:42 -0400, John-Michael Fischer <fischej at umich.edu> wrote:
>> Hi, I'm fighting this issue.
>>
>> In the follow code which is macro for a struct divide I get three errors about casting PetscErrorCode types into the name of the struct.
>>
>> This is the code
>> struct IMPACT_Moment Divide(struct IMPACT_Moment * M1, struct IMPACT_Moment * M3)
>> { // does M1./M3 and returns M2
>> PetscErrorCode ierr;
>> struct IMPACT_Moment M2;
>> M2.Nx = M1->Nx;
>> M2.Ny = M1->Ny;
>> M2.coords[0] = M1->coords[0];
>> M2.coords[1] = M1->coords[1];
>>
>> 78: ierr = VecCopy(M1->xaxis, M2.xaxis);CHKERRQ(ierr);
>> 79: ierr = VecCopy(M1->yaxis, M2.yaxis);CHKERRQ(ierr);
>>
>> 81: ierr = MatCopy(M1->values, M2.values, DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
>> ...... goes on
>>
>>
>> and these are the only three error messages I get
>>
>> IMPACTA_Moments.h: In function ‘IMPACT_Moment Divide(IMPACT_Moment*, IMPACT_Moment*)’:
>> IMPACTA_Moments.h:78: error: conversion from ‘PetscErrorCode’ to non-scalar type ‘IMPACT_Moment’ requested
>> IMPACTA_Moments.h:79: error: conversion from ‘PetscErrorCode’ to non-scalar type ‘IMPACT_Moment’ requested
>> IMPACTA_Moments.h:81: error: conversion from ‘PetscErrorCode’ to non-scalar type ‘IMPACT_Moment’ requested
>
> The CHKERRQ macro expects that the enclosing function returns
> PetscErrorCode. Because your code has to handle errors somehow, your
> functions should either return PetscErrorCode (int) or you should use
> CHKERRXX and C++ exceptions (if you are writing C++ and prefer to use
> exceptions).
>
> Jed
>
>
More information about the petsc-users
mailing list