Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
e7c3a325
Commit
e7c3a325
authored
6 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Add the ability to have i/o conversion functions for star particles as well.
parent
e565c542
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common_io.c
+40
-0
40 additions, 0 deletions
src/common_io.c
src/io_properties.h
+119
-2
119 additions, 2 deletions
src/io_properties.h
with
159 additions
and
2 deletions
src/common_io.c
+
40
−
0
View file @
e7c3a325
...
@@ -522,6 +522,46 @@ void io_convert_gpart_d_mapper(void* restrict temp, int N,
...
@@ -522,6 +522,46 @@ void io_convert_gpart_d_mapper(void* restrict temp, int N,
props
.
convert_gpart_d
(
e
,
gparts
+
delta
+
i
,
&
temp_d
[
i
*
dim
]);
props
.
convert_gpart_d
(
e
,
gparts
+
delta
+
i
,
&
temp_d
[
i
*
dim
]);
}
}
/**
* @brief Mapper function to copy #spart into a buffer of floats using a
* conversion function.
*/
void
io_convert_spart_f_mapper
(
void
*
restrict
temp
,
int
N
,
void
*
restrict
extra_data
)
{
const
struct
io_props
props
=
*
((
const
struct
io_props
*
)
extra_data
);
const
struct
spart
*
restrict
sparts
=
props
.
sparts
;
const
struct
engine
*
e
=
props
.
e
;
const
size_t
dim
=
props
.
dimension
;
/* How far are we with this chunk? */
float
*
restrict
temp_f
=
(
float
*
)
temp
;
const
ptrdiff_t
delta
=
(
temp_f
-
props
.
start_temp_f
)
/
dim
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
props
.
convert_spart_f
(
e
,
sparts
+
delta
+
i
,
&
temp_f
[
i
*
dim
]);
}
/**
* @brief Mapper function to copy #spart into a buffer of doubles using a
* conversion function.
*/
void
io_convert_spart_d_mapper
(
void
*
restrict
temp
,
int
N
,
void
*
restrict
extra_data
)
{
const
struct
io_props
props
=
*
((
const
struct
io_props
*
)
extra_data
);
const
struct
spart
*
restrict
sparts
=
props
.
sparts
;
const
struct
engine
*
e
=
props
.
e
;
const
size_t
dim
=
props
.
dimension
;
/* How far are we with this chunk? */
double
*
restrict
temp_d
=
(
double
*
)
temp
;
const
ptrdiff_t
delta
=
(
temp_d
-
props
.
start_temp_d
)
/
dim
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
props
.
convert_spart_d
(
e
,
sparts
+
delta
+
i
,
&
temp_d
[
i
*
dim
]);
}
/**
/**
* @brief Copy the particle data into a temporary buffer ready for i/o.
* @brief Copy the particle data into a temporary buffer ready for i/o.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/io_properties.h
+
119
−
2
View file @
e7c3a325
...
@@ -47,6 +47,10 @@ typedef void (*conversion_func_gpart_float)(const struct engine*,
...
@@ -47,6 +47,10 @@ typedef void (*conversion_func_gpart_float)(const struct engine*,
const
struct
gpart
*
,
float
*
);
const
struct
gpart
*
,
float
*
);
typedef
void
(
*
conversion_func_gpart_double
)(
const
struct
engine
*
,
typedef
void
(
*
conversion_func_gpart_double
)(
const
struct
engine
*
,
const
struct
gpart
*
,
double
*
);
const
struct
gpart
*
,
double
*
);
typedef
void
(
*
conversion_func_spart_float
)(
const
struct
engine
*
,
const
struct
spart
*
,
float
*
);
typedef
void
(
*
conversion_func_spart_double
)(
const
struct
engine
*
,
const
struct
spart
*
,
double
*
);
/**
/**
* @brief The properties of a given dataset for i/o
* @brief The properties of a given dataset for i/o
...
@@ -86,6 +90,7 @@ struct io_props {
...
@@ -86,6 +90,7 @@ struct io_props {
const
struct
part
*
parts
;
const
struct
part
*
parts
;
const
struct
xpart
*
xparts
;
const
struct
xpart
*
xparts
;
const
struct
gpart
*
gparts
;
const
struct
gpart
*
gparts
;
const
struct
spart
*
sparts
;
/* Are we converting? */
/* Are we converting? */
int
conversion
;
int
conversion
;
...
@@ -97,6 +102,10 @@ struct io_props {
...
@@ -97,6 +102,10 @@ struct io_props {
/* Conversion function for gpart */
/* Conversion function for gpart */
conversion_func_gpart_float
convert_gpart_f
;
conversion_func_gpart_float
convert_gpart_f
;
conversion_func_gpart_double
convert_gpart_d
;
conversion_func_gpart_double
convert_gpart_d
;
/* Conversion function for spart */
conversion_func_spart_float
convert_spart_f
;
conversion_func_spart_double
convert_spart_d
;
};
};
/**
/**
...
@@ -134,11 +143,14 @@ INLINE static struct io_props io_make_input_field_(
...
@@ -134,11 +143,14 @@ INLINE static struct io_props io_make_input_field_(
r
.
parts
=
NULL
;
r
.
parts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
NULL
;
r
.
conversion
=
0
;
r
.
conversion
=
0
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
return
r
;
}
}
...
@@ -175,11 +187,14 @@ INLINE static struct io_props io_make_output_field_(
...
@@ -175,11 +187,14 @@ INLINE static struct io_props io_make_output_field_(
r
.
partSize
=
partSize
;
r
.
partSize
=
partSize
;
r
.
parts
=
NULL
;
r
.
parts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
NULL
;
r
.
conversion
=
0
;
r
.
conversion
=
0
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
return
r
;
}
}
...
@@ -223,11 +238,14 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT(
...
@@ -223,11 +238,14 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT(
r
.
parts
=
parts
;
r
.
parts
=
parts
;
r
.
xparts
=
xparts
;
r
.
xparts
=
xparts
;
r
.
gparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
NULL
;
r
.
conversion
=
1
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
functionPtr
;
r
.
convert_part_f
=
functionPtr
;
r
.
convert_part_d
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
return
r
;
}
}
...
@@ -242,7 +260,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT(
...
@@ -242,7 +260,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT(
* @param partSize The size in byte of the particle
* @param partSize The size in byte of the particle
* @param parts The particle array
* @param parts The particle array
* @param xparts The xparticle array
* @param xparts The xparticle array
* @param functionPtr The function used to convert a particle to a
float
* @param functionPtr The function used to convert a particle to a
double
*
*
* Do not call this function directly. Use the macro defined above.
* Do not call this function directly. Use the macro defined above.
*/
*/
...
@@ -263,11 +281,14 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE(
...
@@ -263,11 +281,14 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE(
r
.
parts
=
parts
;
r
.
parts
=
parts
;
r
.
xparts
=
xparts
;
r
.
xparts
=
xparts
;
r
.
gparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
NULL
;
r
.
conversion
=
1
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
functionPtr
;
r
.
convert_part_d
=
functionPtr
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
return
r
;
}
}
...
@@ -309,11 +330,14 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT(
...
@@ -309,11 +330,14 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT(
r
.
parts
=
NULL
;
r
.
parts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
gparts
=
gparts
;
r
.
gparts
=
gparts
;
r
.
sparts
=
NULL
;
r
.
conversion
=
1
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
functionPtr
;
r
.
convert_gpart_f
=
functionPtr
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
return
r
;
}
}
...
@@ -327,7 +351,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT(
...
@@ -327,7 +351,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT(
* @param units The units of the dataset
* @param units The units of the dataset
* @param gpartSize The size in byte of the particle
* @param gpartSize The size in byte of the particle
* @param gparts The particle array
* @param gparts The particle array
* @param functionPtr The function used to convert a g-particle to a
float
* @param functionPtr The function used to convert a g-particle to a
double
*
*
* Do not call this function directly. Use the macro defined above.
* Do not call this function directly. Use the macro defined above.
*/
*/
...
@@ -347,11 +371,104 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE(
...
@@ -347,11 +371,104 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE(
r
.
parts
=
NULL
;
r
.
parts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
gparts
=
gparts
;
r
.
gparts
=
gparts
;
r
.
sparts
=
NULL
;
r
.
conversion
=
1
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
functionPtr
;
r
.
convert_gpart_d
=
functionPtr
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
NULL
;
return
r
;
}
/**
* @brief Constructs an #io_props (with conversion) from its parameters
*/
#define io_make_output_field_convert_spart(name, type, dim, units, spart, \
convert) \
io_make_output_field_convert_spart_##type(name, type, dim, units, \
sizeof(spart[0]), spart, convert)
/**
* @brief Construct an #io_props from its parameters
*
* @param name Name of the field to read
* @param type The type of the data
* @param dimension Dataset dimension (1D, 3D, ...)
* @param units The units of the dataset
* @param spartSize The size in byte of the particle
* @param sparts The particle array
* @param functionPtr The function used to convert a g-particle to a float
*
* Do not call this function directly. Use the macro defined above.
*/
INLINE
static
struct
io_props
io_make_output_field_convert_spart_FLOAT
(
const
char
name
[
FIELD_BUFFER_SIZE
],
enum
IO_DATA_TYPE
type
,
int
dimension
,
enum
unit_conversion_factor
units
,
size_t
spartSize
,
const
struct
spart
*
sparts
,
conversion_func_spart_float
functionPtr
)
{
struct
io_props
r
;
strcpy
(
r
.
name
,
name
);
r
.
type
=
type
;
r
.
dimension
=
dimension
;
r
.
importance
=
UNUSED
;
r
.
units
=
units
;
r
.
field
=
NULL
;
r
.
partSize
=
spartSize
;
r
.
parts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
sparts
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
functionPtr
;
r
.
convert_spart_d
=
NULL
;
return
r
;
}
/**
* @brief Construct an #io_props from its parameters
*
* @param name Name of the field to read
* @param type The type of the data
* @param dimension Dataset dimension (1D, 3D, ...)
* @param units The units of the dataset
* @param spartSize The size in byte of the particle
* @param sparts The particle array
* @param functionPtr The function used to convert a s-particle to a double
*
* Do not call this function directly. Use the macro defined above.
*/
INLINE
static
struct
io_props
io_make_output_field_convert_spart_DOUBLE
(
const
char
name
[
FIELD_BUFFER_SIZE
],
enum
IO_DATA_TYPE
type
,
int
dimension
,
enum
unit_conversion_factor
units
,
size_t
spartSize
,
const
struct
spart
*
sparts
,
conversion_func_spart_double
functionPtr
)
{
struct
io_props
r
;
strcpy
(
r
.
name
,
name
);
r
.
type
=
type
;
r
.
dimension
=
dimension
;
r
.
importance
=
UNUSED
;
r
.
units
=
units
;
r
.
field
=
NULL
;
r
.
partSize
=
spartSize
;
r
.
parts
=
NULL
;
r
.
xparts
=
NULL
;
r
.
gparts
=
NULL
;
r
.
sparts
=
sparts
;
r
.
conversion
=
1
;
r
.
convert_part_f
=
NULL
;
r
.
convert_part_d
=
NULL
;
r
.
convert_gpart_f
=
NULL
;
r
.
convert_gpart_d
=
NULL
;
r
.
convert_spart_f
=
NULL
;
r
.
convert_spart_d
=
functionPtr
;
return
r
;
return
r
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment