Last active
January 11, 2017 15:11
-
-
Save Psirus/33920dd0bc4834cc50324eb062e7b010 to your computer and use it in GitHub Desktop.
Visualize with Lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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