Skip to content

Commit

Permalink
Merge pull request #122 from tawhai/generalised_surface_fitting
Browse files Browse the repository at this point in the history
Generalised surface fitting
  • Loading branch information
tawhai authored Sep 1, 2022
2 parents 44b992a + 336041d commit f69e4ff
Show file tree
Hide file tree
Showing 28 changed files with 1,806 additions and 1,176 deletions.
3 changes: 3 additions & 0 deletions src/bindings/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(C_FORTRAN_LIB_SRCS
imports.f90
pressure_resistance_flow.f90
species_transport.f90
surface_fitting.f90
utils.f90
ventilation.f90
wave_transmission.f90
Expand All @@ -34,6 +35,7 @@ set(C_C_LIB_SRCS
imports.c
pressure_resistance_flow.c
species_transport.c
surface_fitting.c
utils.c
ventilation.c
wave_transmission.c
Expand All @@ -54,6 +56,7 @@ set(C_LIB_HDRS
imports.h
pressure_resistance_flow.h
species_transport.h
surface_fitting.h
utils.h
ventilation.h
wave_transmission.h
Expand Down
3 changes: 3 additions & 0 deletions src/bindings/c/arrays.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

#include "arrays.h"
#include "string.h"

void set_node_field_value_c(int *row, int *col, double *value);

void set_node_field_value(int row, int col, double value)
{
set_node_field_value_c(&row, &col, &value);
}


1 change: 1 addition & 0 deletions src/bindings/c/arrays.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ subroutine set_node_field_value_c(row, col, value) bind(C, name="set_node_field_

end subroutine set_node_field_value_c



end module arrays_c
66 changes: 48 additions & 18 deletions src/bindings/c/exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,54 @@

#include <string.h>

void export_cubic_lagrange_2d_c(const char *EXFILE, int *exfile_len,
const char *group_name, int *group_name_len);
void export_1d_elem_field_c(int *ne_field, const char *EXELEMFILE, int *EXELEMFILE_LEN,
const char *group_name, int *group_name_len, const char *field_name, int *field_name_len );
void export_1d_elem_geometry_c(const char *EXELEMFILE, int *EXELEMFILE_LEN, const char *name, int *name_len);
void export_elem_geometry_2d_c(const char *EXELEMFILE, int *EXELEMFILE_LEN, const char *name, int *name_len, int *offset_elem, int *offset_node);
const char *group_name, int *group_name_len,
const char *field_name, int *field_name_len );
void export_1d_elem_geometry_c(const char *EXELEMFILE, int *EXELEMFILE_LEN,
const char *name, int *name_len);
void export_elem_geometry_2d_c(const char *EXELEMFILE, int *EXELEMFILE_LEN,
const char *name, int *name_len, int *offset_elem, int *offset_node);
void export_node_field_c(int *nj_field, const char *EXNODEFIELD, int *EXNODEFIELD_LEN,
const char *name, int *name_len, const char *field_name, int *field_name_len);
void export_elem_geometry_2d_c(const char *EXELEMFILE, int *EXELEMFILE_LEN, const char *name, int *name_len, int *offset_elem, int *offset_node);
void export_terminal_solution_c(const char *EXNODEFILE, int *EXNODEFILE_LEN, const char *name, int *name_len);
void export_terminal_perfusion_c(const char *EXNODEFILE, int *EXNODEFILE_LEN, const char *name, int *name_len);
void export_node_geometry_c(const char *EXNODEFILE, int *EXNODEFILE_LEN, const char *name, int *name_len);
void export_node_geometry_2d_c(const char *EXNODEFILE, int *EXNODEFILE_LEN, const char *name, int *name_len, int *offset);
void export_data_geometry_c(const char *EXDATAFILE, int *EXDATAFILE_LEN, const char *name, int *name_len, int *offset);
void export_elem_geometry_2d_c(const char *EXELEMFILE, int *EXELEMFILE_LEN,
const char *name, int *name_len, int *offset_elem, int *offset_node);
void export_terminal_solution_c(const char *EXNODEFILE, int *EXNODEFILE_LEN,
const char *name, int *name_len);
void export_terminal_perfusion_c(const char *EXNODEFILE, int *EXNODEFILE_LEN,
const char *name, int *name_len);
void export_node_geometry_c(const char *EXNODEFILE, int *EXNODEFILE_LEN,
const char *name, int *name_len);
void export_node_geometry_2d_c(const char *EXNODEFILE, int *EXNODEFILE_LEN,
const char *name, int *name_len, int *offset);
void export_data_geometry_c(const char *EXDATAFILE, int *EXDATAFILE_LEN,
const char *name, int *name_len, int *offset);
void export_elem_field_c(const char *EXELEMFIELD, int *EXELEMFIELD_LEN,
const char *name, int *name_len, const char *field_name, int *field_name_len);
void export_terminal_ssgexch_c(const char *EXNODEFILE, int *filename_len, const char *name, int *name_len);
const char *name, int *name_len, const char *field_name,
int *field_name_len);
void export_terminal_ssgexch_c(const char *EXNODEFILE, int *filename_len,
const char *name, int *name_len);



void export_cubic_lagrange_2d(const char *EXFILE, const char *group_name)
{
int filename_len = strlen(EXFILE);
int group_name_len = strlen(group_name);

export_cubic_lagrange_2d_c(EXFILE, &filename_len, group_name, &group_name_len);
}

void export_1d_elem_field(int ne_field, const char *EXELEMFILE, const char *group_name, const char *field_name )
void export_1d_elem_field(int ne_field, const char *EXELEMFILE,
const char *group_name, const char *field_name )
{
int filename_len = strlen(EXELEMFILE);
int group_name_len = strlen(group_name);
int field_name_len = strlen(field_name);

export_1d_elem_field_c(&ne_field, EXELEMFILE, &filename_len, group_name, &group_name_len, field_name, &field_name_len);
export_1d_elem_field_c(&ne_field, EXELEMFILE, &filename_len, group_name,
&group_name_len, field_name, &field_name_len);
}

void export_1d_elem_geometry(const char *EXELEMFILE, const char *name)
Expand All @@ -37,21 +62,25 @@ void export_1d_elem_geometry(const char *EXELEMFILE, const char *name)
export_1d_elem_geometry_c(EXELEMFILE, &filename_len, name, &name_len);
}

void export_elem_geometry_2d(const char *EXELEMFILE, const char *name, int offset_elem, int offset_node)
void export_elem_geometry_2d(const char *EXELEMFILE, const char *name,
int offset_elem, int offset_node)
{
int filename_len = strlen(EXELEMFILE);
int name_len = strlen(name);

export_elem_geometry_2d_c(EXELEMFILE, &filename_len, name, &name_len, &offset_elem, &offset_node);
export_elem_geometry_2d_c(EXELEMFILE, &filename_len, name, &name_len,
&offset_elem, &offset_node);
}

void export_node_field(int nj_field, const char *EXNODEFIELD, const char *name, const char *field_name)
void export_node_field(int nj_field, const char *EXNODEFIELD,
const char *name, const char *field_name)
{
int filename_len = strlen(EXNODEFIELD);
int name_len = strlen(name);
int field_name_len = strlen(field_name);

export_node_field_c(&nj_field, EXNODEFIELD, &filename_len, name, &name_len, field_name, &field_name_len);
export_node_field_c(&nj_field, EXNODEFIELD, &filename_len, name,
&name_len, field_name, &field_name_len);
}

void export_terminal_solution(const char *EXNODEFILE, const char *name)
Expand Down Expand Up @@ -108,6 +137,7 @@ void export_elem_field(const char *EXELEMFIELD, const char *name, const char *fi
int name_len = strlen(name);
int field_name_len = strlen(field_name);

export_elem_field_c(EXELEMFIELD, &filename_len, name, &name_len, field_name, &field_name_len);
export_elem_field_c(EXELEMFIELD, &filename_len, name, &name_len,
field_name, &field_name_len);
}

24 changes: 24 additions & 0 deletions src/bindings/c/exports.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ module exports_c
private

contains


!!!################################################################

subroutine export_cubic_lagrange_2d_c(EXFILE, filename_len, group_name, group_name_len) &
bind(C, name="export_cubic_lagrange_2d_c")

use iso_c_binding, only: c_ptr
use utils_c, only: strncpy
use exports, only: export_cubic_lagrange_2d
use other_consts, only: MAX_STRING_LEN, MAX_FILENAME_LEN
implicit none
integer,intent(in) :: filename_len, group_name_len
type(c_ptr), value, intent(in) :: EXFILE, group_name
character(len=MAX_FILENAME_LEN) :: filename_f
character(len=MAX_STRING_LEN) :: group_name_f

call strncpy(filename_f, EXFILE, filename_len)
call strncpy(group_name_f, group_name, group_name_len)

call export_cubic_lagrange_2d(filename_f, group_name_f)

end subroutine export_cubic_lagrange_2d_c

!!!################################################################

subroutine export_1d_elem_field_c(ne_field, EXELEMFILE, filename_len, group_name, group_name_len, field_name, field_name_len) &
Expand Down
1 change: 1 addition & 0 deletions src/bindings/c/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "symbol_export.h"

SHO_PUBLIC void export_cubic_lagrange_2d(const char *EXFILE, const char *group_name);
SHO_PUBLIC void export_1d_elem_field(int ne_field, const char *EXELEMFILE, const char *group_name, const char *field_name );
SHO_PUBLIC void export_1d_elem_geometry(const char *EXELEMFILE, const char *name);
SHO_PUBLIC void export_elem_geometry_2d(const char *EXELEMFILE, const char *name, int offset_elem, int offset_node);
Expand Down
2 changes: 0 additions & 2 deletions src/bindings/c/gas_exchange.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "gas_exchange.h"

void steadystate_gasexchange_c(double *c_art_o2, double *c_ven_o2,
Expand All @@ -11,4 +10,3 @@ void steadystate_gasexchange(double *c_art_o2, double *c_ven_o2,
{
steadystate_gasexchange_c(c_art_o2, c_ven_o2, p_art_co2, p_art_o2, p_i_o2, p_ven_co2, p_ven_o2, shunt_fraction, VCO2, VO2);
}

18 changes: 9 additions & 9 deletions src/bindings/c/gas_exchange.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module gas_exchange_c
implicit none
private

contains
!!!######################################################################
subroutine steadystate_gasexchange_c(c_art_o2,c_ven_o2,&
Expand All @@ -10,18 +10,18 @@ subroutine steadystate_gasexchange_c(c_art_o2,c_ven_o2,&
use gas_exchange, only: steadystate_gasexchange
use arrays,only: dp
implicit none

!!! Parameter List
real(dp),intent(in) :: p_i_o2,shunt_fraction,VCO2,VO2
real(dp), intent(inout) :: c_art_o2,c_ven_o2,p_art_co2,p_art_o2,p_ven_o2,p_ven_co2

call steadystate_gasexchange(c_art_o2,c_ven_o2,&
p_art_co2,p_art_o2,p_i_o2,p_ven_co2,p_ven_o2,shunt_fraction,&
VCO2,VO2)

p_art_co2,p_art_o2,p_i_o2,p_ven_co2,p_ven_o2,shunt_fraction,&
VCO2,VO2)
end subroutine steadystate_gasexchange_c



end module gas_exchange_c

13 changes: 7 additions & 6 deletions src/bindings/c/geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void define_mesh_geometry_test_c(void);
void define_node_geometry_c(const char *NODEFILE, int *filename_len);
void define_node_geometry_2d_c(const char *NODEFILE, int *filename_len);
void define_data_geometry_c(const char *DATAFILE, int *filename_len);
void import_node_geometry_2d_c(const char *NODEFILE, int *filename_len);
extern void make_data_grid_c(int *elemlist_len, int elemlist[], double *offset, double *spacing, const char *filename, int *filename_len, const char *groupname, int *groupname_len);
extern void make_2d_vessel_from_1d_c(int *elemlist_len, int elemlist[]);
void define_rad_from_file_c(const char *FIELDFILE, int *filename_len, const char *radius_type, int *radius_type_len);
Expand All @@ -21,7 +22,6 @@ void define_rad_from_geom_c(const char *order_system, int *order_system_len, dou
const char *group_type, int *group_type_len, const char *group_options, int *group_options_len);
void element_connectivity_1d_c(void);
void evaluate_ordering_c(void);
void set_initial_volume_c(int *Gdirn, double *COV, double *total_volume, double *Rmax, double *Rmin);
void volume_of_mesh_c(double *volume_model, double *volume_tree);
void write_elem_geometry_2d_c(const char *ELEMFILE, int *filename_len);
void write_geo_file_c(int *ntype, const char *GEOFILE, int *filename_len);
Expand Down Expand Up @@ -79,6 +79,12 @@ void define_data_geometry(const char *DATAFILE)
define_data_geometry_c(DATAFILE, &filename_len);
}

void import_node_geometry_2d(const char *NODEFILE)
{
int filename_len = (int)strlen(NODEFILE);
import_node_geometry_2d_c(NODEFILE, &filename_len);
}

void make_data_grid(int elemlist_len, int elemlist[], double offset, double spacing, const char *filename, const char *groupname)
{
int filename_len = (int)strlen(filename);
Expand Down Expand Up @@ -127,11 +133,6 @@ void evaluate_ordering()
evaluate_ordering_c();
}

void set_initial_volume(int Gdirn, double COV, double total_volume, double Rmax, double Rmin)
{
set_initial_volume_c(&Gdirn, &COV, &total_volume, &Rmax, &Rmin);
}

void volume_of_mesh(double *volume_model, double *volume_tree)
{
volume_of_mesh_c(volume_model, volume_tree);
Expand Down
40 changes: 21 additions & 19 deletions src/bindings/c/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ subroutine define_node_geometry_c(NODEFILE, filename_len) bind(C, name="define_n

end subroutine define_node_geometry_c

!
!###################################################################################
!
subroutine import_node_geometry_2d_c(NODEFILE, filename_len) bind(C, name="import_node_geometry_2d_c")

use iso_c_binding, only: c_ptr
use utils_c, only: strncpy
use other_consts, only: MAX_FILENAME_LEN
use geometry, only: import_node_geometry_2d
implicit none

integer,intent(in) :: filename_len
type(c_ptr), value, intent(in) :: NODEFILE
character(len=MAX_FILENAME_LEN) :: filename_f

call strncpy(filename_f, NODEFILE, filename_len)

call import_node_geometry_2d(filename_f)

end subroutine import_node_geometry_2d_c

!
!###################################################################################
!
Expand Down Expand Up @@ -285,25 +306,6 @@ subroutine evaluate_ordering_c() bind(C, name="evaluate_ordering_c")

end subroutine evaluate_ordering_c

!###################################################################################
!
!>*set_initial_volume:* assigns a volume to terminal units appended on a tree structure
!>based on an assumption of a linear gradient in the gravitational direction with max
!> min and COV values defined.
subroutine set_initial_volume_c(Gdirn, COV, total_volume, Rmax, Rmin) bind(C, name="set_initial_volume_c")

use geometry, only: set_initial_volume
use arrays, only: dp
implicit none

! Parameter List
integer,intent(in) :: Gdirn
real(dp),intent(in) :: COV, total_volume, Rmax, Rmin

call set_initial_volume(Gdirn, COV, total_volume, Rmax, Rmin)

end subroutine set_initial_volume_c

!
!###################################################################################
!
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/c/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SHO_PUBLIC void define_mesh_geometry_test();
SHO_PUBLIC void define_node_geometry(const char *NODEFILE);
SHO_PUBLIC void define_node_geometry_2d(const char *NODEFILE);
SHO_PUBLIC void define_data_geometry(const char *DATAFILE);
SHO_PUBLIC void import_node_geometry_2d(const char *NODEFILE);
SHO_PUBLIC void make_data_grid(int elemlist_len, int elemlist[], double offset, double spacing, const char *filename, const char *groupname);
SHO_PUBLIC void make_2d_vessel_from_1d(int elemlist_len, int elemlist[]);
SHO_PUBLIC void define_rad_from_file(const char *FIELDFILE, const char *radius_type);
Expand All @@ -21,7 +22,6 @@ SHO_PUBLIC void define_rad_from_geom(const char *ORDER_SYSTEM, double CONTROL_PA
double START_RAD, const char *GROUP_TYPE, const char *GROUP_OPTIONS);
SHO_PUBLIC void element_connectivity_1d();
SHO_PUBLIC void evaluate_ordering();
SHO_PUBLIC void set_initial_volume(int Gdirn, double COV, double total_volume, double Rmax, double Rmin);
SHO_PUBLIC void volume_of_mesh(double *volume_model, double *volume_tree);
SHO_PUBLIC void write_elem_geometry_2d(const char *ELEMFILE);
SHO_PUBLIC void write_geo_file(int ntype, const char *GEOFILE);
Expand Down
6 changes: 5 additions & 1 deletion src/bindings/c/surface_fitting.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
#include "string.h"

void fit_surface_geometry_c(int *niterations,const char *fitting_file,int *fitting_file_len);

void initialise_fit_mesh_c(void);

void fit_surface_geometry(int niterations,const char *fitting_file)
{
int filename_len = strlen(fitting_file);
fit_surface_geometry_c(&niterations, fitting_file, &filename_len);
}

void initialise_fit_mesh()
{
initialise_fit_mesh_c();
}

11 changes: 10 additions & 1 deletion src/bindings/c/surface_fitting.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module surface_fitting_c
subroutine fit_surface_geometry_c(niterations, fitting_file, filename_len) &
bind(C, name="fit_surface_geometry_c")

use iso_c_binding, only: c_ptr
use iso_c_binding, only: c_ptr
use utils_c, only: strncpy
use other_consts, only: MAX_STRING_LEN, MAX_FILENAME_LEN
use surface_fitting, only: fit_surface_geometry
Expand All @@ -27,4 +27,13 @@ end subroutine fit_surface_geometry_c

!!!############################################################################

subroutine initialise_fit_mesh_c() bind(C, name="initialise_fit_mesh_c")
use surface_fitting, only: initialise_fit_mesh
implicit none

call initialise_fit_mesh

end subroutine initialise_fit_mesh_c

!!!############################################################################
end module surface_fitting_c
1 change: 1 addition & 0 deletions src/bindings/c/surface_fitting.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include "symbol_export.h"

SHO_PUBLIC void fit_surface_geometry(int niterations, const char *fitting_file);
SHO_PUBLIC void initialise_fit_mesh();

#endif /* AETHER_SURFACE_FITTING_H */
Loading

0 comments on commit f69e4ff

Please sign in to comment.