Electric Kettle: Model Calibration

Introduction

This model studies how heating and cooling in an electric kettle can be modeled and controlled. In this notebook, the parameters for heating and cooling are fitted to real-world measurements.

Explore the available scenarios by evaluating each cell in order. Evaluation is done by selecting a cell and pressing Shift+Enter.

In order to get the full experience of this example, you need the following:

Wolfram SystemModeler; a free trial download is available at www.wolfram.com/system-modeler

The model that came in the same bundle as this notebook

For more information about Wolfram SystemModeler, visit www.wolfram.com/system-modeler.

Initialize

Define the model name:

mmodel="IndustryExamples.ConsumerProducts.ElectricKettle.ElectricKettleControl";

Model Calibration

To simplify the workflow and increase performance, the calibration is done in two parts: one where the cooling part of the simulation is calibrated to fit, and one where the heating circuit is fitted.

Data

Here is the measured data used to fit parameters in the model:

coolingdata={{0.`,99.`},{60.`,97.`},{120.`,96.`},{180.`,95.`},{240.`,94.`},{300.`,93.`},{360.`,91.`},{420.`,90.`},{480.`,89.`},{540.`,88.`},{600.`,88.`},{660.`,87.`},{720.`,86.`},{780.`,85.`},{900.`,84.`},{1200.`,81.`},{1500.`,78.`},{1800.`,75.`},{2100.`,73.`},{2400.`,71.`},{2700.`,68.`},{3000.`,66.`},{3015.`,66.`}};

heatdata={{0.`,22.`},{15.`,25.`},{30.`,31.`},{45.`,35.`},{60.`,39.`},{75.`,44.`},{90.`,48.`},{105.`,52.`},{120.`,57.`},{135.`,61.`},{150.`,66.`},{165.`,71.`},{180.`,75.`},{195.`,79.`},{210.`,83.`},{225.`,87.`},{240.`,91.`},{255.`,95.`},{265.`,98.`},{270.`,99.`}};

alldata=Join[heatdata,coolingdata+Table[{300,0},{Length[coolingdata]}]];

ListPlot[alldata]

Fit the Cooling Process by Varying the Radiation Conductance

Switch off the heating circuit:

fittingModel=SystemModel[mmodel,<|"ParameterValues"-> {"controlTable"-> {{0,0},{3015,0}}}|>];

Set up a function that simulates the cooling process with a certain parameter value and returns the resulting temperature curve:

fcool[pName_,pVal_?NumericQ]:=fcool[pName,pVal]=SystemModelSimulate[fittingModel,{0,3015},<|"InitialValues"->{"Water.T"->372.2},"ParameterValues"->{pName->pVal}|>,Method->{"InterpolationPoints"->3000}]["TemperatureInC"]

Find a fit for the radiation parameter by simulating and fitting to the measured cooling temperatures:

pars1=FindFit[coolingdata,fcool["Radiation.Gr",p][t],{{p,0.2}},t,StepMonitor:>PrintTemporary[p]]

Simulate with the fitted parameter:

simcool=SystemModelSimulate[fittingModel,{0,3000},<|"InitialValues"->{"Water.T"->372.2},"ParameterValues"->{"Radiation.Gr",p/.pars1}|>];

Compare with the measurement data:

Show[SystemModelPlot[simcool,"TemperatureInC",PlotStyle->Red],ListPlot[coolingdata]]

Fit the Heating Process by Varying the Resistance

Turn on the heating circuit:

fittingModel2=SystemModel[mmodel,<|"ParameterValues"-> {"controlTable"-> {{0,1},{270,1}}}|>];

Set up another function for simulating, this time simulating the heating process. Set a fixed number of interpolation points to increase performance:

fheat[pName_,pVal_?NumericQ]:=fheat[pName,pVal]=SystemModelSimulate[fittingModel2,{0,270},<|"ParameterValues"->{pName->pVal}|>,Method->{"InterpolationPoints"->3000}]["TemperatureInC"]

Compute the gradient with respect to the parameter, using the sensitivity functionality. This will give a faster and more accurate fit:

gheat[pName_,pVal_?NumericQ]:=gheat[pName,pVal]=SystemModelSimulateSensitivity[fittingModel2,{0,270},{pName},<|"ParameterValues"->{pName->pVal}|>,Method->{"InterpolationPoints"->3000}]["Water.T.sens("<>pName<>")"]

Find a resistance parameter that fits the data:

pars2=FindFit[heatdata,fheat["Resistor.R",p][t],{{p,14}},t,Gradient:>{Quiet[gheat["Resistor.R",p]][t]},StepMonitor:>PrintTemporary[p]]

Simulate with the found parameter:

simheat=SystemModelSimulate[fittingModel2,{0,270},<|"ParameterValues"->{"Resistor.R"->p/.pars2}|>];

Compare with the measurement data:

Show[SystemModelPlot[simheat,"TemperatureInC",PlotStyle->Red],ListPlot[heatdata]]

The Complete Simulation

Turn off the heating after 300 seconds to match the measurement data:

fittedModel=SystemModel[mmodel,<|"ParameterValues"-> {"controlTable"-> {{0,0},{13,1},{301,0},{3600,0}}}|>];

Now run the full simulation with both parameters fitted:

simall=SystemModelSimulate[fittedModel,{0,3430},<|"ParameterValues"->{{"Resistor.R",p/.pars2},{"Radiation.Gr",p/.pars1}}|>]

Compare with the measurement data:

Show[SystemModelPlot[simall,{"TemperatureInC"},PlotStyle->Red],ListPlot[alldata]]

Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

License

All content in this bundle is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. By accessing the content or using it in any way, you accept and agree to be bound by the terms of this license. If you do not agree to these Terms of Use, you may not use this content. Wolfram Research reserves the right to change, modify, add to, or remove portions of these Terms of Use at any time without notice. Please refer back to www.wolfram.com for the latest Terms of Use.

A summary of the licensing terms can be found at:
http://creativecommons.org/licenses/by-nc-sa/3.0

The full legal code can be found at: 
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode