Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/api/t8_fortran_interface/t8_fortran_interface.h
504 views
1
/*
2
This file is part of t8code.
3
t8code is a C library to manage a collection (a forest) of multiple
4
connected adaptive space-trees of general element classes in parallel.
5
6
Copyright (C) 2025 the developers
7
8
t8code is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
t8code is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with t8code; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
*/
22
23
/** \file t8_fortran_interface.h
24
* In this file we provide a basic Fortran interface
25
* for some functions of t8code.
26
* Mostly, the C functions here are wrappers around more complex
27
* t8code function.
28
* We only export a minimum of the actual t8code functionality
29
* to Fortran.
30
*/
31
32
#ifndef T8_FORTRAN_INTERFACE_H
33
#define T8_FORTRAN_INTERFACE_H
34
35
#include <t8.h>
36
#include <t8_cmesh.h>
37
#include <t8_forest/t8_forest_general.h>
38
#include <t8_forest/t8_forest_geometrical.h>
39
40
typedef int (*t8_fortran_adapt_coordinate_callback) (double x, double y, double z, int is_family);
41
42
/* A fallback type if t8code is not built with MPI */
43
typedef
44
#if T8_ENABLE_MPI
45
MPI_Fint
46
#else
47
int
48
#endif
49
MPI_T8_Fint;
50
51
T8_EXTERN_C_BEGIN ();
52
53
/** Initialize sc and t8code with SC_MPI_COMM_WORLD communicator
54
* and SC_LP_DEFAULT logging.
55
* This call is equivalent to
56
* sc_init (comm, 1, 1, NULL, SC_LP_ESSENTIAL);
57
* t8_init (SC_LP_DEFAULT);
58
* \param [in] comm The MPI communicator to use.
59
*/
60
void
61
t8_fortran_init_all (sc_MPI_Comm *comm);
62
63
/** Finalize sc. This wraps sc_finalize in order to have consistent
64
* naming with t8_fortran_init_all.
65
*/
66
void
67
t8_fortran_finalize ();
68
69
/** Commit cmesh. This wraps cmesh_commit in order to use the dereferenced communicator.
70
* \param [in, out] cmesh Cmesh to commit
71
* \param [in] Ccomm Pointer to a C MPI communicator.
72
*/
73
void
74
t8_fortran_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm *comm);
75
76
/** This function calls t8_cmesh_set_join_by_stash with connectivity = NULL.
77
* \param[in,out] cmesh Pointer to a t8code cmesh object. If set to NULL this argument is ignored.
78
* \param[in] do_both_directions Compute the connectivity from both neighboring sides.
79
* Takes much longer to compute.
80
*
81
* \warning This routine might be too expensive for very large meshes. In this case,
82
* consider to use a fully featured mesh generator.
83
*
84
* \note This routine does not detect periodic boundaries.
85
*/
86
void
87
t8_fortran_cmesh_set_join_by_stash_noConn (t8_cmesh_t cmesh, const int do_both_directions);
88
89
/** Translate a fortran MPI communicator into a C MPI communicator
90
* and return a pointer to it.
91
* \param [in] Fcomm Fortran MPI Communicator
92
* \return Pointer to the corresponding C MPI communicator.
93
* \note This function allocated memory for the new C MPI communicator.
94
* Call \ref t8_fortran_MPI_Comm_delete to free this memory.
95
* \note t8code needs to be configured with MPI support to be able to use
96
* this function.
97
*/
98
sc_MPI_Comm *
99
t8_fortran_MPI_Comm_new (MPI_T8_Fint Fcomm);
100
101
/** Free the memory of a C MPI Communicator pointer that was created
102
* with \ref t8_fortran_MPI_Comm_new.
103
* \param [in] Ccomm Pointer to a C MPI communicator.
104
*/
105
void
106
t8_fortran_MPI_Comm_delete (sc_MPI_Comm *Ccomm);
107
108
/** Wraps t8_cmesh_new_periodic_tri, passing the MPI communicator as pointer instead of by value
109
* \param [in] Ccomm Pointer to a C MPI communicator.
110
* \param [out] Example cmesh
111
*/
112
t8_cmesh_t
113
t8_cmesh_new_periodic_tri_wrap (sc_MPI_Comm *Ccomm);
114
115
/** Wraps \ref t8_forest_new_uniform with the default scheme as scheme
116
* and passes MPI communicator as pointer instead of by value.
117
* Build a uniformly refined forest on a coarse mesh.
118
* \param [in] cmesh A coarse mesh.
119
* \param [in] level An initial uniform refinement level.
120
* \param [in] do_face_ghost If true, a layer of ghost elements is created for the forest.
121
* \param [in] comm MPI communicator to use.
122
* \return A uniform forest with coarse mesh \a cmesh, eclass_scheme
123
* \a scheme and refinement level \a level.
124
*/
125
t8_forest_t
126
t8_forest_new_uniform_default (t8_cmesh_t cmesh, int level, int do_face_ghost, sc_MPI_Comm *comm);
127
128
/**
129
* \param [in, out] forest The forest
130
* \param [in] recursive A flag specifying whether adaptation is to be done recursively
131
* or not. If the value is zero, adaptation is not recursive
132
* and it is recursive otherwise.
133
* \param [in] callback A pointer to a user defined function. t8code will never touch the function.
134
*/
135
t8_forest_t
136
t8_forest_adapt_by_coordinates (t8_forest_t forest, int recursive, t8_fortran_adapt_coordinate_callback callback);
137
138
/** Log a message on the root rank with priority SC_LP_PRODUCTION.
139
* \param [in] string String to log.
140
*/
141
void
142
t8_global_productionf_noargs (const char *string);
143
144
T8_EXTERN_C_END ();
145
146
#endif /* !T8_FORTRAN_INTERFACE_H */
147
148