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

Add ports / MCT Model #73

Merged
merged 32 commits into from
Feb 7, 2024
Merged

Add ports / MCT Model #73

merged 32 commits into from
Feb 7, 2024

Conversation

schmoelder
Copy link
Contributor

@schmoelder schmoelder commented Nov 28, 2023

This PR adds ports to UnitOperations in CADET process which are required by models such as the 2D-GRM.

For starters, we will test this with the Multi-Channel Transport-Model

To fix #3, we also need to fix #70.

To do

  • Add ports to add_connection method
  • Add discretization class for MCT
  • Add SolutionRecorder for MCT
  • Store connections with ports in FlowSheet
    • Add tests
    • How to expose discretization n_rad to flow_sheet/ports
  • Add check methods
    • Unconnected ports
    • Changes in discretization configuration
    • flow rate balance
  • Open question: Should ports have individual output states?
  • Add parameters to the Name Converter for the MCT in cadetAdapter
  • Create a SizedMatrix Type and/or check SizednDArray if it meets our requirements
  • Add MCT tests in test_unit_operation
    • add create_MCT
  • In unitOperation change flow_direction into array of Switches
  • Check dimensionality for all unit operations, see also in solution

Open question

Should the MCT (and other potential 2D models) inherit from TubularReactor? How would this look like.
Should every channel of the MCT have a port by default?

@schmoelder
Copy link
Contributor Author

Ok, I can now setup an MCT unit operation. We should still test whether all parameters are transferred correctly to CADET in the CadetAdapter.

Next steps should address the ports. Please add some tests so that we have something to work with. Also, we should work on adding the multiplex features (see #70).

@schmoelder
Copy link
Contributor Author

After some brainstorming, @hannahlanzrath and I tried to come up with some better structure for storing connections. Here are some general ideas.

CASE 1:
    - Inlet
    - Outlet

_connections['inlet'] = Dict({
    'origins': [],
    'destinations': ['outlet'],
})

_connections['outlet'] = Dict({
    'origins': ['inlet'],
    'destinations': [],
})


CASE 2: No ports
    - Inlet 1
    - Inlet 2
    - Column
    - Outlet

_connections['inlet_1'] = Dict({
    'origins': [],
    'destinations': ['mct'],
})

_connections['inlet_2'] = Dict({
    'origins': ['column'],
    'destinations': [],
})

_connections['column'] = Dict({
    'origins': ['inlet_1', 'inlet_2'],
    'destinations': ['outlet'],
})

_connections['outlet'] = Dict({
    'origins': ['column'],
    'destinations': [],
})


CASE 3a: With ports # Option 1; distinguish between ports and no ports
    - Inlet 1
    - Inlet 2
    - MCT
    - Outlet

_connections['inlet_1'] = Dict({
    'origins': [],
    'destinations': {
        'mct': [0],
    }
})

_connections['inlet_2'] = Dict({
    'origins': [],
    'destinations': {
        'mct': [1],
    }
})

_connections['mct'] = Dict({
    'origins': {
        0:
            'inlet_1': None,
        },
        1: {
            'inlet_2': None,
        }
    },
    'destinations': {
        0: {
            'outlet': None,
        },
        1: {
            'outlet': None,
        }
    }
})

_connections['outlet'] = Dict({
    'origins': {
        'mct': [0, 1],
    },
    'destinations': [],
})

    'origins': [('mct', 0), ('mct', 1)]


    'origins': ['inlet_1', ('mct', 0), ('mct', 1), 'inlet_2']

CASE 3b: With ports # Option 1; distinguish between ports and no ports
    - Inlet 1
    - Inlet 2
    - MCT
    - Outlet

_connections['inlet_1'] = Dict({
    'origins': [],
    'destinations': {
        'mct': [0],
    }
})

_connections['inlet_2'] = Dict({
    'origins': [],
    'destinations': {
        'mct': [1],
    }
})

_connections['mct'] = Dict({
    'origins': {
        0: {
            'inlet_1': None,
        },
        1: {
            'inlet_2': None,
        }
    },
    'destinations': {
        0: {
            'outlet': None,
        },
        1: {
            'outlet': None,
        }
    }
})

_connections['outlet'] = Dict({
    'origins': {
        'mct': [0, 1],
    },
    'destinations': [],
})


CASE 4: With ports # Option 1; All units have ports (some only one)
    - Inlet 1
    - Inlet 2
    - MCT
    - Outlet

_connections['inlet_1'] = Dict({
    'origins': None,
    'destinations': {
        0: {
            'mct': [0],
        },
    },
})

_connections['inlet_2'] = Dict({
    'origins': None,
    'destinations': {
        0: {
            'mct': [1],
        },
    },
})

_connections['mct'] = Dict({
    'origins': {
        0: {
            'inlet_1': [0],
        },
        1: {
            'inlet_2': [0],
        }
    },
    'destinations': {
        0: {
            'outlet': [0],
        },
        1: {
            'outlet': [0],
        }
    }
})

_connections['outlet'] = Dict({
    'origins': {
        0: {
            'mct': [0, 1],
        },
    },
    'destinations': None,
})

For now, we went with Case 4. We'll see how this works out when having to calculate flow rates.

@hannahlanzrath
Copy link
Collaborator

Test cases for the MCT

image

schmoelder and others added 27 commits February 2, 2024 10:09
…utre, change CSTR tests to reflect new dict structure
…ry port, Test_flow_sheet.test_connections runs without errors.
@schmoelder schmoelder changed the base branch from master to dev February 7, 2024 10:48
def create_MCT(self):
mct = MCT(ComponentSystem(1), nchannel=3, name='test')

mct.length = length
Copy link
Contributor Author

@schmoelder schmoelder Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider moving this outside the Test_Unit_Operation class definition s.t. we could potentially reuse the same fixture for other tests.

(Same goes for all other units / binding / reaction models)

'exchange_matrix': exchange_matrix,
'flow_direction' : 1, #TODO: Update when multiplex is implemented
}
np.testing.assert_equal(parameters_expected, {key: value for key, value in mct.parameters.items() if key != 'discretization'}) #Why does mct give out discretization parameters and e.g. cstr does not?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because a Cstr has no spatial discretization. In fact, its core assumption is a spatial homogeneity.

self.assertTrue(mct.nchannel*mct.component_system.n_comp == mct.c.size)



Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the white space.

)


# @n_ports.setter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove code that is commented out or add TODO flag.

@schmoelder schmoelder merged commit 5936f62 into dev Feb 7, 2024
0 of 5 checks passed
@schmoelder
Copy link
Contributor Author

Sorry, merged the wrong branch. 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for parameter multiplexing Add 2D-GRM
3 participants