Skip to content

Commit

Permalink
Merge branch 'yyc-bc'
Browse files Browse the repository at this point in the history
  • Loading branch information
yungyuc committed Jul 19, 2016
2 parents e27612c + 1ab3ca9 commit 5f12269
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 82 deletions.
7 changes: 0 additions & 7 deletions libmarch/include/march/core/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ class Buffer: public std::enable_shared_from_this<Buffer> {
Buffer & operator=(const Buffer &) = delete;

Buffer & operator=(Buffer &&) = delete;
/*Buffer & operator=(Buffer && other) {
m_data = other.m_data;
m_data = nullptr;
m_length = other.m_length;
m_own_data = other.m_own_data;
return *this;
}*/

explicit operator bool() const { return nullptr == m_data; }

Expand Down
109 changes: 109 additions & 0 deletions libmarch/include/march/mesh/BoundaryData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once

/*
* Copyright (c) 2016, Yung-Yu Chen <yyc@solvcon.net>
* BSD 3-Clause License, see COPYING
*/

#include <utility>
#include <string>

#include "march/core/core.hpp"

#include "march/mesh/LookupTable.hpp"

namespace march
{

namespace mesh
{

/**
* SOLVCON legacy C interface for boundary conditions.
*/
struct sc_bound_t {
index_type nbound, nvalue;
index_type *facn;
real_type *value;
}; /* end struct sc_bound_t */

class BoundaryData {

public:

static constexpr size_t BFREL = 3;

private:

/**
* First column is the face index in block. The second column is the face
* index in bndfcs. The third column is the face index of the related
* block (if exists).
*/
LookupTable<index_type, BFREL> m_facn;

/**
* Values attached (specified) for each boundary face. Each row is a
* boundary face, and each column is a value.
*/
LookupTableCore m_values;

public:

BoundaryData() {}

BoundaryData(index_type nvalue)
: m_values(0, 0, {0, nvalue}, type_to<real_type>::id)
{}

BoundaryData(const BoundaryData &) = delete;

BoundaryData(BoundaryData && other) {
m_facn = std::move(other.m_facn);
m_values = std::move(other.m_values);
}

BoundaryData & operator=(const BoundaryData &) = delete;

BoundaryData & operator=(BoundaryData && other) {
m_facn = std::move(other.m_facn);
m_values = std::move(other.m_values);
return *this;
}

~BoundaryData() = default;

index_type nvalue() const { return m_values.ncolumn(); }

LookupTable<index_type, BFREL> const & facn() const { return m_facn; }

LookupTable<index_type, BFREL> & facn() { return m_facn; }

LookupTableCore const & values() const { return m_values; }

LookupTableCore & values() { return m_values; }

template< size_t NVALUE >
LookupTable< real_type, NVALUE > const & values() const {
assert(NVALUE == m_values.ncolumn());
return *reinterpret_cast< LookupTable< real_type, NVALUE > const * >(&m_values);
}

template< size_t NVALUE >
LookupTable< real_type, NVALUE > & values() {
assert(NVALUE == m_values.ncolumn());
return *reinterpret_cast< LookupTable< real_type, NVALUE > * >(&m_values);
}

bool good_shape() const {
return m_facn.nghost() == 0 && m_values.nghost() == 0
&& m_facn.nbody() == m_values.nbody();
}

}; /* end class BoundaryData */

} /* end namespace mesh */

} /* end namespace march */

// vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4:
18 changes: 16 additions & 2 deletions libmarch/include/march/mesh/LookupTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LookupTableCore {
std::vector<index_type> m_dims;
index_type m_nghost = 0;
index_type m_nbody = 0;
index_type m_ncolumn = 1;
index_type m_ncolumn = 0;
index_type m_elsize = 1; ///< Element size in bytes.
DataTypeId m_datatypeid = MH_INT8;

Expand Down Expand Up @@ -70,7 +70,21 @@ class LookupTableCore {

LookupTableCore & operator=(const LookupTableCore &) = delete;

LookupTableCore & operator=(LookupTableCore &&) = delete;
LookupTableCore & operator=(LookupTableCore && other) {
m_buffer = other.m_buffer; other.m_buffer.reset();
m_dims.swap(other.m_dims);
m_nghost = other.m_nghost;
m_nbody = other.m_nbody;
m_ncolumn = other.m_ncolumn;
m_elsize = other.m_elsize;
// reset to initial state
other.m_nghost = 0;
other.m_nbody = 0;
other.m_ncolumn = 0;
other.m_elsize = 1;
m_datatypeid = other.m_datatypeid;
return *this;
}

const std::vector<index_type> & dims() const { return m_dims; }

Expand Down
2 changes: 2 additions & 0 deletions libmarch/include/march/mesh/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
*/

#include "march/mesh/Block.hpp"
#include "march/mesh/LookupTable.hpp"
#include "march/mesh/BoundaryData.hpp"

// vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4:
1 change: 1 addition & 0 deletions libmarch/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_executable(test_libmarch
core_types.cpp
core_Buffer.cpp
mesh_LookupTable.cpp
mesh_BoundaryData.cpp
)
target_link_libraries(test_libmarch stdc++ pthread)

Expand Down
42 changes: 42 additions & 0 deletions libmarch/tests/mesh_BoundaryData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2016, Yung-Yu Chen <yyc@solvcon.net>
* BSD 3-Clause License, see LICENSE.txt
*/

#include <gtest/gtest.h>

#include <vector>

#include "march/march.hpp"

using namespace march;
using namespace march::mesh;

TEST(BoundaryDataTest, DefaultConstruction) {
BoundaryData bnd;
EXPECT_EQ(bnd.facn().nbyte(), 0);
EXPECT_EQ(bnd.values().nbyte(), 0);
EXPECT_EQ(bnd.nvalue(), 0);
}

TEST(BoundaryDataTest, UsefulConstruction) {
BoundaryData bnd(5);
EXPECT_EQ((bnd.values<5>().nelem()), 0);
bnd.values<5>() = LookupTable<real_type, 5>(0, 10);
EXPECT_EQ((bnd.values<5>().nelem()), 50);
}

TEST(BoundaryDataTest, InVector) {
std::vector<BoundaryData> bvec;
bvec.push_back(BoundaryData(5));
EXPECT_EQ((bvec[0].values<5>().nelem()), 0);
EXPECT_TRUE(bvec[0].good_shape());
bvec[0].values<5>() = LookupTable<real_type, 5>(0, 10);
EXPECT_EQ((bvec[0].values<5>().nelem()), 50);
EXPECT_FALSE(bvec[0].good_shape());
}

TEST(BoundaryDataTest, SetValue) {
}

// vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4:
48 changes: 37 additions & 11 deletions solvcon/boundcond.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from . import dependency
from .gendata import TypeNameRegistry, TypeWithBinder
dependency.import_module_may_fail('.mesh')
dependency.import_module_may_fail('.march')

class Glue(object):
"""
Expand Down Expand Up @@ -185,11 +186,18 @@ class BCMeta(TypeWithBinder):
"""
Meta class for boundary condition class.
"""

def __new__(cls, name, bases, namespace):
newcls = super(BCMeta, cls).__new__(cls, name, bases, namespace)
bctregy.register(newcls)
return newcls

@property
def BFREL(self):
"""Boundary face relation number."""
return march.BoundaryData.BFREL


# Base/abstract BC type.
class BC(with_metaclass(BCMeta)):
"""
Expand All @@ -199,9 +207,6 @@ class BC(with_metaclass(BCMeta)):
FIXME: provide doctests as examples.
"""

#: Boundary face relation number.
BFREL = 3

#: Holding names as pointers. Used for binder.
_pointers_ = []

Expand Down Expand Up @@ -247,14 +252,6 @@ def __init__(self, bc=None, fpdtype=None):
#: Associated :py:class:`Glue` object gluing two collocated
#: :py:class:`BC` objects.
self.glue = None
#: An :py:class:`numpy.ndarray` as a list of faces. First column
#: is the face index in block. The second column is the face index
#: in bndfcs. The third column is the face index of the related
#: block (if exists).
self.facn = empty((0,self.BFREL), dtype='int32')
#: An :py:class:`numpy.ndarray` for attached (specified) value for
#: each boundary face.
self.value = empty((0,self.nvalue), dtype=self.fpdtype)
else:
bc.cloneTo(self)
super(BC, self).__init__()
Expand All @@ -275,6 +272,35 @@ def nvalue(self):
"""
return len(self.vnames)

@property
def _data(self):
if not hasattr(self, "_data_store"):
self._data_store = march.BoundaryData(self.nvalue)
return self._data_store

@property
def facn(self):
"""
An :py:class:`numpy.ndarray` as a list of faces. First column is the
face index in block. The second column is the face index in bndfcs.
The third column is the face index of the related block (if exists).
"""
return self._data.facn
@facn.setter
def facn(self, arr):
self._data.facn = arr

@property
def value(self):
"""
An :py:class:`numpy.ndarray` for attached (specified) value for each
boundary face.
"""
return self._data.values
@value.setter
def value(self, arr):
self._data.values = arr

def __len__(self):
"""
Return the first shape element of :py:class:`facn`.
Expand Down

0 comments on commit 5f12269

Please sign in to comment.