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

Fix run time of adding multible connection #171

Open
AntoniaBerger opened this issue Oct 1, 2024 · 0 comments
Open

Fix run time of adding multible connection #171

AntoniaBerger opened this issue Oct 1, 2024 · 0 comments

Comments

@AntoniaBerger
Copy link
Collaborator

AntoniaBerger commented Oct 1, 2024

While simulating a stage model with about 300 cstrs we observed that connecting the cstr in the configuration step took around 50x longer then the simulation. We have not done any profiling jet.
The inital guess is that solving equations in every connecting iteration is very expensive.

Here is the configuration code:

from CADETProcess.processModel import ComponentSystem, Inlet, Outlet, Cstr, FlowSheet
from CADETProcess.processModel import  LRMDiscretizationFV, Process,LRMDiscretizationDG
from CADETProcess.simulator import Cadet, SolverTimeIntegratorParameters
from CADETProcess.processModel import  LumpedRateModelWithoutPores
from CADETProcess.processModel import Langmuir
    
import math

volume = 18.2 #ml 
col_length = (volume)/((math.pi/4)*(0.08)**2)
ncol = 357

component_system = ComponentSystem(['cm']) 

LangmuirIsotherm = Langmuir(component_system, 'LangmuirIsotherm')
LangmuirIsotherm.is_kinetic = False 
LangmuirIsotherm.adsorption_rate = [0.021]
LangmuirIsotherm.desorption_rate = [1] 
LangmuirIsotherm.capacity = [2.81/0.021]

epsilonCSTR = 1-Sf


inletCSTR = Inlet(component_system,'inletCSTR')
inletCSTR.flow_rate =  0.97/60

start_time = time.time()
cstrs = dict()
for i in range(ncol):
    name = f'cstr{i}'
    cstr = Cstr(component_system, name)
    cstr.c = [0]
    cstr.V = (volume/ncol)*(epsilonCSTR)
    cstr.binding_model = LangmuirIsotherm
    cstr.porosity = 1-0.456
    cstrs[name] = cstr
end_time = time.time()
duration_create_cstr = end_time - start_time

outlet_CSTR = Outlet(component_system,'outletCSTR')

flow_sheet_CSTR = FlowSheet(component_system)

start_time = time.time()
for i in cstrs.keys():
    flow_sheet_CSTR.add_unit(cstrs[i])
end_time = time.time()
duration_addUnit = end_time - start_time

flow_sheet_CSTR.add_unit(inletCSTR)
flow_sheet_CSTR.add_unit(outlet_CSTR)

start_time = time.time()
flow_sheet_CSTR.add_connection(inletCSTR,cstrs[f'cstr{0}'])
for i in range(0,ncol-1):
    flow_sheet_CSTR.add_connection(cstrs[f'cstr{i}'],cstrs[f'cstr{i+1}'])
flow_sheet_CSTR.add_connection(cstrs[f'cstr{ncol-1}'],outlet_CSTR)
end_time = time.time()
duration_addConnection = end_time - start_time

process_CSTR = Process(flow_sheet_CSTR, 'process_CSTR')
process_CSTR.cycle_time = 50*60

_ = process_CSTR.add_event('start load LR', 'flow_sheet.inletCSTR.c', [40.0], 0)
_ = process_CSTR.add_event('stop load LR', 'flow_sheet.inletCSTR.c', [0],1/0.97*60)


process_simulator = Cadet()
process_simulator.save_to_h5(process_CSTR, 'Stage_Model.h5')

#SolverTimeIntegratorParameters.abstol = 1e-15
#SolverTimeIntegratorParameters.reltol = 1e-10
start_time = time.time()
simulation_results_CSTR = process_simulator.simulate(process_CSTR)
end_time = time.time()
duration_simulation = end_time - start_time
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

No branches or pull requests

1 participant