Skip to content

Instantly share code, notes, and snippets.

@Psirus
Last active January 11, 2017 15:11
Show Gist options
  • Save Psirus/33920dd0bc4834cc50324eb062e7b010 to your computer and use it in GitHub Desktop.
Save Psirus/33920dd0bc4834cc50324eb062e7b010 to your computer and use it in GitHub Desktop.
Visualize with Lambdas
#include <iostream>
#include <functional>
class ConstitutiveLaw {};
class ElementBase
{
public:
ElementBase(ConstitutiveLaw* law) : mLaw(law) {}
ConstitutiveLaw* GetConstitutiveLawPtr()
{
return mLaw;
}
private:
ConstitutiveLaw* mLaw;
};
class Visualize
{
public:
static void VisualizeElementFunction(ElementBase& element, std::function<int(ElementBase&)> function,
std::string paraviewName)
{
std::cout << paraviewName << ": " << function(element) << std::endl;
}
};
int main()
{
ConstitutiveLaw* heatConduction = new ConstitutiveLaw;
ConstitutiveLaw* linearElastic = new ConstitutiveLaw;
std::function<int(ElementBase&)> integerLaws = [=](ElementBase& element)
{
return heatConduction == element.GetConstitutiveLawPtr() ? 1 : 0;
};
ElementBase elementOne(heatConduction);
ElementBase elementTwo(linearElastic);
Visualize::VisualizeElementFunction(elementOne, integerLaws, "ConstitutiveLaw");
Visualize::VisualizeElementFunction(elementTwo, integerLaws, "ConstitutiveLaw");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment