Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placeholder for the 2/3D Euler CESE solver #403

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cpp/modmesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_subdirectory(mesh)
add_subdirectory(toggle)
add_subdirectory(universe)
add_subdirectory(onedim)
add_subdirectory(multidim)
add_subdirectory(python)
add_subdirectory(spacetime)
add_subdirectory(view)
Expand Down Expand Up @@ -84,6 +85,7 @@ set(MODMESH_TERMINAL_FILES
${MODMESH_TOGGLE_FILES}
${MODMESH_UNIVERSE_FILES}
${MODMESH_MESH_FILES}
${MODMESH_MULTIDIM_FILES}
${MODMESH_DEVICE_FILES}
${MODMESH_ONEDIM_FILES}
${MODMESH_SPACETIME_FILES}
Expand Down
30 changes: 30 additions & 0 deletions cpp/modmesh/multidim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2019, Yung-Yu Chen <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to be 2024.

Copy link
Member Author

Choose a reason for hiding this comment

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

The year remained in the past because the content was almost identical to the original file it copied from.

# BSD-style license; see COPYING

cmake_minimum_required(VERSION 3.16)

set(MODMESH_MULTIDIM_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/multidim.hpp
${CMAKE_CURRENT_SOURCE_DIR}/euler.hpp
CACHE FILEPATH "" FORCE)

set(MODMESH_MULTIDIM_SOURCES
CACHE FILEPATH "" FORCE)

set(MODMESH_MULTIDIM_PYMODHEADERS
${CMAKE_CURRENT_SOURCE_DIR}/pymod/multidim_pymod.hpp
CACHE FILEPATH "" FORCE)

set(MODMESH_MULTIDIM_PYMODSOURCES
${CMAKE_CURRENT_SOURCE_DIR}/pymod/multidim_pymod.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pymod/wrap_multidim.cpp
CACHE FILEPATH "" FORCE)

set(MODMESH_MULTIDIM_FILES
${MODMESH_MULTIDIM_HEADERS}
${MODMESH_MULTIDIM_SOURCES}
${MODMESH_MULTIDIM_PYMODHEADERS}
${MODMESH_MULTIDIM_PYMODSOURCES}
CACHE FILEPATH "" FORCE)

# vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4 sts=4:
86 changes: 86 additions & 0 deletions cpp/modmesh/multidim/euler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

/*
* Copyright (c) 2024, Yung-Yu Chen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* The space-time CESE solver for the Euler equation.
*/

#include <modmesh/mesh/mesh.hpp>

namespace modmesh
{

class EulerCore
Copy link
Member Author

Choose a reason for hiding this comment

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

The solver core for the Euler equation. I hope there is a better name than core, but I haven't got one. I will wait a while before adding code comment block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"Core" sounds fine, unless you have other Euler stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

My concern is that core.py is already used. That could be clumsy when making shorthands for local variable names. But I do not have a better idea yet. It's not practical to spend a lot of time pondering a "perfect name". Only time can tell.

: public NumberBase<int32_t, double>
, public std::enable_shared_from_this<EulerCore>
{

private:

class ctor_passkey
{
};

public:

using number_base = NumberBase<int32_t, double>;
using int_type = typename number_base::int_type;
using uint_type = typename number_base::uint_type;
using real_type = typename number_base::real_type;

template <typename... Args>
static std::shared_ptr<EulerCore> construct(Args &&... args)
{
return std::make_shared<EulerCore>(std::forward<Args>(args)..., ctor_passkey());
}

EulerCore(std::shared_ptr<StaticMesh> const & mesh, real_type time_increment, ctor_passkey const &)
: m_mesh(mesh)
, m_time_increment(time_increment)
{
}

EulerCore() = delete;
EulerCore(EulerCore const &) = delete;
EulerCore(EulerCore &&) = delete;
EulerCore operator=(EulerCore const &) = delete;
EulerCore operator=(EulerCore &&) = delete;
~EulerCore() = default;

private:

std::shared_ptr<StaticMesh> m_mesh;
real_type m_time_increment = 0.0;

}; /* end class EulerCore */

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
38 changes: 38 additions & 0 deletions cpp/modmesh/multidim/multidim.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
Copy link
Member Author

Choose a reason for hiding this comment

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

Placeholder header for the new multidim module. But it should just use the modmesh namespace without a sub-namespace.


/*
* Copyright (c) 2024, Yung-Yu Chen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* Multi-dimensional space-time CESE solver.
*/

#include <modmesh/mesh/mesh.hpp>
#include <modmesh/multidim/euler.hpp>

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
66 changes: 66 additions & 0 deletions cpp/modmesh/multidim/pymod/multidim_pymod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2024, Yung-Yu Chen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <modmesh/multidim/pymod/multidim_pymod.hpp> // Must be the first include for Python.
#include <pybind11/stl.h>

#include <modmesh/modmesh.hpp>
#include <modmesh/python/common.hpp>

namespace modmesh
{

namespace python
{

struct multidim_pymod_tag
{
};

template <>
OneTimeInitializer<multidim_pymod_tag> & OneTimeInitializer<multidim_pymod_tag>::me()
{
static OneTimeInitializer<multidim_pymod_tag> instance;
return instance;
}

void initialize_multidim(pybind11::module & mod)
{
auto initialize_impl = [](pybind11::module & mod)
{
wrap_multidim(mod);
};

OneTimeInitializer<multidim_pymod_tag>::me()(mod, initialize_impl);
}

} /* end namespace python */

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
50 changes: 50 additions & 0 deletions cpp/modmesh/multidim/pymod/multidim_pymod.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

/*
* Copyright (c) 2024, Yung-Yu Chen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <modmesh/python/python.hpp> // Must be the first include.
#include <pybind11/stl.h>

#include <modmesh/modmesh.hpp>
#include <modmesh/python/common.hpp>

namespace modmesh
{

namespace python
{

void initialize_multidim(pybind11::module & mod);
void wrap_multidim(pybind11::module & mod);

} /* end namespace python */

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
83 changes: 83 additions & 0 deletions cpp/modmesh/multidim/pymod/wrap_multidim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2024, Yung-Yu Chen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <modmesh/python/common.hpp> // Must be the first include.

#include <modmesh/multidim/multidim.hpp>

namespace modmesh
{

namespace python
{

using namespace modmesh; // NOLINT(google-build-using-namespace)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't. Thanks for spotting it. It will be fixed in the next upload.


class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEulerCore
: public WrapBase<WrapEulerCore, EulerCore, std::shared_ptr<EulerCore>>
{

public:

using base_type = WrapBase<WrapEulerCore, EulerCore, std::shared_ptr<EulerCore>>;
using wrapper_type = typename base_type::wrapper_type;
using wrapped_type = typename base_type::wrapped_type;

friend base_type;

protected:

WrapEulerCore(pybind11::module & mod, const char * pyname, const char * clsdoc)
Copy link
Member Author

Choose a reason for hiding this comment

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

Make the placeholding C++ class available in Python.

: base_type(mod, pyname, clsdoc)
{

namespace py = pybind11;

(*this)
.def(
py::init(
[](std::shared_ptr<StaticMesh> const & mesh, wrapped_type::real_type time_increment)
{
return wrapped_type::construct(mesh, time_increment);
}),
py::arg("mesh"),
py::arg("time_increment"));
}

}; /* end class WrapEulerCore */

void wrap_multidim(pybind11::module & mod)
{
WrapEulerCore::commit(mod, "EulerCore", "Solve the Euler equation");
}

} /* end namespace python */

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
2 changes: 2 additions & 0 deletions cpp/modmesh/python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <modmesh/inout/pymod/inout_pymod.hpp>
#include <modmesh/mesh/pymod/mesh_pymod.hpp>
#include <modmesh/onedim/pymod/onedim_pymod.hpp>
#include <modmesh/multidim/pymod/multidim_pymod.hpp>
#include <modmesh/python/module.hpp>
#include <modmesh/spacetime/pymod/spacetime_pymod.hpp>
#include <modmesh/toggle/pymod/toggle_pymod.hpp>
Expand All @@ -48,6 +49,7 @@ void initialize(pybind11::module_ mod)
initialize_buffer(mod);
initialize_universe(mod);
initialize_mesh(mod);
initialize_multidim(mod);
Copy link
Member Author

Choose a reason for hiding this comment

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

Add code in the multidim directory.

initialize_inout(mod);
pybind11::module_ spacetime_mod = mod.def_submodule("spacetime", "spacetime");
initialize_spacetime(spacetime_mod);
Expand Down
1 change: 1 addition & 0 deletions modmesh/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'StaticGrid2d',
'StaticGrid3d',
'StaticMesh',
'EulerCore',
'HierarchicalToggleAccess',
'Toggle',
'CommandLineInfo',
Expand Down
Loading
Loading