!!!Purpose!!! This recipe assumes you have completed sucessfully the DataStorageRecipe.

The purpose of this recipe is to show the use of the following features of the COOLFluiD framework:

  • NumericalIntegration in GeometricEntity's
  • Functor's

At the end of this recipe you should be able to use the IntegrationFacility for performing integrations in GeometricEntity's. You should also be able to create your own custom Functor's to use in these integrations.


!!Step 1!! Go to the "Recipes" directory. Go into the "Recipe04" directory. Edit the file "main.cxx". The code present here is the result of the work already done in recipes SelfRegistrationRecipe, SelfConfigurationRecipe and DataStorageRecipe.

Edit main.cxx and assign the following coordinates to the nodes, and the values to the states:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ...

pdata.getData(statesInCell,nodesInCell,i);

(*nodesInCell[0])[XX] = 0.0; (*nodesInCell[0])[YY] = 0.0;

(*nodesInCell[1])[XX] = 2.0; (*nodesInCell[1])[YY] = 0.0;

(*nodesInCell[2])[XX] = 0.0; (*nodesInCell[2])[YY] = 2.0;

*statesInCell[0] = 1.0; *statesInCell[1] = 1.0; *statesInCell[2] = 1.0;

GeometricEntity * cell = cellProvider->create(statesInCell,nodesInCell);

... </span> [</html>]


!!Step 2!!

In order to make an integration possible you must have something to integrate on. This is were a Functor comes in. Implement the following lines in th main.cxx:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ...

CFLog(INFO,"Created GeometricEntity " << i << std::endl);

VolumeIntegrator::getInstance().setUp();

typedef ConstantFunctor&#60;1&#62; CteFunctor;

CteFunctor functor; functor.setValue(1.0);

RealVector result(functor.size());

VolumeIntegrator::getInstance().integrateConstantFunctorOnGeo<CteFunctor>(cell,functor,result);

CFLog(INFO,"Integration result: " << result << std::endl);

deletePtr(cell);

... </span> [</html>]

You should also include the header files related to the new class you are using: ConstantFunctor.

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ... #include "Framework/BaseGeometricEntityProvider.hh" #include "MathTools/ConstantFunctor.hh"

#include "ProgramConfig.hh" ... </span> [</html>]

Open also the namespace COOLFluiD::MathTools for use, since that's were the ConstantFunctor is defined.

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ... using namespace COOLFluiD; using namespace COOLFluiD::Framework; using namespace COOLFluiD::MathTools; ... </span> [</html>]

Then the code should be able to compile without errors or warnings.


!!Step 3!!

First lets reduce the level of output. Edit the line:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ... int main() {

CFLogLevel::set(INFO);

CFLog(INFO, "COOLFluiD Recipe 4 starting: " << endl);

... </span> [</html>]

Trying to run the code should yield the following result:

[<html>] <SPAN style="color:#000000;background-color:#FFFFCC;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> prompt:Recipe04> ./program COOLFluiD Recipe 4 starting: Created 30 states and nodes. Created GeometricEntity 0 Integration result: 2 Created GeometricEntity 1 Integration result: 2 Created GeometricEntity 2 Integration result: 2 Created GeometricEntity 3 Integration result: 2 Created GeometricEntity 4 Integration result: 2 Created GeometricEntity 5 Integration result: 2 Created GeometricEntity 6 Integration result: 2 Created GeometricEntity 7 Integration result: 2 Created GeometricEntity 8 Integration result: 2 Created GeometricEntity 9 Integration result: 2 </span> [</html>]


!!Step 4!!

Now lets try to create a custom functor and use it to compute a function dependent on the coordinates of the GeometricEntity. First we start to create another file, CustomFunctor.hh, to host the new Functor class:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> #ifndef CustomFunctor_hh #define CustomFunctor_hh

#include <cmath>

#include "MathTools/RealVector.hh"

class CustomFunctor { public:

explicit CustomFunctor() : _result(1) { }

COOLFluiD::CFluint size() const {

return _result.size();

}

COOLFluiD::RealVector& operator()(const COOLFluiD::RealVector& coord) {

using namespace COOLFluiD;

assert(coord.size() == DIM_2D);

_result = sqrt(coord[XX] * coord[XX] + coord[YY] * coord[YY]);

return _result;

}

private:

COOLFluiD::RealVector _result;

}; // end class CustomFunctor #endif // CustomFunctor_hh </span> [</html>]

This functor will calculate the integration of the radius with respect to the origin of the OXY coodinate system.


!!Step 5!!

Now lets make use of the new class in the main.cxx. Edit it and include the header:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ... #include "ProgramData.hh" #include "CustomFunctor.hh" ... </span> [</html>]

and edit the main() function to insert the following lines:

[<html>] <SPAN style="color:#333333;background-color:#cccccc;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> ...

CFLog(INFO,"Integration result: " << result << std::endl);

CustomFunctor custfunctor;

VolumeIntegrator::getInstance().integrateGeometricFunctorOnGeo<CustomFunctor>(cell,custfunctor,result);

CFLog(INFO,"Integration result: " << result << std::endl);

deletePtr(cell);

... </span> [</html>]

The first new line initializes an object of the type CustomFunctorm, while the next line uses that functor to integrate it on the specified GeometricEntity. Then the result is outputted.

The result of running the program should be:

[<html>] <SPAN style="color:#000000;background-color:#FFFFCC;font-size:10px;border: 1px solid gray;padding:5px 5px 5px 5px;white-space: pre; display:block;"> prompt:Recipe04> ./program COOLFluiD Recipe 4 starting: Created 30 states and nodes. Created GeometricEntity 0 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 1 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 2 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 3 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 4 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 5 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 6 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 7 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 8 Integration result: 2 Integration result: 1.88562 Created GeometricEntity 9 Integration result: 2 Integration result: 1.88562 </span> [</html>]

Now you can imagine that if different coordinates are given to each GeometricEntity, the code remains exactly the same and this turns out to be a quite general way to compute general functors on GeometricEntity's. COOL hein?!

Congratulations!! You're done with this recipe'''


!!!See also!!! References to other recipes, models and fragments of source code examples go here.

#metadata