Page MenuHomec4science

mesh1d.hpp
No OneTemporary

File Metadata

Created
Mon, Jul 1, 20:07

mesh1d.hpp

/*-------------------------------------------------------
- Module : reactmicp/meshes
- File : mesh1d.hpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#ifndef SPECMICP_REACTMICP_MESH_MESH1D_HPP
#define SPECMICP_REACTMICP_MESH_MESH1D_HPP
#include "reactmicp/common.hpp"
#include "boost/range/irange.hpp"
#include <iostream>
namespace specmicp {
namespace reactmicp {
namespace mesh {
using range_t = boost::iterator_range<boost::range_detail::integer_iterator<ind_t>>;
//! a one dimensional mesh
class Mesh1D
{
public:
Mesh1D(ind_t elements, double dx, double cross_section):
m_dx(dx), m_crosssection(cross_section), m_nel(elements)
{}
const int nen = 2;
ind_t nel() {return m_nel;}
ind_t nnodes() {return m_nel+1;}
ind_t get_node(ind_t element, ind_t index) {
assert(index < nen);
return element+index;}
double get_dx(ind_t element) {return m_dx;}
double crosssection() { return m_crosssection;}
double cell_volume(ind_t node) {
if (node ==0 or node == nnodes()-1) return m_dx*m_crosssection/2;
else return m_dx*m_crosssection;
}
range_t range_elements() {return boost::irange(0, nel());}
range_t range_nodes() {return boost::irange(0, nnodes());}
range_t range_nen() {return boost::irange(0, nen);}
private:
double m_dx;
double m_crosssection;
ind_t m_nel;
};
} // end namespace mesh
} // end namespace reactmicp
} // end namespace specmicp
#endif // SPECMICP_REACTMICP_MESH_MESH1D_HPP

Event Timeline