Skip to content

Commit

Permalink
Estimate panel temperature from ambient temperature and radiation
Browse files Browse the repository at this point in the history
Additional parameter: temperature coefficient
Adapt efficiency according to these values
Bugfix input filter
Prepare V1.2
  • Loading branch information
woheller69 committed Apr 13, 2023
1 parent ab477f2 commit a1f1468
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 145 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "org.woheller69.solxpect"
minSdkVersion 26
targetSdkVersion 31
versionCode 11
versionName "1.1"
versionCode 12
versionName "1.2"

buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/solxpect/\""
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/assets/help/help-de.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ <h3>Zellen max. Leistung [W]</h3>
<h3>Zelleneffizienz [%]</h3>
Energieanteil in Form von Sonnenlicht, der von der Solarzelle in Strom umgewandelt werden kann.

<h3>Temperaturkoeffizient [%/K]</h3>
Abhängigkeit der Leistung der Solarmodule von der Temperatur (normalerweise im Bereich von -0.4%/K).

<h3>Zellenfläche [m<sup>2</sup>]</h3>
Größe der aktiven Fläche Ihres Solarpanels.
Fläche Ihres Solarpanels.

<h3>Diffuse Strahlungseffizienz [%]</h3>
Wirkungsgrad Ihres Solarkraftwerks bei diffuser Strahlung. Bei der Ausrichtung nach oben sollte er etwa 100 % betragen, bei der Ausrichtung zum Horizont etwa 50 %.
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/assets/help/help-en.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ <h3>Cells max power [W]</h3>
<h3>Cells efficiency [%]</h3>
Portion of energy in the form of sunlight that can be converted into electricity by the solar cell.

<h3>Temperature coefficient [%/K]</h3>
Dependence of the cell power on temperature (usually in the range of -0.4%/K).

<h3>Cell area [m<sup>2</sup>]</h3>
Size of the active area your solar panel.
Size of your solar panel.

<h3>Diffuse radiation efficiency [%]</h3>
Efficiency of your solar power plant for diffuse radiation. When pointing up it should be around 100%, when pointing to the horizon it may be around 50%.
Expand Down
21 changes: 18 additions & 3 deletions app/src/main/java/org/woheller69/weather/SolarPowerPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SolarPowerPlant {
double cellsMaxPower;
double cellsArea;
double cellsEfficiency;
double cellsTempCoeff;
double diffuseEfficiency;
double inverterPowerLimit;
double inverterEfficiency;
Expand All @@ -22,7 +23,7 @@ public class SolarPowerPlant {
private int[] shadingElevation;
private int[] shadingOpacity;

public SolarPowerPlant(double latitude, double longitude, double cellsMaxPower, double cellsArea, double cellsEfficiency, double diffuseEfficiency, double inverterPowerLimit, double inverterEfficiency, double azimuthAngle, double tiltAngle, int[] shadingElevation, int[] shadingOpacity ) {
public SolarPowerPlant(double latitude, double longitude, double cellsMaxPower, double cellsArea, double cellsEfficiency, double cellsTempCoeff, double diffuseEfficiency, double inverterPowerLimit, double inverterEfficiency, double azimuthAngle, double tiltAngle, int[] shadingElevation, int[] shadingOpacity ) {
this.latitude = latitude;
this.longitude = longitude;
this.cellsMaxPower = cellsMaxPower;
Expand All @@ -35,10 +36,11 @@ public SolarPowerPlant(double latitude, double longitude, double cellsMaxPower,
this.tiltAngle = tiltAngle;
this.shadingElevation = shadingElevation;
this.shadingOpacity = shadingOpacity;
this.cellsTempCoeff = cellsTempCoeff / 100;

}

public float getPower(double solarPowerNormal, double solarPowerDiffuse, long epochTimeSeconds) {
public float getPower(double solarPowerNormal, double solarPowerDiffuse, long epochTimeSeconds, float ambientTemperature) {
Instant i = Instant.ofEpochSecond(epochTimeSeconds); //currentTimeMillis is in GMT
ZonedDateTime dateTime = ZonedDateTime.ofInstant(i, ZoneId.of("GMT"));

Expand Down Expand Up @@ -70,10 +72,23 @@ public float getPower(double solarPowerNormal, double solarPowerDiffuse, long ep
}
}
}
double dcPower = (solarPowerNormal * efficiency + solarPowerDiffuse * diffuseEfficiency )* cellsEfficiency * cellsArea;

float totalRadiationOnCell = (float) (solarPowerNormal * efficiency + solarPowerDiffuse * diffuseEfficiency); //flat plate equivalent of the solar irradiance
float cellTemperature = calcCellTemperature(ambientTemperature,totalRadiationOnCell);

double dcPower = totalRadiationOnCell * cellsEfficiency * (1+(cellTemperature - 25)*cellsTempCoeff) * cellsArea;

double acPower = Math.min(dcPower * inverterEfficiency, inverterPowerLimit);

return (float) acPower;
}

public static float calcCellTemperature(float ambientTemperature, float totalIrradiance){
//models from here: https://www.scielo.br/j/babt/a/FBq5Pmm4gSFqsfh3V8MxfGN/ Photovoltaic Cell Temperature Estimation for a Grid-Connect Photovoltaic Systems in Curitiba
//float cellTemperature = 30.006f + 0.0175f*(totalIrradiance-300f)+1.14f*(ambientTemperature-25f); //Lasnier and Ang Lasnier, F.; Ang, T. G. Photovoltaic engineering handbook, 1st ed.; IOP Publishing LTD: Lasnier, France, 1990; pp. 258.
//float cellTemperature = ambientTemperature + 0.028f*totalIrradiance-1f; //Schott Schott, T. Operation temperatures of PV modules. Photovoltaic solar energy conference 1985, pp. 392-396.
float cellTemperature = ambientTemperature + 0.0342f*totalIrradiance; //Ross model: https://www.researchgate.net/publication/275438802_Thermal_effects_of_the_extended_holographic_regions_for_holographic_planar_concentrator
//assuming "not so well cooled" : 0.0342
return cellTemperature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private void editCityToWatch(CityToWatch city) {
EditText editCellsMaxPower = (EditText) dialogView.findViewById(R.id.EditLocation_Cell_Max_Power);
EditText editCellsArea = (EditText) dialogView.findViewById(R.id.EditLocation_Cells_Area);
EditText editCellsEfficiency = (EditText) dialogView.findViewById(R.id.EditLocation_Cell_Efficiency);
EditText editCellsTempCoeff = (EditText) dialogView.findViewById(R.id.EditLocation_Cell_Temp_Coeff);
EditText editDiffuseEfficiency = (EditText) dialogView.findViewById(R.id.EditLocation_Diffuse_Efficiency);
EditText editInverterPowerLimit = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Power_Limit);
EditText editInverterEfficiency = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Efficiency);
Expand All @@ -204,6 +205,8 @@ private void editCityToWatch(CityToWatch city) {
editCellsArea.setText(Float.toString(city.getCellsArea()));
editCellsEfficiency.setText(Float.toString(city.getCellsEfficiency()));
editCellsEfficiency.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
editCellsTempCoeff.setText(Float.toString(city.getCellsTempCoeff()));
editCellsTempCoeff.setFilters(new InputFilter[]{ new InputFilterMinMax(-100, 100)});
editDiffuseEfficiency.setText(Float.toString(city.getDiffuseEfficiency()));
editDiffuseEfficiency.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
editInverterPowerLimit.setText(Float.toString(city.getInverterPowerLimit()));
Expand Down Expand Up @@ -237,6 +240,7 @@ public void afterTextChanged(Editable editable) {
Float.parseFloat(editCellsMaxPower.getText().toString().isEmpty() ? "0" : editCellsMaxPower.getText().toString()),
Float.parseFloat(editCellsArea.getText().toString().isEmpty() ? "0" : editCellsArea.getText().toString()),
Float.parseFloat(editCellsEfficiency.getText().toString().isEmpty() ? "0" : editCellsEfficiency.getText().toString()),
Float.parseFloat(editCellsTempCoeff.getText().toString().isEmpty() ? "0" : editCellsTempCoeff.getText().toString()),
Float.parseFloat(editDiffuseEfficiency.getText().toString().isEmpty() ? "0" : editDiffuseEfficiency.getText().toString()),
Float.parseFloat(editInverterPowerLimit.getText().toString().isEmpty() ? "0" : editInverterPowerLimit.getText().toString()),
Float.parseFloat(editInverterEfficiency.getText().toString().isEmpty() ? "0" : editInverterEfficiency.getText().toString()),
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/org/woheller69/weather/database/CityToWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CityToWatch {
private float cellsMaxPower;
private float cellsArea;
private float cellsEfficiency;
private float cellsTempCoeff;
private float diffuseEfficiency;
private float inverterPowerLimit;
private float inverterEfficiency;
Expand All @@ -36,14 +37,15 @@ public CityToWatch(int rank, int id, int cityId, float lon, float lat, String ci
this.id = id;
this.cityId = cityId;
this.cityName = cityName;
this.cellsMaxPower=650;
this.cellsArea=3.18f;
this.cellsEfficiency=19.3f;
this.diffuseEfficiency=40;
this.inverterPowerLimit =600;
this.inverterEfficiency =95;
this.azimuthAngle=170;
this.tiltAngle =90;
this.cellsMaxPower = 650;
this.cellsArea = 3.18f;
this.cellsEfficiency = 19.3f;
this.cellsTempCoeff = -0.4f;
this.diffuseEfficiency = 40;
this.inverterPowerLimit = 600;
this.inverterEfficiency = 95;
this.azimuthAngle = 170;
this.tiltAngle = 90;

}

Expand Down Expand Up @@ -182,4 +184,12 @@ public String getShadingElevationString() {
public String getShadingOpacityString() {
return Arrays.toString(shadingOpacity).replaceAll("\\[|\\]|\\s", "");
}

public float getCellsTempCoeff() {
return cellsTempCoeff;
}

public void setCellsTempCoeff(float cellsTempCoeff) {
this.cellsTempCoeff = cellsTempCoeff;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class SQLiteHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;
private Context context;

private List<City> allCities = new ArrayList<>();
Expand Down Expand Up @@ -53,6 +53,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
private static final String CITIES_TO_WATCH_TILT_ANGLE = "tilt_angle";
private static final String CITIES_TO_WATCH_SHADING_ELEVATION = "shading_elevation";
private static final String CITIES_TO_WATCH_SHADING_OPACITY = "shading_opacity";
private static final String CITIES_TO_WATCH_CELLS_TEMP_COEFF = "cells_temp_coeff";

//Names of columns in TABLE_FORECAST
private static final String FORECAST_ID = "forecast_id";
Expand Down Expand Up @@ -135,7 +136,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {
CITIES_TO_WATCH_AZIMUTH_ANGLE + " REAL NOT NULL," +
CITIES_TO_WATCH_TILT_ANGLE + " REAL NOT NULL," +
CITIES_TO_WATCH_SHADING_ELEVATION + " VARCHAR(255) NOT NULL," +
CITIES_TO_WATCH_SHADING_OPACITY + " VARCHAR(255) NOT NULL)";
CITIES_TO_WATCH_SHADING_OPACITY + " VARCHAR(255) NOT NULL," +
CITIES_TO_WATCH_CELLS_TEMP_COEFF + " REAL NOT NULL)";

public static SQLiteHelper getInstance(Context context) {
if (instance == null && context != null) {
Expand All @@ -160,6 +162,12 @@ public void onCreate(SQLiteDatabase db) {

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
switch(oldVersion) {
case 1:
db.execSQL("ALTER TABLE "+TABLE_CITIES_TO_WATCH+" ADD COLUMN "+CITIES_TO_WATCH_CELLS_TEMP_COEFF+" REAL DEFAULT 0");
// we want both updates, so no break statement here...
}

}


Expand All @@ -185,6 +193,7 @@ public synchronized long addCityToWatch(CityToWatch city) {
values.put(CITIES_TO_WATCH_TILT_ANGLE,city.getTiltAngle());
values.put(CITIES_TO_WATCH_SHADING_ELEVATION,city.getShadingElevationString());
values.put(CITIES_TO_WATCH_SHADING_OPACITY,city.getShadingOpacityString());
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,city.getCellsTempCoeff());

long id=database.insert(TABLE_CITIES_TO_WATCH, null, values);

Expand Down Expand Up @@ -218,6 +227,7 @@ public synchronized CityToWatch getCityToWatch(int id) {
", " + CITIES_TO_WATCH_TILT_ANGLE +
", " + CITIES_TO_WATCH_SHADING_ELEVATION +
", " + CITIES_TO_WATCH_SHADING_OPACITY +
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
", " + CITIES_TO_WATCH_COLUMN_RANK +
" FROM " + TABLE_CITIES_TO_WATCH +
" WHERE " + CITIES_TO_WATCH_CITY_ID + " = ?", arguments);
Expand All @@ -240,7 +250,8 @@ public synchronized CityToWatch getCityToWatch(int id) {
cityToWatch.setTiltAngle(Float.parseFloat(cursor.getString(12)));
cityToWatch.setShadingElevation(cursor.getString(13));
cityToWatch.setShadingOpacity(cursor.getString(14));
cityToWatch.setRank(Integer.parseInt(cursor.getString(15)));
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
cityToWatch.setRank(Integer.parseInt(cursor.getString(16)));

cursor.close();
}
Expand Down Expand Up @@ -271,6 +282,7 @@ public synchronized List<CityToWatch> getAllCitiesToWatch() {
", " + CITIES_TO_WATCH_TILT_ANGLE +
", " + CITIES_TO_WATCH_SHADING_ELEVATION +
", " + CITIES_TO_WATCH_SHADING_OPACITY +
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
", " + CITIES_TO_WATCH_COLUMN_RANK +
" FROM " + TABLE_CITIES_TO_WATCH
, new String[]{});
Expand All @@ -295,7 +307,8 @@ public synchronized List<CityToWatch> getAllCitiesToWatch() {
cityToWatch.setTiltAngle(Float.parseFloat(cursor.getString(12)));
cityToWatch.setShadingElevation(cursor.getString(13));
cityToWatch.setShadingOpacity(cursor.getString(14));
cityToWatch.setRank(Integer.parseInt(cursor.getString(15)));
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
cityToWatch.setRank(Integer.parseInt(cursor.getString(16)));

cityToWatchList.add(cityToWatch);
} while (cursor.moveToNext());
Expand Down Expand Up @@ -325,6 +338,7 @@ public synchronized void updateCityToWatch(CityToWatch cityToWatch) {
values.put(CITIES_TO_WATCH_TILT_ANGLE,cityToWatch.getTiltAngle());
values.put(CITIES_TO_WATCH_SHADING_ELEVATION,cityToWatch.getShadingElevationString());
values.put(CITIES_TO_WATCH_SHADING_OPACITY,cityToWatch.getShadingOpacityString());
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,cityToWatch.getCellsTempCoeff());

database.update(TABLE_CITIES_TO_WATCH, values, CITIES_TO_WATCH_ID + " = ?",
new String[]{String.valueOf(cityToWatch.getId())});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,40 @@

public class InputFilterMinMax implements InputFilter {

private int min, max;
private float min, max;

public InputFilterMinMax(int min, int max) {
public InputFilterMinMax(float min, float max) {
this.min = min;
this.max = max;
}


@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
String oldString = dest.toString();
String insertString = source.toString();
String newString = new StringBuilder(oldString).insert(dstart,insertString).toString();
float input = Float.parseFloat(newString);
if (isInRange(min, max, input))
return null;
else
return "";
try {
String oldString = dest.toString();
String insertString = source.toString();
String newString = oldString.substring(0, dstart) + oldString.substring(dend);
newString = newString.substring(0, dstart) + insertString + newString.substring(dstart);
float input = Float.parseFloat(newString);

if (isInRange(min, max, input)) {
return null;
} else {
if (source.equals("") && dest.toString().length() != 1) {
//backspace was clicked, do not accept that change, unless user is deleting the last char
return dest.subSequence(dstart, dend);
} else {
return "";
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return "";
}

private boolean isInRange(int a, int b, float c) {
private boolean isInRange(float a, float b, float c) {
return b > a ? c >= a && c <= b : c >= b && c <= a;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ItemViewHolder extends RecyclerView.ViewHolder {
public TextView cellsMaxPower;
public TextView cellsArea;
public TextView cellsEfficiency;
public TextView cellsTempCoeff;
public TextView diffuseEfficiency;
public TextView inverterPowerLimit;
public TextView inverterEfficiency;
Expand All @@ -41,6 +42,7 @@ public ItemViewHolder(View itemView) {
this.cellsMaxPower = (TextView) itemView.findViewById(R.id.city_cells_max_power);
this.cellsArea = (TextView) itemView.findViewById(R.id.city_cells_area);
this.cellsEfficiency = (TextView) itemView.findViewById(R.id.city_cells_efficiency);
this.cellsTempCoeff = (TextView) itemView.findViewById(R.id.city_cells_temp_coeff);
this.diffuseEfficiency = (TextView) itemView.findViewById(R.id.city_diffuse_efficiency);
this.inverterPowerLimit = (TextView) itemView.findViewById(R.id.city_inverter_power_limit);
this.inverterEfficiency = (TextView) itemView.findViewById(R.id.city_inverter_efficiency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void onBindViewHolder(ItemViewHolder holder, int position) {
holder.tiltAngle.setText(context.getString(R.string.edit_location_hint_tilt) +": "+ cities.get(position).getTiltAngle());
holder.cellsMaxPower.setText(context.getString(R.string.edit_location_hint_cells_max_power) +": "+ cities.get(position).getCellsMaxPower());
holder.cellsEfficiency.setText(context.getString(R.string.edit_location_hint_cells_efficiency) +": "+ cities.get(position).getCellsEfficiency());
holder.cellsTempCoeff.setText(context.getString(R.string.edit_location_hint_cells_temp_coeff) +": "+ cities.get(position).getCellsTempCoeff());
holder.cellsArea.setText(context.getString(R.string.edit_location_hint_cells_area) +": "+ cities.get(position).getCellsArea());
holder.diffuseEfficiency.setText(context.getString(R.string.edit_location_hint_diffuse_efficiency) +": "+ cities.get(position).getDiffuseEfficiency());
holder.inverterPowerLimit.setText(context.getString(R.string.edit_location_hint_inverter_power_limit) +": "+ cities.get(position).getInverterPowerLimit());
Expand Down Expand Up @@ -114,7 +115,7 @@ public void onItemMove(int fromPosition, int toPosition) {
public CityToWatch getCitytoWatch(int position){
return cities.get(position);
}
public void updateCity(CityToWatch cityToWatch, String cityName, float latitude, float longitude, float azimuth, float tilt, float cellsMaxPower, float cellsArea, float cellsEfficiency, float diffuseEfficiency, float inverterPowerLimit, float inverterEfficiency, int[] shadingElevation, int[] shadingOpacity) {
public void updateCity(CityToWatch cityToWatch, String cityName, float latitude, float longitude, float azimuth, float tilt, float cellsMaxPower, float cellsArea, float cellsEfficiency, float cellsTempCoeff, float diffuseEfficiency, float inverterPowerLimit, float inverterEfficiency, int[] shadingElevation, int[] shadingOpacity) {
cityToWatch.setCityName(cityName);
cityToWatch.setLatitude(latitude);
cityToWatch.setLongitude(longitude);
Expand All @@ -123,6 +124,7 @@ public void updateCity(CityToWatch cityToWatch, String cityName, float latitude,
cityToWatch.setCellsMaxPower(cellsMaxPower);
cityToWatch.setCellsArea(cellsArea);
cityToWatch.setCellsEfficiency(cellsEfficiency);
cityToWatch.setCellsTempCoeff(cellsTempCoeff);
cityToWatch.setDiffuseEfficiency(diffuseEfficiency);
cityToWatch.setInverterPowerLimit(inverterPowerLimit);
cityToWatch.setInverterEfficiency(inverterEfficiency);
Expand Down
Loading

0 comments on commit a1f1468

Please sign in to comment.