w03-g04-dump-output
Write output file with data to be plotted
Objective
Part 1
Write a code to write output files which contain the nodes coordinates, element connectivity, and displacements. Name your code file dump_output.cpp
and place it into tehpc/basics/
.
Your code should have the following variables:
-
dim
for the spatial dimension -
nb_nodes
for the number of nodes -
nb_elements
for the number of elements -
nb_nodes_per_element
for number of nodes per element -
coordinates
a 2D array with the node coordinates, accessible bycoordinages[node-index][direction]
-
connectivity
a 2D array with the node indexes creating the elements, and accessible byconnectivity[element-index][0 or 1]
and returns the node index -
displacements
, a 2D array with nodal displacement, where access to values is given by[node-index][direction]
.
Use the following values:
-
node 0:
x=1
,y=0
-
node 1:
x=0
,y=0
-
node 2:
x=1
,y=1
-
element 0 connects nodes:
0
and2
-
element 1 connects nodes:
1
and2
-
displacement of node 0:
ux=0
,uy=0
-
displacement of node 1:
ux=0
,uy=0
-
displacement of node 2:
ux=0.382843
,uy=-0.1
Name the output files:
results.coord.csv
results.conn.csv
results.disp.csv
and use comma-seperate format, where you each line corresponds to a node or element, respectively, and each column to a direction, or node-of-element.
Part 2
Write code to print the displacements
matrix to the terminal. Make sure that 1) you can define the precision of the values to be printed, and 2) that values show as a matrix and are nicely aligned by the decimal point.
Notes
Compile and run your code by:
- going into the
tehpc/build/basics/
folder - compile with the following command:
g++ -Werror -Wpedantic -g -o dump_output ../../basics/dump_output.cpp
- run code with
./dump_output
- check results by
../../basics/dump_output.py results
Guidance
- define a string with the dump location
"."
- define a string for the name of the data, ie.
"results"
- define and initialize all variables and arrays
- open file with name as described above
- check if it is open
- define that you want to write in scientific notation into the file
- loop over the coordinates array and write values to file (use "," to seprate values, and "\n" for new lines)
- close the file
- Repeat points 4.-8. for connectivity and displacements
- do a similar thing but write to the terminal screen the values of the displacement. Use also scientific notations.