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

schwarz WIP #133

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions include/pressiodemoapps/adapter_cpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PublicProblemEigenMixinCpp : public T
using rhs_type = typename T::velocity_type;
using right_hand_side_type = typename T::velocity_type;
using jacobian_type = typename T::jacobian_type;
using graph_type = typename T::graph_type;

private:
using typename T::index_t;
Expand Down Expand Up @@ -148,6 +149,14 @@ class PublicProblemEigenMixinCpp : public T
return createApplyJacobianResult(operand);
}

void setStateBc(state_type * stateBc){
T::setStateBc(stateBc);
}

void setGraphBc(graph_type * ghostGraph){
T::setGraphBc(ghostGraph);
}

//
// evaluation
//
Expand Down
1 change: 1 addition & 0 deletions include/pressiodemoapps/impl/advection_1d_prob_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type, Eigen::Dynamic, 1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type,Eigen::Dynamic,1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{2};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type,Eigen::Dynamic,1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{2};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type,Eigen::Dynamic,1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type, Eigen::Dynamic, 1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{2};
Expand Down
1 change: 1 addition & 0 deletions include/pressiodemoapps/impl/euler_1d_prob_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class EigenApp
using state_type = Eigen::Matrix<scalar_type, Eigen::Dynamic, 1>;
using velocity_type = state_type;
using jacobian_type = Eigen::SparseMatrix<scalar_type, Eigen::RowMajor, index_t>;
using graph_type = typename MeshType::graph_t;

private:
static constexpr int dimensionality{1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,228 @@

namespace pressiodemoapps{ namespace impleuler2d{


template<class state_t, class mesh_t, class ghost_t>
class DoubleMachReflection2dGhostFillerWithCustomBc
{
using scalar_type = typename mesh_t::scalar_t;
using graph_t = typename mesh_t::graph_t;

public:
DoubleMachReflection2dGhostFillerWithCustomBc() = delete;
DoubleMachReflection2dGhostFillerWithCustomBc(const int stencilSize,
const state_t & stateIn,
const scalar_type evaluationTime,
const scalar_type gamma,
const mesh_t & meshIn,
ghost_t & ghostLeft,
ghost_t & ghostFront,
ghost_t & ghostRight,
ghost_t & ghostBack,
const state_t & stateBcs,
const graph_t & graphBcs)
: m_stencilSize(stencilSize),
m_state(stateIn),
m_evaluationTime(evaluationTime),
m_gamma(gamma),
m_meshObj(meshIn),
m_ghostLeft(ghostLeft),
m_ghostFront(ghostFront),
m_ghostRight(ghostRight),
m_ghostBack(ghostBack),
m_stateBcs(stateBcs),
m_graphBcs(graphBcs)
{
computeShockConditions();
}

template<class index_t>
void operator()(index_t smPt, int gRow)
{
/* use m_stateBcs here */

constexpr int numDofPerCell = 4;
constexpr scalar_type zero{0};

const auto & graph = m_meshObj.graph();
assert(::pressiodemoapps::extent(graph, 0) >= 5);
const auto cellGID = graph(smPt, 0);
const auto uIndex = cellGID*numDofPerCell;

const auto & x = m_meshObj.viewX();
const auto & y = m_meshObj.viewY();
const auto myX = x(cellGID);
const auto myY = y(cellGID);
const auto dy = m_meshObj.dy();

const auto left0 = graph(smPt, 1);
const auto front0 = graph(smPt, 2);
const auto right0 = graph(smPt, 3);
const auto back0 = graph(smPt, 4);

if (left0 == -1)
{
const auto bcIndex = m_graphBcs(gRow, 0);
if (bcIndex == -1) {
m_ghostLeft(gRow, 0) = m_state(uIndex+0);
m_ghostLeft(gRow, 1) = m_state(uIndex+1);
m_ghostLeft(gRow, 2) = m_state(uIndex+2);
m_ghostLeft(gRow, 3) = m_state(uIndex+3);
}
else {
m_ghostLeft(gRow, 0) = m_stateBcs(bcIndex+0);
m_ghostLeft(gRow, 1) = m_stateBcs(bcIndex+1);
m_ghostLeft(gRow, 2) = m_stateBcs(bcIndex+2);
m_ghostLeft(gRow, 3) = m_stateBcs(bcIndex+3);
}
}

if (front0 == -1){
const auto bcIndex = m_graphBcs(gRow, 1);
if (bcIndex == -1) {
if (distanceFromShock(myX, myY+dy) < zero){
m_ghostFront(gRow, 0) = m_postShockState[0];
m_ghostFront(gRow, 1) = m_postShockState[1];
m_ghostFront(gRow, 2) = m_postShockState[2];
m_ghostFront(gRow, 3) = m_postShockState[3];
}
else{
m_ghostFront(gRow, 0) = m_preShockState[0];
m_ghostFront(gRow, 1) = m_preShockState[1];
m_ghostFront(gRow, 2) = m_preShockState[2];
m_ghostFront(gRow, 3) = m_preShockState[3];
}
}
else {
m_ghostFront(gRow, 0) = m_stateBcs(bcIndex+0);
m_ghostFront(gRow, 1) = m_stateBcs(bcIndex+1);
m_ghostFront(gRow, 2) = m_stateBcs(bcIndex+2);
m_ghostFront(gRow, 3) = m_stateBcs(bcIndex+3);
}
}

if (right0 == -1)
{
const auto bcIndex = m_graphBcs(gRow, 2);
if (bcIndex == -1) {
m_ghostRight(gRow, 0) = m_state(uIndex+0);
m_ghostRight(gRow, 1) = m_state(uIndex+1);
m_ghostRight(gRow, 2) = m_state(uIndex+2);
m_ghostRight(gRow, 3) = m_state(uIndex+3);
}
else {
m_ghostRight(gRow, 0) = m_stateBcs(bcIndex+0);
m_ghostRight(gRow, 1) = m_stateBcs(bcIndex+1);
m_ghostRight(gRow, 2) = m_stateBcs(bcIndex+2);
m_ghostRight(gRow, 3) = m_stateBcs(bcIndex+3);
}
}

if (back0 == -1)
{
const auto bcIndex = m_graphBcs(gRow, 3);
if (bcIndex == -1) {
if (myX < m_wedgePosition){
m_ghostBack(gRow, 0) = m_state(uIndex+0);
m_ghostBack(gRow, 1) = m_state(uIndex+1);
m_ghostBack(gRow, 2) = m_state(uIndex+2);
m_ghostBack(gRow, 3) = m_state(uIndex+3);
}
else{
m_ghostBack(gRow, 0) = m_state(uIndex+0);
m_ghostBack(gRow, 1) = m_state(uIndex+1);
m_ghostBack(gRow, 2) = -m_state(uIndex+2);
m_ghostBack(gRow, 3) = m_state(uIndex+3);
}
}
else {
m_ghostBack(gRow, 0) = m_stateBcs(bcIndex+0);
m_ghostBack(gRow, 1) = m_stateBcs(bcIndex+1);
m_ghostBack(gRow, 2) = m_stateBcs(bcIndex+2);
m_ghostBack(gRow, 3) = m_stateBcs(bcIndex+3);
}
}

if (m_stencilSize >= 5){
throw std::runtime_error("Invalid case");
}

if (m_stencilSize >= 7){
throw std::runtime_error("Invalid case");
}
}

private:
void computeShockConditions()
{
constexpr scalar_type zero{0};
constexpr scalar_type one{1};
using namespace ::pressiodemoapps::ee;

m_preShockPrim[0] = m_gamma;
m_preShockPrim[1] = zero;
m_preShockPrim[1] = zero;
m_preShockPrim[3] = one;
computePostShockConditionsFromPreshockAtRest(m_postShockPrim,
m_preShockPrim,
-m_angle,
m_machShock,
m_gamma);

m_preShockState[0] = m_preShockPrim[0];
m_preShockState[1] = m_preShockPrim[0]*m_preShockPrim[1];
m_preShockState[2] = m_preShockPrim[0]*m_preShockPrim[2];
m_preShockState[3] = eulerEquationsComputeEnergyFromPrimitive2(m_gammaMinusOneInv,
m_preShockPrim);

m_postShockState[0] = m_postShockPrim[0];
m_postShockState[1] = m_postShockPrim[0]*m_postShockPrim[1];
m_postShockState[2] = m_postShockPrim[0]*m_postShockPrim[2];
m_postShockState[3] = eulerEquationsComputeEnergyFromPrimitive2(m_gammaMinusOneInv,
m_postShockPrim);
}

scalar_type distanceFromShock(scalar_type xIn, scalar_type yIn)
{
return (xIn - m_wedgePosition - m_shockSpeed*m_evaluationTime - m_shockSlope*yIn );
};

private:
const int m_stencilSize;
const state_t & m_state;
const scalar_type m_evaluationTime;
const scalar_type m_gamma;
const mesh_t & m_meshObj;
ghost_t & m_ghostLeft;
ghost_t & m_ghostFront;
ghost_t & m_ghostRight;
ghost_t & m_ghostBack;

std::array<scalar_type, 4> m_preShockPrim = {0,0,0,0};
std::array<scalar_type, 4> m_preShockState = {0,0,0,0};
std::array<scalar_type, 4> m_postShockPrim = {0,0,0,0};
std::array<scalar_type, 4> m_postShockState = {0,0,0,0};

const scalar_type one = static_cast<scalar_type>(1);
const scalar_type six = static_cast<scalar_type>(6);
const scalar_type m_gammaMinusOneInv = one/(m_gamma-one);
const scalar_type m_machShock{10};
const scalar_type m_angle = M_PI/6.;
const scalar_type m_wedgePosition = one/six;
const scalar_type m_shockSpeed = m_machShock/std::cos(m_angle);
const scalar_type m_shockSlope = std::tan(m_angle);
const scalar_type m_shockSlopeInv = one/m_shockSlope;
const scalar_type m_shockSlopeInv_sq = m_shockSlopeInv*m_shockSlopeInv;

// Schwarz coupling
const state_t & m_stateBcs;
const graph_t & m_graphBcs;
};





template<class state_t, class mesh_t, class ghost_t>
class DoubleMachReflection2dGhostFiller
{
Expand Down Expand Up @@ -327,7 +549,6 @@ class DoubleMachReflection2dGhostFiller
const scalar_type m_shockSlope = std::tan(m_angle);
const scalar_type m_shockSlopeInv = one/m_shockSlope;
const scalar_type m_shockSlopeInv_sq = m_shockSlopeInv*m_shockSlopeInv;

};

}}
Expand Down
Loading