1 /*
2 HMat-OSS (HMatrix library, open source software)
3
4 Copyright (C) 2014-2015 Airbus Group SAS
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 http://github.com/jeromerobert/hmat-oss
21 */
22
23 /*! \file
24 \ingroup HMatrix
25 \brief Geometric coordinates.
26 */
27 #include "coordinates.hpp"
28 #include "common/my_assert.h"
29 #include <cstring>
30
31 namespace hmat {
init(double * coord,unsigned * span_offsets,unsigned * spans)32 void DofCoordinates::init(double* coord, unsigned* span_offsets, unsigned* spans)
33 {
34 if (ownsMemory_) {
35 v_ = new double[size_ * dimension_];
36 std::memcpy(v_, coord, sizeof(double) * size_ * dimension_);
37 if(span_offsets) {
38 spanOffsets_ = new unsigned[numberOfDof_];
39 std::memcpy(spanOffsets_, span_offsets, sizeof(unsigned) * numberOfDof_);
40 unsigned n = span_offsets[numberOfDof_-1];
41 spans_ = new unsigned[n];
42 std::memcpy(spans_, spans, sizeof(unsigned) * n);
43 } else {
44 spanOffsets_ = NULL;
45 spans_ = NULL;
46 }
47 } else {
48 v_ = coord;
49 spanOffsets_ = span_offsets;
50 spans_ = spans;
51 }
52 if(spanOffsets_) {
53 spanAABBs_ = new double[numberOfDof_ * dimension_ * 2];
54 double * aabb = spanAABBs_;
55 for(int dof = 0; dof < numberOfDof_; dof++) {
56 unsigned offset = dof == 0 ? 0 : spanOffsets_[dof - 1];
57 int n = spanSize(dof);
58 double * v = v_ + spans_[offset] * dimension_;
59 memcpy(aabb, v, dimension_ * sizeof(double));
60 memcpy(aabb + dimension_, v, dimension_ * sizeof(double));
61 for(int i = 1; i < n; i++) {
62 v = v_ + spans_[offset + i] * dimension_;
63 for(int dim = 0; dim < dimension_; dim++) {
64 aabb[dim] = std::min(aabb[dim], v[dim]);
65 aabb[dim + dimension_] = std::max(aabb[dim + dimension_], v[dim]);
66 }
67 }
68 aabb += 2 * dimension_;
69 }
70 } else {
71 spanAABBs_ = NULL;
72 }
73 }
74
DofCoordinates(double * coord,unsigned dim,unsigned size,bool ownsMemory,unsigned number_of_dof,unsigned * span_offsets,unsigned * spans)75 DofCoordinates::DofCoordinates(double* coord, unsigned dim, unsigned size, bool ownsMemory,
76 unsigned number_of_dof, unsigned * span_offsets, unsigned * spans)
77 : dimension_(dim)
78 , size_(size)
79 , ownsMemory_(ownsMemory), numberOfDof_(number_of_dof)
80 {
81 init(coord, span_offsets, spans);
82 }
83
DofCoordinates(const DofCoordinates & other)84 DofCoordinates::DofCoordinates(const DofCoordinates& other)
85 : dimension_(other.dimension_)
86 , size_(other.size_)
87 , ownsMemory_(true), numberOfDof_(other.numberOfDof_)
88 {
89 init(other.v_, other.spanOffsets_, other.spans_);
90 }
91
~DofCoordinates()92 DofCoordinates::~DofCoordinates()
93 {
94 if (ownsMemory_) {
95 delete[] v_;
96 if(spanOffsets_ != NULL) {
97 delete[] spanOffsets_;
98 delete[] spans_;
99 }
100 }
101 if(spanOffsets_ != NULL)
102 delete[] spanAABBs_;
103 }
104
size() const105 int DofCoordinates::size() const {
106 HMAT_ASSERT(spanOffsets_ == NULL);
107 return size_;
108 }
109
get(int i,int j)110 double& DofCoordinates::get(int i, int j) {
111 HMAT_ASSERT(spanOffsets_ == NULL);
112 return v_[j * dimension_ + i];
113 }
114
get(int i,int j) const115 const double& DofCoordinates::get(int i, int j) const {
116 HMAT_ASSERT(spanOffsets_ == NULL);
117 return v_[j * dimension_ + i];
118 }
119
120 } // end namespace hmat
121
122