Skip to content

Commit

Permalink
Redirection of console stream to consolePane; Added missing output
Browse files Browse the repository at this point in the history
values/controls; Added input parameter check; Added first tooltip (test)
  • Loading branch information
d.emmel authored and d.emmel committed Jul 10, 2023
1 parent 41a5e48 commit 915e531
Show file tree
Hide file tree
Showing 17 changed files with 3,749 additions and 1,677 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@
<version>2.2</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.scilab.forge/jlatexmath -->
<dependency>
<groupId>org.scilab.forge</groupId>
<artifactId>jlatexmath</artifactId>
<version>1.0.7</version>
</dependency>

</dependencies>

Expand Down
76 changes: 76 additions & 0 deletions src/main/java/de/dominikemmel/reflowlab/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@

import java.awt.Color;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;

import de.dominikemmel.reflowlab.controller.maincontrol.ConsoleOverviewController;
import de.dominikemmel.reflowlab.controller.maincontrol.ReaderThread;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;



public class MainApp extends Application {

private final PipedInputStream pipeIn = new PipedInputStream();
private final PipedInputStream pipeIn2 = new PipedInputStream();
Thread errorThrower;
private Thread reader;
private Thread reader2;
boolean quit;
private TextArea txtArea;

@Override
public void start(Stage primaryStage) throws IOException {
Expand All @@ -36,12 +53,71 @@ public void start(Stage primaryStage) throws IOException {
// Database.createConnection("electrolyte");
// Database.createConnection("costAnalysis");
// Database.createConnection("reference");


txtArea = ConsoleOverviewController.staticTxtArea;

//Thread execution for reading output stream
executeReaderThreads();

//Thread closing on stag close event
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {

closeThread();
Platform.exit();
System.exit(0);
}
});


}

//method to handle thread closing on stage closing
synchronized void closeThread() {
System.out.println("Message: Stage is closed.");
this.quit = true;
notifyAll();
try { this.reader.join(1000L); this.pipeIn.close(); } catch (Exception e) {
}try { this.reader2.join(1000L); this.pipeIn2.close(); } catch (Exception e) {
}System.exit(0);
}

/**
* @param args the command line arguments
*/

public static void main(String[] args) throws Exception {

launch(args);
}

public void executeReaderThreads() {
try {
PipedOutputStream pout = new PipedOutputStream(this.pipeIn);
System.setOut(new PrintStream(pout, true));
}
catch (IOException io) {

}
catch (SecurityException se) {

}

try {
PipedOutputStream pout2 = new PipedOutputStream(this.pipeIn2);
System.setErr(new PrintStream(pout2, true));
}
catch (IOException io) {

}
catch (SecurityException se) {

}

ReaderThread obj = new ReaderThread(pipeIn, pipeIn2, errorThrower, reader, reader2, quit, txtArea);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public void reloadDataActiveMaterials() {

try {
tblActiveMaterial.refresh();

Database.createConnection("activeMaterial");

ResultSet res = Database.selectData("activeMaterial");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,

// if (reversibleVoltage == 0) {
if (!standardSelected) {
if (catholyteReversiblePotential == 0) {
if (catholyteReversiblePotential == 42) {
// catholyteReversiblePotential = calculationElectrolytePotential("standardE_Input", catholyteStandardPotential, temp, z, catholyteActMatRedConc, catholyteActMatOxConc, catholyteActMatCoeff, protonConc, catholyteActMatNumberProton);

catholyteReversiblePotential = catholyteStandardPotential - G*temp/(z*F)*
Expand All @@ -355,7 +355,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,
// Math.log(Math.pow(catholyteActMatRedConc,catholyteActMatCoeff)/(Math.pow(catholyteActMatOxConc,catholyteActMatCoeff)*Math.pow(1,catholyteActMatNumberProton)));

}
if (anolyteReversiblePotential == 0) {
if (anolyteReversiblePotential == 42) {
anolyteReversiblePotential= anolyteStandardPotential - G*temp/(z*F)*
Math.log(Math.pow(anolyteActMatRedConc,anolyteActMatCoeff)/(Math.pow(anolyteActMatOxConc,anolyteActMatCoeff)*Math.pow(protonConc,anolyteActMatNumberProton)));

Expand All @@ -376,7 +376,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,
} else {
//Anolyte = standard:
if (anolyteStandard) {
if (anolyteReversiblePotential == 0) {
if (anolyteReversiblePotential == 42) {
if (leftAqueous) {
anolyteReversiblePotential = -0.6 - G*temp/(2*F)*Math.log(1/Math.pow(protonConc,2));

Expand All @@ -385,7 +385,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,
//TODO: organic solvents
}
}
if (catholyteReversiblePotential == 0) {
if (catholyteReversiblePotential == 42) {
catholyteReversiblePotential = catholyteStandardPotential - G*temp/(z*F)*
Math.log(Math.pow(catholyteActMatRedConc,catholyteActMatCoeff)/(Math.pow(catholyteActMatOxConc,catholyteActMatCoeff)*Math.pow(protonConc,catholyteActMatNumberProton)));

Expand All @@ -400,7 +400,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,
//Catholyte = standard:
if (catholyteStandard) {

if (catholyteReversiblePotential == 0) {
if (catholyteReversiblePotential == 42) {
if (leftAqueous) {
catholyteReversiblePotential = 1.6 - G*temp/(4*F)*Math.log(1/Math.pow(protonConc,4));

Expand All @@ -410,7 +410,7 @@ public ObjCostAnalysisOutput calculationPolarisation(ObjCostAnalysisInput input,
}
}

if (anolyteReversiblePotential == 0) {
if (anolyteReversiblePotential == 42) {
anolyteReversiblePotential = anolyteStandardPotential - G*temp/(z*F)*
Math.log(Math.pow(anolyteActMatRedConc,anolyteActMatCoeff)/(Math.pow(anolyteActMatOxConc,anolyteActMatCoeff)*Math.pow(protonConc,anolyteActMatNumberProton)));

Expand Down Expand Up @@ -991,12 +991,12 @@ public ObjCostAnalysisOutput calculationElectrolyte(ObjCostAnalysisInput input,

// electrolyte:
double anolyteSaltConc = input.anolyteSaltConc.getValue();
double anolyteSaltSol = input.anolyteSaltSol.getValue();
// double anolyteSaltSol = input.anolyteSaltSol.getValue();
double anolyteSaltMolMass = input.anolyteSaltMolMass.getValue();
double anolyteSolventDensity = input.anolyteSolventDensity.getValue();
double anolyteActMatMolMass = input.anolyteActMatMolMass.getValue();
double catholyteSaltConc = input.catholyteSaltConc.getValue();
double catholyteSaltSol = input.catholyteSaltSol.getValue();
// double catholyteSaltSol = input.catholyteSaltSol.getValue();
double catholyteSaltMolMass = input.catholyteSaltMolMass.getValue();
double catholyteSolventDensity = input.catholyteSolventDensity.getValue();
double catholyteActMatMolMass = input.catholyteActMatMolMass.getValue();
Expand Down Expand Up @@ -1031,15 +1031,12 @@ public ObjCostAnalysisOutput calculationElectrolyte(ObjCostAnalysisInput input,


// L / kg kg^-1:
if (anolyteSaltSol == 0) {
anolyteSaltSol = anolyteSaltConc * anolyteSaltMolMass / (anolyteSolventDensity*1000);
}

double anolyteSaltSol = anolyteSaltConc * anolyteSaltMolMass / (anolyteSolventDensity*1000);

double anolyteActMatSol = anolyteActMatConc * anolyteActMatMolMass / (anolyteSolventDensity*1000);

if (catholyteSaltSol == 0) {
catholyteSaltSol = catholyteSaltConc * catholyteSaltMolMass / (catholyteSolventDensity*1000);
}
double catholyteSaltSol = catholyteSaltConc * catholyteSaltMolMass / (catholyteSolventDensity*1000);

double catholyteActMatSol = catholyteActMatConc * catholyteActMatMolMass / (catholyteSolventDensity*1000);

Expand Down Expand Up @@ -1280,7 +1277,7 @@ public ObjCostAnalysisOutput calculationTotalCosts(ObjCostAnalysisInput input, O
double anolyteEnergyDensityKg = anolyteEnergyDensity / (anolyteSolventDensity + (anolyteActMatMolMass * Math.pow(10, -3) * anolyteActMatConc));
double catholyteEnergyDensityKg = catholyteEnergyDensity / (catholyteSolventDensity + (catholyteActMatMolMass * Math.pow(10, -3) * catholyteActMatConc));
double energyDensityKg = 0;
//TODO: Export with EnergyDensity(Working electrode) + Frontend: Add anolyte and catholyte EnergyDensity

if (standardSelected) {
//Anolyte = standard:
if (anolyteStandard) {
Expand Down Expand Up @@ -1322,8 +1319,8 @@ public ObjCostAnalysisOutput calculationTotalCosts(ObjCostAnalysisInput input, O
output.anolyteEnergyDensity.set(anolyteEnergyDensity);
output.catholyteEnergyDensity.set(catholyteEnergyDensity);
output.energyDensity.set(energyDensity);
// output.anolyteEnergyDensityKg.set(anolyteEnergyDensityKg);
// output.catholyteEnergyDensityKg.set(catholyteEnergyDensityKg);
output.anolyteEnergyDensityKg.set(anolyteEnergyDensityKg);
output.catholyteEnergyDensityKg.set(catholyteEnergyDensityKg);
output.energyDensityKg.set(energyDensityKg);


Expand Down
Loading

0 comments on commit 915e531

Please sign in to comment.