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.
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;
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
std::string getString(const char *name, const char *value=0) const
bool getBool(const char *name) const
Returns a bool from the hash of bools.
Concepts provides methods to create meshes from given dat-files.
Import2dMeshGeneral * import2dMeshGeneralFromInput(const InOutParameters input, bool verbose=false)
Finally, we create a space with certain refinement strategies, which are contained in 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:
Plot of the refined mesh:
Complete Source Code
#include <iostream>
#include "geometry.hh"
#include "graphics.hh"
#include "hp2D.hh"
#include "space.hh"
int main(int argc, char** argv) {
try {
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::cout << "Mesh: " << *mesh << std::endl;
std::cout << "Space: " << space << std::endl;
}
std::cout << e << std::endl;
return 1;
}
return 0;
}
bool apply(int argc, char **argv)
void rebuild(bool sameIndices=false)
MeshEPS< Real > drawMeshEPS(concepts::Mesh &msh, std::string filename, const Real scale=100, const Real greyscale=1.0, const unsigned int nPoints=2)