Skip to content

Commit eb6c00e

Browse files
committed
Add a check for Lagrange polynomials order
And replace x, y, z by a pos vector for ibvFunction
1 parent dbaf3dc commit eb6c00e

File tree

6 files changed

+34
-36
lines changed

6 files changed

+34
-36
lines changed

srcs/mesh/Mesh.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ static void addElement(Entity& entity, int elementTag, int eleTypeHD,
389389
* \param currentOffset Offset in u unknown vector.
390390
* \param intScheme Integration scheme for the basis functions evaluation.
391391
* \param basisFuncType The type of basis function you will use.
392+
* \return true if then entity was added flawlessly, false otherwise.
392393
*/
393394
static bool addEntity(Mesh& mesh, int entityTag, unsigned int& currentOffset,
394395
const std::string& intScheme, const std::string& basisFuncType)
@@ -424,6 +425,14 @@ static bool addEntity(Mesh& mesh, int entityTag, unsigned int& currentOffset,
424425
unsigned int numNodes = mesh.elementProperties[eleTypeHD].numNodes;
425426
unsigned int order = mesh.elementProperties[eleTypeHD].order;
426427

428+
if(intScheme == "Lagrange" && order > 7)
429+
{
430+
std::cerr << "Lagrange polynomials are not stable with an order superior to 7"
431+
<< std::endl;
432+
433+
return false;
434+
}
435+
427436
//Get the elements barycenters (for normal computation)
428437
std::vector<double> baryCenters;
429438
gmsh::model::mesh::getBarycenters(eleTypeHD, entityTag, false, true, baryCenters);

srcs/params/Params.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ static bool handleBoundaryCondition(std::ifstream& paramFile, SolverParams& solv
115115
return false;
116116
}
117117

118-
std::cout << "Inital Condition present and " << nBC
119-
<< " boundary conditions present in file " << fileName << std::endl;
118+
std::cout << "Initial condition present and " << nBC
119+
<< " boundary conditions present in "<< std::endl
120+
<< "file " << fileName << std::endl;
120121

121122
return true;
122123
}

srcs/params/ibvFunction.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,44 @@
22
#include <cassert>
33
#include "ibvFunction.hpp"
44

5-
double sinus(double x, double y, double z, double u,
5+
double sinus(const std::vector<double>& pos, double u,
66
double t, const std::vector<double>& coeffs)
77
{
88
assert(coeffs.size() == 3);
99

1010
return coeffs[0]*sin(2*M_PI*coeffs[1]*t + coeffs[2]);
1111
}
1212

13-
double gaussian(double x, double y, double z, double u,
13+
double gaussian(const std::vector<double>& pos, double u,
1414
double t, const std::vector<double>& coeffs)
1515
{
1616
assert(coeffs.size() == 3);
1717

1818
return coeffs[0]*exp(-(t-coeffs[1])*(t-coeffs[1])/(2*coeffs[2]));
1919
}
2020

21-
double constant(double x, double y, double z, double u,
21+
double constant(const std::vector<double>& pos, double u,
2222
double t, const std::vector<double>& coeffs)
2323
{
2424
assert(coeffs.size() == 1);
2525

2626
return coeffs[0];
2727
}
2828

29-
double constantNeumann(double x, double y, double z, double u,
29+
double constantNeumann(const std::vector<double>& pos, double u,
3030
double t, const std::vector<double>& coeffs)
3131
{
3232
return u;
3333
}
3434

35-
double gaussian2D(double x, double y, double z, double u,
35+
double gaussian2D(const std::vector<double>& pos, double u,
3636
double t, const std::vector<double>& coeffs)
3737
{
3838
assert(coeffs.size() == 5);
39+
assert(pos.size() == 3);
3940

40-
double X = (x-coeffs[1])*(x-coeffs[1])/(2*coeffs[2]);
41-
double Y = (y-coeffs[3])*(y-coeffs[3])/(2*coeffs[4]);
41+
double X = (pos[0]-coeffs[1])*(pos[0]-coeffs[1])/(2*coeffs[2]);
42+
double Y = (pos[1]-coeffs[3])*(pos[1]-coeffs[3])/(2*coeffs[4]);
4243

4344
return coeffs[0]*exp(-(X+Y));
4445
}

srcs/params/ibvFunction.hpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,68 @@
1212
struct ibc
1313
{
1414
std::vector<double> coefficients; /**< Coefficient for the mathematical function */
15-
std::function<double(double x, double y, double z,
15+
std::function<double(const std::vector<double>& pos,
1616
double u, double t,
1717
std::vector<double> coeffs)> ibcFunc; /**< Pointer to the mathematical function */
1818
};
1919

2020

2121
/**
2222
* \brief Compute a simple A*sin(2*pi*nu*t + phi)
23-
* \param x x coordinate.
24-
* \param y y coordinate.
25-
* \param z z coordinate.
23+
* \param pos Node position.
2624
* \param u The current solution.
2725
* \param t Current time.
2826
* \param coeffs Coefficient for the sinus. coeffs[0] = A, coeffs[1] = nu
2927
* coeffs[2] = phi.
3028
* \return Value of the function at (x, y , z, t).
3129
*/
32-
double sinus(double x, double y, double z, double u,
30+
double sinus(const std::vector<double>& pos, double u,
3331
double t, const std::vector<double>& coeffs);
3432

3533
/**
3634
* \brief Compute a simple A*exp(-(t-t_peak)^2/(2*var))
37-
* \param x x coordinate.
38-
* \param y y coordinate.
39-
* \param z z coordinate.
35+
* \param pos Node position.
4036
* \param u The current solution.
4137
* \param t Current time.
4238
* \param coeffs Coefficient for the gaussian. coeffs[0] = A, coeffs[1] = t_peak
4339
* coeffs[2] = var.
4440
* \return Value of the function at (x, y , z, t).
4541
*/
46-
double gaussian(double x, double y, double z, double u,
42+
double gaussian(const std::vector<double>& pos, double u,
4743
double t, const std::vector<double>& coeffs);
4844

4945
/**
5046
* \brief Compute a constant
51-
* \param x x coordinate.
52-
* \param y y coordinate.
53-
* \param z z coordinate.
47+
* \param pos Node position.
5448
* \param u The current solution.
5549
* \param t Current time.
5650
* \param coeffs Coefficient for the constant. coeffs[0] = constant.
5751
* \return Value of the function at (x, y , z, t).
5852
*/
59-
double constant(double x, double y, double z, double u,
53+
double constant(const std::vector<double>& pos, double u,
6054
double t, const std::vector<double>& coeffs);
6155

6256
/**
6357
* \brief Compute a Von Neumann constant value
64-
* \param x x coordinate.
65-
* \param y y coordinate.
66-
* \param z z coordinate.
58+
* \param pos Node position.
6759
* \param u The current solution.
6860
* \param t Current time.
6961
* \param coeffs Coefficient (not used here).
7062
* \return u.
7163
*/
72-
double constantNeumann(double x, double y, double z, double u,
64+
double constantNeumann(const std::vector<double>& pos, double u,
7365
double t, const std::vector<double>& coeffs);
7466

7567
/**
7668
* \brief Compute a simple A*exp(-(x-x0)^2/(2*var_y) -(y-y0)^2/(2*var_y))
77-
* \param x x coordinate.
78-
* \param y y coordinate.
79-
* \param z z coordinate.
69+
* \param pos Node position.
8070
* \param u The current solution.
8171
* \param t Current time.
8272
* \param coeffs Coefficient for the gaussian. coeffs[0] = A, coeffs[1] = x_0
8373
* coeffs[2] = var_x, coeffs[3]=y_0, coeffs[4]=var_y.
8474
* \return Value of the function at (x, y , z, t).
8575
*/
86-
double gaussian2D(double x, double y, double z, double u,
76+
double gaussian2D(const std::vector<double>& pos, double u,
8777
double t, const std::vector<double>& coeffs);
8878

8979
#endif // bcFunction_hpp_included

srcs/solver/buildFlux.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ void buildFlux(const Mesh& mesh, Eigen::VectorXd& I, const Eigen::VectorXd& u,
8383
ibc boundary = boundaries.at(edge.bcName);
8484

8585
// node "in front" (at boundary condition)
86-
uAtBC = boundary.ibcFunc(edge.nodeCoordinate[j][0],
87-
edge.nodeCoordinate[j][1],
88-
0.0, u[indexJ], t, boundary.coefficients);
86+
uAtBC = boundary.ibcFunc(edge.nodeCoordinate[j],
87+
u[indexJ], t, boundary.coefficients);
8988

9089
// physical flux "in front" (at boundary condition)
9190
flux(fxAtBC, fyAtBC, uAtBC, fluxCoeffs);

srcs/solver/timeInteg.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ bool timeInteg(const Mesh& mesh, const SolverParams& solverParams,
145145
{
146146
for(unsigned int n = 0 ; n < element.nodeTags.size() ; ++n)
147147
{
148-
double x = element.nodesCoord[n][0];
149-
double y = element.nodesCoord[n][1];
150148
u(element.offsetInU + n) =
151-
solverParams.initCondition.ibcFunc(x, y, 0, 0, 0,
149+
solverParams.initCondition.ibcFunc(element.nodesCoord[n], 0, 0,
152150
solverParams.initCondition.coefficients);
153151
}
154152
}

0 commit comments

Comments
 (0)