Exemplo n.º 1
0
    def check_cadet(self):
        """Wrapper around a basic CADET example for testing functionality"""
        if platform.system() == 'Windows':
            lwe_path = self.install_path / "bin" / "createLWE.exe"
        else:
            lwe_path = self.install_path / "bin" / "createLWE"
        ret = subprocess.run(
            [lwe_path.as_posix()],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=self.temp_dir
        )
        if ret.returncode != 0:
            if ret.stdout:
                print('Output', ret.stdout.decode('utf-8'))
            if ret.stderr:
                print('Errors', ret.stderr.decode('utf-8'))
            raise CADETProcessError(
                "Failure: Creation of test simulation ran into problems"
            )

        lwe_hdf5_path = Path(self.temp_dir) / 'LWE.h5'

        sim = CadetAPI()
        sim.filename = lwe_hdf5_path.as_posix()
        data = sim.run()
        os.remove(sim.filename)

        if data.returncode == 0:
            print("Test simulation completed successfully")
        else:
            print(data)
            raise CADETProcessError(
                "Simulation failed"
            )
Exemplo n.º 2
0
def main():
    simulation = Cadet(common.common.root)
    simulation.filename = "f:/temp/LWE.h5"
    createSimulation(simulation)
    simulation.save()
    simulation.run()
    simulation.load()

    #read sensitivity data

    #sensitivity of protein 1 to nu 1
    #s1 = simulation.root.output.sensitivity.param_000.unit_001.sens_column_outlet_comp_001

    #sensitivity of protein 2 to nu 1
    #s2 = simulation.root.output.sensitivity.param_000.unit_001.sens_column_outlet_comp_002

    #sensitivity of protein 1 to nu 2
    #s3 = simulation.root.output.sensitivity.param_001.unit_001.sens_column_outlet_comp_001

    #sensitivity of protein 1 to sigma 1
    #s4 = simulation.root.output.sensitivity.param_002.unit_001.sens_column_outlet_comp_001

    #sensitivity of protein 1 to lambda
    #s5 = simulation.root.output.sensitivity.param_003.unit_001.sens_column_outlet_comp_001

    #Sensitvity of first species to loads of all species (except salt)
    #s6 = simulation.root.output.sensitivity.param_004.unit_001.sens_column_outlet_comp_001

    #Sensitvity of first species to velocity
    #s7 = simulation.root.output.sensitivity.param_005.unit_001.sens_column_outlet_comp_001

    plotSimulation(simulation)
Exemplo n.º 3
0
def main():
    simulation = Cadet(common.common.root)
    simulation.filename = "MSSMA.h5"
    createSimulation(simulation)
    simulation.save()
    simulation.run()
    simulation.load()
    plotSimulation(simulation)
Exemplo n.º 4
0
def main():
    smb = Cadet()
    smb.filename = 'F:/temp/SMB.h5'
    createSimulation(smb)
    print("Simulated Created")
    smb.save()
    smb.run()
    smb.load()
    print("Simulation Run")
    plotSimulation(smb)
Exemplo n.º 5
0
def main():
    simulation = Cadet(common.common.root)
    simulation.filename = "MSSMA_2comp.h5"
    createSimulation(simulation)
    simulation.save()
    data = simulation.run()
    print(data)
    simulation.load()
    plotSimulation(simulation)
Exemplo n.º 6
0
def main():
    #sim = Cadet(common.root, column_setup.root, io.root, connectivity.root)
    #sim.filename = "F:/temp/test_file.h5"
    #createSimulation(sim)
    #sim.save()
    #sim.run()
    #sim.load()
    #plotSimulation(sim)

    sim = Cadet(common.root, cstr.root, io.root, connectivity.root)
    sim.root.input['return'].unit_001.write_solution_volume = 1
    sim.root.input.model.connections.switch_000.connections = [
        0, 1, -1, -1, 1.5, 1, 2, -1, -1, 1.0
    ]
    sim.filename = "F:/temp/test_file_cstr.h5"
    sim.save()
    sim.run()
    sim.load()
    plotSimulation(sim)
    plotVolume(sim)

    writer = pandas.ExcelWriter('F:/temp/test_file_cstr.xlsx')

    inputs = pandas.DataFrame.from_items([
        ('Time', sim.root.output.solution.solution_times),
        ('Concentration',
         sim.root.output.solution.unit_002.solution_inlet_comp_000)
    ])
    outputs = pandas.DataFrame.from_items([
        ('Time', sim.root.output.solution.solution_times),
        ('Concentration',
         sim.root.output.solution.unit_002.solution_outlet_comp_000)
    ])
    volumes = pandas.DataFrame.from_items([
        ('Time', sim.root.output.solution.solution_times),
        ('Volume',
         numpy.squeeze(sim.root.output.solution.unit_001.solution_volume))
    ])

    inputs.to_excel(writer, 'Input', index=False)
    outputs.to_excel(writer, 'Output', index=False)
    volumes.to_excel(writer, 'Volume', index=False)

    writer.save()
Exemplo n.º 7
0
def main():
    sim = Cadet(common.root, dpfr.root, io.root, cstr.root, connectivity.root)
    sim.filename = r"F:\jurgen\Pilot_test.h5"
    #createSimulation(sim)
    sim.save()
    sim.run()
    sim.load()
    plotSimulation(sim)

    #sim = Cadet(common.root, cstr.root, io.root, connectivity.root)
    #sim.root.input['return'].unit_001.write_solution_volume = 1
    #sim.root.input.model.connections.switch_000.connections = [0, 1, -1, -1, 1.5,
    #                                                    1, 2, -1, -1, 1.0]
    #sim.filename = r"C:\Users\Kohl\Desktop\Cadet\test_file_cstr.h5"
    #sim.save()
    #sim.run()
    #sim.load()
    #plotSimulation(sim)
    #plotVolume(sim)

    writer = pandas.ExcelWriter(r'F:\jurgen\test_file_cstr.xlsx')

    inputs = pandas.DataFrame.from_items([
        ('Time', sim.root.output.solution.solution_times),
        ('Concentration',
         sim.root.output.solution.unit_000.solution_inlet_comp_000)
    ])
    outputs = pandas.DataFrame.from_items([
        ('Time', sim.root.output.solution.solution_times),
        ('Concentration',
         sim.root.output.solution.unit_002.solution_outlet_comp_000)
    ])
    #volumes = pandas.DataFrame.from_items([('Time', sim.root.output.solution.solution_times), ('Volume', numpy.squeeze(sim.root.output.solution.unit_001.solution_volume))])

    inputs.to_excel(writer, 'Input', index=False)
    outputs.to_excel(writer, 'Output', index=False)
    #volumes.to_excel(writer, 'Volume', index=False)

    writer.save()
Exemplo n.º 8
0
from cadet import Cadet

common = Cadet()

root = common.root

root.input.model.solver.gs_type = 1
root.input.model.solver.max_krylov = 0
root.input.model.solver.max_restarts = 10
root.input.model.solver.schur_safety = 1e-8

#CADET 3.1 and CADET-dev flags are in here so that it works with both
#CADET-dev removed column from the name on the inputs and outputs since for many
#operations it no longer makes sense
root.input['return'].write_solution_times = 1
root.input['return'].split_components_data = 1
root.input['return'].unit_000.write_sens_bulk = 0
root.input['return'].unit_000.write_sens_flux = 0
root.input['return'].unit_000.write_sens_inlet = 1
root.input['return'].unit_000.write_sens_outlet = 1
root.input['return'].unit_000.write_sens_particle = 0
root.input['return'].unit_000.write_solution_bulk = 0
root.input['return'].unit_000.write_solution_flux = 0
root.input['return'].unit_000.write_solution_inlet = 1
root.input['return'].unit_000.write_solution_outlet = 1
root.input['return'].unit_000.write_solution_particle = 0
root.input['return'].unit_000.write_sens_column = 0
root.input['return'].unit_000.write_sens_column_inlet = 1
root.input['return'].unit_000.write_sens_column_outlet = 1
root.input['return'].unit_000.write_solution_column = 0
root.input['return'].unit_000.write_solution_column_inlet = 1
Exemplo n.º 9
0
import matplotlib.pyplot as plt

import numpy

import pandas

from cadet import Cadet
Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe"

common = Cadet()
root = common.root

root.input.model.unit_001.discretization.par_disc_type = 'EQUIDISTANT_PAR'
root.input.model.unit_001.discretization.schur_safety = 1.0e-8
root.input.model.unit_001.discretization.use_analytic_jacobian = 1
root.input.model.unit_001.discretization.weno.boundary_model = 0
root.input.model.unit_001.discretization.weno.weno_eps = 1e-10
root.input.model.unit_001.discretization.weno.weno_order = 3
root.input.model.unit_001.discretization.gs_type = 1
root.input.model.unit_001.discretization.max_krylov = 0
root.input.model.unit_001.discretization.max_restarts = 10

root.input.solver.time_integrator.abstol = 1e-8
root.input.solver.time_integrator.algtol = 1e-12
root.input.solver.time_integrator.init_step_size = 1e-6
root.input.solver.time_integrator.max_steps = 1000000
root.input.solver.time_integrator.reltol = 1e-6

root.input.model.solver.gs_type = 1
root.input.model.solver.max_krylov = 0
root.input.model.solver.max_restarts = 10
Exemplo n.º 10
0
import matplotlib.pyplot as plt

import numpy

from cadet import Cadet

Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe"

import pandas

common = Cadet()
root = common.root

root.input.model.unit_001.discretization.par_disc_type = 'EQUIDISTANT_PAR'
root.input.model.unit_001.discretization.schur_safety = 1.0e-8
root.input.model.unit_001.discretization.use_analytic_jacobian = 1
root.input.model.unit_001.discretization.weno.boundary_model = 0
root.input.model.unit_001.discretization.weno.weno_eps = 1e-10
root.input.model.unit_001.discretization.weno.weno_order = 3
root.input.model.unit_001.discretization.gs_type = 1
root.input.model.unit_001.discretization.max_krylov = 0
root.input.model.unit_001.discretization.max_restarts = 10

root.input.solver.time_integrator.abstol = 1e-8
root.input.solver.time_integrator.algtol = 1e-12
root.input.solver.time_integrator.init_step_size = 1e-6
root.input.solver.time_integrator.max_steps = 1000000
root.input.solver.time_integrator.reltol = 1e-6

root.input.model.solver.gs_type = 1
root.input.model.solver.max_krylov = 0
Exemplo n.º 11
0
    def load_from_h5(self, file_path):
        cadet = CadetAPI()
        cadet.filename = file_path
        cadet.load()

        return cadet
Exemplo n.º 12
0
 def save_to_h5(self, process, file_path):
     cadet = CadetAPI()
     cadet.root = self.get_process_config(process)
     cadet.filename = file_path
     cadet.save()
Exemplo n.º 13
0
    def run(self, process, file_path=None):
        """Interface to the solver run function

        The configuration is extracted from the process object and then saved
        as a temporary .h5 file. After termination, the same file is processed
        and the results are returned.

        Cadet Return information:
        - 0: pass (everything allright)
        - 1: Standard Error
        - 2: IO Error
        - 3: Solver Error

        Parameters
        ----------
        process : Process
            process to be simulated

        Returns
        -------
        results : SimulationResults
            Simulation results including process and solver configuration.

        Raises
        ------
        TypeError
            If process is not instance of Process

        See also
        --------
        get_process_config
        get_simulation_results
        """
        if not isinstance(process, Process):
            raise TypeError('Expected Process')

        cadet = CadetAPI()
        cadet.root = self.get_process_config(process)

        if file_path is None:
            cadet.filename = self.get_tempfile_name()
        else:
            cadet.filename = file_path

        cadet.save()

        try:
            start = time.time()
            return_information = cadet.run(timeout=self.timeout)
            elapsed = time.time() - start
        except TimeoutExpired:
             raise CADETProcessError('Simulator timed out')

        if return_information.returncode != 0:
            self.logger.error(
                'Simulation of {} with parameters {} failed.'.format(
                    process.name, process.config
                )
            )
            raise CADETProcessError(
                'CADET Error: {}'.format(return_information.stderr)
            )

        try:
            cadet.load()
            results = self.get_simulation_results(
                process, cadet, elapsed, return_information
            )
        except TypeError:
            raise CADETProcessError('Unexpected error reading SimulationResults.')

        # Remove files
        if file_path is None:
            os.remove(cadet.filename)

        return results
Exemplo n.º 14
0
from cadet import Cadet

fix = Cadet()
fix.filename = r"F:\output\dextran\dextran_pulse.h5"
fix.load()
fix.root.input.model.unit_001.adsorption_model = "LINEAR"
fix.root.input.model.unit_001.adsorption.is_kinetic = 1
fix.root.input.model.unit_001.adsorption.lin_ka = [0.0]
fix.root.input.model.unit_001.adsorption.lin_kd = [1e3]
fix.save()
Exemplo n.º 15
0
# Import libraries
import numpy as np
import matplotlib.pyplot as plt

from cadet import Cadet
Cadet.cadet_path = '/path/to/cadet-cli'

# Create model object
model = Cadet()

# Number of unit operations
model.root.input.model.nunits = 3

# Inlet
model.root.input.model.unit_000.unit_type = 'INLET'
model.root.input.model.unit_000.ncomp = 1
model.root.input.model.unit_000.inlet_type = 'PIECEWISE_CUBIC_POLY'

# General Rate Model
model.root.input.model.unit_001.unit_type = 'GENERAL_RATE_MODEL'
model.root.input.model.unit_001.ncomp = 1

## Geometry
model.root.input.model.unit_001.col_length = 0.1  # m
model.root.input.model.unit_001.cross_section_area = 0.01  # m
model.root.input.model.unit_001.col_porosity = 0.37  # -
model.root.input.model.unit_001.par_porosity = 0.33  # -
model.root.input.model.unit_001.par_radius = 1e-6  # m

## Transport
model.root.input.model.unit_001.col_dispersion = 1e-8  # m^2 / s (interstitial volume)