BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_append.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California,
4
* through Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
18
19
#ifndef FN_APPEND_HPP
20
#define FN_APPEND_HPP
21
22
#ifdef BELFEM_BLAZE
23
#include <algorithm>
// for std::copy
24
#endif
25
#include "
cl_Vector.hpp
"
26
27
namespace
belfem
28
{
43
template
<
typename
T >
44
void
45
append
(
Vector< T >
& aA,
Vector< T >
& aB )
46
{
47
#ifdef BELFEM_ARMADILLO
48
aA.
vector_data
() = arma::join_cols( aA.
vector_data
(), aB.
vector_data
() );
49
50
#elif BELFEM_BLAZE
51
// grow in place ( resize with preserve keeps the existing entries ),
52
// then copy aB into the new tail; DynamicVector has no insert()
53
BELFEM_ASSERT
( &aA != &aB,
"append: aA and aB must not be the same vector"
);
54
55
const
size_t
tOldLength = aA.
length
();
56
57
aA.
vector_data
().resize( tOldLength + aB.
length
(),
true
);
58
59
std::copy( aB.
data
(), aB.
data
() + aB.
length
(), aA.
data
() + tOldLength );
60
61
#else
62
// Store original data in temporary container
63
Vector< T >
tTempA = aA;
64
aA.
set_size
( tTempA.
length
() + aB.
length
() );
65
66
index_t
tCount = 0;
67
for
( T tVal : tTempA )
68
{
69
aA( tCount++ ) = tVal;
70
}
71
for
( T tVal : aB )
72
{
73
aA( tCount++ ) = tVal;
74
}
75
#endif
76
}
77
78
template
<
typename
T >
79
void
80
append
(
Vector< T >
& aA,
const
Vector< T >
& aB )
81
{
82
#ifdef BELFEM_ARMADILLO
83
aA.
vector_data
() = arma::join_cols( aA.
vector_data
(), aB.
vector_data
() );
84
85
#elif BELFEM_BLAZE
86
// grow in place ( resize with preserve keeps the existing entries ),
87
// then copy aB into the new tail; DynamicVector has no insert()
88
BELFEM_ASSERT
( &aA != &aB,
"append: aA and aB must not be the same vector"
);
89
90
const
size_t
tOldLength = aA.
length
();
91
92
aA.
vector_data
().resize( tOldLength + aB.
length
(),
true
);
93
94
std::copy( aB.
data
(), aB.
data
() + aB.
length
(), aA.
data
() + tOldLength );
95
96
#else
97
// Store original data in temporary container
98
Vector< T >
tTempA = aA;
99
aA.
set_size
( tTempA.
length
() + aB.
length
() );
100
101
index_t
tCount = 0;
102
for
( T tVal : tTempA )
103
{
104
aA( tCount++ ) = tVal;
105
}
106
for
( T tVal : aB )
107
{
108
aA( tCount++ ) = tVal;
109
}
110
#endif
111
}
112
113
}
// namespace belfem
114
115
#endif
//FN_APPEND_HPP
BELFEM_ASSERT
#define BELFEM_ASSERT(aCheck,...)
Definition
assert.hpp:244
cl_Vector.hpp
belfem::Vector
Column vector.
Definition
cl_BZ_Vector.hpp:41
belfem::Vector::data
T * data()
expose the underlying raw pointer ( writable version )
Definition
cl_AR_Vector.hpp:182
belfem::Vector::set_size
void set_size(const size_t aNumRows)
change the size of the vector
Definition
cl_AR_Vector.hpp:237
belfem::Vector::length
size_t length() const
get the length of the vector
Definition
cl_AR_Vector.hpp:257
belfem::Vector::vector_data
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition
cl_AR_Vector.hpp:204
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::append
void append(Cell< T > &aA, const Cell< T > &aB)
Definition
cl_Cell.hpp:537
belfem::index_t
uint32_t index_t
Definition
typedefs.hpp:52
src
linalg
fn_append.hpp
Generated by
1.18.0