-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6568779
commit 0db8015
Showing
27 changed files
with
1,465 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @file Naive.h | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace mmft{ | ||
|
||
/** | ||
* @brief The Naive Scheme is an update scheme that sets the relaxation factor of an iterative update scheme to a | ||
* given constant for all nodes. | ||
*/ | ||
template<typename T> | ||
class DynamicDampingScheme : public Scheme<T> { | ||
|
||
private: | ||
|
||
Eigen::VectorXd x_prev; | ||
Eigen::VectorXd factor; | ||
|
||
public: | ||
/** | ||
* @brief Constructor of the Naive Scheme with provided constants. | ||
* @param[in] modules The map of modules with boundary nodes upon which this scheme acts. | ||
* @param[in] alpha The relaxation value for the pressure value update. | ||
* @param[in] beta The relaxation value of the flow rate value update. | ||
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module. | ||
*/ | ||
DynamicDampingScheme(int theta, int size); | ||
|
||
/** | ||
* @brief Compute the update value alpha according to alpha = 1/(1 + 10*d2xdt2). | ||
*/ | ||
void compute() override; | ||
|
||
}; | ||
|
||
} // namespace mmft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "DynamicDamping.h" | ||
|
||
namespace mmft { | ||
|
||
template<typename T> | ||
DynamicDampingScheme<T>::DynamicDampingScheme(int theta_, int size_) : | ||
Scheme<T>() | ||
{ | ||
/* | ||
this->theta.try_emplace(0,theta_); | ||
for (int i = 0; i < size_; i++) { | ||
this->alpha.try_emplace(i, 0.0); | ||
} | ||
*/ | ||
} | ||
|
||
template<typename T> | ||
void DynamicDampingScheme<T>::compute() { | ||
|
||
if (this->x_star.size() == this->x.size() && this->x.size() == x_prev.size()) { | ||
// Central difference scheme for second order derivative | ||
Eigen::VectorXd d2x_dt2 = this->x_star.array() - 2*this->x.array() + x_prev.array(); | ||
factor = (1.0/(1.0 + 10*(d2x_dt2.array().abs()))); | ||
x_prev = this->x; | ||
this->x = (1 - factor.array()) * this->x.array() + factor.array() * this->x_star.array(); | ||
} else { | ||
x_prev = this->x; | ||
this->x = this->x_star; | ||
} | ||
|
||
} | ||
|
||
} // namespace mmft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @file Naive.h | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace mmft{ | ||
|
||
/** | ||
* @brief The Naive Scheme is an update scheme that sets the relaxation factor of an iterative update scheme to a | ||
* given constant for all nodes. | ||
*/ | ||
template<typename T> | ||
class LinearDecouplingScheme : public Scheme<T> { | ||
|
||
private: | ||
|
||
Eigen::VectorXd x_prev; | ||
Eigen::VectorXd factor; | ||
Eigen::VectorXd lambda; | ||
Eigen::VectorXd omega; | ||
|
||
T zeta = 10; | ||
Eigen::VectorXd b = Eigen::VectorXd::Zero(2); | ||
Eigen::MatrixXd A = Eigen::MatrixXd::Zero(2,2); | ||
Eigen::VectorXd ab = Eigen::VectorXd::Zero(2); | ||
|
||
public: | ||
/** | ||
* @brief Constructor of the Naive Scheme with provided constants. | ||
* @param[in] modules The map of modules with boundary nodes upon which this scheme acts. | ||
* @param[in] alpha The relaxation value for the pressure value update. | ||
* @param[in] beta The relaxation value of the flow rate value update. | ||
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module. | ||
*/ | ||
LinearDecouplingScheme(); | ||
|
||
/** | ||
* @brief Compute the update value alpha according to alpha = 1/(1 + 10*d2xdt2). | ||
*/ | ||
void compute() override; | ||
|
||
}; | ||
|
||
} // namespace mmft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "LinearDecoupling.h" | ||
|
||
namespace mmft { | ||
|
||
template<typename T> | ||
LinearDecouplingScheme<T>::LinearDecouplingScheme() : | ||
Scheme<T>() | ||
{ | ||
/* | ||
this->theta.try_emplace(0,theta_); | ||
for (int i = 0; i < size_; i++) { | ||
this->alpha.try_emplace(i, 0.0); | ||
} | ||
*/ | ||
} | ||
|
||
template<typename T> | ||
void LinearDecouplingScheme<T>::compute() { | ||
|
||
if (this->x_star.size() == this->x.size() && this->x.size() == x_prev.size()) { | ||
// Central difference scheme for second order derivative | ||
Eigen::VectorXd d2x_dt2 = this->x_star.array() - 2*this->x.array() + x_prev.array(); | ||
|
||
lambda = d2x_dt2.array()/this->x.array(); | ||
|
||
int n = 0; | ||
T l_sum = 0.0; | ||
T w_sum = 0.0; | ||
T inv_l_sum = 0.0; | ||
T inv_w_sum = 0.0; | ||
|
||
for (int i = 0; i < lambda.size(); i++) { | ||
if (lambda[i] > 1e-12) { | ||
T w = sqrt(lambda[i]); | ||
l_sum += lambda[i]; | ||
w_sum += w; | ||
inv_l_sum += 1.0/lambda[i]; | ||
inv_w_sum += 1.0/w; | ||
n++; | ||
} | ||
} | ||
|
||
|
||
A(0,0) = 0.25*inv_l_sum; | ||
A(1,0) = 0.25*n; | ||
A(0,1) = 0.25*n; | ||
A(1,1) = 0.25*l_sum; | ||
|
||
b(0) = 0.5*inv_w_sum*zeta; | ||
b(1) = 0.5*w_sum*zeta; | ||
|
||
ab = A.colPivHouseholderQr().solve(b); | ||
|
||
T factor_a = (1.0)/(1.0 + ab[0]); | ||
T factor_b = (ab[1] - 1.0)/(1.0 + ab[0]); | ||
T factor_c = 1.0 + (-1.0)/(1.0 + ab[0]); | ||
|
||
std::cout << "alpha: " << ab[0] << "\tbeta: " << ab[1] << std::endl; | ||
std::cout << "a: " << factor_a << "\tb: " << factor_b << "\tc: " << factor_c << std::endl; | ||
|
||
factor = (1.0/(1.0 + 10*(d2x_dt2.array().abs()))); | ||
|
||
x_prev = this->x; | ||
|
||
this->x = factor_a*this->x_star.array() + factor_b*lambda.array()*this->x_star.array() + factor_c*this->x.array(); | ||
//this->x = (1 - factor.array()) * this->x.array() + factor.array() * this->x_star.array(); | ||
} else { | ||
x_prev = this->x; | ||
this->x = this->x_star; | ||
} | ||
|
||
} | ||
|
||
} // namespace mmft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.