Skip to content

Commit 423640b

Browse files
ImperatorS79tgregov
authored andcommitted
Fix weak vs strong form (youpiee) (#30)
Commits: * Documentation Fixes * Add a check for normals ofedge and edgeInFront * (Maybe) fix bad behaviour of the solution N.B.: I still need to check the details
1 parent ff7e4fe commit 423640b

File tree

8 files changed

+120
-82
lines changed

8 files changed

+120
-82
lines changed

Params/param.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Gauss4
1+
Gauss3
22
Lagrange
33
RK1
44
strong
5-
3
5+
300
66
0.01

srcs/Mesh2D.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void loadElementProperties(std::map<int, ElementProperty>& meshElementPro
9797
* \param element The parent element.
9898
* \param nodesTagsEdge Node tags per edge of the element.
9999
* \param determinant1D Determinant associated with the edge of the element.
100+
* \param nNodesElement Number of nodes of the parent element.
100101
*/
101102
static void addEdge(Element2D& element, std::vector<int> nodesTagsEdge,
102103
std::vector<double> determinant1D, unsigned int nNodesElement)
@@ -122,10 +123,9 @@ static void addEdge(Element2D& element, std::vector<int> nodesTagsEdge,
122123

123124

124125
/**
125-
* \brief Compute the outward normal of an edge
126-
* \param element the parent element
127-
* \param nodesTagsEdge Node tags per edge of the element
128-
* \param baryCenter Barycenter of the parent element
126+
* \brief Compute the outward normal of an edge.
127+
* \param edge The edge of which the normal is computed.
128+
* \param baryCenter Barycenter of the parent element.
129129
*/
130130
static void computeEdgeNormalCoord(Edge& edge,
131131
const std::vector<double>& baryCenter)
@@ -170,10 +170,10 @@ static void computeEdgeNormalCoord(Edge& edge,
170170
}
171171

172172
/**
173-
* \brief Compute the outward normal of an edge
173+
* \brief Find the second position of the edge in the entity.
174174
* \param entity The parent entity.
175175
* \param currentEdge The edge of which you want to find the neighbor.
176-
* \param edgePos Index of the edge in his element.
176+
* \param edgePos Index of the edge in its element.
177177
*/
178178
static void findInFrontEdge(Entity2D& entity, Edge& currentEdge, unsigned int edgePos)
179179
{
@@ -213,6 +213,11 @@ static void findInFrontEdge(Entity2D& entity, Edge& currentEdge, unsigned int ed
213213
}
214214
}
215215

216+
/**
217+
* \brief Check if an edge lies on a boundary (and which one)
218+
* \param nodesTagBoundaries Map which stores the tags of the nodes belonging to a certain boundary.
219+
* \param edge The edge which we check if it is a boundary.
220+
*/
216221
static bool IsBounbdary(const std::map<std::string, std::vector<int>>& nodesTagBoundaries, Edge& edge)
217222
{
218223
for(std::pair<std::string, std::vector<int>> nodeTagBoundary : nodesTagBoundaries)
@@ -247,8 +252,9 @@ static bool IsBounbdary(const std::map<std::string, std::vector<int>>& nodesTagB
247252
* \param nGP1D Number of Gauss point for integration.
248253
* \param offsetInU Offset of the element in the u unknown vector.
249254
* \param nodesTagsPerEdge Node tags of the element, per edge.
250-
* \param intScheme Integration scheme for the basis functions evaluation.
251-
* \param basisFuncType The type of basis function you will use.
255+
* \param elementBarycenter Element barycenter coordinate.
256+
* \param nodesTagBoundaries Map which stores the tags of the nodes belonging to a certain boundary.
257+
* \param element2DProperty Structure containing informations about a certain element type.
252258
*/
253259
static void addElement(Entity2D& entity, int elementTag, int eleType2D,
254260
int eleType1D, std::vector<double> jacobians2D,
@@ -257,9 +263,8 @@ static void addElement(Entity2D& entity, int elementTag, int eleType2D,
257263
unsigned int nGP1D, unsigned int offsetInU,
258264
const std::vector<int>& nodesTagsPerEdge,
259265
const std::vector<double>& elementBarycenter,
260-
const std::string& intScheme,
261-
const std::string& basisFuncType,
262-
const std::map<std::string, std::vector<int>>& nodesTagBoundary)
266+
const std::map<std::string, std::vector<int>>& nodesTagBoundaries,
267+
const ElementProperty& element2DProperty)
263268
{
264269
Element2D element;
265270
element.elementTag = elementTag;
@@ -270,7 +275,6 @@ static void addElement(Entity2D& entity, int elementTag, int eleType2D,
270275

271276
element.determinant2D = std::move(determinants2D);
272277
element.jacobian2D = std::move(jacobians2D);
273-
unsigned int nNodesElement = nodesTagsPerEdge.size()/2; //Use elementProp map ?
274278

275279
for(unsigned int i = 0 ; i < nodesTagsPerEdge.size()/2 ; ++i)
276280
{
@@ -279,16 +283,16 @@ static void addElement(Entity2D& entity, int elementTag, int eleType2D,
279283

280284
std::vector<double> determinantsEdge1D(determinants1D.begin() + nGP1D*i, determinants1D.begin() + nGP1D*(i + 1));
281285

282-
addEdge(element, std::move(nodesTagsEdge), std::move(determinantsEdge1D), nNodesElement);
286+
addEdge(element, std::move(nodesTagsEdge), std::move(determinantsEdge1D), element2DProperty.numNodes);
283287
if(entity.elements.size() != 0)
284288
{
285-
if(!IsBounbdary(nodesTagBoundary, element.edges[i]))
289+
if(!IsBounbdary(nodesTagBoundaries, element.edges[i]))
286290
findInFrontEdge(entity, element.edges[i], i);
287291

288292
}
289293
else
290294
{
291-
IsBounbdary(nodesTagBoundary, element.edges[i]);
295+
IsBounbdary(nodesTagBoundaries, element.edges[i]);
292296
}
293297

294298
computeEdgeNormalCoord(element.edges[i], elementBarycenter);
@@ -396,8 +400,9 @@ static void addEntity(Mesh2D& mesh, const std::pair<int, int>& entityHandle, uns
396400
std::move(determinantElement1D),
397401
nGP1D, currentOffset,
398402
nodesTagPerEdgeElement,
399-
elementBarycenter, intScheme, basisFuncType,
400-
mesh.nodesTagBoundary);
403+
elementBarycenter,
404+
mesh.nodesTagBoundary,
405+
mesh.elementProperties2D[eleType2D]);
401406

402407
currentOffset += nodesTagPerEdgeElement.size()/2;
403408
}

srcs/Mesh2D.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Edge
2929
std::string bcName; /**< Name of the physical group of the boundary condition
3030
in which the edge is in (if any)*/
3131

32-
std::vector<unsigned int> offsetInElm;
32+
std::vector<unsigned int> offsetInElm; /**< Offset of the edge nodes in the element*/
3333
};
3434

3535
/**
@@ -42,7 +42,7 @@ struct Element2D
4242
int elementType2D; /**< 2D type of the element*/
4343
int elementType1D; /**< 1D type of the element*/ //Store it only once
4444

45-
unsigned int offsetInU;
45+
unsigned int offsetInU; /**< Offset of the element in the unknowns vector*/
4646

4747
std::vector<double> determinant2D; /**< Determinant of the variable change for Gauss integration,
4848
evaluated at each Gauss point*/
@@ -103,8 +103,7 @@ struct Mesh2D
103103
std::map<int, ElementProperty> elementProperties2D; /**< Store element properties for each 2D element type */
104104
std::map<int, ElementProperty> elementProperties1D; /**< Store element properties for each 1D element type */
105105

106-
std::map<std::string, std::vector<int>> nodesTagBoundary;
107-
//std::map<std::string, std::vector<double>> coordNodesBoundary;
106+
std::map<std::string, std::vector<int>> nodesTagBoundary;/**< Tags of the nodes per BC */
108107

109108
std::vector<Entity2D> entities; /**< List of entities inside the mesh */
110109
};
@@ -113,13 +112,15 @@ struct Mesh2D
113112
/**
114113
* \brief Get the number of nodes (i.e. of unknowns) given a mesh.
115114
* \param mesh2D The structure that contains the mesh.
115+
* \return The number of unknowns inside a mesh.
116116
*/
117117
unsigned int getNumNodes(const Mesh2D& mesh2D);
118118

119119

120120
/**
121121
* \brief Get the tags of nodes (i.e. of unknowns) given a mesh.
122122
* \param mesh2D The structure that contains the mesh.
123+
* \return Vector containing all the tags of the nodes inside a mesh.
123124
*/
124125
std::vector<int> getTags(const Mesh2D& mesh2D);
125126

srcs/buildFlux.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,23 @@ void flux(Eigen::VectorXd& fx, Eigen::VectorXd& fy, double& C,
77
const Eigen::VectorXd& u)
88
{
99
// first basic flux: simple transport
10-
std::vector<double> a;
11-
a.push_back(1.0);
12-
a.push_back(0.0);
10+
double ax = 1.0;
11+
double ay = 0.0;
1312

14-
fx = a[0]*u;
15-
fy = a[1]*u;
13+
fx = ax*u;
14+
fy = ay*u;
1615

17-
C = sqrt(a[0]*a[0] + a[1]*a[1]);
16+
C = sqrt(ax*ax + ay*ay);
1817
}
1918

2019
void flux(double& fx, double& fy, double u)
2120
{
2221
// first basic flux: simple transport
23-
std::vector<double> a;
24-
a.push_back(1.0);
25-
a.push_back(0.0);
22+
double ax = 1.0;
23+
double ay = 0.0;
2624

27-
fx = a[0]*u;
28-
fy = a[1]*u;
25+
fx = ax*u;
26+
fy = ay*u;
2927
}
3028

3129

@@ -34,7 +32,7 @@ double valueAtBC(const std::string& bcName,
3432
{
3533
if(!bcName.compare("BC_Left"))
3634
{
37-
return 0.01;//sin(20*t);
35+
return exp(-(t-2)*(t-2)/0.1);
3836
}
3937
else
4038
{
@@ -45,19 +43,10 @@ double valueAtBC(const std::string& bcName,
4543

4644
bool buildFlux(const Mesh2D& mesh, Eigen::VectorXd& I, const Eigen::VectorXd& u,
4745
const Eigen::VectorXd& fx, const Eigen::VectorXd& fy, const double& C,
48-
const std::string& typeForm, unsigned int numNodes, double t)
46+
double factor, unsigned int numNodes, double t)
4947
{
5048

5149
// the type of form is stored in factor
52-
float factor;
53-
if(!typeForm.compare("strong")) factor = -1.0;
54-
else if(!typeForm.compare("weak")) factor = +1.0;
55-
else
56-
{
57-
std::cerr << "The form " << typeForm << "does not exist !"
58-
<< std::endl;
59-
return false;
60-
}
6150

6251
// loop over the entities
6352
for(unsigned int ent = 0 ; ent < mesh.entities.size() ; ent++)
@@ -136,11 +125,11 @@ bool buildFlux(const Mesh2D& mesh, Eigen::VectorXd& I, const Eigen::VectorXd& u,
136125
edge.nodeCoordinate[j].second,
137126
0.0, t);
138127

139-
flux(fxAtBC, fyAtBC, uAtBC);
128+
flux(fxAtBC, fyAtBC, uAtBC);
140129

141-
gx[j] = -(factor*fx[indexJ] + fxAtBC)/2
130+
gx[edge.offsetInElm[j]] += -(factor*fx[indexJ] + fxAtBC)/2
142131
- C*element.edges[s].normal.first*(u[indexJ] - uAtBC)/2;
143-
gy[j] = -(factor*fy[indexJ] + fyAtBC)/2
132+
gy[edge.offsetInElm[j]] += -(factor*fy[indexJ] + fyAtBC)/2
144133
- C*element.edges[s].normal.second*(u[indexJ] - uAtBC)/2;
145134
}
146135
else
@@ -154,9 +143,9 @@ bool buildFlux(const Mesh2D& mesh, Eigen::VectorXd& I, const Eigen::VectorXd& u,
154143
.edges[edge.edgeInFront.second]
155144
.offsetInElm[edge.nodeIndexEdgeInFront[j]];
156145

157-
gx[j] = -(factor*fx[indexJ] + fx[indexFrontJ])/2
146+
gx[edge.offsetInElm[j]] += -(factor*fx[indexJ] + fx[indexFrontJ])/2
158147
- C*element.edges[s].normal.first*(u[indexJ] - u[indexFrontJ])/2;
159-
gy[j] = -(factor*fy[indexJ] + fy[indexFrontJ])/2
148+
gy[edge.offsetInElm[j]] += -(factor*fy[indexJ] + fy[indexFrontJ])/2
160149
- C*element.edges[s].normal.second*(u[indexJ] - u[indexFrontJ])/2;
161150
std::cout << "==========>" << gx[j] << std::endl;
162151
}

srcs/buildFlux.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ void flux(double& fx, double& fy, double u);
1212

1313
bool buildFlux(const Mesh2D& mesh, Eigen::VectorXd& I, const Eigen::VectorXd& u,
1414
const Eigen::VectorXd& fx, const Eigen::VectorXd& fy, const double& C,
15-
const std::string& typeForm, unsigned int numNodes, double t);
15+
double factor, unsigned int numNodes, double t);
1616

1717
#endif /* buildFlux_hpp */

srcs/displayMesh.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ void displayMesh(const Mesh2D& mesh)
8080
<< edges[k].edgeInFront.first<<", "
8181
<< "edge " << edges[k].edgeInFront.second<<", "
8282
<< std::endl; //[TO DO]: put again inverted
83+
if((edges[k].normal.first != -entitity.elements[edges[k].edgeInFront.first].edges[edges[k].edgeInFront.second].normal.first)
84+
|| (edges[k].normal.second != -entitity.elements[edges[k].edgeInFront.first].edges[edges[k].edgeInFront.second].normal.second))
85+
{
86+
std::cerr<<"Bug in the normal of that edge !"<<std::endl;
87+
return;
88+
}
8389
}
8490
else
8591
{

0 commit comments

Comments
 (0)