Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalised surface fitting #122

Merged
merged 28 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b4f5066
reducing the dimension of 'arclength' array and removing 'parentlist'…
May 11, 2021
428f305
new subroutine 'import_node_geometry_2d' and its bindings
May 11, 2021
5472ae5
surface fitting including python bindings. Includes subroutines to ad…
May 12, 2021
bca1757
subroutines to refine 1d tree, and reorder a refined tree to be seque…
Jun 21, 2021
bab75ab
bindings for specifying file, branch type, and refinement for add_mesh'
Jul 16, 2021
bf69622
removed write statement in add_mesh
Jul 16, 2021
9113eb6
starting to move ventilation parameters out of files
Jul 18, 2021
a2606db
setting up default parameters for ventilation model
Jul 18, 2021
711a720
removing the chest wall compliance from tissue compliance calculation
Jul 18, 2021
49b0548
writing ventilation output to file
Jul 18, 2021
41e61ce
muscle pressure functions for passive expiration
Jul 20, 2021
a606193
in refine_1d_elements, included call to renumber_tree_in_order so tha…
Aug 19, 2021
e1345dd
bindings for initial_gasexchange and steadystate_gasexchange, and rep…
Aug 19, 2021
f10f2de
bindings and updates to make gas transfer work
Aug 22, 2021
69dcc5a
export option for 2d cubic hermite mesh; change in method for setting…
Sep 2, 2021
03046ab
Merge branch 'develop' into unit_ventilation
tawhai Aug 14, 2022
39065f6
Merge pull request #127 from tawhai/unit_ventilation
tawhai Aug 14, 2022
c03d972
Merge branch 'develop' into generalised_surface_fitting
tawhai Aug 15, 2022
247cbbd
removing WIN32 from bindings
Aug 18, 2022
9252505
removed changes to gas_exchange.* in bindings. removed all changes to…
Aug 18, 2022
db6d91d
removed changes to add_mesh from bindings and lib
Aug 18, 2022
0a3934c
removed refine_1d_elements and renumber_tree_in_order from bindings a…
Aug 18, 2022
7ba445b
removing default arrays for defining parameters from arrays.f90 and u…
Aug 19, 2022
79e4f20
removed DEC$ ATTRIBUTES from export_cubic_lagrange_2d
Aug 19, 2022
2f639c2
removed all changes in ventilation.f90 and bindings. removed initiali…
Aug 19, 2022
68e8888
removing changes to capillaryflow, wave_transmission, pressure_resist…
Aug 19, 2022
c29ddc4
removing DEC$ ATTRIBUTEs from surface_fitting
Aug 19, 2022
336041d
fix to line_segments_for_2d_mesh to use local node index referencing …
Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 21 additions & 23 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 All @@ -152,11 +173,7 @@ subroutine make_data_grid_c(surface_elems_len, surface_elems, offset, spacing, &
call strncpy(filename_f, filename, filename_len)
call strncpy(groupname_f, groupname, groupname_len)

#if defined _WIN32 && defined __INTEL_COMPILER
call so_make_data_grid(surface_elems, offset, spacing, filename_f, groupname_f)
#else
call make_data_grid(surface_elems, offset, spacing, filename_f, groupname_f)
#endif

end subroutine make_data_grid_c

Expand Down Expand Up @@ -289,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
5 changes: 0 additions & 5 deletions src/bindings/c/growtree.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ subroutine grow_tree_c(surface_elems_len, surface_elems, parent_ne, &
real(dp),intent(in) :: shortest_length
real(dp),intent(in) :: rotation_limit

#if defined _WIN32 && defined __INTEL_COMPILER
call so_grow_tree(surface_elems, parent_ne, angle_max, angle_min, branch_fraction, length_limit,&
shortest_length, rotation_limit)
#else
call grow_tree(surface_elems, parent_ne, angle_max, angle_min, branch_fraction, length_limit,&
shortest_length, rotation_limit)
#endif

end subroutine grow_tree_c

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();
}

Loading