Class documentation of Concepts

Loading...
Searching...
No Matches
cig_create_input_data.py

We will create input data using the Concepts Input Generator (CIG), which was written in Python. In another tutorial, we will load the input data into a C++ code. See Concepts tutorials for more tutorials.

Introduction

Imagine you have a piece of code written in C++ and there are some parameters, which you want to modify after each run, e.g. you want to solve the Maxwell equations with various relative perimittivities or you want to try out different refinements of the mesh.

To avoid recompiling your whole code over and over again, it makes sense to encapsulate the definition of all parameters, which can vary, from the main code. Using CIG together with the class concepts::InOutParameters is one possible way to achieve this.

Commented Program

First, let us define some inputs which we want to pass to our main code in C++.

4some_project_name = 'cig_input_data'
5some_folder = '.'
6
7some_string = "Live long and prosper!"
8some_float = 3.14159265359
9some_int = 42
10some_boolean = True

While the input parameters above use standard python classes, there is a special class for the mesh, which is also part of CIG.

13some_mesh = RhomboidMesh()
14
15p1=some_mesh.addPoint((0, 0.))
16p2=some_mesh.addPoint((1, 0.))
17p3=some_mesh.addPoint((1, 1.))
18p4=some_mesh.addPoint((0, 1.))
19
20some_mesh.setPointAttr(Nr=p1,Attr=777)
21some_mesh.addQuad(p1,p2,p3,p4)

Finally, we specify some refinement strategy: We perform one h-refinement, followed by two p-refinements and finally three hp-refinements towards the vertex with attribute number 777, which is the point p1=(0,0) .

24some_refinement = "h1,p2,hp3->v777"

Now we initialize a cigProject.Project object and write all the parameters above into this object

27project = Project()
28
29project['some_project_name'] = some_project_name
30project['some_folder'] = some_folder
31project['some_string'] = some_string
32project['some_float'] = some_float
33project['some_int'] = some_int
34project['some_boolean'] = some_boolean

While the names above were arbitrarily chosen, the following two names are keywords (e.g. using the name 'some_mesh' would not work).

37project['mesh'] = some_mesh
38project['refinement'] = some_refinement

With the following command, we finally generate our CIG input data, which consist of a cig-file and several dat-files for the mesh.

40project.save(filename=some_project_name,dataDir=some_folder)

The Python code can be directly executed with the command

python cig_create_input_data.py

If nothing went wrong, there should be a cig-file and five dat-files in the directory, where the python code was executed.

Click here to see how to load the input data into a C++ code.

Complete Source Code

1from cigProject import Project
2from cigPatterns import RhomboidMesh
3
4some_project_name = 'cig_input_data'
5some_folder = '.'
6
7some_string = "Live long and prosper!"
8some_float = 3.14159265359
9some_int = 42
10some_boolean = True
11
12some_mesh = RhomboidMesh()
13
14p1=some_mesh.addPoint((0, 0.))
15p2=some_mesh.addPoint((1, 0.))
16p3=some_mesh.addPoint((1, 1.))
17p4=some_mesh.addPoint((0, 1.))
18
19some_mesh.setPointAttr(Nr=p1,Attr=777)
20some_mesh.addQuad(p1,p2,p3,p4)
21
22some_refinement = "h1,p2,hp3->v777"
23
24project = Project()
25
26project['some_project_name'] = some_project_name
27project['some_folder'] = some_folder
28project['some_string'] = some_string
29project['some_float'] = some_float
30project['some_int'] = some_int
31project['some_boolean'] = some_boolean
32
33project['mesh'] = some_mesh
34project['refinement'] = some_refinement
35
36project.save(filename=some_project_name,dataDir=some_folder)