Skip to content

Commit 38a61b7

Browse files
committed
5
1 parent e1ccc79 commit 38a61b7

26 files changed

Lines changed: 2039 additions & 10 deletions
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
add_executable(4_friction)
1+
add_executable(4_friction_debug)
22

3-
target_compile_options(4_friction PRIVATE -g)
4-
set_target_properties(4_friction PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
3+
target_compile_options(4_friction_debug PRIVATE -g)
4+
set_target_properties(4_friction_debug PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
55

6-
target_link_libraries(4_friction PRIVATE muda cusolver cublas cusparse )
6+
target_link_libraries(4_friction_debug PRIVATE muda cusolver cublas cusparse )
77

88
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
99

1010
include_directories(include)
1111

12-
file(GLOB_RECURSE 4_friction_CU_SOURCE CONFIGURE_DEPENDS "src/*.cu")
13-
target_sources(4_friction PRIVATE ${4_friction_CU_SOURCE})
12+
file(GLOB_RECURSE 4_friction_debug_CU_SOURCE CONFIGURE_DEPENDS "src/*.cu")
13+
target_sources(4_friction_debug PRIVATE ${4_friction_debug_CU_SOURCE})
1414

15-
file(GLOB_RECURSE 4_friction_CPP_SOURCE CONFIGURE_DEPENDS "src/*.cpp")
16-
target_sources(4_friction PRIVATE ${4_friction_CPP_SOURCE})
15+
file(GLOB_RECURSE 4_friction_debug_CPP_SOURCE CONFIGURE_DEPENDS "src/*.cpp")
16+
target_sources(4_friction_debug PRIVATE ${4_friction_debug_CPP_SOURCE})
1717

18-
target_link_libraries(4_friction PRIVATE sfml-graphics)
18+
target_link_libraries(4_friction_debug PRIVATE sfml-graphics)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
add_executable(5_mov_dirichlet)
2+
3+
target_compile_options(5_mov_dirichlet PRIVATE -g)
4+
set_target_properties(5_mov_dirichlet PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
5+
6+
target_link_libraries(5_mov_dirichlet 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 5_mov_dirichlet_CU_SOURCE CONFIGURE_DEPENDS "src/*.cu")
13+
target_sources(5_mov_dirichlet PRIVATE ${5_mov_dirichlet_CU_SOURCE})
14+
15+
file(GLOB_RECURSE 5_mov_dirichlet_CPP_SOURCE CONFIGURE_DEPENDS "src/*.cpp")
16+
target_sources(5_mov_dirichlet PRIVATE ${5_mov_dirichlet_CPP_SOURCE})
17+
18+
target_link_libraries(5_mov_dirichlet PRIVATE sfml-graphics)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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> n, const std::vector<T> o, const std::vector<T> &contact_area);
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+
const DeviceBuffer<T> compute_mu_lambda(T mu);
23+
T init_step_size(const DeviceBuffer<T> &p); // Calculate the initial step size for the line search
24+
25+
private:
26+
// The implementation details of the VecAdder class are placed in the implementation class declared here.
27+
struct Impl;
28+
// The private pointer to the implementation class Impl
29+
std::unique_ptr<Impl> pimpl_;
30+
};
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 <vector>
6+
#include "uti.h"
7+
8+
template <typename T, int dim>
9+
class FrictionEnergy
10+
{
11+
public:
12+
FrictionEnergy(const std::vector<T> &v, T hhat, const std::vector<T> &n);
13+
FrictionEnergy();
14+
~FrictionEnergy();
15+
FrictionEnergy(FrictionEnergy &&rhs);
16+
FrictionEnergy(const FrictionEnergy &rhs);
17+
FrictionEnergy &operator=(FrictionEnergy &&rhs);
18+
19+
void update_v(const DeviceBuffer<T> &v);
20+
void update_mu_lambda(const DeviceBuffer<T> &mu_lambda);
21+
T val(); // Calculate the value of the energy
22+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
23+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
24+
25+
private:
26+
struct Impl;
27+
std::unique_ptr<Impl> pimpl_;
28+
T __device__ f0(T vbarnorm, T Epsv, T hhat);
29+
T __device__ f1_div_vbarnorm(T vbarnorm, T Epsv);
30+
T __device__ f_hess_term(T vbarnorm, T Epsv);
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 <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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <vector>
5+
#include <Eigen/Dense>
6+
#include "uti.h"
7+
#include "device_uti.h"
8+
9+
template <typename T, int dim>
10+
class SpringEnergy
11+
{
12+
public:
13+
SpringEnergy(const std::vector<T> &x, const std::vector<T> &m, const std::vector<int> &DBC, const std::vector<Eigen::Matrix<T, dim, 1>> &DBC_target, T k);
14+
SpringEnergy();
15+
~SpringEnergy();
16+
SpringEnergy(SpringEnergy &&rhs);
17+
SpringEnergy(const SpringEnergy &rhs);
18+
SpringEnergy &operator=(SpringEnergy &&rhs);
19+
20+
void update_x(const DeviceBuffer<T> &x);
21+
T val(); // Calculate the value of the energy
22+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
23+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
24+
25+
private:
26+
struct Impl;
27+
std::unique_ptr<Impl> pimpl_;
28+
};
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);

0 commit comments

Comments
 (0)