Skip to content

Commit f32f249

Browse files
committed
4_friction
1 parent b26be73 commit f32f249

44 files changed

Lines changed: 3359 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

simulators/2_dirichlet/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int main()
44
{
5-
float rho = 1000, k = 1e3, initial_stretch = 1, n_seg = 10, h = 0.02, side_len = 1, tol = 0.01;
5+
float rho = 1000, k = 1e3, initial_stretch = 1, n_seg = 20, h = 0.02, side_len = 1, tol = 0.01;
66
// printf("Running mass-spring simulator with parameters: rho = %f, k = %f, initial_stretch = %f, n_seg = %d, h = %f, side_len = %f, tol = %f\n", rho, k, initial_stretch, n_seg, h, side_len, tol);
77
DirichletSimulator<float, 2> simulator(rho, side_len, initial_stretch, k, h, tol, n_seg);
88
simulator.run();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
add_executable(3_contact)
2+
3+
target_compile_options(3_contact PRIVATE -g)
4+
set_target_properties(3_contact PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
5+
6+
target_link_libraries(3_contact PRIVATE muda cusolver cublas cusparse )
7+
8+
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
9+
10+
include_directories(include)
11+
12+
file(GLOB_RECURSE 3_contact_CU_SOURCE CONFIGURE_DEPENDS "src/*.cu")
13+
target_sources(3_contact PRIVATE ${3_contact_CU_SOURCE})
14+
15+
file(GLOB_RECURSE 3_contact_CPP_SOURCE CONFIGURE_DEPENDS "src/*.cpp")
16+
target_sources(3_contact PRIVATE ${3_contact_CPP_SOURCE})
17+
18+
target_link_libraries(3_contact PRIVATE sfml-graphics)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <Eigen/Dense>
5+
#include "uti.h"
6+
7+
template <typename T, int dim>
8+
class BarrierEnergy
9+
{
10+
public:
11+
BarrierEnergy(const std::vector<T> &x, const std::vector<T> &contact_area, T y_ground);
12+
BarrierEnergy();
13+
~BarrierEnergy();
14+
BarrierEnergy(BarrierEnergy &&rhs);
15+
BarrierEnergy(const BarrierEnergy &rhs);
16+
BarrierEnergy &operator=(BarrierEnergy &&rhs);
17+
18+
void update_x(const DeviceBuffer<T> &x);
19+
T val(); // Calculate the value of the energy
20+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
21+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
22+
T init_step_size(const DeviceBuffer<T> &p); // Calculate the initial step size for the line search
23+
24+
private:
25+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
26+
struct Impl;
27+
// The private pointer to the implementation class Impl
28+
std::unique_ptr<Impl> pimpl_;
29+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <Eigen/Dense>
5+
#include "square_mesh.h"
6+
#include <muda/muda.h>
7+
#include <muda/container.h>
8+
#include <muda/ext/linear_system.h>
9+
10+
using namespace muda;
11+
12+
template <typename T, int dim>
13+
class GravityEnergy
14+
{
15+
public:
16+
GravityEnergy(int N, T m);
17+
GravityEnergy();
18+
~GravityEnergy();
19+
GravityEnergy(GravityEnergy &&rhs);
20+
GravityEnergy(const GravityEnergy &rhs);
21+
GravityEnergy &operator=(GravityEnergy &&rhs);
22+
GravityEnergy &operator=(const GravityEnergy &rhs);
23+
24+
void update_x(const DeviceBuffer<T> &x);
25+
void update_x_tilde(const DeviceBuffer<T> &x_tilde);
26+
void update_m(T m);
27+
T val(); // Calculate the value of the energy
28+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
29+
30+
private:
31+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
32+
struct Impl;
33+
// The private pointer to the implementation class Impl
34+
std::unique_ptr<Impl> pimpl_;
35+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <Eigen/Dense>
5+
#include "square_mesh.h"
6+
#include <muda/muda.h>
7+
#include <muda/container.h>
8+
#include <muda/ext/linear_system.h>
9+
10+
using namespace muda;
11+
12+
template <typename T, int dim>
13+
class InertialEnergy
14+
{
15+
public:
16+
InertialEnergy(int N, T m);
17+
InertialEnergy();
18+
~InertialEnergy();
19+
InertialEnergy(InertialEnergy &&rhs);
20+
InertialEnergy(const InertialEnergy &rhs);
21+
InertialEnergy &operator=(InertialEnergy &&rhs);
22+
23+
void update_x(const DeviceBuffer<T> &x);
24+
void generate_hess();
25+
void update_x_tilde(const DeviceBuffer<T> &x_tilde);
26+
void update_m(T m);
27+
T val(); // Calculate the value of the energy
28+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
29+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
30+
31+
private:
32+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
33+
struct Impl;
34+
// The private pointer to the implementation class Impl
35+
std::unique_ptr<Impl> pimpl_;
36+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <Eigen/Dense>
5+
#include "uti.h"
6+
7+
template <typename T, int dim>
8+
class MassSpringEnergy
9+
{
10+
public:
11+
MassSpringEnergy(const std::vector<T> &x, const std::vector<int> &e, const std::vector<T> &l2, const std::vector<T> &k);
12+
MassSpringEnergy();
13+
~MassSpringEnergy();
14+
MassSpringEnergy(MassSpringEnergy &&rhs);
15+
MassSpringEnergy(const MassSpringEnergy &rhs);
16+
MassSpringEnergy &operator=(MassSpringEnergy &&rhs);
17+
18+
void update_x(const DeviceBuffer<T> &x);
19+
void update_e(const std::vector<int> &e);
20+
void update_l2(const std::vector<T> &l2);
21+
void update_k(const std::vector<T> &k);
22+
T val(); // Calculate the value of the energy
23+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
24+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
25+
26+
private:
27+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
28+
struct Impl;
29+
// The private pointer to the implementation class Impl
30+
std::unique_ptr<Impl> pimpl_;
31+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
template <typename T>
6+
class SparseMatrix
7+
{
8+
public:
9+
SparseMatrix(int size);
10+
SparseMatrix();
11+
~SparseMatrix();
12+
SparseMatrix(SparseMatrix<T> &&rhs);
13+
SparseMatrix<T> &operator=(SparseMatrix<T> &&rhs);
14+
SparseMatrix<T> &operator=(SparseMatrix<T> &rhs);
15+
SparseMatrix<T> &operator*(const T &a);
16+
SparseMatrix(const SparseMatrix<T> &rhs);
17+
void set_value(int row, int col, T val, int loc);
18+
void set_diagonal(T val);
19+
20+
const std::vector<int> &get_row_buffer() const;
21+
const std::vector<int> &get_col_buffer() const;
22+
const std::vector<T> &get_val_buffer() const;
23+
std::vector<int> &set_row_buffer();
24+
std::vector<int> &set_col_buffer();
25+
std::vector<T> &set_val_buffer();
26+
SparseMatrix<T> &combine(const SparseMatrix<T> &other);
27+
28+
int get_size() const;
29+
30+
private:
31+
int size;
32+
std::vector<int> row_idx;
33+
std::vector<int> col_idx;
34+
std::vector<T> val;
35+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <muda/muda.h>
2+
#include <muda/container.h>
3+
#include <muda/cub/device/device_reduce.h>
4+
#include <Eigen/Dense>
5+
// utility functions
6+
template <typename T>
7+
T devicesum(const muda::DeviceBuffer<T> &buffer);
8+
9+
template <typename T, int Size>
10+
void __device__ make_PSD(const Eigen::Matrix<T, Size, Size> &hess, Eigen::Matrix<T, Size, Size> &PSD);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <cmath>
5+
#include "square_mesh.h"
6+
#include <iostream>
7+
template <typename T, int dim>
8+
class ContactSimulator
9+
{
10+
public:
11+
ContactSimulator();
12+
~ContactSimulator();
13+
ContactSimulator(ContactSimulator &&rhs);
14+
ContactSimulator &operator=(ContactSimulator &&rhs);
15+
ContactSimulator(T rho, T side_len, T initial_stretch, T K, T h, T tol, int n_seg);
16+
void run();
17+
18+
private:
19+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
20+
struct Impl;
21+
// The private pointer to the implementation class Impl
22+
std::unique_ptr<Impl> pimpl_;
23+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include <vector>
3+
#include <memory>
4+
5+
// Function to generate mesh points and edges
6+
template <typename T>
7+
void generate(T side_length, int n_seg, std::vector<T> &x, std::vector<int> &e);

0 commit comments

Comments
 (0)