cig_load_input_data.cc

We will load the CIG input data from here into a C++ code. The input data was created with the Concepts Input Generator (CIG). See Concepts tutorials for more tutorials.

Introduction

In a previous tutorial we generated a cig-file, which contains several paramters and five dat-files, which contain information about the mesh. Now we are going to show, how to access this information from C++.

Commented Program

First, we initialize input and make it contain all the parameters from the CIG input data.

concepts::ProcessParameter parameter(input);
std::cout << "Parameters have been processed" << std::endl;
if (!parameter.apply(argc, argv))
exit(1);

Now we can access all the parameters by appropriate getter-methods and by the respective names, which we specified in the Python code used for generating the input data.

std::cout << "Some string : " << input.getString("some_string") << std::endl;
std::cout << "Some float : " << input.getDouble("some_float") << std::endl;
std::cout << "Some int : " << input.getInt("some_int") << std::endl;
std::cout << "Some boolean : " << input.getBool("some_boolean") << std::endl;

Concepts provides methods to create meshes from given dat-files.

std::unique_ptr<concepts::Mesh2> mesh(concepts::import2dMeshGeneralFromInput(input, false));

Finally, we create a space with certain refinement strategies, which are contained in input.

hp2D::hpAdaptiveSpaceH1 space(*mesh,input);

Supposing that your compiled program is named cig_load_input_data, the code is executed with the command

./cig_load_input_data -f cig_input_demo.cig

If nothing went wrong, you should get the following output in the terminal:

Some string : Live long and prosper!
Some float : 3.14159
Some int : 42
Some boolean : 1
Space: hp2D::hpAdaptiveSpaceH1(dim = 286 (V:18, E:102, I:166), nelm = 13)

and there should be two eps-files showing the defined mesh in the from the input data and the hp-refined mesh.

Plot of the initial mesh: Mesh

Plot of the refined mesh: Space

Complete Source Code

#include <iostream>
#include "geometry.hh"
#include "graphics.hh"
#include "hp2D.hh"
#include "space.hh"
int main(int argc, char** argv) {
try {
concepts::ProcessParameter parameter(input);
std::cout << "Parameters have been processed" << std::endl;
if (!parameter.apply(argc, argv))
exit(1);
std::cout << "Some string : " << input.getString("some_string") << std::endl;
std::cout << "Some float : " << input.getDouble("some_float") << std::endl;
std::cout << "Some int : " << input.getInt("some_int") << std::endl;
std::cout << "Some boolean : " << input.getBool("some_boolean") << std::endl;
std::unique_ptr<concepts::Mesh2> mesh(concepts::import2dMeshGeneralFromInput(input, false));
std::cout << "Mesh: " << *mesh << std::endl;
graphics::drawMeshEPS( *mesh, input.getString("some_project_name") + "_mesh.eps", 100, 1.0, 100);
hp2D::hpAdaptiveSpaceH1 space(*mesh,input);
space.rebuild();
std::cout << "Space: " << space << std::endl;
graphics::drawMeshEPS(space, input.getString("some_project_name") + "_space.eps",100,1.0,20);
}
std::cout << e << std::endl;
return 1;
}
return 0;
}
void hpAdaptiveSpaceH1(hp2D::hpAdaptiveSpaceH1 &spc, std::string str)
Import2dMeshGeneral * import2dMeshGeneralFromInput(const InOutParameters input, bool verbose=false)
Loads a mesh from a paramater list.
Base class for exceptions.
Definition: exceptions.hh:86
MeshEPS< Real > drawMeshEPS(concepts::Mesh &msh, std::string filename, const Real scale=100, const Real greyscale=1.0, const unsigned int nPoints=2)
Trampoline function to create a MeshEPS.
Holds parameters in hashes.
Definition: inputOutput.hh:75
2D hp-FEM for H1-conforming elements.
double getDouble(const char *name) const
Returns a double from the hash of doubles.
int getInt(const char *name, const int value=INT_MAX) const
Returns an int from the hash of ints.
void rebuild(bool sameIndices=false)
Rebuilds the mesh and the elements due to adjustment orders.
bool apply(int argc, char **argv)
Process the command line arguments.
std::string getString(const char *name, const char *value=0) const
Returns a string from the hash of strings.
bool getBool(const char *name) const
Returns a bool from the hash of bools.
Reads command line.
Definition: inputParam.hh:81
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich