Skip to content
Snippets Groups Projects
Commit 7ced1c29 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Add scripts for figures of results of ODE solvers.

parent e65c78a5
No related branches found
No related tags found
1 merge request!125ODE solvers
......@@ -44,4 +44,14 @@ ADD_CUSTOM_COMMAND(
DEPENDS ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticODESolver-SineExample.out
VERBATIM )
ADD_CUSTOM_TARGET( ProcessODESolversExamplesResults ALL DEPENDS StaticODESolver-SineExample.png )
\ No newline at end of file
ADD_CUSTOM_COMMAND(
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/StaticODESolver-LorenzExample.py
${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticODESolver-LorenzExample.out
${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticODESolver-LorenzExample.png
OUTPUT StaticODESolver-LorenzExample.png
DEPENDS ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticODESolver-LorenzExample.out
VERBATIM )
ADD_CUSTOM_TARGET( ProcessODESolversExamplesResults ALL DEPENDS
StaticODESolver-SineExample.png
StaticODESolver-LorenzExample.png )
\ No newline at end of file
#!/usr/bin/env python3
import sys
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['text.usetex'] = True
f = open( sys.argv[1], 'r' )
x_lst = []
y_lst = []
z_lst = []
for line in f:
line = line.strip()
a = line.split()
x_lst.append( float( a[ 0 ] ) )
y_lst.append( float( a[ 1 ] ) )
z_lst.append( float( a[ 2 ] ) )
x = np.array(x_lst)
y = np.array(y_lst)
z = np.array(z_lst)
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
ax.plot(x, y, z, label='Lorenz attractor')
ax.legend()
plt.savefig( sys.argv[2] )
plt.close(fig)
......@@ -8,7 +8,7 @@ int main( int argc, char* argv[] )
using ODESolver = TNL::Solvers::ODE::StaticEuler< Real >;
const Real final_t = 10.0;
const Real tau = 0.001;
const Real output_time_step = 0.5;
const Real output_time_step = 0.25;
ODESolver solver;
solver.setTau( tau );
......
......@@ -4,6 +4,7 @@ import sys
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['text.usetex'] = True
f = open( sys.argv[1], 'r' )
x_lst = []
......@@ -17,16 +18,13 @@ for line in f:
x = np.array(x_lst)
y = np.array(y_lst)
#print( x )
#print( y )
fig, ax = plt.subplots()
#ax.set_aspect('auto')
ax.set_xlim( [0,10] )
ax.set_ylim( [-10,10] )
#ax.set(xlim=(0,10), xticks=np.arange(1, 10), ylim=(0, 10), yticks=np.arange(1, 10))
ax.plot(x, y, linewidth=2.0)
plt.xlim( xmin=0, xmax=10 )
ax.set_xlabel( "t" )
ax.set_ylabel( "u(t)" )
plt.savefig( sys.argv[2] )
plt.close(fig)
......
......@@ -70,7 +70,7 @@ The code is very similar to the previous example. There are the following differ
The result looks as follows:
[comment]: <> (\include StaticODESolver-LorenzExample.out)
\image{inline} html StaticODESolver-LorenzExample.png "Solution of the Lorenz problem"
## Combining static ODE solvers with parallel for
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment