tsimulation.c: add VTK export for grains - granular - granular dynamics simulat… | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 22b76f0ca163f3753c5f6b973c6320e50edd4491 | |
parent 99c38f2f6c2fd472b1056e8cf72e55a56358f573 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Fri, 19 Mar 2021 18:32:00 +0100 | |
simulation.c: add VTK export for grains | |
Diffstat: | |
M simulation.c | 51 +++++++++++++++++++++++++++++… | |
M simulation.h | 5 +---- | |
2 files changed, 51 insertions(+), 5 deletions(-) | |
--- | |
diff --git a/simulation.c b/simulation.c | |
t@@ -13,7 +13,56 @@ print_grains(FILE *stream, const struct grain *grains, size… | |
{ | |
size_t i; | |
- /* fprintf(stream, "N = %zu\n", n); */ | |
for (i = 0; i < n; i++) | |
grain_print(stream, &grains[i]); | |
} | |
+ | |
+void | |
+print_grains_vtk(FILE *stream, const struct grain *grains, size_t n) | |
+{ | |
+ size_t i; | |
+ | |
+ fprintf(stream, | |
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" | |
+ "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" " | |
+ "byte_order=\"LittleEndian\">\n" | |
+ "\t<UnstructuredGrid>\n" | |
+ "\t\t<Piece NumberOfPoints=\"%zu\" NumberOfCells=\"0\"… | |
+ fprintf(stream, | |
+ "\t\t\t<Points>\n" | |
+ "\t\t\t\t<DataArray type=\"Float64\" Name=\"Points\" " | |
+ "NumberOfComponents=\"3\" format=\"ascii\">\n"); | |
+ for (i = 0; i < n; i++) | |
+ fprintf(stream, "%.17g %.17g %.17g ", | |
+ grains[i].pos[0], grains[i].pos[1], grains[i].pos[2]); | |
+ fprintf(stream, "\n"); | |
+ fprintf(stream, | |
+ "\t\t\t\t</DataArray>\n" | |
+ "\t\t\t</Points>\n"); | |
+ | |
+ fprintf(stream, | |
+ "\t\t\t<Cells>\n" | |
+ "\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity… | |
+ "NumberOfComponents=\"1\" format=\"ascii\"/>\n" | |
+ "\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" " | |
+ "NumberOfComponents=\"1\" format=\"ascii\"/>\n" | |
+ "\t\t\t\t<DataArray type=\"UInt8\" Name=\"types\" " | |
+ "NumberOfComponents=\"1\" format=\"ascii\"/>\n" | |
+ "\t\t\t</Cells>\n"); | |
+ | |
+ fprintf(stream, | |
+ "\t\t\t<PointData>\n" | |
+ "\t\t\t\t<DataArray type=\"Float64\" Name=\"Diameter [… | |
+ "NumberOfComponents=\"1\" format=\"ascii\">\n"); | |
+ for (i = 0; i < n; i++) | |
+ fprintf(stream, "%.17g ", grains[i].radius * 2.0); | |
+ fprintf(stream, | |
+ "\n" | |
+ "\t\t\t\t</DataArray>\n" | |
+ "\t\t\t</PointData>\n"); | |
+ | |
+ fprintf(stream, | |
+ "\t\t</Piece>\n" | |
+ "\t</UnstructuredGrid>\n" | |
+ "</VTKFile>\n"); | |
+} | |
diff --git a/simulation.h b/simulation.h | |
t@@ -37,12 +37,9 @@ struct simulation { | |
struct grain *grains; | |
}; | |
-void init_sim(struct simulation *sim); | |
void free_sim(struct simulation *sim); | |
void print_grains(FILE *stream, const struct grain *grains, size_t n); | |
- | |
-void write_output_file(struct simulation *sim, const int normalize); | |
-void print_output(FILE *stream, struct simulation *sim); | |
+void print_grains_vtk(FILE *stream, const struct grain *grains, size_t n); | |
#endif |