Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Solver will coming soon.
  • Loading branch information
truongdangqe authored Jun 25, 2018
1 parent 8e7ef10 commit 5a7cdeb
Show file tree
Hide file tree
Showing 11 changed files with 1,023 additions and 0 deletions.
401 changes: 401 additions & 0 deletions Cell2D.cpp

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions Cell2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <sstream>
#include <iomanip>
#include <vector>
#include <iostream>
#include "MyPoint.h"
#include "GmshReader.h"

class face {
public:
MyPoint p1, p2;
int bc_typ;
unsigned idface;
double area = 0.0;
MyPoint centroid;
};

class Cell2D : public MyPoint {
public:
unsigned ident = 0;
MyPoint vertex[4];
face faces[4];
Cell2D *neighbor1 = nullptr;
Cell2D *neighbor2 = nullptr;
Cell2D *neighbor3 = nullptr;
Cell2D *neighbor4 = nullptr;
double vol = 0.0;
void calcul_vol();
};

class ListCell2D : public Cell2D {
public:
unsigned nbfaces;
GmshReader msh_reader;
vector<Cell2D> cells;
void assign_vextex();
void assign_faces();
void assign_boundary_condition();
void detect_nearest_neighbor();
void calcul_vol_cells();
void write_vtk();
};


18 changes: 18 additions & 0 deletions FvmFace2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <vector>
#include "Vector2D.h"
#include "Cell2D.h"

class FvmFace2D, public: face{
Vector2d normal_vector;
Vector2d tangent_vector;
Cell2D *left_cell = nullptr;
Cell2D *right_cell = nullptr;
double len_nor;
double len_tan;
};

class ListFvmFace2D {
public:
vector<FvmFace2D> face_2D;
ListCell2D *short_cut;
};
120 changes: 120 additions & 0 deletions GmshReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "GmshReader.h"

GmshReader::GmshReader()
{
this -> nbnode = 0;
this -> nbelm = 0;
this -> nbel_msh = 0;
this -> fname = "";
}

void GmshReader::GmshLoadMesh()
{
read_mesh();
construct_id_nodes();
}

void GmshReader::read_mesh()
{
// open input file
fname = "input.dat";
ifstream stream( fname );
if (stream.fail()) throw runtime_error( "could not open input file." );

string str;
str = ReadLine( stream );
fname = str;

// open mesh file .msh of GMSH
string str_msh = str + ".msh";
ifstream stream_msh(str_msh);
if (stream_msh.fail()) throw runtime_error("could not open mesh file");

string line;
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);
line = ReadLine(stream_msh);

line = ReadLine(stream_msh);
stringstream(line) >> nbnode;

for (unsigned i = 0; i < nbnode; i++)
{
line = ReadLine(stream_msh);
unsigned ident;
double x, y, z;
stringstream(line) >> ident >> x >> y >> z;
MyPoint p(x, y, z, ident);
coord_nodes.push_back(p);
}

line = ReadLine(stream_msh);
line = ReadLine(stream_msh);

line = ReadLine(stream_msh);
stringstream(line) >> nbel_msh;

for (unsigned i = 0; i < nbel_msh; i++)
{
line = ReadLine(stream_msh);
node_ident_msh node_msh;
stringstream ss = stringstream(line); // no error with Visual C++ 2015, error with g++
vector <unsigned> line_number;
while (!ss.eof()) {
unsigned number;
ss >> number;
line_number.push_back(number);
//cout << number << " ";
}
//cout << endl;
node_msh.id_node = line_number;
node_msh.ident = line_number[0];
node_msh.elem_typ = line_number[1];
node_msh.nb_tags = line_number[2];
node_msh.tag1 = line_number[3];
node_msh.tag2 = line_number[4];
id_nodes_msh.push_back(node_msh);
unsigned elem_typ = id_nodes_msh[i].elem_typ;
switch (elem_typ)
{
case 1: // 2 - node line.
break;
case 3: // 4-node quadrangle.
nbelm = nbelm + 1;
break;
case 15: // 1-node point.
break;
case 37: // 5-node edge quadrangle.
nbelm = nbelm + 1;
break;
case 27: // boundary 5-node edge.
break;
default:
throw runtime_error("Element type is not suppoted. Comming soon !");
break;
}
}

}

void GmshReader::construct_id_nodes()
{
for (unsigned i = 0; i < nbel_msh; i++)
{
if (id_nodes_msh[i].elem_typ == 3)
{
node_ident node;
node.id_node = id_nodes_msh[i].id_node;
id_nodes.push_back(node);
}

if (id_nodes_msh[i].elem_typ == 37)
{
node_ident node;
node.id_node = id_nodes_msh[i].id_node;
id_nodes.push_back(node);
}
}
}

44 changes: 44 additions & 0 deletions GmshReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <vector>
#include <iostream>
#include <sstream>
#include "MyPoint.h"
#include "streamIO.h"

using namespace std;

struct node_ident
{
vector<unsigned> id_node;
};

struct node_ident_msh: public node_ident
{
unsigned ident;
unsigned elem_typ;
unsigned nb_tags;
unsigned tag1;
unsigned tag2;
};

class GmshReader : public MyPoint{

public:
unsigned nbnode;
unsigned nbel_msh;
unsigned nbelm;
string fname;

GmshReader();
void GmshLoadMesh();
vector<MyPoint> coord_nodes;
vector<node_ident> id_nodes;
vector<node_ident_msh> id_nodes_msh;

private:
void read_mesh();
void construct_id_nodes();
GmshReader(const GmshReader &gmshReader); // override default copy constructor
GmshReader & operator = (const GmshReader &gmshReader); // and assignment operator

};

44 changes: 44 additions & 0 deletions MyPoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "MyPoint.h"

MyPoint::MyPoint(double x, double y, double z, unsigned ident)
{
this -> x = x;
this -> y = y;
this -> z = z;
this -> ident = ident;
}

bool MyPoint::operator==(MyPoint rhs)
{
if (abs(this->x - rhs.x) <= 1.0e-9 && abs(this->y - rhs.y) <= 1.0e-9 && abs(this->z - rhs.z) <= 1.0e-9)
{
return true;
}
return false;
}

int MyPoint::get_ident()
{
return this->ident;
}

double MyPoint::get_x()
{
return this->x;
}

double MyPoint::get_y()
{
return this->y;
}

double MyPoint::get_z()
{
return this->z;
}

void MyPoint::print()
{
cout << this -> x << " " << this -> y << " " << this -> z << "\n" << endl;
}

25 changes: 25 additions & 0 deletions MyPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <iostream>
#include <cmath>

using namespace std;

class MyPoint{

public:
MyPoint(){};
MyPoint(double, double, double, unsigned);
bool operator==(MyPoint);
void print();
int get_ident();
double get_x();
double get_y();
double get_z();

private:
double x;
double y;
double z;
unsigned ident;
};

Loading

0 comments on commit 5a7cdeb

Please sign in to comment.