Skip to content

Commit

Permalink
Change handling of saved files so that it doesn't crash when loading …
Browse files Browse the repository at this point in the history
…files whose names were changed after saving
  • Loading branch information
NickKarpowicz committed Nov 6, 2024
1 parent ffb18e0 commit 4b793ae
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
Binary file modified Documentation/Images/flatpakScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions Documentation/LightwaveExplorerDocumentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"<p style=\"text-align: center;\">Nick Karpowicz</p>\n",
"<p style=\"text-align: center;\">Max Planck Institute of Quantum optics</p>\n",
"\n",
"<p style=\"text-align: center;\"><img src=\"Images/LWEicon.png\" width=\"200\" height=\"200\"></p>\n",
"\n",
"<p style=\"text-align: center;\">(icon made by Stable Diffusion)</p>\n",
"<p style=\"text-align: center;\"><img src=\"../Source/BuildResources/Icon.svg\" width=\"200\" height=\"200\"></p>\n",
"\n",
"\n",
"### Welcome to Lightwave Explorer\n",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Linux: [Get it on Flathub!](https://flathub.org/apps/io.github.NickKarpowicz.Lig

Lightwave explorer is an open source nonlinear optics simulator, intended to be fast, visual, and flexible for students and researchers to play with ultrashort laser pulses and nonlinear optics without having to buy a laser first.

<p style="text-align: center;"><img src="Documentation/Images/Interface_screenshot_Qt.png"></p>
<p style="text-align: center;"><img src="Documentation/Images/flatpakScreenshot.png"></p>

The simulation was written CUDA in order to run quickly on modern graphics cards. I've subsequently generalized it so that it can be run in two other ways: SYCL on CPUs and Intel GPUs, and using OpenMP to run on CPUs. Accordingly, I hope that the results are fast enough that even complicated systems can be simulated within a human attention span.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<project_license>MIT</project_license>
<content_rating type="oars-1.1" />
<releases>
<release version="2024.05" date="2024-11-06" urgency="high">
<description>
<p>This version fixes issues with biaxial crystals, and introduces a pair of sequence functions, rotateIntoBiaxial() and rotateFromBiaxial() to move in and out of the refractive index ellipse minor and major axes, even for arbitrary crystal orientations.</p>
<p>It also includes a fix for a bug where files could not be loaded if their names were changed.</p>
</description>
</release>
<release version="2024.04" date="2024-09-19" urgency="high">
<description>
<p>This is a bug-fix release, which corrects a missing factor of 2 in UPPE propagation, and corrects the BiBO second order nonlinear tensor</p>
Expand Down Expand Up @@ -84,4 +90,10 @@
<image>https://raw.githubusercontent.com/NickKarpowicz/LightwaveExplorer/master/Documentation/Images/flatpakScreenshot.png</image>
</screenshot>
</screenshots>

<branding>
<color type="primary" scheme_preference="light">#bbffff</color>
<color type="primary" scheme_preference="dark">#613583</color>
</branding>

</component>
33 changes: 24 additions & 9 deletions Source/LightwaveExplorerUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <iomanip>
#include <sstream>
#include <filesystem>
#ifdef USEFFTW
#include <fftw3.h>
#else
Expand Down Expand Up @@ -44,6 +45,19 @@ bool zipContainsFile(std::string zipPath, std::string filename){
return fileIndex > 0;
}

std::string zipGetBasename(const std::string& zipPath){
mz_zip_archive zip = {};
mz_zip_reader_init_file(&zip, zipPath.c_str(), 0);
auto nfiles = mz_zip_reader_get_num_files(&zip);
if(nfiles > 0){
char name[1024]={};
mz_zip_reader_get_filename(&zip, 0, name, 1024);
std::string interiorName(name);
return std::filesystem::path(interiorName).stem().string();
}
else return "ERROR";
}

loadedInputData::loadedInputData(const std::string& zipPath, const std::string& filename){
if(zipContainsFile(zipPath, filename)){
std::vector<char> data;
Expand All @@ -58,17 +72,18 @@ loadedInputData::loadedInputData(const std::string& zipPath, const std::string&
int simulationParameterSet::loadSavedFields(const std::string& outputBase, bool isZipFile) {
if(isZipFile){
std::string zipPath = outputBase + ".zip";
std::string trueBase = zipGetBasename(zipPath);
zipIntoMemory(zipPath,
getBasename(outputBase)+"_Ext.dat",
trueBase+"_Ext.dat",
ExtOut,
2 * (Ngrid * Nsims * Nsims2) * sizeof(double));
zipIntoMemory(zipPath,
getBasename(outputBase)+"_spectrum.dat",
trueBase+"_spectrum.dat",
totalSpectrum,
Nsims * Nsims2 * 3 * Nfreq * sizeof(double));
pulse1LoadedData = loadedInputData(zipPath,getBasename(outputBase)+"_pulse1.dat");
pulse2LoadedData = loadedInputData(zipPath,getBasename(outputBase)+"_pulse2.dat");
fittingLoadedData = loadedInputData(zipPath,getBasename(outputBase)+"_fittingTarget.dat");
pulse1LoadedData = loadedInputData(zipPath,trueBase+"_pulse1.dat");
pulse2LoadedData = loadedInputData(zipPath,trueBase+"_pulse2.dat");
fittingLoadedData = loadedInputData(zipPath,trueBase+"_fittingTarget.dat");
}
else{
std::string Epath = outputBase;
Expand Down Expand Up @@ -500,7 +515,7 @@ std::string simulationParameterSet::settingsString(){
}
fs << '\x0A';
}
fs << "Code version: 2024.3";
fs << "Code version: 2024.5";
fs << '\x0A';
return fs.str();
}
Expand Down Expand Up @@ -616,8 +631,8 @@ int simulationParameterSet::readInputParametersFile(
if(filePath.length() >= 4
&& filePath.substr(filePath.length()-4)==".zip") {
std::vector<char> dataVector;
std::string textPath = getBasename(filePath);
textPath = textPath.substr(0,textPath.length()-4) + ".txt";
std::string textPath = zipGetBasename(filePath);
textPath = textPath + ".txt";
zipIntoMemory(filePath, textPath, dataVector);
dataVector.push_back(0);
contents = std::string(dataVector.data(), dataVector.size());
Expand Down Expand Up @@ -1067,7 +1082,7 @@ void simulationBatch::loadPulseFiles() {
}
void simulationBatch::loadOptics(const std::string& zipPath){
bool keepLoading = true;
std::string base = std::filesystem::path(zipPath).stem().string() + "_optic";
std::string base = zipGetBasename(zipPath) + "_optic";
int ind = 0;
while(keepLoading){
std::string currentFile = base + std::to_string(ind) + ".txt";
Expand Down
2 changes: 1 addition & 1 deletion Source/LightwaveExplorerUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ double parameterStringToDouble(const std::string& ss, const double* iBl
void stripWhiteSpace(std::string& s);
void stripLineBreaks(std::string& s);
int interpretParameters(const std::string& cc, const int n, const double *iBlock, const double *vBlock, double *parameters, bool* defaultMask);

std::string zipGetBasename(const std::string& zipPath);

//Enum for determining the FFT type:
// D2Z: real to complex (time to frequency)
Expand Down

0 comments on commit 4b793ae

Please sign in to comment.