Skip to content

Commit 06b751f

Browse files
ImperatorS79tgregov
authored andcommitted
Find the index of the node when it is in an edge in front (#23)
I still need to review @ImperatorS79's code, but I will do that tomorrow calmly 😄 Summary of the commits: * Find opposite * Update buildFlux.cpp * Fix to my stupidity
1 parent 5ac79f1 commit 06b751f

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

srcs/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SET(SRCS main.cpp readMesh.cpp readMesh.hpp buildM.cpp buildM.hpp buildS.cpp buildS.hpp buildDM.cpp buildDM.hpp)
1+
SET(SRCS main.cpp readMesh.cpp readMesh.hpp buildM.cpp buildM.hpp buildS.cpp buildS.hpp buildDM.cpp buildDM.hpp buildFlux.hpp buildFlux.cpp)
22
ADD_EXECUTABLE(main ${SRCS})
3-
TARGET_LINK_LIBRARIES(main ${GMSH_LIBRARIES})
3+
TARGET_LINK_LIBRARIES(main ${GMSH_LIBRARIES})

srcs/buildDM.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void buildDM(MeshParams& meshParams)
1111
double lala = 0.0;
1212
double lalb = 0.0;
1313
unsigned int nSigma = meshParams.nSigma;
14-
14+
1515
for (unsigned int k = 0 ; k < meshParams.nGPInf ; k++)
1616
{
1717
lala += meshParams.intPointsInferior[4*k + 3]
@@ -24,19 +24,18 @@ void buildDM(MeshParams& meshParams)
2424
}
2525

2626

27-
2827
for(unsigned int s = 0 ; s < meshParams.nSigma ; s++)
2928
{
3029
meshParams.dM.push_back(Eigen::SparseMatrix<double>(meshParams.nSF,meshParams.nSF));
31-
30+
3231
std::vector<Eigen::Triplet<double>> index;
3332
index.push_back(Eigen::Triplet<double>(s, s, lala));
3433
index.push_back(Eigen::Triplet<double>(s, (s+1) % nSigma, lalb));
3534
index.push_back(Eigen::Triplet<double>((s+1) % nSigma, s, lalb));
3635
index.push_back(Eigen::Triplet<double>((s+1) % nSigma, (s+1)%nSigma, lala));
3736

3837
meshParams.dM[s].setFromTriplets(index.begin(), index.end());
39-
38+
4039
}
4140

4241
}

srcs/buildFlux.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "readMesh.hpp"
88
#include <cmath>
99

10-
void flux(Eigen::VectorXd<double>& fx, Eigen::VectorXd<double>& fy, double& C,
11-
const Eigen::VectorXd<double>& u)
10+
void flux(Eigen::VectorXd& fx, Eigen::VectorXd& fy, double& C,
11+
const Eigen::VectorXd& u)
1212
{
1313
// first basic flux: simple transport
1414
std::vector<double> a;
@@ -22,12 +22,12 @@ void flux(Eigen::VectorXd<double>& fx, Eigen::VectorXd<double>& fy, double& C,
2222
}
2323

2424

25-
bool buildFlux(const MeshParams& meshParams, Eigen::VectorXd<double>& I,
26-
const Eigen::VectorXd<double>& u, const std::string& typeForm)
25+
bool buildFlux(const MeshParams& meshParams, Eigen::VectorXd& I,
26+
const Eigen::VectorXd& u, const std::string& typeForm)
2727
{
2828

2929

30-
Eigen::VectorXd<double> fx(meshParams.nE*meshParams.nSF), fy(meshParams.nE*meshParams.nSF);
30+
Eigen::VectorXd fx(meshParams.nE*meshParams.nSF), fy(meshParams.nE*meshParams.nSF);
3131
double C;
3232
flux(fx, fy, C, u);
3333

@@ -62,17 +62,19 @@ bool buildFlux(const MeshParams& meshParams, Eigen::VectorXd<double>& I,
6262
factor = -1.0;
6363
} else if(typeForm.compare("weak")){
6464
factor = +1.0;
65+
}
6566
else{
66-
std::cerr << "The form " << typeForm << "does not exist !"
67+
std::cerr << "The form " << typeForm << "does not exist !"
6768
<< std::endl;
6869
return false;
6970
}
7071

71-
gx[j] = -(factor*fx[index[j]] + fx[opp(s, index[j])])/2
72-
- C*meshParams.normals[elm][s][0]*(u[index[j]] - u[opp(s, index[j])])/2;
72+
//DO NOT forget BC !!!
73+
gx[j] = -(factor*fx[index[j]] + fx[meshParams.indexInFront[index[j]]])/2
74+
- C*meshParams.normals[elm][s][0]*(u[index[j]] - u[meshParams.indexInFront[index[j]]])/2;
7375

74-
gy[j] = -(factor*fy[index[j]] + fy[opp(s, index[j])])/2
75-
- C*meshParams.normals[elm][s][1]*(u[index[j]] - u[opp(s, index[j])])/2;
76+
gy[j] = -(factor*fy[index[j]] + fy[meshParams.indexInFront[index[j]]])/2
77+
- C*meshParams.normals[elm][s][1]*(u[index[j]] - u[meshParams.indexInFront[index[j]]])/2;
7678

7779
}
7880

@@ -95,4 +97,4 @@ bool buildFlux(const MeshParams& meshParams, Eigen::VectorXd<double>& I,
9597
}
9698

9799
return true;
98-
}
100+
}

srcs/readMesh.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ bool readMesh(MeshParams& meshParams, const std::string& fileName,
163163
// compute a vector of nodes per edge per element and normal per edge
164164
// per element => to be generalized to 1D and 3D
165165

166+
meshParams.indexInFront.resize(nodeTags.size());
167+
for(unsigned int i = 0 ; i < nodeTags.size() ; ++i)
168+
{
169+
std::cout<<"Lol "<<nodeTags[i]<<std::endl;
170+
bool founded = false;
171+
for(unsigned int j = 0 ; j < nodeTags.size() ; ++j)
172+
{
173+
if(j != i)
174+
{
175+
if(nodeTags[i] == nodeTags[j])
176+
{
177+
meshParams.indexInFront[i]=j;
178+
founded=true;
179+
break;
180+
}
181+
}
182+
}
183+
if(!founded)
184+
meshParams.indexInFront[i]=-1;
185+
std::cout<<"Smite "<<meshParams.indexInFront[i]<<std::endl;
186+
}
187+
166188
// loop over the elements
167189
for(std::size_t elm = 0; elm < meshParams.nE; elm++)
168190
{
@@ -173,6 +195,11 @@ bool readMesh(MeshParams& meshParams, const std::string& fileName,
173195
std::vector<std::pair<int, int>> edgeList;
174196
std::vector<std::vector<double>> normalList;
175197
std::vector<double> meanNormal(2,0);
198+
std::vector<unsigned int> elementIndex;
199+
elementIndex.push_back(nEdgePerEl*elm);
200+
elementIndex.push_back(nEdgePerEl*elm+1);
201+
elementIndex.push_back(nEdgePerEl*elm+2);
202+
meshParams.index.push_back(elementIndex);
176203

177204
// loop over the edges of the current element
178205
for(unsigned short k = 0 ; k < nEdgePerEl; k++)
@@ -232,15 +259,7 @@ bool readMesh(MeshParams& meshParams, const std::string& fileName,
232259
// normal
233260
meshParams.nodes.push_back(edgeList);
234261
meshParams.normals.push_back(normalList);
235-
meshParams.meanElementNormal.push_back(meanNormal);
236-
}
237-
238-
// [TO REMOVE]
239-
for(unsigned int e = 0; e < meshParams.meanElementNormal.size() ; ++e)
240-
{
241-
std::cout<<"Element: "<<e<<", mean normal ("<<meshParams.meanElementNormal[e][0]<<","<<meshParams.meanElementNormal[e][1]<<")"<<std::endl;
242262
}
243-
std::cout<<std::endl;
244263

245264
// [TO REMOVE] display the normals to check that it works
246265
for(std::size_t j = 0; j < meshParams.nE; j++)

srcs/readMesh.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ struct MeshParams
7272
(length = number of edges per element)
7373
of normals (length depends on dimension */
7474

75-
std::vector<std::vector<double>> meanElementNormal;
75+
std::vector<std::vector<unsigned int>> index; //index[elm]=index of nodes f element elm, in the nodes vector returned somewhere in meshparams.
76+
std::vector<int> indexInFront; //give it an index, gives you the index of the node in front of
7677

7778
std::vector<double> basisFunc;
7879
std::vector<double> basisFuncGrad;
@@ -98,8 +99,8 @@ struct MeshParams
9899
int elementType;
99100
int elementTypeInferior = -1; //type of the boundary, dummy value for dim 0
100101

101-
std::vector<Eigen::SparseMatrix<double>> dM ;
102-
unsigned int nSigma = 3;
102+
std::vector<Eigen::SparseMatrix<double>> dM ;
103+
unsigned int nSigma = 3;
103104
};
104105

105106
bool readMesh(MeshParams& meshParams, const std::string& fileName,

0 commit comments

Comments
 (0)