Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Python flux connections, even if they are slow #78

Closed
philippkraft opened this issue Sep 18, 2019 · 1 comment
Closed

Allow for Python flux connections, even if they are slow #78

philippkraft opened this issue Sep 18, 2019 · 1 comment
Assignees
Labels
C++ Need to change C++ files (.h, .cpp) enhancement swig Need to change SWIG-interface files (.i)

Comments

@philippkraft
Copy link
Owner

philippkraft commented Sep 18, 2019

The connections in cmf are written in C++ to use the full potential of speed. However, when new connections are developed, the write, compile, link, install, debug cycle is clumsy. Using Python flux connections would speed up development and can be translated into C++ when the math is working. This would also be a way to include Python developers more easily in the extension of cmf.

Proposed usage:

class CustomConnection(cmf.flux_connection):
    def __init__(self, left, right):
        super().__init__(left, right, type(self).__name__)
        self.left = left
        self.right = right

    def calc_q(self, t):
        return self.left.volume - self.right.volume

p = cmf.project()
t = cmf.Time()
s1 = p.NewStorage('S1')
s1.volume = 1.0
s2 = p.NewStorage('S2')
con = CustomConnection(s1, s2)
s1.dxdt(t)
@philippkraft
Copy link
Owner Author

Due to the protected status of calc_q, this is not possible for flux_connection. However with a new class BaseConnection which exposes calc_q it works.

namespace cmf { 
    namespace water {
        class BaseConnection: public flux_connection{
        public:
            BaseConnection(cmf::water::WaterStorage::ptr left, 
                           cmf::water::flux_node::ptr right, 
                           std::string type)
            : flux_connection(left, right, type) 
            {}
            
            real calc_q(cmf::math::Time t) override    
            {
                throw std::runtime_error("BaseConnection.calc_q needs to be overriden by child class");
            }
        };
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Need to change C++ files (.h, .cpp) enhancement swig Need to change SWIG-interface files (.i)
Projects
None yet
Development

No branches or pull requests

1 participant