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

[Solver] Semi-implicit Navier-Stokes solver #681

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1c8caac
add fluid particle
bodhinandach Mar 11, 2020
32aa0f4
add some functions to base classes
bodhinandach Mar 11, 2020
0705b03
fluid particle compiled
bodhinandach Mar 11, 2020
96349e4
add solver all commented
bodhinandach Mar 11, 2020
d76a013
add matrix
bodhinandach Mar 11, 2020
2615f21
add empty solver
bodhinandach Mar 11, 2020
6975f03
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Mar 11, 2020
1618d47
before loop begin
bodhinandach Mar 11, 2020
c43daff
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Mar 11, 2020
63b2483
some nodal function updates
bodhinandach Mar 12, 2020
47eec5a
add function until prediction
bodhinandach Mar 12, 2020
55b887b
add free surface particle computation
bodhinandach Mar 12, 2020
161d8f4
change matrix to linear solvers
bodhinandach Mar 12, 2020
56ac0c2
change mesh to shared_ptr
bodhinandach Mar 12, 2020
14b7eea
initialise and reinitialise matrices
bodhinandach Mar 13, 2020
e0ddac0
complete PPE
bodhinandach Mar 14, 2020
cf21e40
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Mar 14, 2020
a99ad6a
add update pressure increment
bodhinandach Mar 14, 2020
953c9da
compute corrected force - step 1
bodhinandach Mar 15, 2020
8ec176c
correction force - step 2
bodhinandach Mar 15, 2020
8552f8b
update velocity position
bodhinandach Mar 15, 2020
fe75ce9
add pressure smoothing
bodhinandach Mar 15, 2020
3bb5e2e
cleanup
bodhinandach Mar 15, 2020
1d490eb
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Mar 18, 2020
4f412ed
remove vtk attribute
bodhinandach Mar 18, 2020
f875118
pressure_smoothing
bodhinandach Mar 18, 2020
1d52272
minor cleanup
bodhinandach Mar 18, 2020
1378824
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Mar 18, 2020
c69acfa
adding LES turbulent viscosity
bodhinandach Mar 20, 2020
290d53a
move locate particle inside solver
bodhinandach Mar 21, 2020
5eabcdc
add framework compute_free_surface based on geom
bodhinandach Mar 26, 2020
94a6fba
add RBF
bodhinandach Mar 26, 2020
82d4a9f
add RBF kernel
bodhinandach Mar 26, 2020
2280ff7
add gradient RBF
bodhinandach Mar 26, 2020
356ceab
modify default radial basis function
bodhinandach Mar 27, 2020
a5ac395
add particle diameter
bodhinandach Apr 1, 2020
71c60b3
compute numerical normal
bodhinandach Apr 1, 2020
c4ca0ae
add normals in particles
bodhinandach Apr 1, 2020
fc03f99
fix structure
bodhinandach Apr 2, 2020
5a54f43
add secondary check
bodhinandach Apr 2, 2020
e156c26
move initial pressure to a separate function
bodhinandach Apr 2, 2020
211bb84
reset free surface particle
bodhinandach Apr 2, 2020
d5f101d
reset normal
bodhinandach Apr 4, 2020
b2955e6
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Apr 4, 2020
d1b8d91
improve accuracy fs detection
bodhinandach Apr 5, 2020
0c880f3
move compute free surface position
bodhinandach Apr 6, 2020
a9889eb
correct compute_density
bodhinandach Apr 6, 2020
473fa0c
modify compute free surface
bodhinandach Apr 6, 2020
32eec61
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Apr 7, 2020
d4e6744
register parallel assembler
bodhinandach Apr 8, 2020
ac9dbd2
modify function
bodhinandach Apr 9, 2020
1b877d1
Merge branch 'solver/navier-stokes' of https://github.com/cb-geo/mpm …
bodhinandach Apr 10, 2020
921e00c
:computer: Add PETSc to CMake
kks32 Apr 10, 2020
d59d84a
add mkl
bodhinandach Apr 11, 2020
89e1fbb
change template argument
bodhinandach Apr 11, 2020
7fff2ae
cleanup eigen cg
bodhinandach Apr 11, 2020
23323d9
Merge branch 'solver/navier-stokes-parallel' of https://github.com/cb…
bodhinandach Apr 13, 2020
998629b
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Apr 13, 2020
132d1e6
:construction: Test PETSc environment variables
kks32 Apr 13, 2020
b087eca
remove mkl
bodhinandach Apr 14, 2020
337504e
Merge branch 'solver/navier-stokes-parallel' of https://github.com/cb…
bodhinandach Apr 14, 2020
992e983
add default using PETSC as off
Apr 14, 2020
78a77d8
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Apr 14, 2020
2696abe
Merge branch 'solver/navier-stokes-parallel' of https://github.com/cb…
bodhinandach Apr 14, 2020
5eeecaa
add sign distance computation
bodhinandach Apr 15, 2020
bba0ec9
add sign distance
bodhinandach Apr 15, 2020
266e16c
add modification free surface
bodhinandach Apr 15, 2020
a24fb37
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach May 1, 2020
458891f
add nodal pressure constraint - tobe CP
bodhinandach May 10, 2020
0a656dc
:rewind: reverting PETSC from the current branch
bodhinandach May 27, 2020
9277579
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach May 27, 2020
c210996
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach May 28, 2020
ad1f83e
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jun 14, 2020
f3ebc7e
:wrench: fix compilation error
bodhinandach Jun 14, 2020
6cf5e7d
:wrench: move pressure constraint to constraints.h
bodhinandach Jun 16, 2020
424bd60
:art: change linear solver name
bodhinandach Jun 16, 2020
bf7d687
:art: cleanup assemble function arguments
bodhinandach Jun 17, 2020
17d8332
:wrench: fix argument error
bodhinandach Jun 17, 2020
60b501c
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 1, 2020
35ef202
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 2, 2020
c0b3250
:wrench: remove unused private variable
bodhinandach Jul 5, 2020
d444b84
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 5, 2020
4c8813f
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 14, 2020
b8d693b
:wrench: fix clang-format
bodhinandach Jul 14, 2020
7e07053
:wrench: change tbb to openmp
bodhinandach Jul 14, 2020
3f06493
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 25, 2020
81c5426
:wrench: add parallel schedule to iterate over particle predicate
bodhinandach Jul 25, 2020
13692de
:wrench: fix clang-format
bodhinandach Jul 25, 2020
acc7d54
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 25, 2020
f8fa3e9
:wrench: fix material and state variable phase
bodhinandach Jul 25, 2020
766991a
Merge branch 'develop' of https://github.com/cb-geo/mpm into solver/n…
bodhinandach Jul 28, 2020
965b3fd
:wrench: add assign_state_var and pressure and cleanup
bodhinandach Jul 28, 2020
d73a5f0
:wrench: change initial_pressure to assign_pressure
bodhinandach Jul 28, 2020
48b56c6
:wrench: reformat free surface detection
bodhinandach Jul 29, 2020
b38c3c2
:wrench: refactor assembler, linear solver, and fs_detection
bodhinandach Jul 29, 2020
76a7e0b
:construction: modify linear solver
bodhinandach Jul 30, 2020
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ if (MKL_FOUND)
endif()
endif()


# KaHIP
if (MPI_FOUND)
if (NO_KAHIP)
Expand Down Expand Up @@ -138,10 +137,12 @@ include_directories(BEFORE
${mpm_SOURCE_DIR}/include/functions/
${mpm_SOURCE_DIR}/include/generators/
${mpm_SOURCE_DIR}/include/io/
${mpm_SOURCE_DIR}/include/linear_solvers/
${mpm_SOURCE_DIR}/include/loads_bcs/
${mpm_SOURCE_DIR}/include/materials/
${mpm_SOURCE_DIR}/include/particles/
${mpm_SOURCE_DIR}/include/solvers/
${mpm_SOURCE_DIR}/include/utilities/
${mpm_SOURCE_DIR}/external/
${mpm_SOURCE_DIR}/tests/include/
)
Expand All @@ -161,6 +162,7 @@ SET(mpm_src
${mpm_SOURCE_DIR}/src/io/logger.cc
${mpm_SOURCE_DIR}/src/io/partio_writer.cc
${mpm_SOURCE_DIR}/src/io/vtk_writer.cc
${mpm_SOURCE_DIR}/src/linear_solver.cc
${mpm_SOURCE_DIR}/src/material.cc
${mpm_SOURCE_DIR}/src/mpm.cc
${mpm_SOURCE_DIR}/src/nodal_properties.cc
Expand Down
70 changes: 70 additions & 0 deletions include/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,66 @@ class Cell {
//! Return rank
unsigned rank() const;

//! Assign free surface
//! \param[in] free_surface boolean indicating free surface cell
void assign_free_surface(bool free_surface) { free_surface_ = free_surface; };

//! Return free surface bool
//! \retval free_surface_ indicating free surface cell
bool free_surface() { return free_surface_; };
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make all unaltered functions as const and add inline when appropriate?


//! Assign volume traction to node
//! \param[in] volume_fraction cell volume fraction
void assign_volume_fraction(double volume_fraction) {
volume_fraction_ = volume_fraction;
};

//! Return cell volume fraction
//! \retval volume_fraction_ cell volume fraction
double volume_fraction() { return volume_fraction_; };

//! Map cell volume to the nodes
//! \param[in] phase to map volume
bool map_cell_volume_to_nodes(unsigned phase);

//! Initialize local elemental matrices
bool initialise_element_matrix();

//! Return local node indices
Eigen::VectorXi local_node_indices();

//! Return local laplacian
const Eigen::MatrixXd& laplacian_matrix() { return laplacian_matrix_; };

//! Compute local laplacian matrix (Used in poisson equation)
//! \param[in] grad_shapefn shape function gradient
//! \param[in] pvolume volume weight
//! \param[in] multiplier multiplier
void compute_local_laplacian(const Eigen::MatrixXd& grad_shapefn,
double pvolume,
double multiplier = 1.0) noexcept;

//! Return local laplacian RHS matrix
const Eigen::MatrixXd& poisson_right_matrix() {
return poisson_right_matrix_;
};

//! Compute local poisson RHS matrix (Used in poisson equation)
//! \param[in] shapefn shape function
//! \param[in] grad_shapefn shape function gradient
//! \param[in] pvolume volume weight
void compute_local_poisson_right(const Eigen::VectorXd& shapefn,
const Eigen::MatrixXd& grad_shapefn,
double pvolume,
double multiplier = 1.0) noexcept;

//! Return local correction matrix
const Eigen::MatrixXd& correction_matrix() { return correction_matrix_; };

//! Compute local correction matrix (Used to correct velocity)
void compute_local_correction_matrix(const Eigen::VectorXd& shapefn,
const Eigen::MatrixXd& grad_shapefn,
double pvolume) noexcept;
//! Return previous mpi rank
unsigned previous_mpirank() const;

Expand Down Expand Up @@ -264,6 +324,16 @@ class Cell {
//! Normal of face
//! first-> face_id, second->vector of the normal
std::map<unsigned, Eigen::VectorXd> face_normals_;
//! Free surface bool
bool free_surface_{false};
//! Volume fraction
double volume_fraction_{0.0};
//! Local laplacian matrix
Eigen::MatrixXd laplacian_matrix_;
//! Local poisson RHS matrix
Eigen::MatrixXd poisson_right_matrix_;
//! Local correction RHS matrix
Eigen::MatrixXd correction_matrix_;
//! Logger
std::unique_ptr<spdlog::logger> console_;
}; // Cell class
Expand Down
106 changes: 105 additions & 1 deletion include/cell.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ inline Eigen::Matrix<double, 2, 1> mpm::Cell<2>::local_coordinates_point(
if (indices.size() == 3) {
// 2 0
// |\
// | \
// | \
// c | \ b
// | \
// | \
Expand Down Expand Up @@ -844,3 +844,107 @@ template <unsigned Tdim>
inline unsigned mpm::Cell<Tdim>::previous_mpirank() const {
return this->previous_mpirank_;
}

//! Map cell volume to nodes
template <unsigned Tdim>
bool mpm::Cell<Tdim>::map_cell_volume_to_nodes(unsigned phase) {
bool status = true;
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to use exception handling here, instead, use assert. A failure here will give incorrect results, so this should fail.

// Check if cell volume is set
if (volume_ == std::numeric_limits<double>::lowest())
this->compute_volume();

for (unsigned i = 0; i < nodes_.size(); ++i) {
nodes_[i]->update_volume(true, phase, volume_ / nnodes_);
}

} catch (std::exception& exception) {
console_->error("{} #{}: {}\n", __FILE__, __LINE__, exception.what());
status = false;
}
return status;
}

//! Return local node indices
template <unsigned Tdim>
Eigen::VectorXi mpm::Cell<Tdim>::local_node_indices() {
Eigen::VectorXi indices;
try {
indices.resize(nodes_.size());
indices.setZero();
unsigned node_idx = 0;
for (auto node_itr = nodes_.cbegin(); node_itr != nodes_.cend();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be the same for both standard linear and GIMP elements?

++node_itr) {
indices(node_idx) = (*node_itr)->active_id();
node_idx++;
}
} catch (std::exception& exception) {
console_->error("{} #{}: {}\n", __FILE__, __LINE__, exception.what());
}
return indices;
}

//! Initialise element matrix
template <unsigned Tdim>
bool mpm::Cell<Tdim>::initialise_element_matrix() {
bool status = true;
if (this->status()) {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need an exception block

// Initialse Laplacian matrix (NxN)
laplacian_matrix_.resize(nnodes_, nnodes_);
laplacian_matrix_.setZero();

// Initialse poisson RHS matrix (Nx(N*Tdim))
poisson_right_matrix_.resize(nnodes_, nnodes_ * Tdim);
poisson_right_matrix_.setZero();

// Initialse correction RHS matrix (NxTdim)
correction_matrix_.resize(nnodes_, nnodes_ * Tdim);
correction_matrix_.setZero();

} catch (std::exception& exception) {
console_->error("{} #{}: {}\n", __FILE__, __LINE__, exception.what());
status = false;
}
}
return status;
}

//! Compute local matrix of laplacian
template <unsigned Tdim>
void mpm::Cell<Tdim>::compute_local_laplacian(
const Eigen::MatrixXd& grad_shapefn, double pvolume,
double multiplier) noexcept {

std::lock_guard<std::mutex> guard(cell_mutex_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use mutex lock and unlock

laplacian_matrix_ +=
grad_shapefn * grad_shapefn.transpose() * multiplier * pvolume;
}

//! Compute local poisson RHS matrix
//! Used in poisson equation RHS for Navier Stokes solver
template <unsigned Tdim>
void mpm::Cell<Tdim>::compute_local_poisson_right(
const Eigen::VectorXd& shapefn, const Eigen::MatrixXd& grad_shapefn,
double pvolume, double multiplier) noexcept {

std::lock_guard<std::mutex> guard(cell_mutex_);
for (unsigned i = 0; i < Tdim; i++) {
poisson_right_matrix_.block(0, i * nnodes_, nnodes_, nnodes_) +=
shapefn * grad_shapefn.col(i).transpose() * multiplier * pvolume;
}
}

//! Compute local correction matrix
//! Used to compute corrector of nodal velocity for Navier Stokes solver
template <unsigned Tdim>
void mpm::Cell<Tdim>::compute_local_correction_matrix(
const Eigen::VectorXd& shapefn, const Eigen::MatrixXd& grad_shapefn,
double pvolume) noexcept {

std::lock_guard<std::mutex> guard(cell_mutex_);
for (unsigned i = 0; i < Tdim; i++) {
correction_matrix_.block(0, i * nnodes_, nnodes_, nnodes_) +=
shapefn * grad_shapefn.col(i).transpose() * pvolume;
}
}
5 changes: 5 additions & 0 deletions include/io/io_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class IOMesh {
read_friction_constraints(
const std::string& friction_constraints_file) = 0;

//! Read pressure constraints file
//! \param[in] pressure_constraints_files file name with pressure constraints
virtual std::vector<std::tuple<mpm::Index, double>> read_pressure_constraints(
const std::string& _pressure_constraints_file) = 0;

//! Read forces file
//! \param[in] forces_files file name with nodal concentrated force
virtual std::vector<std::tuple<mpm::Index, unsigned, double>> read_forces(
Expand Down
6 changes: 6 additions & 0 deletions include/io/io_mesh_ascii.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class IOMeshAscii : public IOMesh<Tdim> {
std::vector<std::tuple<mpm::Index, unsigned, double>> read_forces(
const std::string& forces_file) override;

//! Read pressure constraints file
//! \param[in] pressure_constraints_files file name with pressure
//! constraints
std::vector<std::tuple<mpm::Index, double>> read_pressure_constraints(
const std::string& pressure_constraints_file) override;

private:
//! Logger
std::shared_ptr<spdlog::logger> console_;
Expand Down
43 changes: 43 additions & 0 deletions include/io/io_mesh_ascii.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,49 @@ std::vector<std::tuple<mpm::Index, unsigned, int, double>>
return constraints;
}

//! Read pressure constraints file
template <unsigned Tdim>
std::vector<std::tuple<mpm::Index, double>>
mpm::IOMeshAscii<Tdim>::read_pressure_constraints(
const std::string& pressure_constraints_file) {
// Particle pressure constraints
std::vector<std::tuple<mpm::Index, double>> constraints;
constraints.clear();

// input file stream
std::fstream file;
file.open(pressure_constraints_file.c_str(), std::ios::in);

try {
if (file.is_open() && file.good()) {
// Line
std::string line;
while (std::getline(file, line)) {
boost::algorithm::trim(line);
std::istringstream istream(line);
// ignore comment lines (# or !) or blank lines
if ((line.find('#') == std::string::npos) &&
(line.find('!') == std::string::npos) && (line != "")) {
while (istream.good()) {
// ID
mpm::Index id;
// Pressure
double pressure;
// Read stream
istream >> id >> pressure;
constraints.emplace_back(std::make_tuple(id, pressure));
}
}
}
}
file.close();
} catch (std::exception& exception) {
console_->error("Read pressure constraints: {}", exception.what());
file.close();
}
return constraints;
}

//! Return particles force
template <unsigned Tdim>
std::vector<std::tuple<mpm::Index, unsigned, double>>
Expand Down
4 changes: 4 additions & 0 deletions include/io/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct Logger {

// Create a logger for MPM Explicit USL
static const std::shared_ptr<spdlog::logger> mpm_explicit_usl_logger;

// Create a logger for MPM Semi-implicit Navier Stokes
static const std::shared_ptr<spdlog::logger>
mpm_semi_implicit_navier_stokes_logger;
};

} // namespace mpm
Expand Down
Loading