Class documentation of Concepts

Loading...
Searching...
No Matches
inputoutput.doxy
1
40bool subdivide false @endcode
41
42The results from the program are stored in a similar structure. At the end of a program, it is possible to write the input and output data into one file. The output file has the same syntax and structure as the input file and can therefore be used as an input file to reproduce the results at a later time.
43See the <a href="#Results">results section</a> for an example.
44
45@dontinclude inputoutput.py
46@section commented Commented Program
47
48First we have to import certain modules from the \c libconceptspy package and other required python modules.
49
50 @skip from libconceptspy import concepts
51 @until import argparse
52
53All code in this example is in one large routine, the main program.
54
55 @skip def main(args,argv):
56 @until def main(args,argv):
57
58Some default values for the parameters used. \c l and \c p are just two variables. If \c debug is set to true, more information is printed to screen.
59
60 @skip l = 0
61 @until debug = False
62
63First, set up the input parameter class: some parameters are set up with a default value.
64
65 @skip inp = concepts.InputParser(True)
66 @until inputParameters.addString('parameterout',"inputoutput.out")
67
68The variable outputParameter is for easier access to the output area. There, the results of the computations can be stored and eventually written to disk if necessary.
69
70 @skip outputParameters = concepts.InOutParameters()
71 @until outputParameters = concepts.InOutParameters()
72
73Prepare an array for values computed later. This array is then added to \c table which is able to nicely format the content of the different arrays (e.g. for later processing with Gnuplot).
74
75 @skip outputParameters.addArrayDouble("error")
76 @until inputfile = ''
77
78@subsection parsing Command Line Parsing
79Here, we start with the command line parsing.
80 @code
81 parser = argparse.ArgumentParser()
82 parser.add_argument('-l',help='LEVEL: level of refinement',required=False, type = int)
83 parser.add_argument('-p',help='DEGREE: polynomial degree', required=False, type = int)
84 parser.add_argument('-f',help='FILE: name of the input file',required=False, type = str)
85 parser.add_argument('-d',action = "store_true",help='-d: print the matrices',required=False)
86 args = parser.parse_args()
87 @endcode
88
89Enter \c -h as command line argument for more information. The parameters are processed in the order they appear in the command line. When first specifying an input file with \c -f, the values in the file can be overridden with additional command line arguments after \c -f.
90
91 @skip if (len(argv)>1):
92 @until inputParameters.addBool('debug', True)
93
94If there is an error reading the input file, then an exception error message is returned.
95
96 @skip except RuntimeError:
97 @until print("Input file not found.Cannot open input file.")
98
99Print the parameters to show the user what is going on.
100
101 @skip print('['+argv[0]+']')
102 @until print(' input file = %s\n%s'%(inputfile,inputParameters))
103
104Next, the parameters from the command line or the input file are stored in the respective variables. This is only used for abbrevation.
105
106 @skip l = inputParameters.getInt('level')
107 @until p = inputParameters.getInt('polynomial')
108
109@subsection comp Computations
110Here are some dummy computations to fill the output area with content.
111
112 @skip outputParameters.addInt("nelm", 10)
113 @until outputParameters.addArrayDouble("error",i,1.0/(1<<i))
114
115@section output Output
116Finally, the input and output data are written to disk with some more information about the user and the system in the header of the file.
117
118 @skip print 'Writing gathered data to disk: ',inputParameters.getString("parameterout")
119 @until ofile.close()
120
121This prints the table and its content to the screen and also stores it with high precision in a file suitable for later processing with Gnuplot.
122
123 @skip print(table)
124 @until gnu_file.close()
125
126@section Results
127The output of the program called without parameters: @code
128[inputoutput]
129--
130Parameters:
131 input file =
132string author "(empty)"
133string comment "(empty)"
134string parameterout "inputoutput.out"
135string title "(empty)"
136int level 0
137int polynomial 1
138bool debug false
139--
140--
141Writing gathered data to disk: inputoutput.out
142ResultsTable(
143error error
1440 1
1451 0.5
1462 0.25
1473 0.125
1484 0.0625
1495 0.03125
1506 0.015625
1517 0.0078125
1528 0.00390625
1539 0.00195312
154) @endcode
155The program creates the following output files:
156 - \c inputoutput.out:
157@code
158/* program: inputoutput
159 * command: inputoutput
160 * input file:
161 */
162string author "(empty)"
163string comment "(empty)"
164string parameterout "inputoutput.out"
165string title "(empty)"
166int level 0
167int polynomial 1
168bool debug false
169end
170// output starts here
171int nelm 10
172array double error {
173 0 1
174 1 0.5
175 2 0.25
176 3 0.125
177 4 0.0625
178 5 0.03125
179 6 0.015625
180 7 0.0078125
181 8 0.00390625
182 9 0.00195312
183} @endcode
184 - \c inputoutput.gnuplot:
185@code
186# error error
1870 1q
1881 0.5
1892 0.25
1903 0.125
1914 0.0625
1925 0.03125
1936 0.015625
1947 0.0078125
1958 0.00390625
1969 0.00195312 @endcode
197
198Note the \c end keyword at the end of the input part and right before the output part. When reading in this file as input file, the parsing stops right there, ie. the previous output data is not read in.
199
200 @section complete Complete Source Code
201*/
void addArrayDouble(const char *array, const bool newArray=false)