Line |
Branch |
Exec |
Source |
1 |
|
|
// ______ ______ _ _ _____ ______ |
2 |
|
|
// | ____| ____| | (_)/ ____| | ____| |
3 |
|
|
// | |__ | |__ | | _| (___ ___| |__ |
4 |
|
|
// | __| | __| | | | |\___ \ / __| __| |
5 |
|
|
// | | | |____| |____| |____) | (__| |____ |
6 |
|
|
// |_| |______|______|_|_____/ \___|______| |
7 |
|
|
// Finite Elements for Life Sciences and Engineering |
8 |
|
|
// |
9 |
|
|
// License: LGL2.1 License |
10 |
|
|
// FELiScE default license: LICENSE in root folder |
11 |
|
|
// |
12 |
|
|
// Main authors: |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
// System includes |
16 |
|
|
|
17 |
|
|
// External includes |
18 |
|
|
|
19 |
|
|
// Project includes |
20 |
|
|
#include "Solver/linearProblemNSFracStepExplAdv.hpp" |
21 |
|
|
#include "Core/felisceTransient.hpp" |
22 |
|
|
#include "FiniteElement/elementVector.hpp" |
23 |
|
|
#include "FiniteElement/elementMatrix.hpp" |
24 |
|
|
|
25 |
|
|
namespace felisce { |
26 |
|
✗ |
LinearProblemNSFracStepExplAdv::LinearProblemNSFracStepExplAdv(): |
27 |
|
|
LinearProblem("Navier-Stokes Fractional Step: Explicit Advection"), |
28 |
|
✗ |
m_viscosity(0.), |
29 |
|
✗ |
m_density(0.), |
30 |
|
✗ |
m_explicitAdvection(0), |
31 |
|
✗ |
m_buildTeporaryMatrix(false) |
32 |
|
|
//m_bdf(NULL), |
33 |
|
|
//allocateSeqVec(false), |
34 |
|
|
//allocateSeqVecExt(false) |
35 |
|
|
{} |
36 |
|
|
|
37 |
|
✗ |
LinearProblemNSFracStepExplAdv::~LinearProblemNSFracStepExplAdv() { |
38 |
|
✗ |
if(m_buildTeporaryMatrix) |
39 |
|
✗ |
m_matrix.destroy(); |
40 |
|
|
} |
41 |
|
|
|
42 |
|
✗ |
void LinearProblemNSFracStepExplAdv::initialize(std::vector<GeometricMeshRegion::Pointer>& mesh, FelisceTransient::Pointer fstransient, MPI_Comm& comm, bool doUseSNES) { |
43 |
|
✗ |
LinearProblem::initialize(mesh,comm, doUseSNES); |
44 |
|
✗ |
m_fstransient = fstransient; |
45 |
|
✗ |
m_explicitAdvection = FelisceParam::instance().explicitAdvection; |
46 |
|
✗ |
if (!m_explicitAdvection) { |
47 |
|
✗ |
FEL_ERROR(" LinearProblemNSFracStepExplAdv should be only used when explicitAdvection>0: check your input file."); |
48 |
|
|
} |
49 |
|
✗ |
std::vector<PhysicalVariable> listVariable; |
50 |
|
✗ |
std::vector<std::size_t> listNumComp; |
51 |
|
|
|
52 |
|
|
// list the variable used in the formulation |
53 |
|
✗ |
listVariable.push_back(velocityAdvection); |
54 |
|
✗ |
listNumComp.push_back(this->dimension()); |
55 |
|
✗ |
listVariable.push_back(velocity); |
56 |
|
✗ |
listNumComp.push_back(this->dimension()); |
57 |
|
|
// note: all the variables present in the |
58 |
|
|
// global problem should be defined |
59 |
|
✗ |
listVariable.push_back(pressure); |
60 |
|
✗ |
listNumComp.push_back(1); |
61 |
|
|
|
62 |
|
|
//define unknown of the linear system. |
63 |
|
✗ |
m_listUnknown.push_back(velocityAdvection); |
64 |
|
|
|
65 |
|
✗ |
definePhysicalVariable(listVariable,listNumComp); |
66 |
|
|
|
67 |
|
✗ |
m_viscosity = FelisceParam::instance().viscosity; |
68 |
|
✗ |
m_density = FelisceParam::instance().density; |
69 |
|
|
|
70 |
|
✗ |
this->setNumberOfMatrix(2); |
71 |
|
✗ |
_RungeKutta = 1; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
void LinearProblemNSFracStepExplAdv::initPerElementType(ElementType eltType, FlagMatrixRHS flagMatrixRHS) { |
75 |
|
|
IGNORE_UNUSED_ELT_TYPE; |
76 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
77 |
|
|
|
78 |
|
✗ |
m_iVelocityAdvection = m_listVariable.getVariableIdList(velocityAdvection); |
79 |
|
✗ |
m_iVelocity = m_listVariable.getVariableIdList(velocity); |
80 |
|
|
|
81 |
|
|
// get FE for each variable |
82 |
|
✗ |
m_feVelAdv = m_listCurrentFiniteElement[m_iVelocityAdvection]; |
83 |
|
✗ |
m_feVel = m_listCurrentFiniteElement[m_iVelocity]; |
84 |
|
✗ |
m_velocityAdvection = &m_listVariable[m_iVelocityAdvection]; |
85 |
|
✗ |
m_velocity = &m_listVariable[m_iVelocity]; |
86 |
|
|
|
87 |
|
|
// initialize element fields for different contributions |
88 |
|
✗ |
m_elemFieldAdv.initialize(DOF_FIELD,*m_feVelAdv,this->dimension()); |
89 |
|
✗ |
m_elemFieldExt.initialize(DOF_FIELD,*m_feVel,this->dimension()); |
90 |
|
|
|
91 |
|
|
} |
92 |
|
|
|
93 |
|
✗ |
void LinearProblemNSFracStepExplAdv::computeElementArray(const std::vector<Point*>& elemPoint, const std::vector<felInt>& elemIdPoint, felInt& iel, FlagMatrixRHS flagMatrixRHS) { |
94 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
95 |
|
|
IGNORE_UNUSED_ELEM_ID_POINT; |
96 |
|
|
|
97 |
|
✗ |
m_feVel->updateFirstDeriv(0, elemPoint); |
98 |
|
✗ |
m_feVelAdv->updateFirstDeriv(0, elemPoint); |
99 |
|
|
|
100 |
|
✗ |
double dt = m_fstransient->timeStep; |
101 |
|
✗ |
if ( m_fstransient->iteration == 0) { |
102 |
|
|
|
103 |
|
|
//================================ |
104 |
|
|
// matrix[0] |
105 |
|
|
//================================ |
106 |
|
|
// mass matrix |
107 |
|
✗ |
m_elementMat[0]->phi_i_phi_j(m_density,*m_feVelAdv,0,0,this->dimension()); |
108 |
|
|
|
109 |
|
|
} else { |
110 |
|
|
|
111 |
|
✗ |
m_elemFieldExt.setValue(externalVec(0), *m_feVel, iel, m_iVelocity, m_externalAO[0], *m_externalDof[0]); |
112 |
|
|
|
113 |
|
|
//================================ |
114 |
|
|
// matrix[1] |
115 |
|
|
//================================ |
116 |
|
|
// advection matrix dt*rho*(U.grad(phi),phi) |
117 |
|
✗ |
m_elementMat[1]->u_grad_phi_j_phi_i(m_density,m_elemFieldExt,*m_feVel,0,0,this->dimension()); |
118 |
|
|
// + stabilization matrix |
119 |
|
|
// TODO |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
//================================ |
123 |
|
|
// RHS |
124 |
|
|
//================================ |
125 |
|
|
|
126 |
|
|
// to assemble advection explicitly on the RHS |
127 |
|
|
// RK-1 |
128 |
|
✗ |
if (_RungeKutta==1) { |
129 |
|
|
// -> assemble advection explicitly on the RHS |
130 |
|
✗ |
assert(!m_elementVector.empty()); |
131 |
|
✗ |
m_elementVector[0]->u_grad_u_phi_i(-1*m_density*dt, *m_feVel, m_elemFieldExt,0,this->dimension()); |
132 |
|
|
// -> rho(udiff^n,phi) |
133 |
|
✗ |
m_elementVector[0]->source(m_density,*m_feVel,m_elemFieldExt,0,this->dimension()); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
// for boundary terms (weak boundary conditions at inflow) |
142 |
|
✗ |
void LinearProblemNSFracStepExplAdv::initPerElementTypeBoundaryCondition(ElementType& eltType, FlagMatrixRHS flagMatrixRHS) { |
143 |
|
|
IGNORE_UNUSED_ELT_TYPE; |
144 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
145 |
|
|
/* |
146 |
|
|
// is this function used?? |
147 |
|
|
m_iVelocity = m_listVariable.getVariableIdList(velocity); |
148 |
|
|
CurvilinearFiniteElement* bdFeVel = m_listCurvilinearFiniteElement[m_iVelocity]; |
149 |
|
|
m_elemFieldDiffBD.initialize(DOF_FIELD, *bdFeVel, this->dimension()); |
150 |
|
|
*/ |
151 |
|
|
} |
152 |
|
|
|
153 |
|
✗ |
void LinearProblemNSFracStepExplAdv::computeElementArrayBoundaryCondition(const std::vector<Point*>& elemPoint, const std::vector<felInt>& elemIdPoint, felInt& iel, FlagMatrixRHS flagMatrixRHS) { |
154 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
155 |
|
|
IGNORE_UNUSED_ELEM_ID_POINT; |
156 |
|
✗ |
double dt = m_fstransient->timeStep; |
157 |
|
✗ |
m_iVelocity = m_listVariable.getVariableIdList(velocity); |
158 |
|
✗ |
CurvilinearFiniteElement* bdFeVel = m_listCurvilinearFiniteElement[m_iVelocity]; |
159 |
|
✗ |
bdFeVel->updateMeasNormal(0, elemPoint); |
160 |
|
|
|
161 |
|
✗ |
m_iVelocityAdvection = m_listVariable.getVariableIdList(velocityAdvection); |
162 |
|
✗ |
CurvilinearFiniteElement* bdFeVelAdv = m_listCurvilinearFiniteElement[m_iVelocityAdvection]; |
163 |
|
✗ |
bdFeVelAdv->updateMeasNormal(0, elemPoint); |
164 |
|
|
|
165 |
|
✗ |
m_elemFieldExt.setValue(externalVec(0),*bdFeVel,iel,m_iVelocity,m_externalAO[0],*m_externalDof[0]); |
166 |
|
|
//================================ |
167 |
|
|
// bd. matrix[0] |
168 |
|
|
//================================ |
169 |
|
✗ |
if (_RungeKutta==1) { |
170 |
|
✗ |
m_elementMatBD[0]->abs_u_dot_n_phi_i_phi_j(dt*m_density,m_elemFieldExt,*bdFeVelAdv,0,0,this->dimension()); |
171 |
|
✗ |
} else if (_RungeKutta==2) { |
172 |
|
✗ |
m_elementMatBD[1]->abs_u_dot_n_phi_i_phi_j(dt*m_density,m_elemFieldExt,*bdFeVelAdv,0,0,this->dimension()); |
173 |
|
|
} else { |
174 |
|
✗ |
FEL_ERROR("This order of Runge-Kutta has not been implemented yet"); |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
//================================ |
178 |
|
|
// bd. RHS |
179 |
|
|
//================================ |
180 |
|
|
// rho(udiff^n,phi) |
181 |
|
✗ |
assert(!m_elementVector.empty()); |
182 |
|
✗ |
m_elementVectorBD[0]->abs_u_dot_n_u_dot_phi_i(dt*1.,m_elemFieldExt,*bdFeVel,0,this->dimension()); |
183 |
|
|
|
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
✗ |
void LinearProblemNSFracStepExplAdv::copyMatrixRHS() { |
189 |
|
✗ |
m_matrix.duplicateFrom(matrix(0),MAT_COPY_VALUES); |
190 |
|
✗ |
m_matrix.assembly(MAT_FINAL_ASSEMBLY); |
191 |
|
✗ |
m_buildTeporaryMatrix = true; |
192 |
|
|
} |
193 |
|
|
|
194 |
|
✗ |
void LinearProblemNSFracStepExplAdv::addMatrixRHS() { |
195 |
|
✗ |
matrix(0).axpy(1,m_matrix,SAME_NONZERO_PATTERN); |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
|