Skip to content

suhaybabsi/thermal-core

Repository files navigation

Thermal-core

Java framework for modelling and solving thermal systems. It was inspired by the work described in the following papers:

The framewok is exposed to web through a REST API. Currently, it is used by application Thermal-visualizer to demonstrate framework full capabilities.

Try The Visualizer

Running Locally

Make sure you have Java and Maven installed.

$ git clone https://github.com/suhaybabsi/thermal-core.git
$ cd thermal-core
$ mvn install
$ java -jar target/thermal-core-1.0.jar

The app should now be running on localhost:5000.

Adding More Devices

All devices are subclasses of Device. You can subclass SteadyFlowDevice if your device have flows of mass streaming in and out (Steady State, Steady Flow "SSSF").

Devices that consume or produce work must implement either WorkConsumingDevice or WorkProducingDevice interface, respectively. Likewise, devices that produce heat must implement HeatProducingDevice.

Properties

Property class is used to define all themophysical properties included in the mathematical model. Use it to define all device-related properties.

For example, the property "compression ratio" of Compressors can defined as follows:

private final Property compressionRatio = new Property("Compression Ratio");

Flows

Flow class is used to store all thermodynamics properties related to fluid/gas flow. Devices that have flows streaming in and out of them can access those properties by the use of FlowManager class property:

Flow inFlow = flowManager.getIn(0);
Flow outFlow = flowManager.getOut(0);

Property massRateIn = inFlow.getMassRateProp();
Property massRateOut = outFlow.getMassRateProp();

Work

Use Work class to store the amount of work, and to define weather the device is consuming or producing that amount.

public Compressor() {
    super("Compressor", "compressor");
    work = new Work(WorkType.CONSUMED);
    ...

Governing Equations

The mathematical model of device should be defined using ThermalEquation inteface. See below example for mass conversation.

private static class MassConservationEquation extends ThermalEquation {
    private final Property massIn;
    private final Property massOut;
    public MassConservationEquation(
        Property massIn, Property massOut) {
        super(massIn, massOut);
        setName("Mass Conservation Equation");
        this.massIn = massIn;
        this.massOut = massOut;
    }
    
    @Override
    protected double evaluate() {
        
        double m_in = massIn.getValue();
        double m_out = massOut.getValue();
        return m_in - m_out;
    }   
}

After you define all equations classes, override configureEquations() method to create and add instances of those equations to the device model.

@Override
protected void configureEquations() throws ConfigurationException  {
    
    insureSingleFlowFluids();
    
    Flow inFlow = flowManager.getIn(0);
    Flow outFlow = flowManager.getOut(0);
    
    Property massRateIn = inFlow.getMassRateProp();
    Property massRateOut = outFlow.getMassRateProp();
    Fluid gas = inFlow.getFluid();
    
    Property P1 = inFlow.getPressureProp();
    Property P2 = outFlow.getPressureProp();
    
    Property T1 = inFlow.getTemperatureProp();
    Property T2 = outFlow.getTemperatureProp();

    addEquation(new CompressionEquation(compressionRatio, P1, P2));
    addEquation(new PolytropicTemperatureEquation(T1, T2, compressionRatio, polytropicEfficiency, gas));
    addEquation(new WorkEquation(this.work, massRateIn, T1, T2, gas));
    addEquation(new MassConservationEquation(massRateIn, massRateOut));
    
    outFlow.setFluid(Air.getInstance());
}

Contributing

If you'd like to introduce your device into the framework, please consider making a pull request