Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rboman committed Mar 8, 2024
2 parents c6093c6 + fc233aa commit 70dc07c
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 8 deletions.
8 changes: 8 additions & 0 deletions classes/sph0/louis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ Run C++ code in debug using 10 threads
cmake . -B build -DCMAKE_BUILD_TYPE=Debug && ninja -C build && run.py --cpp -k 10 tests\waterdrop.py
```



## MSYS2

```
pacman -S mingw64/mingw-w64-x86_64-eigen3
```

## Win

```
cmake . -B build && cmake --build build --config Release && run.py --cpp tests\small.py
```
37 changes: 35 additions & 2 deletions classes/sph0/louis/src_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON)
# increase warning level
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-Wall" WALL)
# IF(WALL)
# IF(WALL) # ! trop de warnings sous msvc (liés aux inline d'eigen)
# ADD_COMPILE_OPTIONS(-Wall)
# ENDIF()






# find OpenMP
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
Expand All @@ -44,6 +49,28 @@ IF(NOT EIGEN_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Eigen include dir not found!")
ENDIF()

SET(CMAKE_AUTOMOC ON)
# SET(CMAKE_AUTORCC ON)
# SET(CMAKE_AUTOUIC ON)
FIND_PACKAGE(VTK 9.0 COMPONENTS
GUISupportQt
InteractionWidgets
FiltersHybrid
IOExport
IOXML
CommonColor
CommonCore
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)

FIND_PACKAGE(Qt5 COMPONENTS Widgets REQUIRED)


FILE(GLOB SRCS *.h *.cpp)
ADD_EXECUTABLE(louis++ ${SRCS})
Expand All @@ -53,8 +80,14 @@ IF(OpenMP_CXX_FOUND)
TARGET_LINK_LIBRARIES(louis++ PUBLIC OpenMP::OpenMP_CXX)
ENDIF()


TARGET_COMPILE_DEFINITIONS(louis++ PUBLIC EIGEN_DONT_PARALLELIZE)
# try to increase Eigen performance in Debug mode (inlining and no assertions)
# TARGET_COMPILE_DEFINITIONS(louis++ PUBLIC $<$<CONFIG:Debug>: EIGEN_NO_DEBUG >)
# TARGET_COMPILE_DEFINITIONS(louis++ PUBLIC $<$<CONFIG:Debug>: "EIGEN_STRONG_INLINE=__attribute__((always_inline)) inline" > )

# VTK/Qt
TARGET_LINK_LIBRARIES(louis++ PUBLIC ${VTK_LIBRARIES} Qt5::Widgets)

vtk_module_autoinit(
TARGETS louis++
MODULES ${VTK_LIBRARIES})
3 changes: 2 additions & 1 deletion classes/sph0/louis/src_cpp/DisplayHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
class DisplayHook
{
public:
DisplayHook();
DisplayHook() {}
virtual ~DisplayHook() = default;
virtual void display() = 0;
virtual void loop() = 0;
};

#endif //SPH_DISPLAYHOOK_H
Expand Down
2 changes: 1 addition & 1 deletion classes/sph0/louis/src_cpp/EqState.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class IdealGas : public EqState

class QincFluid : public EqState
{
double gamma;
int gamma;

public:
QincFluid(double _rho0, double _c0, double _gamma)
Expand Down
7 changes: 6 additions & 1 deletion classes/sph0/louis/src_cpp/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ Model::solve()
// Test for the data saving
if (to_save)
{
if(this->displayHook != nullptr)
this->displayHook->display();


this->save_particles("resMP", ite, this->numFP, this->numFP + this->numMP - 1);
this->save_particles("resFP", ite, 0, this->numFP - 1);

Expand Down Expand Up @@ -186,7 +190,8 @@ Model::load_parameters(std::string const &param_path)
file >> this->alpha;
file >> this->beta;
int eqnState;
double gamma, molMass;
int gamma;
double molMass;
file >> eqnState;
file >> gamma;
file >> molMass;
Expand Down
153 changes: 153 additions & 0 deletions classes/sph0/louis/src_cpp/QtVTKHook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#include "QtVTKHook.h"
#include "Model.h"
#include <vtkCubeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <QHBoxLayout>
#include <vtkProperty.h>


DisplayWindow::DisplayWindow(QWidget *parent) : QWidget(parent)
{
setWindowTitle("VTK in Qt");
resize(800, 600);

setupGUI();

addCube();

}

DisplayWindow::~DisplayWindow()
{
}

void
DisplayWindow::setupGUI()
{
this->vtkwidget = new QVTKOpenGLNativeWidget(this);

vtkNew<vtkGenericOpenGLRenderWindow> window;
vtkwidget->setRenderWindow(window.Get());

// Camera
// vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
// camera->SetViewUp(0, 1, 0);
// camera->SetPosition(0, 0, 10);
// camera->SetFocalPoint(0, 0, 0);

// Renderer
renderer = vtkSmartPointer<vtkRenderer>::New();
// renderer->SetActiveCamera(camera);
renderer->SetBackground(1.0, 1.0, 1.0);
vtkwidget->renderWindow()->AddRenderer(renderer);

// Reset the camera
renderer->ResetCamera();

// Layout Qt
QHBoxLayout *hbox = new QHBoxLayout();
this->setLayout(hbox);
hbox->addWidget(this->vtkwidget);
}

void
DisplayWindow::addCube()
{
// Create a cube source
vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New();

// Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cubeSource->GetOutputPort());

// Create an actor
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0); // Set color to red
actor->GetProperty()->SetSpecular(1.0); // Enable specular reflection
actor->GetProperty()->SetSpecularPower(50.0); // Set specular power

// Add the actor to the scene
renderer->AddActor(actor);
}

// -----------------------------------------------------------------------------

QtVTKHook::QtVTKHook(int &argc, char **argv,
Model &model) : DisplayHook(), model(model)
{
app = new QApplication(argc, argv);

window = new DisplayWindow();
//window->show();

//window->setAttribute(Qt::WA_QuitOnClose);
QObject::connect( app, SIGNAL( lastWindowClosed() ), app, SLOT( quit() ) );

// app->exec();


model.displayHook = this;
}

QtVTKHook::~QtVTKHook()
{
delete app;
}

void
QtVTKHook::display()
{
//window->show();

// app->exec();
// std::cout << "quit()" << std::endl;
}


void
QtVTKHook::loop()
{
//window->show();

app->exec();
std::cout << "quit()" << std::endl;
}

void
QtVTKHook::demo()
{
// Create a cube source
vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New();

// Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cubeSource->GetOutputPort());

// Create an actor
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

// Create a renderer
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);

// Create a render window
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);

// Create an interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

// Initialize the interactor and start the rendering loop
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
}
46 changes: 46 additions & 0 deletions classes/sph0/louis/src_cpp/QtVTKHook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef QTVTKHOOK_H
#define QTVTKHOOK_H

#include "sph.h"
#include "DisplayHook.h"
#include <QWidget>
#include <QApplication>
#include <QVTKOpenGLNativeWidget.h>
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>

class DisplayWindow : public QWidget
{
Q_OBJECT;

QVTKOpenGLNativeWidget *vtkwidget;
vtkSmartPointer<vtkRenderer> renderer;

public:
DisplayWindow(QWidget *parent = nullptr);
~DisplayWindow();

private:
void setupGUI();
void addCube();
};

// -----------------------------------------------------------------------------

class QtVTKHook : public DisplayHook
{
QApplication *app;
DisplayWindow *window;
Model &model;

public:
QtVTKHook(int &argc, char **argv, Model &model);
virtual ~QtVTKHook();
virtual void display() override;

virtual void loop() override;

void demo();
};

#endif // QTVTKHOOK_H
12 changes: 9 additions & 3 deletions classes/sph0/louis/src_cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
// @version 1.0.0

#include "Model.h"
#include "QtVTKHook.h"
#include <iostream>
#include <iomanip>
#ifdef _OPENMP
#include <omp.h>
#endif

int
main()
main(int argc, char *argv[])
{
int retcode = EXIT_SUCCESS;

Expand All @@ -27,12 +28,17 @@ main()
{
Model model;
model.initialise();

//QtVTKHook gui(argc, argv, model);

model.solve();

//gui.loop();
}
catch (const std::exception &e)
{
std::cerr << "\n** ERROR: " << e.what() << "\n\n";
retcode = EXIT_FAILURE;
std::cerr << "\n** ERROR: " << e.what() << "\n\n";
retcode = EXIT_FAILURE;
}
timers["TOTAL"].stop();

Expand Down

0 comments on commit 70dc07c

Please sign in to comment.