Skip to content

Commit da794f4

Browse files
committed
create matrixview
1 parent 161be5d commit da794f4

File tree

12 files changed

+102
-134
lines changed

12 files changed

+102
-134
lines changed

SU2_CFD/include/drivers/CDriverBase.hpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,15 @@ class CDriverBase {
452452
return CPyWrapperMatrixView(solver->GetNodes()->GetSolution(), "Solution of " + solver->GetSolverName(), false);
453453
}
454454

455+
/*!
456+
* \brief Get a read/write view of the usrr defined source on all mesh nodes of a solver.
457+
*/
458+
inline CPyWrapperMatrixView UserDefinedSource(unsigned short iSolver) {
459+
auto* solver = GetSolverAndCheckMarker(iSolver);
460+
return CPyWrapperMatrixView(
461+
solver->GetNodes()->GetUserDefinedSource(), "User Defined Source of " + solver->GetSolverName(), false);
462+
}
463+
455464
/*!
456465
* \brief Get a read/write view of the current solution on the mesh nodes of a marker.
457466
*/
@@ -759,24 +768,6 @@ class CDriverBase {
759768
}
760769
}
761770

762-
/*!
763-
* \brief Set the array of variables for the source in the point
764-
* \param[in] iSolver - Solver index.
765-
* \param[in] iPoint - Point index.
766-
* \param[in] values - Vector values of the source term.
767-
*/
768-
void SetPointCustomSource(unsigned short iSolver, unsigned long iPoint, std::vector<passivedouble> values) {
769-
auto* solver = solver_container[selected_zone][INST_0][MESH_0][iSolver];
770-
solver->SetCustomPointSource(iPoint, values);
771-
}
772-
773-
/*!
774-
* \brief Get the solution vector in a point for a specific solver
775-
* \param[in] iSolver - Solver index.
776-
* \param[in] iPoint - Point index.
777-
* \param[out] solutionvector - Vector values of the solution.
778-
*/
779-
780771
/// \}
781772

782773
protected:

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ class CFVMFlowSolverBase : public CSolver {
170170
vector<vector<su2double> > Inlet_Ptotal; /*!< \brief Value of the Total P. */
171171
vector<vector<su2double> > Inlet_Ttotal; /*!< \brief Value of the Total T. */
172172
vector<su2activematrix> Inlet_FlowDir; /*!< \brief Value of the Flow Direction. */
173-
su2activematrix PointSource; /*!< \brief Value of the Flow Direction. */
174173
vector<vector<su2double> > HeatFlux; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
175174
vector<vector<su2double> > HeatFluxTarget; /*!< \brief Heat transfer coefficient for each boundary and vertex. */
176175
vector<su2activematrix> CharacPrimVar; /*!< \brief Value of the characteristic variables at each boundary. */
@@ -339,7 +338,7 @@ inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_contain
339338

340339
/*--- Compute the residual for this control volume and subtract. ---*/
341340
for (iVar = 0; iVar < nVar; iVar++) {
342-
LinSysRes(iPoint, iVar) += PointSource(iPoint, iVar) * Volume;
341+
LinSysRes(iPoint, iVar) += nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
343342
}
344343
}
345344
END_SU2_OMP_FOR
@@ -2182,17 +2181,7 @@ inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_contain
21822181
return Inlet_FlowDir[val_marker][val_vertex][val_dim];
21832182
}
21842183

2185-
/*!
2186-
* \brief A component of the unit vector representing the flow direction at an inlet boundary.
2187-
* \param[in] val_marker - Surface marker where the flow direction is evaluated
2188-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is evaluated
2189-
* \param[in] val_dim - The component of the flow direction unit vector to be evaluated
2190-
* \return Component of a unit vector representing the flow direction.
2191-
*/
2192-
inline su2double GetCustomPointSource(unsigned long val_point,
2193-
unsigned short val_var) const final {
2194-
return PointSource[val_point][val_var];
2195-
}
2184+
21962185

21972186
/*!
21982187
* \brief Set the value of the total temperature at an inlet boundary.
@@ -2247,26 +2236,7 @@ inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_contain
22472236
Inlet_FlowDir[val_marker][val_vertex][val_dim] = val_flowdir;
22482237
}
22492238

2250-
/*!
2251-
* \brief Set a component of the unit vector representing the flow direction at an inlet boundary.
2252-
* \param[in] val_marker - Surface marker where the flow direction is set.
2253-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is set.
2254-
* \param[in] val_dim - The component of the flow direction unit vector to be set
2255-
* \param[in] val_flowdir - Component of a unit vector representing the flow direction.
2256-
*/
2257-
inline void SetCustomPointSource(unsigned long val_point,
2258-
vector<passivedouble> val_source) final {
2259-
/*--- Since this call can be accessed indirectly using python, do some error
2260-
* checking to prevent segmentation faults ---*/
2261-
if (val_point > nPointDomain)
2262-
SU2_MPI::Error("Out-of-bounds point index used on solver.", CURRENT_FUNCTION);
2263-
else if (val_source.size() > nVar)
2264-
SU2_MPI::Error("Out-of-bounds source size used on solver.", CURRENT_FUNCTION);
2265-
else {
2266-
for (size_t iVar=0; iVar < val_source.size(); iVar++)
2267-
PointSource[val_point][iVar] = val_source[iVar];
2268-
}
2269-
}
2239+
22702240

22712241
/*!
22722242
* \brief Update the multi-grid structure for the customized boundary conditions.

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
123123
/*--- Store the value of the Flow direction at the inlet BC ---*/
124124

125125
AllocVectorOfMatrices(nVertex, nDim, Inlet_FlowDir);
126-
PointSource.resize(nPointDomain, nVar) = su2double(0.0);
127126

128127
/*--- Force definition and coefficient arrays for all of the markers ---*/
129128

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,15 +2852,7 @@ class CSolver {
28522852
inline virtual su2double GetInletFlowDir(unsigned short val_marker,
28532853
unsigned long val_vertex,
28542854
unsigned short val_dim) const { return 0; }
2855-
/*!
2856-
* \brief A virtual member
2857-
* \param[in] val_marker - Surface marker where the flow direction is evaluated
2858-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is evaluated
2859-
* \param[in] val_dim - The component of the flow direction unit vector to be evaluated
2860-
* \return Component of a unit vector representing the flow direction.
2861-
*/
2862-
inline virtual su2double GetCustomPointSource(unsigned long val_point,
2863-
unsigned short val_var) const { return 0; }
2855+
28642856
/*!
28652857
* \brief A virtual member
28662858
* \param[in] val_marker - Surface marker where the total temperature is set.
@@ -2892,15 +2884,7 @@ class CSolver {
28922884
unsigned long val_vertex,
28932885
unsigned short val_dim,
28942886
su2double val_flowdir) { }
2895-
/*!
2896-
* \brief A virtual member
2897-
* \param[in] val_marker - Surface marker where the flow direction is set.
2898-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is set.
2899-
* \param[in] val_dim - The component of the flow direction unit vector to be set
2900-
* \param[in] val_flowdir - Component of a unit vector representing the flow direction.
2901-
*/
2902-
inline virtual void SetCustomPointSource(unsigned long val_Point,
2903-
vector<passivedouble> val_source) { }
2887+
29042888
/*!
29052889
* \brief Updates the components of the farfield velocity vector.
29062890
*/

SU2_CFD/include/solvers/CSpeciesSolver.hpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
4040
protected:
4141
unsigned short Inlet_Position; /*!< \brief Column index for scalar variables in inlet files. */
4242
vector<su2activematrix> Inlet_SpeciesVars; /*!< \brief Species variables at inlet profiles. */
43-
su2activematrix SpeciesPointSource; /*!< \brief User defined source term. */
4443

4544
public:
4645
/*!
@@ -195,38 +194,4 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
195194
geometry, solver_container, conv_numerics, visc_numerics, config);
196195
}
197196

198-
/*!
199-
* \brief Set a component of the unit vector representing the flow direction at an inlet boundary.
200-
* \param[in] val_marker - Surface marker where the flow direction is set.
201-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is set.
202-
* \param[in] val_dim - The component of the flow direction unit vector to be set
203-
* \param[in] val_flowdir - Component of a unit vector representing the flow direction.
204-
*/
205-
inline void SetCustomPointSource(unsigned long val_point,
206-
vector<passivedouble> val_source) final {
207-
/*--- Since this call can be accessed indirectly using python, do some error
208-
* checking to prevent segmentation faults ---*/
209-
if (val_point > nPointDomain)
210-
SU2_MPI::Error("Out-of-bounds point index used on solver.", CURRENT_FUNCTION);
211-
else if (val_source.size() > nVar)
212-
SU2_MPI::Error("Out-of-bounds source size used on solver.", CURRENT_FUNCTION);
213-
else {
214-
for (size_t iVar=0; iVar < val_source.size(); iVar++) {
215-
SpeciesPointSource[val_point][iVar] = val_source[iVar];
216-
}
217-
}
218-
}
219-
220-
/*!
221-
* \brief A component of the unit vector representing the flow direction at an inlet boundary.
222-
* \param[in] val_marker - Surface marker where the flow direction is evaluated
223-
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is evaluated
224-
* \param[in] val_dim - The component of the flow direction unit vector to be evaluated
225-
* \return Component of a unit vector representing the flow direction.
226-
*/
227-
inline su2double GetCustomPointSource(unsigned long val_point,
228-
unsigned short val_var) const final {
229-
return SpeciesPointSource[val_point][val_var];
230-
}
231-
232197
};

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CVariable {
5555
MatrixType Solution; /*!< \brief Solution of the problem. */
5656
MatrixType Solution_Old; /*!< \brief Old solution of the problem R-K. */
5757

58+
MatrixType UserDefinedSource; /*!< \brief User Defined Source of the problem. */
59+
5860
MatrixType External; /*!< \brief External (outer) contribution in discrete adjoint multizone problems. */
5961

6062
su2vector<bool> Non_Physical; /*!< \brief Non-physical points in the solution (force first order). */
@@ -289,6 +291,11 @@ class CVariable {
289291
*/
290292
void Set_Solution_time_n1();
291293

294+
/*!
295+
* \brief Set the variable solution at time n-1.
296+
*/
297+
void Set_UserDefinedSource();
298+
292299
/*!
293300
* \brief Set the variable solution at time n.
294301
* \param[in] iPoint - Point index.
@@ -306,6 +313,15 @@ class CVariable {
306313
Solution_time_n1(iPoint,iVar) = val_sol[iVar];
307314
}
308315

316+
/*!
317+
* \brief Set the variable solution at time n-1.
318+
* \param[in] iPoint - Point index.
319+
*/
320+
inline void Set_UserDefinedSource(unsigned long iPoint, const su2double* val_sol) {
321+
for (unsigned long iVar = 0; iVar < nVar; iVar++)
322+
UserDefinedSource(iPoint,iVar) = val_sol[iVar];
323+
}
324+
309325
/*!
310326
* \brief Set the variable solution at time n.
311327
* \param[in] iPoint - Point index.
@@ -322,6 +338,14 @@ class CVariable {
322338
Solution_time_n1(iPoint,iVar) = val_sol;
323339
}
324340

341+
/*!
342+
* \brief Set the variable solution at time n-1.
343+
* \param[in] iPoint - Point index.
344+
*/
345+
inline void Set_UserDefinedSource(unsigned long iPoint, unsigned long iVar, su2double val_sol) {
346+
UserDefinedSource(iPoint,iVar) = val_sol;
347+
}
348+
325349
/*!
326350
* \brief Virtual Member. Specify a vector to set the velocity components of the solution.
327351
* Multiplied by density for compressible cases.
@@ -485,6 +509,20 @@ class CVariable {
485509
*/
486510
inline su2double *GetSolution(unsigned long iPoint) { return Solution[iPoint]; }
487511

512+
/*!
513+
* \brief Get the entire solution of the problem.
514+
* \return Reference to the solution matrix.
515+
*/
516+
inline const MatrixType& GetUserDefinedSource() const { return UserDefinedSource; }
517+
inline MatrixType& GetUserDefinedSource() { return UserDefinedSource; }
518+
519+
/*!
520+
* \brief Get the solution of the problem.
521+
* \param[in] iPoint - Point index.
522+
* \return Pointer to the solution vector.
523+
*/
524+
inline su2double *GetUserDefinedSource(unsigned long iPoint) { return UserDefinedSource[iPoint]; }
525+
488526
/*!
489527
* \brief Get the old solution of the problem (Runge-Kutta method)
490528
* \param[in] iPoint - Point index.
@@ -2168,6 +2206,11 @@ class CVariable {
21682206
*/
21692207
void RegisterSolution_time_n1();
21702208

2209+
/*!
2210+
* \brief Register the variables in the user defined source array as input/output variable.
2211+
*/
2212+
void RegisterUserDefinedSource();
2213+
21712214
/*!
21722215
* \brief Set the adjoint values of the solution.
21732216
* \param[in] adj_sol - The adjoint values of the solution.

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ void CIncEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_cont
18111811
}
18121812
}
18131813

1814-
//Custom_Source_Residual(geometry, solver_container, numerics_container, config, iMesh);
1814+
Custom_Source_Residual(geometry, solver_container, numerics_container, config, iMesh);
18151815

18161816
}
18171817

SU2_CFD/src/solvers/CSpeciesSolver.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ void CSpeciesSolver::Initialize(CGeometry* geometry, CConfig* config, unsigned s
110110

111111
nDim = geometry->GetnDim();
112112

113-
SpeciesPointSource.resize(nPointDomain,nVar) = su2double(0.0);
114-
115-
116113
if (iMesh == MESH_0 || config->GetMGCycle() == FULLMG_CYCLE) {
117114

118115
/*--- Define some auxiliary vector related with the residual ---*/
@@ -587,10 +584,9 @@ void CSpeciesSolver::Custom_Source_Residual(CGeometry *geometry, CSolver **solve
587584

588585
/*--- Get control volume size. ---*/
589586
su2double Volume = geometry->nodes->GetVolume(iPoint);
590-
591587
/*--- Compute the residual for this control volume and subtract. ---*/
592588
for (iVar = 0; iVar < nVar; iVar++) {
593-
LinSysRes[iPoint*nVar+iVar] -= SpeciesPointSource[iPoint][iVar] * Volume;
589+
LinSysRes(iPoint,iVar) -= nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
594590
}
595591
}
596592
END_SU2_OMP_FOR

SU2_CFD/src/variables/CVariable.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ CVariable::CVariable(unsigned long npoint, unsigned long ndim, unsigned long nva
6464
if (config->GetTime_Marching() != TIME_MARCHING::STEADY)
6565
Solution_time_n1.resize(nPoint,nVar) = su2double(0.0);
6666

67+
/*--- User defined source terms ---*/
68+
UserDefinedSource.resize(nPoint,nVar) = su2double(0.0);
69+
70+
6771
if (config->GetDiscrete_Adjoint()) {
6872
if (adjoint && config->GetMultizone_Problem())
6973
External.resize(nPoint,nVar) = su2double(0.0);
@@ -98,6 +102,11 @@ void CVariable::Set_Solution_time_n1() {
98102
parallelCopy(Solution_time_n.size(), Solution_time_n.data(), Solution_time_n1.data());
99103
}
100104

105+
void CVariable::Set_UserDefinedSource() {
106+
assert(UserDefinedSource.size() == UserDefinedSource.size());
107+
parallelCopy(UserDefinedSource.size(), UserDefinedSource.data(), UserDefinedSource.data());
108+
}
109+
101110
void CVariable::Set_BGSSolution_k() {
102111
assert(Solution_BGS_k.size() == Solution.size());
103112
parallelCopy(Solution.size(), Solution.data(), Solution_BGS_k.data());
@@ -127,3 +136,6 @@ void CVariable::RegisterSolution_time_n() {
127136
void CVariable::RegisterSolution_time_n1() {
128137
RegisterContainer(true, Solution_time_n1);
129138
}
139+
void CVariable::RegisterUserDefinedSource() {
140+
RegisterContainer(true, UserDefinedSource);
141+
}

TestCases/py_wrapper/custom_source_buoyancy/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def main():
108108
for iDim in range(nDim):
109109
custom_source_vector[iDim+1] = -(DensityInc_i - DensityInc_0) * Body_Force_Vector[iDim] / Force_Ref
110110

111-
driver.SetPointCustomSource(iSOLVER, i_node, custom_source_vector)
111+
#driver.SetPointCustomSource(iSOLVER, i_node, custom_source_vector)
112112

113113
print(" *** inner iteration:",inner_iter)
114114
driver.Preprocess(inner_iter)

0 commit comments

Comments
 (0)