source: CIVL/examples/fortran/nek5000/core/fcrs.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 3.4 KB
Line 
1#include <stdio.h>
2#include <stddef.h>
3#include <stdlib.h>
4#include <string.h>
5#include "gslib.h"
6#include "crs.h"
7
8/*--------------------------------------------------------------------------
9 FORTRAN wrapper interface to coarse solver
10 --------------------------------------------------------------------------*/
11
12#undef crs_xxt_setup
13#undef crs_xxt_solve
14#undef crs_xxt_stats
15#undef crs_xxt_free
16#define ccrs_xxt_setup PREFIXED_NAME(crs_xxt_setup)
17#define ccrs_xxt_solve PREFIXED_NAME(crs_xxt_solve)
18#define ccrs_xxt_stats PREFIXED_NAME(crs_xxt_stats)
19#define ccrs_xxt_free PREFIXED_NAME(crs_xxt_free )
20
21#undef crs_amg_setup
22#undef crs_amg_solve
23#undef crs_amg_stats
24#undef crs_amg_free
25#define ccrs_amg_setup PREFIXED_NAME(crs_amg_setup)
26#define ccrs_amg_solve PREFIXED_NAME(crs_amg_solve)
27#define ccrs_amg_stats PREFIXED_NAME(crs_amg_stats)
28#define ccrs_amg_free PREFIXED_NAME(crs_amg_free )
29
30#define fcrs_setup FORTRAN_NAME(crs_setup,CRS_SETUP)
31#define fcrs_solve FORTRAN_NAME(crs_solve,CRS_SOLVE)
32#define fcrs_stats FORTRAN_NAME(crs_stats,CRS_STATS)
33#define fcrs_free FORTRAN_NAME(crs_free ,CRS_FREE)
34
35static struct crs_data **handle_array = 0;
36static int handle_max = 0;
37static int handle_n = 0;
38static int *sid_array;
39
40#define CHECK_HANDLE(func) do \
41 if(*handle<0 || *handle>=handle_n || !handle_array[*handle]) \
42 fail(1,__FILE__,__LINE__,func ": invalid handle"); \
43while(0)
44
45void fcrs_setup(sint *handle, const sint *sid, const MPI_Fint *comm, const sint *np,
46 const sint *n, const slong id[], const sint *nz,
47 const sint Ai[], const sint Aj[], const double A[],
48 const sint *null_space, const double *param,
49 const char *datafname, uint *ierr)
50{
51 struct comm c;
52 if(handle_n==handle_max)
53 handle_max+=handle_max/2+1,
54 handle_array=trealloc(struct crs_data*,handle_array,handle_max),
55 sid_array=trealloc(int,sid_array,handle_max);
56 comm_init_check(&c, *comm, *np);
57
58 sid_array[handle_n]=*sid;
59
60 switch(sid_array[handle_n]) {
61 case 0: handle_array[handle_n]=ccrs_xxt_setup(*n,(const ulong*)id,
62 *nz,(const uint*)Ai,(const uint*)Aj,A,
63 *null_space,&c); break;
64 case 1: handle_array[handle_n]=ccrs_amg_setup(*n,(const ulong*)id,
65 *nz,(const uint*)Ai,(const uint*)Aj,A,
66 *null_space,&c,
67 datafname,ierr); break;
68 case 2: handle_array[handle_n]=ccrs_hypre_setup(*n,(const ulong*)id,
69 *nz,(const uint*)Ai,(const uint*)Aj,A,
70 *null_space,&c,param); break;
71 }
72
73 comm_free(&c);
74 *handle = handle_n++;
75}
76
77void fcrs_solve(const sint *handle, double x[], double b[])
78{
79 CHECK_HANDLE("crs_solve");
80 switch(sid_array[*handle]) {
81 case 0: ccrs_xxt_solve(x,handle_array[*handle],b); break;
82 case 1: ccrs_amg_solve(x,handle_array[*handle],b); break;
83 case 2: ccrs_hypre_solve(x,handle_array[*handle],b); break;
84 }
85}
86
87void fcrs_free(sint *handle)
88{
89 CHECK_HANDLE("crs_free");
90 switch(sid_array[*handle]) {
91 case 0: ccrs_xxt_free(handle_array[*handle]); break;
92 case 1: ccrs_amg_free(handle_array[*handle]); break;
93 case 2: ccrs_hypre_free(handle_array[*handle]); break;
94 }
95 handle_array[*handle] = 0;
96}
Note: See TracBrowser for help on using the repository browser.