-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to add your own models to teqp without re-compiling the core
Adds a lot of flexibility, maybe should be used for ALL models?
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include "teqp/cpp/teqpcpp.hpp" | ||
#include "teqp/cpp/deriv_adapter.hpp" | ||
#include "teqp/types.hpp" | ||
|
||
/// A (very) simple implementation of the van der Waals EOS, | ||
class myvdWEOS1 { | ||
private: | ||
double a, b; | ||
public: | ||
myvdWEOS1(double a, double b) : a(a), b(b) {}; | ||
|
||
/// Accessor functions | ||
double get_a() const{ return a; } | ||
double get_b() const{ return b; } | ||
|
||
const double Ru = 1.380649e-23 * 6.02214076e23; ///< Exact value, given by k_B*N_A | ||
|
||
/// \brief Get the universal gas constant | ||
/// \note Here the real universal gas constant, with no composition dependence | ||
template<class VecType> | ||
auto R(const VecType& /*molefrac*/) const { return Ru; } | ||
|
||
/// The evaluation of \f$ \alpha^{\rm r}=a/(RT) \f$ | ||
/// \param T The temperature | ||
/// \param rhotot The molar density | ||
/// \param molefrac The mole fractions of each component | ||
template<typename TType, typename RhoType, typename VecType> | ||
auto alphar(const TType &T, const RhoType& rhotot, const VecType &molefrac) const { | ||
return teqp::forceeval(-log(1.0 - b * rhotot) - (a / (R(molefrac) * T)) * rhotot); | ||
} | ||
}; | ||
|
||
TEST_CASE("Check adding a model at runtime"){ | ||
using namespace teqp::cppinterface; | ||
using namespace teqp::cppinterface::adapter; | ||
|
||
auto j = R"protect( | ||
{"kind": "myvdW", "model": {"a":1.2, "b": 3.4}} | ||
)protect"_json; | ||
|
||
ModelPointerFactoryFunction func = [](const nlohmann::json& j){ return make_owned(myvdWEOS1(j.at("a"), j.at("b"))); }; | ||
add_model_pointer_factory_function("myvdW", func); | ||
|
||
auto ptr = make_model(j); | ||
} |