Skip to content

Conversation

@ArshiaIlaty
Copy link
Contributor

@ArshiaIlaty ArshiaIlaty commented Feb 6, 2025

1. wave1d.cpp: Implements the 1D wave equation solver using:

  • Second-order accurate spatial discretization
  • Position Verlet time integration scheme
  • Mimetic Laplacian operator
  • Visualization using Gnuplot

2. wave2d.cpp: Implements the 2D wave equation solver featuring:

  • Second-order accurate spatial discretization in both dimensions
  • Position Verlet time integration
  • 2D Mimetic Laplacian operator with Robin boundary conditions
  • Interactive 3D visualization using Gnuplot

Key Features:

  • Uses existing mimetic operators (Gradient, Divergence, Laplacian)
  • Implements proper boundary conditions using RobinBC
  • Provides real-time visualization of wave propagation
  • Maintains consistency with existing codebase style and structure
  • Updated Makefile to include new examples

Dependencies

  • Armadillo (Linear algebra library)
  • Boost (For filesystem and gnuplot-iostream)
  • Gnuplot (For visualization)
  • OpenBLAS (Optional, for better performance)
  • SuperLU (For sparse matrix operations)
  • Incorporate C++20 for better filesystem handling

Installation on different platforms:

macOS (using Homebrew):

brew install armadillo
brew install boost
brew install gnuplot
brew install openblas

Ubuntu/Debian:

sudo apt-get install libarmadillo-dev
sudo apt-get install libboost-all-dev
sudo apt-get install gnuplot
sudo apt-get install libopenblas-dev
sudo apt-get install libsuperlu-dev

PR Structure

examples/cpp/
├── wave1d.cpp # First case of 1D wave equation
├── wave1d_case2.cpp # Second case of 1D wave equation
├── wave2d.cpp # First case of 2D wave equation
├── wave2d_case2.cpp # Second case of 2D wave equation
└── Makefile # Build system for examples

Testing

  1. Build the examples:
cd examples/cpp
make wave1d wave1d_case2 wave2d wave2d_case2
  1. Run individual examples
./wave1d
./wave1d_case2
./wave2d
./wave2d_case2

Wave1Dcpp
Wave2Dcpp

Copy link
Collaborator

@aboada aboada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only reviewed examples/cpp/wave1D_case2.cpp. My comments are also applicable to the other cpp files you are adding in this PR.
Let me know if you want me to review the other files.
Thank you.


clean:
rm -f transport1D schrodinger1D parabolic1D elliptic1D elliptic2D convection_diffusion RK2
rm -f transport1D schrodinger1D parabolic1D elliptic1D elliptic2D convection_diffusion RK2 wave1d wave1D_case2 wave2d wave2D_case2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you start splitting these into multiple lines? I suggest:

all: transport1D \
     schrodinger1D \
     elliptic1D \
     elliptic2D \
     parabolic1D \
     convection_diffusion \
     RK2 \
     wave1d \
     wave1D_case2 \
     wave2d \
     wave2D_case2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to stick to the structure but will modify the makefile exactly as you wrote. Thanks a lot.


int main() {
// Parameters
const int k = 4; // Order of accuracy (spatial)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you change to constexpr here for all these constants? You know their values at compile time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think the readability of this code will improve if you adhere to a naming convention for constants. For instance, see: https://google.github.io/styleguide/cppguide.html#Constant_Names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion. I used the same naming as the matlab file. However, sure, Why not. I will name them better

}

// Save data for plotting
std::ofstream outfile("solution_" + std::to_string(step) + ".dat");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use std::stringstream here for faster string-building (vs std::string).

std::stringstream filename;
filename << "solution_" << step << ".dat";
std::ofstream outfile(filename.str());```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Using std::stringstream is indeed more efficient

@ArshiaIlaty
Copy link
Contributor Author

Would you please review the new version of the wave1d_case2? I have tried to apply all your suggestions. Please let me know if I need to do anything else. Thanks a ton.

@aboada
Copy link
Collaborator

aboada commented Feb 11, 2025

Would you please review the new version of the wave1d_case2? I have tried to apply all your suggestions. Please let me know if I need to do anything else. Thanks a ton.

It looks great, other than the two minor things I mentioned. Thanks for the changes!

@aboada
Copy link
Collaborator

aboada commented Feb 12, 2025

1. wave1d.cpp: Implements the 1D wave equation solver using:

  • Second-order accurate spatial discretization
  • Position Verlet time integration scheme
  • Mimetic Laplacian operator
  • Visualization using Gnuplot

2. wave2d.cpp: Implements the 2D wave equation solver featuring:

  • Second-order accurate spatial discretization in both dimensions
  • Position Verlet time integration
  • 2D Mimetic Laplacian operator with Robin boundary conditions
  • Interactive 3D visualization using Gnuplot

Key Features:

  • Uses existing mimetic operators (Gradient, Divergence, Laplacian)
  • Implements proper boundary conditions using RobinBC
  • Provides real-time visualization of wave propagation
  • Maintains consistency with existing codebase style and structure
  • Updated Makefile to include new examples

Dependencies

  • Armadillo (Linear algebra library)
  • Boost (For filesystem and gnuplot-iostream)
  • Gnuplot (For visualization)
  • OpenBLAS (Optional, for better performance)
  • SuperLU (For sparse matrix operations)
  • Incorporate C++20 for better filesystem handling

Installation on different platforms:

macOS (using Homebrew):

brew install armadillo
brew install boost
brew install gnuplot
brew install openblas

Ubuntu/Debian:

sudo apt-get install libarmadillo-dev
sudo apt-get install libboost-all-dev
sudo apt-get install gnuplot
sudo apt-get install libopenblas-dev
sudo apt-get install libsuperlu-dev

PR Structure

examples/cpp/ ├── wave1d.cpp # First case of 1D wave equation ├── wave1d_case2.cpp # Second case of 1D wave equation ├── wave2d.cpp # First case of 2D wave equation ├── wave2d_case2.cpp # Second case of 2D wave equation └── Makefile # Build system for examples

Testing

  1. Build the examples:
cd examples/cpp
make wave1d wave1d_case2 wave2d wave2d_case2
  1. Run individual examples
./wave1d
./wave1d_case2
./wave2d
./wave2d_case2

Wave1Dcpp Wave2Dcpp

This information looks great! Would it be possible to have it on a readme file?

@ArshiaIlaty
Copy link
Contributor Author

I updated the README file and modified the wave2d code as well. Please review wave2d, wave1d, and wave1d_case2. Let me know if you have any questions. If everything looks good, I will proceed with updating wave2d_case2 as well.

@ArshiaIlaty
Copy link
Contributor Author

This is the content for CMakeLists.txt if it helps for code reproducibility.

# examples_C++ Configuration
include_directories("${CMAKE_SOURCE_DIR}/src/cpp")

# Find all .cpp files in the examples directory
file(GLOB EXAMPLE_SOURCES *.cpp)

# Create executables for each source file
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
    get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
    add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
    target_link_libraries(${EXAMPLE_NAME} PUBLIC mole_C++ ${LINK_LIBS})
endforeach()

# Find required packages
find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
find_package(Gnuplot REQUIRED)

# Download gnuplot-iostream header if not exists
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp/gnuplot-iostream.h")
    file(DOWNLOAD
        "https://raw.githubusercontent.com/dstahlke/gnuplot-iostream/master/gnuplot-iostream.h"
        "${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp/gnuplot-iostream.h"
        SHOW_PROGRESS
    )
endif()

# Add wave equation examples
add_executable(wave1d_case2 examples/cpp/wave1d_case2.cpp)
target_link_libraries(wave1d_case2 PRIVATE
    Boost::iostreams
    Boost::system
    Boost::filesystem
)

@jbrzensk
Copy link
Collaborator

This still does not compile.

wave2D_case2.cpp:7:10: fatal error: gnuplot-iostream.h: No such file or directory

If the cmake file needs to be edited, then it should be included in this PR.

@ArshiaIlaty
Copy link
Contributor Author

I updated the cmakelists and makefile. Please try to run it again with all the packages required. I proposed some new packages to be installed in the PR.

@jbrzensk
Copy link
Collaborator

New error on using cmake.

-- Found Gnuplot: /usr/bin/gnuplot (found version "6.0.0") 
-- Configuring done (31.8s)
CMake Error at examples/cpp/CMakeLists.txt:28 (add_executable):
  Cannot find source file:

    examples/cpp/wave1d_case2.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc


CMake Error at examples/cpp/CMakeLists.txt:28 (add_executable):
  No SOURCES given to target: wave1d_case2

@ArshiaIlaty
Copy link
Contributor Author

Please try it again. The file name was wave1D_case2.cpp in my repo. It should have been wave1d_case2.cpp. I modified the names, and it should work now.

@JananiPSrinivasan
Copy link
Collaborator

Hi @ArshiaIlaty, Please try working with the CMake file I have mentioned below. Replace your Cmake file with this file as I have restructured it and avoided redundancy. Hope it resolves your issue.

# Include directories
include_directories("${CMAKE_SOURCE_DIR}/src/cpp")

# Find all .cpp files in the examples directory
file(GLOB EXAMPLE_SOURCES examples/cpp/*.cpp)

# Find required packages
find_package(Boost REQUIRED COMPONENTS iostreams system filesystem)
find_package(Gnuplot REQUIRED)

# Download gnuplot-iostream header if not exists
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp/gnuplot-iostream.h")
    file(DOWNLOAD
        "https://raw.githubusercontent.com/dstahlke/gnuplot-iostream/master/gnuplot-iostream.h"
        "${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp/gnuplot-iostream.h"
        SHOW_PROGRESS
    )
endif()

# Create executables and link them appropriately
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
    get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
    add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
    target_link_libraries(${EXAMPLE_NAME} PUBLIC mole_C++ ${LINK_LIBS})

    # Special handling for wave1D_case2
    if(EXAMPLE_NAME STREQUAL "wave1D_case2")
        target_link_libraries(${EXAMPLE_NAME} PRIVATE Boost::iostreams Boost::system Boost::filesystem)
    endif()
endforeach()

Thanks!

@ArshiaIlaty
Copy link
Contributor Author

Hi @JananiPSrinivasan
Thank you so much for cleaning the file. I appreciate your help and effort. Please let me know if there is anything else I should do. I think all the code should run without any problems on your end.

@jbrzensk
Copy link
Collaborator

Hi @ArshiaIlaty,

The other maintainers and I have been chatting about your examples. They are pretty cool with the interactive visualization. Surely, this is something the other examples do not do. We are worried about the additional requirements your examples put on the MOLE library.

The library already has a set of dependencies, and most are nonnegotiable, having to do with the mathematics involved and solving of sparse systems, which the library is primarily designed to do. With that, we are very hesitant to add additional dependencies, namely the boost library, the gnuplot library, and the C++20 requirement.

Boost is a great library but is unnecessary for the core functionality of the MOLE library. Same for gnuplot. Gnuplot ships standard with Linux and interacts natively with C++, but requiring the dev libraries also might be asking too much of the casual user.

And finally, the C++20 requirement. We wrote most of the library to be as compatible with older software as possible. Some of the codes using MOLE are older, with their own even older dependencies, and forcing a requirement to use 20 may have unforeseen implications on these other applications.

What I do think is that you should keep the final working examples. A good compromise may be to simplify your examples using gnuplot for the MOLE library, and then you have your own hosted interactive examples, and we could link to your code from the MOLE example or repositories, something like a comment in wave1d.cpp like "If you want a more interactive Wave1D, go to https://github.com/ArshiaIlaty/mole_Ash and check out the interactive version".

I would like @aboada , @jcorbino, @cpaolini, @valeriabarra to chime in on this in case I am out of line. And I am sorry @ArshiaIlaty for taking so long to bring this up.

@mdumett mdumett self-requested a review February 21, 2025 19:25
@mdumett
Copy link
Collaborator

mdumett commented Feb 27, 2025

Please, even though that is not in the comments of the MATLAB code, indicate in the top comments of your code which equation is being solved, its time and space domains and its initial and boundary conditions.

@jbrzensk
Copy link
Collaborator

Has there been any progress on this? If not, I will close the pull request.

@mdumett
Copy link
Collaborator

mdumett commented Apr 17, 2025

On 2/13, @jbrzensk suggested removing in your code any dependencies on gnuplot dev, C++ 20 and boost. Were you able to do that?

@ArshiaIlaty
Copy link
Contributor Author

I have been working on it and will push the code for your review. Thank you.

@ArshiaIlaty
Copy link
Contributor Author

@aboada @jbrzensk Hi, hope you are doing well. Please share your thoughts on the new version of these four examples. I guess the conflicts for the gitignore and Makefile should be solved on your end. Please let me know if I should modify it. Thank you, Jared, for your comments, and thank you, Angel, for reviewing my code and guidance.

@mdumett
Copy link
Collaborator

mdumett commented Apr 30, 2025

Which version of the C++ compiler does your code requires?

@ArshiaIlaty
Copy link
Contributor Author

Which version of the C++ compiler does your code requires?

No need for version 20. I utilized 14 in the Makefile

@aboada
Copy link
Collaborator

aboada commented May 6, 2025

@aboada @jbrzensk Hi, hope you are doing well. Please share your thoughts on the new version of these four examples. I guess the conflicts for the gitignore and Makefile should be solved on your end. Please let me know if I should modify it. Thank you, Jared, for your comments, and thank you, Angel, for reviewing my code and guidance.

Thanks, let me know when your PR is ready for review.

@ArshiaIlaty
Copy link
Contributor Author

@aboada @jbrzensk Hi, hope you are doing well. Please share your thoughts on the new version of these four examples. I guess the conflicts for the gitignore and Makefile should be solved on your end. Please let me know if I should modify it. Thank you, Jared, for your comments, and thank you, Angel, for reviewing my code and guidance.

Thanks, let me know when your PR is ready for review.

It is ready to review. I made the visualization cleaner. Please let me know your thoughts on the conflict of the .gitignore and Makefile. I assume I can delete my version or if you want I can resolve the conflict. Thank you

@mdumett
Copy link
Collaborator

mdumett commented May 6, 2025

@aboada: Is it required that the code is in C++ 11 or earlier? Ash's code seems to be C++ 14.

@aboada
Copy link
Collaborator

aboada commented May 6, 2025

@aboada: Is it required that the code is in C++ 11 or earlier? Ash's code seems to be C++ 14.

Don't think we have established that dependency.

> Ash's code compiles without errors on my fresh Ubuntu installation (using the build-essential package).
EDIT: The above sentence may not be true. I need time to confirm.

From what I can see, my build is configured to use C++14, see:

mando@karak-kadrin:~/src/mole$ grep CMAKE_CXX -IrE | head -5
CMakeLists.txt:set(CMAKE_CXX_STANDARD 14)
CMakeLists.txt:set(CMAKE_CXX_STANDARD_REQUIRED True)
CMakeLists.txt:message(STATUS "Detected CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
CMakeLists.txt:if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
CMakeLists.txt:    set(CMAKE_CXX_FLAGS "-O3 -Xclang -fopenmp -DARMA_DONT_USE_WRAPPER -DARMA_USE_SUPERLU")```

@ArshiaIlaty
Copy link
Contributor Author

@aboada: Is it required that the code is in C++ 11 or earlier? Ash's code seems to be C++ 14.

Even if there is a required dependency, I assume my code runs with version 11 as well. I have not tried to run it with 11, but I can give it a shot.

Copy link
Collaborator

@jbrzensk jbrzensk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. I like the plotting, so much simpler!
You can remove a bunch of files, all that is needed is the wave1d, wave1d_case2, wave2d, wave2d_case2.

Most of my comments revolve around the casting MOLE operators to sparse matrices. All MOLE operators are sparse matrices by design. And there is a fix for the Interpolator error that shows up if you don't cast to sparse.
Please edit the src/cpp/operators.h file and add that to the pull request.

@ArshiaIlaty
Copy link
Contributor Author

@jbrzensk Hi Jared,

Thanks for reveiwing the code. I have tried to address all of your comments. Please recheck and let me know if there is something else I need to do.

@jbrzensk
Copy link
Collaborator

jbrzensk commented May 7, 2025

Cool beans!
Looks like you need to fetch from MOLE to catch up on the last 175 commits you are missing!
image

You can Google "fetch from upstream" for more info. Don't blindly follow this, but you will probably:

git remote add upstream https://github.com/csrc-sdsu/mole.git
git fetch upstream
git merge upstream master
git push origin master

Or something like that. It may generate some issues.

@ArshiaIlaty ArshiaIlaty reopened this May 7, 2025
@ArshiaIlaty
Copy link
Contributor Author

@jbrzensk Hi Jared, I did have a lot of conflicts and needed to rebase and so on. I think the final version of the codes and operators.h have been pushed. Please let me know if I should do anything else.

@ArshiaIlaty
Copy link
Contributor Author

Screenshot 2025-05-07 at 5 03 02 PM

I think I still have some issues with the operators.h implementation. Am I right?

@ArshiaIlaty
Copy link
Contributor Author

@jbrzensk Thank you Jared for all of your guidance.

@jbrzensk jbrzensk merged commit 376f6a2 into csrc-sdsu:master May 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants