Skip to content

Commit e0de8eb

Browse files
committed
6_inv_free
1 parent ea0b9be commit e0de8eb

26 files changed

Lines changed: 2755 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
add_executable(7_self_contact)
2+
3+
target_compile_options(7_self_contact PRIVATE -g)
4+
set_target_properties(7_self_contact PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
5+
6+
target_link_libraries(7_self_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 7_self_contact_CU_SOURCE CONFIGURE_DEPENDS "src/*.cu")
13+
target_sources(7_self_contact PRIVATE ${7_self_contact_CU_SOURCE})
14+
15+
file(GLOB_RECURSE 7_self_contact_CPP_SOURCE CONFIGURE_DEPENDS "src/*.cpp")
16+
target_sources(7_self_contact PRIVATE ${7_self_contact_CPP_SOURCE})
17+
18+
target_link_libraries(7_self_contact 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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <Eigen/Dense>
5+
#include "uti.h"
6+
#include "device_uti.h"
7+
8+
template <typename T, int dim>
9+
class NeoHookeanEnergy
10+
{
11+
public:
12+
NeoHookeanEnergy(const std::vector<T> &x, const std::vector<int> &e, T mu, T lam);
13+
NeoHookeanEnergy();
14+
~NeoHookeanEnergy();
15+
NeoHookeanEnergy(NeoHookeanEnergy &&rhs);
16+
NeoHookeanEnergy(const NeoHookeanEnergy &rhs);
17+
NeoHookeanEnergy &operator=(NeoHookeanEnergy &&rhs);
18+
19+
void update_x(const DeviceBuffer<T> &x);
20+
void init_vol_IB();
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+
T init_step_size(const DeviceBuffer<T> &p); // Calculate the initial step size for the line search
25+
26+
private:
27+
struct Impl;
28+
std::unique_ptr<Impl> pimpl_;
29+
// static __device__ void polar_svd(const Eigen::Matrix<T, dim, dim> &F, Eigen::Matrix<T, dim, dim> &U, Eigen::Matrix<T, dim, dim> &V, Eigen::Matrix<T, dim, 1> &s);
30+
// static __device__ Eigen::Matrix<T, dim, 1> dPsi_div_dsigma(const Eigen::Matrix<T, dim, 1> &s, T mu, T lam);
31+
// static __device__ Eigen::Matrix<T, dim, dim> d2Psi_div_dsigma2(const Eigen::Matrix<T, dim, 1> &s, T mu, T lam);
32+
// static __device__ T B_left_coef(const Eigen::Matrix<T, dim, 1> &s, T mu, T lam);
33+
// static __device__ T Psi(const Eigen::Matrix<T, dim, dim> &F, T mu, T lam);
34+
// static __device__ Eigen::Matrix<T, dim, dim> dPsi_div_dF(const Eigen::Matrix<T, dim, dim> &F, T mu, T lam);
35+
// static __device__ Eigen::Matrix<T, 4, 4> d2Psi_div_dF2(const Eigen::Matrix<T, dim, dim> &F, T mu, T lam);
36+
// static __device__ Eigen::Matrix<T, 6, 1> dPsi_div_dx(const Eigen::Matrix<T, dim, dim> &P, const Eigen::Matrix<T, dim, dim> &IB);
37+
// static __device__ Eigen::Matrix<T, 6, 6> d2Psi_div_dx2(const Eigen::Matrix<T, 4, 4> &dP_div_dF, const Eigen::Matrix<T, dim, dim> &IB);
38+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#include "Eigen/Dense"
3+
#include <muda/cub/device/device_reduce.h>
4+
#include <muda/container.h>
5+
#include <muda/muda.h>
6+
#include <muda/ext/linear_system.h>
7+
template <typename T>
8+
__device__ __host__ void NeoHookeanEnergyVal(T &E, const T &Mu, const T &Lambda, const Eigen::Vector<T, 6> &X, const Eigen::Matrix<T, 2, 2> &IB, const T &vol);
9+
10+
template <typename T>
11+
__device__ __host__ void NeoHookeanEnergyGradient(Eigen::Vector<T, 6> &G, const T &Mu, const T &Lambda, const Eigen::Vector<T, 6> &X, const Eigen::Matrix<T, 2, 2> &IB, const T &vol);
12+
13+
template <typename T>
14+
__device__ __host__ void NeoHookeanEnergyHessian(Eigen::Matrix<T, 6, 6> &H, const T &Mu, const T &Lambda, const Eigen::Vector<T, 6> &X, const Eigen::Matrix<T, 2, 2> &IB, const T &vol);
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: 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 <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, 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+
void update_DBC_target(const std::vector<T> &DBC_target);
22+
void update_k(T new_k);
23+
T val(); // Calculate the value of the energy
24+
const DeviceBuffer<T> &grad(); // Calculate the gradient of the energy
25+
const DeviceTripletMatrix<T, 1> &hess(); // Calculate the Hessian matrix of the energy
26+
27+
private:
28+
struct Impl;
29+
std::unique_ptr<Impl> pimpl_;
30+
};
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)