Skip to content

Commit

Permalink
Merge pull request #19 from KAHR-Alpha/bugfix/FDTD_GUI_sensors_fix
Browse files Browse the repository at this point in the history
FDTD GUI sensors fix
  • Loading branch information
KAHR-Alpha authored Dec 26, 2023
2 parents 11cbf7a + 6280b44 commit 05f37e3
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 92 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/Windows Dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ jobs:
path: builds/zlib
key: ${{ runner.os }}-cache-key-zlib

- run: Invoke-WebRequest -URI https://zlib.net/zlib1213.zip -OutFile sources.zip
- run: Invoke-WebRequest -URI https://zlib.net/zlib13.zip -OutFile sources.zip
- run: Expand-Archive ./sources.zip

- run: cmake -B "${{github.workspace}}/cmake_build" -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/builds/zlib" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
working-directory: sources/zlib-1.2.13
working-directory: sources/zlib-1.3

- run: cmake --build "${{github.workspace}}/cmake_build" --config ${{env.BUILD_TYPE}}
working-directory: sources/zlib-1.2.13
working-directory: sources/zlib-1.3

- run: cmake --install "${{github.workspace}}/cmake_build"
working-directory: sources/zlib-1.2.13
working-directory: sources/zlib-1.3

build_libpng:
runs-on: windows-latest
Expand Down Expand Up @@ -120,13 +120,13 @@ jobs:
- run: Expand-Archive ./sources.zip

- run: cmake -B "${{github.workspace}}/cmake_build" -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/builds/freetype" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
working-directory: sources/freetype-2.13.1
working-directory: sources/freetype-2.13.2

- run: cmake --build "${{github.workspace}}/cmake_build" --config ${{env.BUILD_TYPE}}
working-directory: sources/freetype-2.13.1
working-directory: sources/freetype-2.13.2

- run: cmake --install "${{github.workspace}}/cmake_build"
working-directory: sources/freetype-2.13.1
working-directory: sources/freetype-2.13.2

get_fftw:
runs-on: windows-latest
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Todo:
- Tangent vectors managements for Selene
- Implement the Lambertian, Guassian and ABg scattering models ( see "What scattering models are available in OpticStudio?" )

0.11.1
- Fixed materials loading in CLI FDTD
- Fixed the use of the output directory for sensors in GUI FDTD
- Fixed sensors saving as the wrong type in GUI FDTD

0.11
- Added an optimization system to Selene

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endfunction()

set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 11)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_VERSION_PATCH 1)

set(TASK "Build CLI" CACHE STRING "What to do")
set_property(CACHE TASK PROPERTY STRINGS "Build CLI" "Build CLI+GUI")
Expand Down
33 changes: 15 additions & 18 deletions src/GUI/FDTD/gui_fdtd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ void FDTD_Frame::append_tree_sensor(wxTreeItemId const &ID,Sensor_generator &gen
wxString tmp_str_x,tmp_str_y,tmp_str_z;
wxTreeItemId tmp_ID;

if(generator.type==Sensor_generator::BOX_POYNTING) sensor_type="Poynting Box";
else if(generator.type==Sensor_generator::BOX_SPECTRAL_POYNTING) sensor_type="Spectral Poynting Box";
else if(generator.type==Sensor_generator::DIFF_ORDERS) sensor_type="Diffraction orders";
else if(generator.type==Sensor_generator::FIELDBLOCK) sensor_type="FieldBlock";
else if(generator.type==Sensor_generator::FIELDMAP) sensor_type="FieldMap";
else if(generator.type==Sensor_generator::FIELDPOINT) sensor_type="FieldPoint";
else if(generator.type==Sensor_generator::PLANAR_SPECTRAL_POYNTING) sensor_type="Spectral Poynting Plane";
if(generator.type==Sensor_type::BOX_POYNTING) sensor_type="Poynting Box";
else if(generator.type==Sensor_type::BOX_SPECTRAL_POYNTING) sensor_type="Spectral Poynting Box";
else if(generator.type==Sensor_type::DIFF_ORDERS) sensor_type="Diffraction orders";
else if(generator.type==Sensor_type::FIELDBLOCK) sensor_type="FieldBlock";
else if(generator.type==Sensor_type::FIELDMAP) sensor_type="FieldMap";
else if(generator.type==Sensor_type::FIELDPOINT) sensor_type="FieldPoint";
else if(generator.type==Sensor_type::PLANAR_SPECTRAL_POYNTING) sensor_type="Spectral Poynting Plane";

wxTreeItemId sensor_ID=tree->AppendItem(ID,sensor_type);

Expand All @@ -232,9 +232,9 @@ void FDTD_Frame::append_tree_sensor(wxTreeItemId const &ID,Sensor_generator &gen
tree->AppendItem(tmp_ID,tmp_str_y);
tree->AppendItem(tmp_ID,tmp_str_z);

if(generator.type==Sensor_generator::BOX_SPECTRAL_POYNTING ||
generator.type==Sensor_generator::DIFF_ORDERS ||
generator.type==Sensor_generator::PLANAR_SPECTRAL_POYNTING )
if(generator.type==Sensor_type::BOX_SPECTRAL_POYNTING ||
generator.type==Sensor_type::DIFF_ORDERS ||
generator.type==Sensor_type::PLANAR_SPECTRAL_POYNTING )
{
tmp_ID=tree->AppendItem(sensor_ID,"Spectrum");

Expand All @@ -253,9 +253,9 @@ void FDTD_Frame::append_tree_sensor(wxTreeItemId const &ID,Sensor_generator &gen
tree->AppendItem(sensor_ID,tmp_str);
}

if(generator.type==Sensor_generator::FIELDMAP ||
generator.type==Sensor_generator::DIFF_ORDERS ||
generator.type==Sensor_generator::PLANAR_SPECTRAL_POYNTING)
if(generator.type==Sensor_type::FIELDMAP ||
generator.type==Sensor_type::DIFF_ORDERS ||
generator.type==Sensor_type::PLANAR_SPECTRAL_POYNTING)
{
tmp_str="Orientation: ";

Expand Down Expand Up @@ -1004,10 +1004,7 @@ void FDTD_Frame::save(wxFileName const &fname)
std::string s_name="sensor_"+std::to_string(i);

file<<s_name<<"=create_sensor(\"";
if(gen.type==Sensor_generator::BOX_SPECTRAL_POYNTING) file<<"box_spectral_poynting";
else if(gen.type==Sensor_generator::FIELDBLOCK) file<<"fieldblock";
else if(gen.type==Sensor_generator::FIELDMAP) file<<"fieldmap";
else if(gen.type==Sensor_generator::PLANAR_SPECTRAL_POYNTING) file<<"planar_spectral_poynting";
file<<from_sensor_type(gen.type);
file<<"\")\n";

file<<s_name<<":name(\""<<gen.name<<"\")\n";
Expand All @@ -1030,7 +1027,7 @@ void FDTD_Frame::save(wxFileName const &fname)
if(gen.disable_zm) file<<s_name<<":disable(\"-Z\")\n";
if(gen.disable_zp) file<<s_name<<":disable(\"Z\")\n";

if(gen.type==Sensor_generator::FIELDMAP || gen.type==Sensor_generator::FIELDBLOCK)
if(gen.type==Sensor_type::FIELDMAP || gen.type==Sensor_type::FIELDBLOCK)
file<<s_name<<":wavelength("<<gen.lambda_min<<")\n";
else file<<s_name<<":spectrum("<<gen.lambda_min<<","<<gen.lambda_max<<","<<gen.Nl<<")\n";
file<<"\n";;
Expand Down
32 changes: 16 additions & 16 deletions src/GUI/FDTD/gui_fdtd_misc_dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ Sensor_Gen_Dialog::Sensor_Gen_Dialog(Sensor_generator *generator_)
type_ctrl->Append("FieldBlock");
type_ctrl->Append("FieldMap");

if(type==Sensor_generator::BOX_SPECTRAL_POYNTING) type_ctrl->SetSelection(0);
else if(type==Sensor_generator::PLANAR_SPECTRAL_POYNTING) type_ctrl->SetSelection(1);
else if(type==Sensor_generator::DIFF_ORDERS) type_ctrl->SetSelection(2);
else if(type==Sensor_generator::FIELDBLOCK) type_ctrl->SetSelection(3);
else if(type==Sensor_generator::FIELDMAP) type_ctrl->SetSelection(4);
if(type==Sensor_type::BOX_SPECTRAL_POYNTING) type_ctrl->SetSelection(0);
else if(type==Sensor_type::PLANAR_SPECTRAL_POYNTING) type_ctrl->SetSelection(1);
else if(type==Sensor_type::DIFF_ORDERS) type_ctrl->SetSelection(2);
else if(type==Sensor_type::FIELDBLOCK) type_ctrl->SetSelection(3);
else if(type==Sensor_type::FIELDMAP) type_ctrl->SetSelection(4);

type_ctrl->Bind(wxEVT_CHOICE,&Sensor_Gen_Dialog::evt_type,this);

Expand Down Expand Up @@ -185,11 +185,11 @@ void Sensor_Gen_Dialog::evt_type(wxCommandEvent &event)
{
int selection=type_ctrl->GetSelection();

if(selection==0) type=Sensor_generator::BOX_SPECTRAL_POYNTING;
else if(selection==1) type=Sensor_generator::PLANAR_SPECTRAL_POYNTING;
else if(selection==2) type=Sensor_generator::DIFF_ORDERS;
else if(selection==3) type=Sensor_generator::FIELDBLOCK;
else if(selection==4) type=Sensor_generator::FIELDMAP;
if(selection==0) type=Sensor_type::BOX_SPECTRAL_POYNTING;
else if(selection==1) type=Sensor_type::PLANAR_SPECTRAL_POYNTING;
else if(selection==2) type=Sensor_type::DIFF_ORDERS;
else if(selection==3) type=Sensor_type::FIELDBLOCK;
else if(selection==4) type=Sensor_type::FIELDMAP;

refresh_layout();

Expand All @@ -200,9 +200,9 @@ bool Sensor_Gen_Dialog::is_planar()
{
bool plane=true;

if(type==Sensor_generator::BOX_POYNTING ||
type==Sensor_generator::BOX_SPECTRAL_POYNTING ||
type==Sensor_generator::FIELDBLOCK) plane=false;
if(type==Sensor_type::BOX_POYNTING ||
type==Sensor_type::BOX_SPECTRAL_POYNTING ||
type==Sensor_type::FIELDBLOCK) plane=false;

return plane;
}
Expand All @@ -222,8 +222,8 @@ void Sensor_Gen_Dialog::refresh_layout()
else if(orientation==4 || orientation==5) z2_ctrl->Disable();
}

if(type==Sensor_generator::FIELDBLOCK ||
type==Sensor_generator::FIELDMAP) spectrum_ctrl->set_monochromatic();
if(type==Sensor_type::FIELDBLOCK ||
type==Sensor_type::FIELDMAP) spectrum_ctrl->set_monochromatic();
else spectrum_ctrl->set_polychromatic();
}

Expand Down Expand Up @@ -256,7 +256,7 @@ void Sensor_Gen_Dialog::save()
}

disable_xm=disable_xp=disable_ym=disable_yp=disable_zm=disable_zp=false;
if(type==Sensor_generator::BOX_POYNTING || type==Sensor_generator::BOX_SPECTRAL_POYNTING)
if(type==Sensor_type::BOX_POYNTING || type==Sensor_type::BOX_SPECTRAL_POYNTING)
{
bool *disable_X[6]={&disable_xm,&disable_xp,&disable_ym,&disable_yp,&disable_zm,&disable_zp};

Expand Down
31 changes: 16 additions & 15 deletions src/finite_differences/FDTD/core/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@ class Source;
//######################
// Sensor_generator
//######################

enum class Sensor_type
{
BOX_POYNTING=0,
BOX_SPECTRAL_POYNTING,
DIFF_ORDERS,
FARFIELD,
FIELDBLOCK,
FIELDMAP,
FIELDMAP2,
FIELDPOINT,
MOVIE,
PLANAR_SPECTRAL_POYNTING,
UNKNOWN
};

class Sensor_generator
{
public:
int type;
Sensor_type type;
std::string name;

int x1,x2,y1,y2,z1,z2;
Expand All @@ -51,20 +66,6 @@ class Sensor_generator
disable_ym,disable_yp,
disable_zm,disable_zp;

enum
{
BOX_POYNTING=0,
BOX_SPECTRAL_POYNTING,
DIFF_ORDERS,
FARFIELD,
FIELDBLOCK,
FIELDMAP,
FIELDMAP2,
FIELDPOINT,
MOVIE,
PLANAR_SPECTRAL_POYNTING
};

Sensor_generator();
Sensor_generator(Sensor_generator const &sens);

Expand Down
57 changes: 41 additions & 16 deletions src/finite_differences/FDTD/sensors/lua_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,8 @@ int create_sensor(lua_State *L)
lua_setmetatable(L,-2);

Sensor_generator &sens=**p_sens;
sens.type=to_sensor_type(type);

if(type=="box_poynting") sens.type=Sensor_generator::BOX_POYNTING;
else if(type=="box_spectral_poynting") sens.type=Sensor_generator::BOX_SPECTRAL_POYNTING;
else if(type=="diff_orders") sens.type=Sensor_generator::DIFF_ORDERS;
else if(type=="farfield") sens.type=Sensor_generator::FARFIELD;
else if(type=="fieldblock") sens.type=Sensor_generator::FIELDBLOCK;
else if(type=="fieldmap") sens.type=Sensor_generator::FIELDMAP;
else if(type=="fieldmap2") sens.type=Sensor_generator::FIELDMAP2;
else if(type=="fieldpoint") sens.type=Sensor_generator::FIELDPOINT;
else if(type=="movie") sens.type=Sensor_generator::MOVIE;
else if(type=="planar_spectral_poynting") sens.type=Sensor_generator::PLANAR_SPECTRAL_POYNTING;
else
{
std::cout<<"Unknown sensor type: "<<type<<std::endl;
std::cout<<"Press Enter to continue..."<<std::endl;
std::cin.get();
}
return 1;
}

Expand Down Expand Up @@ -137,3 +122,43 @@ void Sensor_generator_create_metatable(lua_State *L)
metatable_add_func(L,"location_grid",sensor_set_location);
metatable_add_func(L,"location",sensor_set_location_real);
}

Sensor_type to_sensor_type(std::string const &type)
{
if(type=="box_poynting") return Sensor_type::BOX_POYNTING;
else if(type=="box_spectral_poynting") return Sensor_type::BOX_SPECTRAL_POYNTING;
else if(type=="diff_orders") return Sensor_type::DIFF_ORDERS;
else if(type=="farfield") return Sensor_type::FARFIELD;
else if(type=="fieldblock") return Sensor_type::FIELDBLOCK;
else if(type=="fieldmap") return Sensor_type::FIELDMAP;
else if(type=="fieldmap2") return Sensor_type::FIELDMAP2;
else if(type=="fieldpoint") return Sensor_type::FIELDPOINT;
else if(type=="movie") return Sensor_type::MOVIE;
else if(type=="planar_spectral_poynting") return Sensor_type::PLANAR_SPECTRAL_POYNTING;
else
{
std::cout<<"Unknown sensor type: "<<type<<std::endl;
std::cout<<"Press Enter to continue..."<<std::endl;
std::cin.get();

return Sensor_type::UNKNOWN;
}
}

std::string from_sensor_type(Sensor_type type)
{
if(type==Sensor_type::BOX_POYNTING) return "box_poynting";
else if(type==Sensor_type::BOX_SPECTRAL_POYNTING) return "box_spectral_poynting";
else if(type==Sensor_type::DIFF_ORDERS) return "diff_orders";
else if(type==Sensor_type::FARFIELD) return "farfield";
else if(type==Sensor_type::FIELDBLOCK) return "fieldblock";
else if(type==Sensor_type::FIELDMAP) return "fieldmap";
else if(type==Sensor_type::FIELDMAP2) return "fieldmap2";
else if(type==Sensor_type::FIELDPOINT) return "fieldpoint";
else if(type==Sensor_type::MOVIE) return "movie";
else if(type==Sensor_type::PLANAR_SPECTRAL_POYNTING) return "planar_spectral_poynting";
else
{
return "unknown";
}
}
4 changes: 4 additions & 0 deletions src/finite_differences/FDTD/sensors/lua_sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.*/
#define LUA_SENSORS_H

#include <lua_base.h>
#include <sensors.h>

//####################
// Sensors
Expand All @@ -29,4 +30,7 @@ int sensor_set_location_real(lua_State *L);

void Sensor_generator_create_metatable(lua_State *L);

std::string from_sensor_type(Sensor_type type);
Sensor_type to_sensor_type(std::string const &type);

#endif
2 changes: 1 addition & 1 deletion src/finite_differences/FDTD/sensors/s_diffrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void DiffSensor::treat()

chk_var(fname);

std::ofstream file(fname,std::ios::out|std::ios::trunc);
std::ofstream file(directory/fname,std::ios::out|std::ios::trunc);

int pmin_sp=std::numeric_limits<int>::max();
int pmax_sp=std::numeric_limits<int>::min();
Expand Down
2 changes: 1 addition & 1 deletion src/finite_differences/FDTD/sensors/s_farfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void FarFieldSensor::treat()
std::string fname=name;
fname.append("_farfield");

std::ofstream file(fname,std::ios::out|std::ios::trunc);
std::ofstream file(directory/fname,std::ios::out|std::ios::trunc);

std::vector<Imdouble> precomp_x(x2-x1),precomp_y(y2-y1);

Expand Down
13 changes: 9 additions & 4 deletions src/finite_differences/FDTD/sensors/s_movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,28 @@ void MovieSensor::deep_feed(FDTD const &fdtd)
image.degra(i,j,tmp_x,0,1.0);
}}

image.write(name+"_"+std::to_string(step/skip)+"_Ex.png");
std::filesystem::path pEx=directory/(name+"_"+std::to_string(step/skip)+"_Ex.png");
std::filesystem::path pEy=directory/(name+"_"+std::to_string(step/skip)+"_Ey.png");
std::filesystem::path pEz=directory/(name+"_"+std::to_string(step/skip)+"_Ez.png");
std::filesystem::path pE=directory/(name+"_"+std::to_string(step/skip)+"_E.png");

image.write(pEx.generic_string());

for(i=0;i<span1;i++){ for(j=0;j<span2;j++)
{
tmp_y=1.0-exp(-exposure*abs(f_y(i,j)));
image.degra(i,j,tmp_y,0,1.0);
}}

image.write(name+"_"+std::to_string(step/skip)+"_Ey.png");
image.write(pEy.generic_string());

for(i=0;i<span1;i++){ for(j=0;j<span2;j++)
{
tmp_z=1.0-exp(-exposure*abs(f_z(i,j)));
image.degra(i,j,tmp_z,0,1.0);
}}

image.write(name+"_"+std::to_string(step/skip)+"_Ez.png");
image.write(pEz.generic_string());

for(i=0;i<span1;i++){ for(j=0;j<span2;j++)
{
Expand All @@ -175,6 +180,6 @@ void MovieSensor::deep_feed(FDTD const &fdtd)
}}


image.write(name+"_"+std::to_string(step/skip)+"_E.png");
image.write(pE.generic_string());
}
}
Loading

0 comments on commit 05f37e3

Please sign in to comment.