Hi Barry, Thanks a lot for the codes ! I will test it and let you know if it works.
Christophe CIEMAT Laboratorio Nacional de Fusión por Confinamiento Magnético Unidad de Materiales Edificio 2 - Planta 0 - Despacho 28m Avenida Complutense 40, 28040 Madrid, Spain Tel: +34 91496 2582 Fax: +34 91346 6442 -- Q Por favor, piense en el medio ambiente antes de imprimir este mensaje. Please consider the environment before printing this email. On Thu, Sep 26, 2013 at 4:09 PM, Barry Smith <[email protected]> wrote: > > Christophe, > > Despite my LinkIn Endorsement for expertise in Fortran :-) I cannot > pretend to be an expert in FortranXX but I have cooked up an example > demonstrating accessing the Vec entries as if they are in an array of > derived types. I've attached the example code; there needs to be a small C > stub that defines the functions for your specific derived type name. > Note that it will only work I think if your N is a compile time constant. > > > > > It worked with > ~/Downloads$ gfortran --version > GNU Fortran (GCC) 4.8.1 20130404 (prerelease) > > > I do not understand exactly why it works since it uses > F90Array1dCreate(fa,PETSC_SCALAR,1,len,ptr PETSC_F90_2PTR_PARAM(ptrd)); > which has a single PETSC_SCALAR as a building block but … I hope it works > for you. If it doesn't, let us know the compiler you are using and we may > be able to get it working for that compiler. > > Barry > > > > On Sep 26, 2013, at 4:41 AM, Christophe Ortiz <[email protected]> > wrote: > > > Hi all, > > > > Me again ! > > > > I have read in previous posts that it is hard in Fortran to declare > something similar to a typedef struct in C to manage a multicomponent > problem. > > > > Is it still the case ? Has the problem been solved ? > > > > I am asking because my plan is to implement a multicomponent problem (in > 1D), with many components that will be organized in arrays of two > dimensions. In C I could define > > > > typedef struct{ > > PetscScalar U; > > PetscScalar V; > > PetscScalar A[N][N]; > > } Field; > > > > and then I could calculate the residual function with > > > > F[i].U = ... > > F[i].V = ... > > F[i].A[k][n] = ... > > > > which is quite convenient. > > > > If in Fortran it is not possible to use a struct as in C, I am afraid > I'll have to deal with > > > > F(jdof,i) = ... > > > > where I will have only jdof to address U, V and A[ ][ ], which can be > difficult and not very convenient I guess. Before I move all my code to C, > does anyone have an alternative idea to manage this multi(many)component > problem in Fortran ? > > > > Many thanks in advance for your help and suggestion ! > > > > Christophe > > >
