Commit 02a3cc06 authored by Pries, Jason's avatar Pries, Jason
Browse files

Start of mesh conversion rewrite to enable higher order elements

Reorganize some code into separate shared libraries
parent 8d16fc38
......@@ -17,6 +17,9 @@ include_directories(./src/)
include_directories(./src/Sketch/include/)
include_directories(./src/Mesh/include/)
include_directories(./src/Quadrature/include/)
include_directories(./src/Elements/include/)
include_directories(./src/Matrix/include/)
include_directories(./src/Materials/include/)
include_directories(./src/Physics/include/)
add_subdirectory(./src/)
......
include_directories(./Sketch/)
include_directories(./Mesh/)
include_directories(./Quadrature/)
include_directories(./Elements/)
include_directories(./Matrix/)
include_directories(./Materials/)
include_directories(./Physics/)
add_subdirectory(./Sketch/)
add_subdirectory(./Mesh/)
add_subdirectory(./Quadrature/)
add_subdirectory(./Elements/)
add_subdirectory(./Matrix/)
add_subdirectory(./Materials/)
add_subdirectory(./Physics/)
\ No newline at end of file
PROJECT(Oersted_Elements)
set(SOURCE_FILES
./include/Elements.hpp
./src/Triangle.cpp ./src/Triangle.h
./src/Node.cpp ./src/Node.h
./src/Element.cpp ./src/Element.h
./src/Facet.cpp ./src/Facet.h
../Materials/include/Materials.hpp)
add_library(elements SHARED ${SOURCE_FILES})
target_link_libraries(elements)
\ No newline at end of file
#ifndef OERSTED_ELEMENTS_HP
#define OERSTED_ELEMENTS_HP
#include "../src/Node.h"
#include "../src/Triangle.h"
#endif //OERSTED_ELEMENTS_HPP
//
// Created by p7k on 8/23/17.
//
#include "Element.h"
#ifndef OERSTED_ELEMENT_H
#define OERSTED_ELEMENT_H
#include <cstddef>
template<size_t Dimension>
class Element {
public:
Element() : ID{0} {};
Element(size_t id) : ID{id} {};
size_t const id() const { return ID; };
void id(size_t i) { ID = i; };
protected:
size_t ID;
};
#endif //OERSTED_ELEMENT_H
//
// Created by p7k on 8/23/17.
//
#include "Facet.h"
#ifndef OERSTED_FACET_H
#define OERSTED_FACET_H
#include "Element.h"
class Facet : public Element<2> {
public:
Facet() : Element{} {};
Facet(size_t id) : Element{id} {};
};
#endif //OERSTED_FACET_H
//
// Created by p7k on 8/23/17.
//
#include "Node.h"
#ifndef OERSTED_NODE_H
#define OERSTED_NODE_H
// TODO: Const
#include <cstddef>
#include "Mesh.hpp"
// TODO: Combine different node/point classes from Mesh and Elements
class XY {
public:
XY() : Value{} {};
XY(double_t x, double_t y) : Value{x, y} {};
XY(XY const &v) : Value{v.x(), v.y()} {};
XY(Point const& p) : Value{p.X, p.Y} {};
double_t value(size_t i) const { return Value[i]; };
double_t x() const { return Value[0]; };
void x(double_t val) { Value[0] = val; };
double_t y() const { return Value[1]; };
void y(double_t val) { Value[1] = val; };
protected:
double_t Value[2];
};
#endif //OERSTED_NODE_H
\ No newline at end of file
#include "Triangle.h"
......@@ -3,36 +3,14 @@
#include <vector>
#include "Eigen"
#include "Eigen/Sparse"
#include "Matrix.hpp"
#include "Quadrature.hpp"
#include "MatrixGroup.h"
#include "Node.h"
#include "Facet.h"
// TODO: Curved elements
template<size_t Dimension>
class Element {
public:
Element() : ID{0} {};
Element(size_t id) : ID{id} {};
size_t const id() const { return ID; };
void id(size_t i) { ID = i; };
protected:
size_t ID;
};
class Facet : public Element<2> {
public:
Facet() : Element{} {};
Facet(size_t id) : Element{id} {};
};
template<size_t P>
class Triangle : public Facet {
public:
......@@ -40,18 +18,14 @@ public:
Triangle() : Facet{}, Node{} {};
Triangle(size_t id, std::array<size_t, NumNodes> const &n) : Facet{id} {
for (size_t i = 0; i != NumNodes; ++i) {
Node[i] = n[i];
}
};
Triangle(size_t id, std::array<size_t, NumNodes> const &n) : Facet{id}, Node{n} {};
void node(size_t const &i, size_t n) { Node[i] = n; };
size_t const &node(size_t const &i) const { return Node[i]; };
template<size_t D>
Eigen::Matrix<double, 2, 2> jacobian(std::vector<XY> const &nodes) const; // TODO: Accept Eigen::Matrix<double,2,2> as input
Oe::Matrix<double_t, 2, 2> jacobian(std::vector<XY> const &nodes) const; // TODO: Accept Eigen::Matrix<double,2,2> as input
template<size_t Q>
void determinant(DiagonalMatrixGroup &mat, std::vector<XY> const &nodes) const;
......@@ -66,38 +40,23 @@ public:
std::vector<XY> quadrature_points(std::vector<XY> const& nodes) const;
protected:
size_t Node[NumNodes]; // TODO: std::array instead?
std::array<size_t, NumNodes> Node;
};
/*
template<>
template<>
inline Eigen::Matrix<double, 2, 2> Triangle<1>::jacobian<0>(std::vector<XY> const &nodes) const {
Eigen::Matrix<double, 2, 2> value;
value(0, 0) = 1.0;
value(0, 1) = 0.0;
value(1, 0) = 0.0;
value(1, 1) = 1.0;
return value;
}
*/
template<>
template<>
inline Eigen::Matrix<double, 2, 2> Triangle<1>::jacobian<1>(std::vector<XY> const &nodes) const {
Eigen::Matrix<double, 2, 2> value;
inline Oe::Matrix<double_t, 2, 2> Triangle<1>::jacobian<1>(std::vector<XY> const &nodes) const {
Oe::Matrix<double_t, 2, 2> value;
XY const &p0 = nodes[Node[0]];
XY const &p1 = nodes[Node[1]];
XY const &p2 = nodes[Node[2]];
double xx = p0.x() - p2.x();
double xy = p0.y() - p2.y();
double yx = p1.x() - p2.x();
double yy = p1.y() - p2.y();
double det = xx * yy - xy * yx;
double_t xx = p0.x() - p2.x();
double_t xy = p0.y() - p2.y();
double_t yx = p1.x() - p2.x();
double_t yy = p1.y() - p2.y();
double_t det = xx * yy - xy * yx;
value(0, 0) = yy / det;
value(0, 1) = -xy / det;
......@@ -115,18 +74,19 @@ void Triangle<1>::determinant(DiagonalMatrixGroup &mat, std::vector<XY> const &n
XY const &p1 = nodes[Node[1]];
XY const &p2 = nodes[Node[2]];
double xx = p0.x() - p2.x();
double xy = p0.y() - p2.y();
double yx = p1.x() - p2.x();
double yy = p1.y() - p2.y();
double_t xx = p0.x() - p2.x();
double_t xy = p0.y() - p2.y();
double_t yx = p1.x() - p2.x();
double_t yy = p1.y() - p2.y();
mat(i)(ID) = xx * yy - xy * yx;
}
}
// TODO? Return Triplets instead of modifying matrix directly
template<>
template<size_t Q>
//void Triangle<1>::basis(SparseMatrixGroup<TriangleQuadrature<Q>::size> &mat, std::vector<XY> const &nodes) const {
void Triangle<1>::basis(SparseMatrixGroup &mat, std::vector<XY> const &nodes) const {
for (size_t i = 0; i != TriangleQuadrature<Q>::size; ++i) {
mat(i, Node[0], ID) += TriangleQuadrature<Q>::a[i];
......
PROJECT(Oersted_Materials)
set(SOURCE_FILES
./include/Materials.hpp
./src/PhysicsConstants.h
./src/MaterialProperties.cpp ./src/MaterialProperties.h
)
add_library(materials SHARED ${SOURCE_FILES})
target_link_libraries(materials)
\ No newline at end of file
#ifndef OERSTED_MATERIALS_HPP
#define OERSTED_MATERIALS_HPP
#include "../src/PhysicsConstants.h"
#include "../src/MaterialProperties.h"
#endif //OERSTED_MATERIALS_HPP
......@@ -7,7 +7,7 @@
#include <utility>
#include <vector>
#include "Eigen"
#include "Matrix.hpp"
#include "PhysicsConstants.h"
......@@ -15,14 +15,14 @@ class MagneticMaterialInterface {
public:
virtual ~MagneticMaterialInterface(){};
virtual void h_from_b(std::vector<size_t> const &index, Eigen::ArrayXd &Fx, Eigen::ArrayXd &Fy, Eigen::ArrayXd &dFxdx, Eigen::ArrayXd &dFydy, Eigen::ArrayXd &dFxdy) = 0;
virtual void h_from_b(std::vector<size_t> const &index, Oe::ArrayXd &Fx, Oe::ArrayXd &Fy, Oe::ArrayXd &dFxdx, Oe::ArrayXd &dFydy, Oe::ArrayXd &dFxdy) = 0;
};
class LinearIsotropicMagneticMaterial : public MagneticMaterialInterface {
public:
LinearIsotropicMagneticMaterial(double relative_permeability) : Reluctivity(1.0 / (mu_0 * relative_permeability)) {};
void h_from_b(std::vector<size_t> const &index, Eigen::ArrayXd &Fx, Eigen::ArrayXd &Fy, Eigen::ArrayXd &dFxdx, Eigen::ArrayXd &dFydy, Eigen::ArrayXd &dFxdy) override {
void h_from_b(std::vector<size_t> const &index, Oe::ArrayXd &Fx, Oe::ArrayXd &Fy, Oe::ArrayXd &dFxdx, Oe::ArrayXd &dFydy, Oe::ArrayXd &dFxdy) override {
for(size_t const &i : index) {
Fx(i) *= Reluctivity;
Fy(i) *= Reluctivity;
......@@ -74,7 +74,7 @@ public:
MSaturation = (s[0] * BSaturation + s[1]) * BSaturation + s[2];
}
void h_from_b(std::vector<size_t> const &index, Eigen::ArrayXd &Fx, Eigen::ArrayXd &Fy, Eigen::ArrayXd &dFxdx, Eigen::ArrayXd &dFydy, Eigen::ArrayXd &dFxdy) override {
void h_from_b(std::vector<size_t> const &index, Oe::ArrayXd &Fx, Oe::ArrayXd &Fy, Oe::ArrayXd &dFxdx, Oe::ArrayXd &dFydy, Oe::ArrayXd &dFxdy) override {
for(size_t const &i : index) {
const double_t &Bx = Fx(i);
const double_t &By = Fy(i);
......
PROJECT(Oersted_Matrix)
set(SOURCE_FILES
./include/Matrix.hpp
./src/Alias.h
./src/MatrixGroup.cpp ./src/MatrixGroup.h
./src/SparseMatrixGroup.cpp ./src/SparseMatrixGroup.h
./src/DiagonalMatrixGroup.cpp ./src/DiagonalMatrixGroup.h
./src/DerivativeMatrixGroup.cpp ./src/DerivativeMatrixGroup.h
)
add_library(matrix SHARED ${SOURCE_FILES})
target_link_libraries(matrix)
\ No newline at end of file
#ifndef OERSTED_ALIAS_H
#define OERSTED_ALIAS_H
#include "./Alias/EigenAlias.h"
#endif //OERSTED_ALIAS_H
#include "DerivativeMatrixGroup.h"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment