Skip to content

Commit

Permalink
Many changes - but they are all (mostly) connected to change from 'in…
Browse files Browse the repository at this point in the history
…t' to 'unsigned' to comply with compiler's requirement on comparison between singed and unsigned numbers.
  • Loading branch information
Mikhail Artemyev committed Mar 12, 2014
1 parent e3b583d commit 3cfd451
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 143 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8)
# --- project ---
#set(CMAKE_CXX_COMPILER mpicxx)
project(fem)
add_definitions(-std=c++0x -Wall)
set(MY_CXX_FLAGS "-std=c++0x -Wall")
# ---------------


Expand All @@ -14,10 +14,12 @@ endif(NOT CMAKE_BUILD_TYPE)

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(DEBUG ON CACHE BOOL "This option is for internal usage - not the compiler debug options" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MY_CXX_FLAGS}")
message("build type: Debug")
message("compiler flags: ${CMAKE_CXX_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
set(DEBUG OFF CACHE BOOL "This option is for internal usage - not the compiler debug options" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MY_CXX_FLAGS}")
message("build type: Release")
message("compiler flags: ${CMAKE_CXX_FLAGS_RELEASE}")
else(CMAKE_BUILD_TYPE MATCHES Debug)
Expand Down
4 changes: 2 additions & 2 deletions headers/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string>

/* #undef DEBUG */
/* #undef HAVE_64BIT_SIZE_T */
#define HAVE_64BIT_SIZE_T

const std::string HOME_DIRECTORY = "/home/artemiev";
const std::string HOME_DIRECTORY = "/u/artemyev";

#endif // FEM_CONFIG_H
8 changes: 7 additions & 1 deletion headers/csr_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class CSRPattern
void make_sparse_format(const std::vector<Rectangle> &rectangles, unsigned int order, CONNECTIVITY connectivity);

/**
* Get the serial number of nonzero element in the pattern
* Get the serial number of nonzero element in the pattern.
* To find it effectively we need to know the number of the row,
* where the element is.
* If there if no such element in the given row,
* the function returns "-1", which means that this element wasn't found.
* "-1" should be correctly treated (ignored or exception should be thrown)
* in user's function - not here.
* @param num_row - the number of the row
* @param num_col - the number of the col
*/
Expand Down
4 changes: 2 additions & 2 deletions headers/fine_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ class FineMesh
* Get the number of mesh triangles
*/
unsigned int n_triangles() const;
void n_triangles(unsigned int amount);
void n_triangles(unsigned int number);

/**
* Get the mesh triangle (its copy)
* @param number - the serial number of the mesh triangle
*/
Triangle triangle(int number) const;
Triangle triangle(unsigned number) const;
void triangle(unsigned int number, const Triangle &tri);

/**
Expand Down
14 changes: 7 additions & 7 deletions headers/mesh_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class MeshElement
*/
std::vector<unsigned int> _faces;

/**
* Type of the element (its number actually) like in Gmsh.
* It must be defined in every derived class.
* It's 0 by default.
*/
unsigned int _gmsh_el_type;

/**
* ID of the physical domain where the element takes place.
* It's necessary to distinguish media with different physical properties.
Expand All @@ -159,13 +166,6 @@ class MeshElement
*/
unsigned int _partition_id;

/**
* Type of the element (its number actually) like in Gmsh.
* It must be defined in every derived class.
* It's 0 by default.
*/
unsigned int _gmsh_el_type;

/**
* Constructor is protected to prevent creating MeshElement objects directly
* @param n_ver - number of vertices
Expand Down
37 changes: 18 additions & 19 deletions sources/csr_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ void CSRPattern::make_cg_sparse_format(const DoFHandler &dof_handler)

// pass through all triangles and all dofs on them
expect(dof_handler.fmesh().n_triangles() != 0, "");
for (int cell = 0; cell < dof_handler.fmesh().n_triangles(); ++cell)
for (unsigned int cell = 0; cell < dof_handler.fmesh().n_triangles(); ++cell)
{
Triangle triangle = dof_handler.fmesh().triangle(cell);

expect(triangle.n_dofs() != 0, "");
for (int di = 0; di < triangle.n_dofs(); ++di)
for (unsigned int di = 0; di < triangle.n_dofs(); ++di)
{
const unsigned int dof_i = triangle.dof(di); // the number of the first degree of freedom
for (int dj = 0; dj < triangle.n_dofs(); ++dj)
for (unsigned int dj = 0; dj < triangle.n_dofs(); ++dj)
{
const unsigned int dof_j = triangle.dof(dj); // the number of the second degree of freedom
// insert the values in the corresponding places
Expand All @@ -82,7 +82,7 @@ void CSRPattern::make_cg_sparse_format(const DoFHandler &dof_handler)
pattern_initialization(connect);

// free the memory
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
connect[i].clear();
delete[] connect;
}
Expand All @@ -103,15 +103,15 @@ void CSRPattern::make_dg_sparse_format(const DoFHandler &dof_handler)

// pass through all triangles and all dofs on them
expect(dof_handler.fmesh().n_triangles() != 0, "");
for (int cell = 0; cell < dof_handler.fmesh().n_triangles(); ++cell)
for (unsigned int cell = 0; cell < dof_handler.fmesh().n_triangles(); ++cell)
{
Triangle triangle = dof_handler.fmesh().triangle(cell);

expect(triangle.n_dofs() != 0, "");
for (int di = 0; di < triangle.n_dofs(); ++di)
for (unsigned int di = 0; di < triangle.n_dofs(); ++di)
{
const unsigned int dof_i = triangle.dof(di); // the number of the first degree of freedom
for (int dj = 0; dj < triangle.n_dofs(); ++dj)
for (unsigned int dj = 0; dj < triangle.n_dofs(); ++dj)
{
const unsigned int dof_j = triangle.dof(dj); // the number of the second degree of freedom
// insert the values in the corresponding places
Expand All @@ -122,7 +122,7 @@ void CSRPattern::make_dg_sparse_format(const DoFHandler &dof_handler)
}

// pass through all interior CG edges
for (int e = 0; e < dof_handler.n_con_edges(); ++e)
for (unsigned int e = 0; e < dof_handler.n_con_edges(); ++e)
{
const Edge edge = dof_handler.con_edge(e); // CG edge
if (edge.n_assoc_edges() == 2) // for interior edges only
Expand Down Expand Up @@ -150,7 +150,7 @@ void CSRPattern::make_dg_sparse_format(const DoFHandler &dof_handler)
pattern_initialization(connect);

// free the memory
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
connect[i].clear();
delete[] connect;
}
Expand All @@ -167,7 +167,7 @@ void CSRPattern::make_sparse_format(const std::vector<Rectangle> &rectangles, un
std::set<unsigned int> *connect = new std::set<unsigned int>[_order];

// pass through all rectangles and all dofs on them
for (int cell = 0; cell < rectangles.size(); ++cell)
for (unsigned int cell = 0; cell < rectangles.size(); ++cell)
{
const Rectangle rect = rectangles[cell];

Expand All @@ -182,7 +182,7 @@ void CSRPattern::make_sparse_format(const std::vector<Rectangle> &rectangles, un
else
require(false, "");

for (int ii = 0; ii < N; ++ii)
for (unsigned int ii = 0; ii < N; ++ii)
{
unsigned int num_i = -1;
if (connectivity == VERTICES)
Expand All @@ -192,7 +192,7 @@ void CSRPattern::make_sparse_format(const std::vector<Rectangle> &rectangles, un
else
require(false, "");

for (int jj = 0; jj < N; ++jj)
for (unsigned int jj = 0; jj < N; ++jj)
{
unsigned int num_j = -1;
if (connectivity == VERTICES)
Expand All @@ -213,7 +213,7 @@ void CSRPattern::make_sparse_format(const std::vector<Rectangle> &rectangles, un
pattern_initialization(connect);

// free the memory
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
connect[i].clear();
delete[] connect;
}
Expand All @@ -228,12 +228,12 @@ void CSRPattern::pattern_initialization(const std::set<unsigned int> *connect)

_row.resize(_order + 1);
_row[0] = 0;
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
_row[i + 1] = _row[i] + connect[i].size();

_col.resize(_row[_order]);
int k = 0;
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
{
for (std::set<unsigned int>::const_iterator iter = connect[i].begin();
iter != connect[i].end();
Expand All @@ -249,12 +249,11 @@ void CSRPattern::pattern_initialization(const std::set<unsigned int> *connect)

int CSRPattern::find(unsigned int num_row, unsigned num_col) const
{
for (int i = _row[num_row]; i < _row[num_row + 1]; ++i)
for (unsigned int i = _row[num_row]; i < _row[num_row + 1]; ++i)
if (num_col == _col[i])
return i;

//require(false, "The serial number of nonzero element cannot be found");
//return 0; // to calm down a compiler
// if we found nothing
return -1;
}

Expand Down Expand Up @@ -286,7 +285,7 @@ unsigned int CSRPattern::col(unsigned int number) const
const int* CSRPattern::nnz() const
{
int *nnz = new int[_order];
for (int i = 0; i < _order; ++i)
for (unsigned int i = 0; i < _order; ++i)
nnz[i] = _row[i + 1] - _row[i];
return nnz;
}
46 changes: 23 additions & 23 deletions sources/dof_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DoFHandler::~DoFHandler()
_discon_edges.clear();
if (_vertices_dofs != 0)
{
for (int i = 0; i < _fmesh->n_vertices(); ++i)
for (unsigned i = 0; i < _fmesh->n_vertices(); ++i)
_vertices_dofs[i].clear();
delete[] _vertices_dofs;
}
Expand Down Expand Up @@ -60,15 +60,15 @@ void DoFHandler::distribute_cg_first(const FiniteElement &fe)
require(fe.order() == 1, "This is not implemented for fe order other than 1");

_dofs.resize(_fmesh->n_vertices());
for (int ver = 0; ver < _fmesh->n_vertices(); ++ver)
for (unsigned ver = 0; ver < _fmesh->n_vertices(); ++ver)
_dofs[ver] = _fmesh->vertex(ver);

// trying to work with triangles first
for (int cell = 0; cell < _fmesh->n_triangles(); ++cell)
for (unsigned cell = 0; cell < _fmesh->n_triangles(); ++cell)
{
Triangle *triangle = _fmesh->triangle_orig(cell);
triangle->n_dofs(Triangle::n_dofs_first); // allocate the memory for degrees of freedom
for (int ver = 0; ver < Triangle::n_vertices; ++ver)
for (unsigned ver = 0; ver < Triangle::n_vertices; ++ver)
{
// set the numbers of degrees of freedom.
// the number of the degree of freedom is the same as the number of the corresponding vertex
Expand All @@ -77,11 +77,11 @@ void DoFHandler::distribute_cg_first(const FiniteElement &fe)
}

// then trying to work with rectangles
for (int cell = 0; cell < _fmesh->n_rectangles(); ++cell)
for (unsigned cell = 0; cell < _fmesh->n_rectangles(); ++cell)
{
Rectangle *rectangle = _fmesh->rectangle_orig(cell);
rectangle->n_dofs(Rectangle::n_dofs_first); // allocate the memory for degrees of freedom
for (int ver = 0; ver < Rectangle::n_vertices; ++ver)
for (unsigned ver = 0; ver < Rectangle::n_vertices; ++ver)
{
// set the numbers of degrees of freedom.
// the number of the degree of freedom is the same as the number of the corresponding vertex
Expand All @@ -106,11 +106,11 @@ void DoFHandler::distribute_dg_first(const FiniteElement &fe)
_vertices_dofs = new std::vector<unsigned int>[_fmesh->n_vertices()];

// fill up the corresponding field in triangle array
for (int tr = 0; tr < _fmesh->n_triangles(); ++tr)
for (unsigned tr = 0; tr < _fmesh->n_triangles(); ++tr)
{
Triangle *triangle = _fmesh->triangle_orig(tr); // get an original triangle (not a copy)
triangle->n_dofs(Triangle::n_dofs_first); // allocate the memory for degrees of freedom
for (int i = 0; i < Triangle::n_vertices; ++i)
for (unsigned i = 0; i < Triangle::n_vertices; ++i)
{
const unsigned int ver_number = triangle->vertex(i); // number of vertex
const unsigned int dof_number = Triangle::n_dofs_first * tr + i; // number of the dof
Expand All @@ -134,15 +134,15 @@ void DoFHandler::numerate_edges()
dof_pattern.make_sparse_format(*this);// make a pattern based on dofs connectivity to numerate edges which tie dofs
_discon_edges.resize(dof_pattern.row(dof_pattern.order()));

for (int cell = 0; cell < _fmesh->n_triangles(); ++cell)
for (unsigned cell = 0; cell < _fmesh->n_triangles(); ++cell)
{
Triangle *triangle = _fmesh->triangle_orig(cell);
int serial_n_of_edge = 0; // serial number of an edge in the structure of triangle
unsigned int serial_n_of_edge = 0; // serial number of an edge in the structure of triangle

for (int vi = 0; vi < triangle->n_dofs(); ++vi)
for (unsigned vi = 0; vi < triangle->n_dofs(); ++vi)
{
const unsigned int dof_i = triangle->dof(vi);
for (int vj = 0; vj < triangle->n_dofs(); ++vj)
for (unsigned vj = 0; vj < triangle->n_dofs(); ++vj)
{
const unsigned int dof_j = triangle->dof(vj);
if (dof_i > dof_j)
Expand All @@ -167,15 +167,15 @@ void DoFHandler::numerate_edges()
ver_pattern.make_sparse_format(*_fmesh); // make a pattern based on mesh vertices connectivity to numerate edges which tie mesh vertices - not dofs
_cg_edges.resize(ver_pattern.row(ver_pattern.order()));

for (int cell = 0; cell < _fmesh->n_triangles(); ++cell)
for (unsigned cell = 0; cell < _fmesh->n_triangles(); ++cell)
{
Triangle *triangle = _fmesh->triangle_orig(cell);
int serial_n_of_edge = 0; // serial number of an edge in the structure of triangle
unsigned serial_n_of_edge = 0; // serial number of an edge in the structure of triangle

for (int vi = 0; vi < Triangle::n_vertices; ++vi)
for (unsigned vi = 0; vi < Triangle::n_vertices; ++vi)
{
const unsigned int ver_i = triangle->vertex(vi);
for (int vj = 0; vj < Triangle::n_vertices; ++vj)
for (unsigned vj = 0; vj < Triangle::n_vertices; ++vj)
{
const unsigned int ver_j = triangle->vertex(vj);
if (ver_i > ver_j)
Expand All @@ -194,7 +194,7 @@ void DoFHandler::numerate_edges()
associated_dg_edges(ver_i, ver_j, _vertices_dofs, dof_pattern, assoc_dg_edges);
_cg_edges[num_edge].edges(assoc_dg_edges);
// change the order of some vertices in DG edges in such a way that they are oriented as CG edges are
for (int ade = 0; ade < assoc_dg_edges.size(); ++ade)
for (unsigned ade = 0; ade < assoc_dg_edges.size(); ++ade)
{
const unsigned int dg_edge = assoc_dg_edges[ade]; // the number of the associated DG edge
// attempt to find the number of the first (begin) vertex of the DG edge
Expand Down Expand Up @@ -290,12 +290,12 @@ Edge DoFHandler::con_edge(unsigned int num) const
void DoFHandler::boundary_dofs(const std::vector<unsigned int> &b_vertices,
std::vector<int> &bound_dofs) const
{
for (int bound_ver = 0; bound_ver < b_vertices.size(); ++bound_ver)
for (unsigned bound_ver = 0; bound_ver < b_vertices.size(); ++bound_ver)
{
for (int cell = 0; cell < _fmesh->n_triangles(); ++cell)
for (unsigned cell = 0; cell < _fmesh->n_triangles(); ++cell)
{
const Triangle tri = _fmesh->triangle(cell);
for (int ver = 0; ver < Triangle::n_vertices; ++ver)
for (unsigned ver = 0; ver < Triangle::n_vertices; ++ver)
{
if (tri.vertex(ver) == b_vertices[bound_ver])
bound_dofs.push_back(tri.dof(ver));
Expand All @@ -318,10 +318,10 @@ void associated_dg_edges(unsigned int ver_i,
std::vector<unsigned int> &assoc_dg_edges)
{
const unsigned int max_n_found_edges = 2; // for 2D case the max number of DG edges associated with CG edge equals to 2, since only 2 triangles can share an edge
int n_found_edges = 0; // current number of found edges
for (int i = 0; i < vertices_dofs[ver_i].size() && n_found_edges < max_n_found_edges; ++i)
unsigned n_found_edges = 0; // current number of found edges
for (unsigned i = 0; i < vertices_dofs[ver_i].size() && n_found_edges < max_n_found_edges; ++i)
{
for (int j = 0; j < vertices_dofs[ver_j].size() && n_found_edges < max_n_found_edges; ++j)
for (unsigned j = 0; j < vertices_dofs[ver_j].size() && n_found_edges < max_n_found_edges; ++j)
{
const unsigned int v0 = std::min(vertices_dofs[ver_i][i], vertices_dofs[ver_j][j]); // begin vertex of the edge
const unsigned int v1 = std::max(vertices_dofs[ver_i][i], vertices_dofs[ver_j][j]); // end vertex of the edge
Expand Down
2 changes: 1 addition & 1 deletion sources/edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Point Edge::normal(const Triangle &tri, const std::vector<Point> &points)
const Point B = points[_vertices[1]]; // second vertex
// take the number of the third vertex
int third_vertex = -1;
for (int i = 0; i < Triangle::n_dofs_first && third_vertex == -1; ++i)
for (unsigned i = 0; i < Triangle::n_dofs_first && third_vertex == -1; ++i)
if (tri.dof(i) != _vertices[0] &&
tri.dof(i) != _vertices[1])
third_vertex = tri.dof(i);
Expand Down
Loading

0 comments on commit 3cfd451

Please sign in to comment.