    

 ## On this page

  

 

 # Example

 Last update: 16.07.2025 

Example helper functions: to include in any other file.

//

// COPYRIGHT ANSYS. ALL RIGHTS RESERVED.

//

\#pragma once

 

\#include &lt;cfloat&gt;

\#include &lt;vector&gt;

\#include &lt;string&gt;

\#include &lt;exception&gt;

 

\#include "dpf\_api.h"

 

// Wrap example code in a call to this as a global funcion

// throw an exception if anything fails

\#define EXAMPLEFUNC(function) \\

 void Example ## function(const std::string &amp;functionName); \\

 const std::string function ## Name("Example" #function); \

 ansys::dpf::Examples::FuncNames::iterator function ## NameIt = ansys::dpf::Examples::GetExampleFuncsNames().insert(ansys::dpf::Examples::GetExampleFuncsNames().end(), function ## Name); \

 ansys::dpf::Examples::FuncPtrs::iterator function ## It = ansys::dpf::Examples::GetExampleFuncs().insert(ansys::dpf::Examples::GetExampleFuncs().end(), Example ## function); \

 void Example ## function(const std::string &amp;functionName)

 

\#define TEST(test\_case\_name, test\_name) \\

 void test\_case\_name ## test\_name(); \\

 const std::string test\_case\_name ## test\_name ## Name(#test\_case\_name #test\_name); \\

 ansys::dpf::Examples::FuncNames::iterator test\_case\_name ## test\_name ## NameIt = ansys::dpf::Examples::GetExampleFuncsNames().insert(ansys::dpf::Examples::GetExampleFuncsNames().end(), test\_case\_name ## test\_name ## Name); \\

 ansys::dpf::Examples::FuncPtrs::iterator test\_case\_name ## test\_name ## It = ansys::dpf::Examples::GetExampleFuncs().insert(ansys::dpf::Examples::GetExampleFuncs().end(), test\_case\_name ## test\_name); \\

 void test\_case\_name ## test\_name()

 

 

\#define THROWERROR(FILE, LINE, MESSAGE)\\

 throw std::runtime\_error("File: " +std::string(FILE) + " Line: " + std::to_string(LINE) + " Condition: " + #MESSAGE)

 

\#define EXPECT\_TRUE(condition)\\

 if (!(condition)) {\\

 THROWERROR(\_\_FILE\_\_, \_\_LINE\_\_, condition);\\

 }

 

\#define EXPECT\_FALSE(condition)\\

 if ((condition)) {\\

 THROWERROR(\_\_FILE\_\_, \_\_LINE\_\_, condition);\\

 }

 

\#define EXPECT\_EQ(v1, v2)\\

 if ((v1) != (v2)) {\\

 THROWERROR(\_\_FILE\_\_, \_\_LINE\_\_, v1 == v2);\\

 }

\#define EXPECT\_ARRAYEQ(a1, a2, len)\\

 for (int i = (len)-1; i &gt;= 0; --i) {\\

 EXPECT\_EQ((a1)\[i\], (a2)\[i\]);\\

 }

\#define EXPECT\_DOUBLE\_EQ(v1, v2)\\

 {\\

 double a=(v1);\\

 double b=(v2);\\

 if (fabs(a - b) &gt; ( (fabs(a) &gt; fabs(b) ? fabs(b) : fabs(a)) \* DBL\_EPSILON \* 100.0)) {\\

 THROWERROR(\_\_FILE\_\_, \_\_LINE\_\_, v1 == v2); \\

 }\\

 }

\#define EXPECT\_STREQ(v1, v2)\\

 if (std::string(v1) != std::string(v2)) {\\

 THROWERROR(\_\_FILE\_\_, \_\_LINE\_\_, v1 == v2);\\

 }

 

 

namespace ansys { namespace dpf { namespace Examples {

 typedef void (*FuncPtr)();

 typedef std::vector&lt;FuncPtr&gt; FuncPtrs;

 typedef std::vector&lt;std::string&gt; FuncNames;

 extern FuncPtrs &amp;GetExampleFuncs();

 extern FuncNames &amp;GetExampleFuncsNames();

 

 extern dpf::DpfError LoadMAPDL();

 extern dpf::DpfError LoadMESH();

} } }