IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Augusto Alves Junior
corsika
Commits
a77d5fce
Commit
a77d5fce
authored
6 years ago
by
Maximilian Reininghaus
Browse files
Options
Downloads
Patches
Plain Diff
defined/fixed some operators for (Quantity-)Vectors
parent
0aa6a48d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/Geometry/QuantityVector.h
+49
-3
49 additions, 3 deletions
Framework/Geometry/QuantityVector.h
Framework/Geometry/Vector.h
+52
-0
52 additions, 0 deletions
Framework/Geometry/Vector.h
with
101 additions
and
3 deletions
Framework/Geometry/QuantityVector.h
+
49
−
3
View file @
a77d5fce
...
@@ -5,16 +5,19 @@
...
@@ -5,16 +5,19 @@
#include
<Eigen/Dense>
#include
<Eigen/Dense>
#include
<iostream>
#include
<iostream>
#include
<utility>
template
<
typename
dim
>
template
<
typename
dim
>
class
QuantityVector
class
QuantityVector
{
{
protected:
protected:
using
Quantity
=
phys
::
units
::
quantity
<
dim
,
double
>
;
using
Quantity
=
phys
::
units
::
quantity
<
dim
,
double
>
;
using
QuantitySquared
=
decltype
(
Quantity
(
phys
::
units
::
detail
::
magnitude_tag
,
0
)
*
Quantity
(
phys
::
units
::
detail
::
magnitude_tag
,
0
));
//
using QuantitySquared = decltype(
std::declval<Quantity>() * std::declval<Quantity>(
));
public:
public:
Eigen
::
Vector3d
eVector
;
Eigen
::
Vector3d
eVector
;
typedef
dim
dimension
;
QuantityVector
(
Quantity
a
,
Quantity
b
,
Quantity
c
)
:
QuantityVector
(
Quantity
a
,
Quantity
b
,
Quantity
c
)
:
eVector
{
a
.
magnitude
(),
b
.
magnitude
(),
c
.
magnitude
()}
eVector
{
a
.
magnitude
(),
b
.
magnitude
(),
c
.
magnitude
()}
...
@@ -38,6 +41,7 @@ public:
...
@@ -38,6 +41,7 @@ public:
auto
squaredNorm
()
const
auto
squaredNorm
()
const
{
{
using
QuantitySquared
=
decltype
(
std
::
declval
<
Quantity
>
()
*
std
::
declval
<
Quantity
>
());
return
QuantitySquared
(
phys
::
units
::
detail
::
magnitude_tag
,
eVector
.
squaredNorm
());
return
QuantitySquared
(
phys
::
units
::
detail
::
magnitude_tag
,
eVector
.
squaredNorm
());
}
}
...
@@ -51,14 +55,56 @@ public:
...
@@ -51,14 +55,56 @@ public:
return
QuantityVector
<
dim
>
(
eVector
-
pQVec
.
eVector
);
return
QuantityVector
<
dim
>
(
eVector
-
pQVec
.
eVector
);
}
}
//auto operator*(
template
<
typename
ScalarDim
>
auto
operator
*
(
phys
::
units
::
quantity
<
ScalarDim
,
double
>
const
p
)
const
{
return
QuantityVector
<
typename
phys
::
units
::
detail
::
Product
<
ScalarDim
,
dim
,
double
,
double
>::
dimension_type
>
(
eVector
*
p
.
magnitude
());
// TODO: this function does not work if the result is dimensionless, as
// dimensionless quantities are "cast" back to plain old double in PhysUnits.
// Either change PhysUnits, or cover this case with a template specialization?
}
auto
operator
*
(
double
const
p
)
const
{
return
QuantityVector
<
dim
>
(
eVector
*
p
);
}
auto
&
operator
*=
(
double
const
p
)
{
eVector
*=
p
;
return
*
this
;
}
auto
&
operator
+=
(
QuantityVector
<
dim
>
const
&
pQVec
)
{
eVector
+=
pQVec
.
eVector
;
return
*
this
;
}
auto
&
operator
-=
(
QuantityVector
<
dim
>
const
&
pQVec
)
{
eVector
-=
pQVec
.
eVector
;
return
*
this
;
}
auto
&
operator
-
()
const
{
return
QuantityVector
<
dim
>
(
-
eVector
);
}
auto
normalized
()
const
{
return
(
*
this
)
*
(
1
/
norm
());
}
};
};
template
<
typename
dim
>
template
<
typename
dim
>
auto
&
operator
<<
(
std
::
ostream
&
os
,
QuantityVector
<
dim
>
qv
)
auto
&
operator
<<
(
std
::
ostream
&
os
,
QuantityVector
<
dim
>
qv
)
{
{
using
Quantity
=
phys
::
units
::
quantity
<
dim
,
double
>
;
os
<<
'('
<<
qv
.
eVector
(
0
)
<<
' '
<<
qv
.
eVector
(
1
)
<<
' '
<<
qv
.
eVector
(
2
)
os
<<
'('
<<
qv
.
eVector
(
0
)
<<
' '
<<
qv
.
eVector
(
1
)
<<
' '
<<
qv
.
eVector
(
2
)
<<
") "
<<
phys
::
units
::
to_unit_symbol
(
phys
::
units
::
quantity
<
dim
,
double
>
(
));
<<
") "
<<
phys
::
units
::
to_unit_symbol
<
dim
,
double
>
(
Quantity
(
phys
::
units
::
detail
::
magnitude_tag
,
1
));
return
os
;
return
os
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Framework/Geometry/Vector.h
+
52
−
0
View file @
a77d5fce
...
@@ -71,6 +71,58 @@ public:
...
@@ -71,6 +71,58 @@ public:
return
parallelProjectionOnto
<
dim2
>
(
pVec
,
*
BaseVector
<
dim
>::
cs
);
return
parallelProjectionOnto
<
dim2
>
(
pVec
,
*
BaseVector
<
dim
>::
cs
);
}
}
auto
operator
+
(
Vector
<
dim
>
const
&
pVec
)
const
{
auto
const
components
=
getComponents
(
*
BaseVector
<
dim
>::
cs
)
+
pVec
.
getComponents
(
*
BaseVector
<
dim
>::
cs
);
return
Vector
<
dim
>
(
*
BaseVector
<
dim
>::
cs
,
components
);
}
auto
operator
-
(
Vector
<
dim
>
const
&
pVec
)
const
{
auto
const
components
=
getComponents
()
-
pVec
.
getComponents
(
*
BaseVector
<
dim
>::
cs
);
return
Vector
<
dim
>
(
*
BaseVector
<
dim
>::
cs
,
components
);
}
auto
&
operator
*=
(
double
const
p
)
{
BaseVector
<
dim
>::
qVector
*=
p
;
return
*
this
;
}
template
<
typename
ScalarDim
>
auto
operator
*
(
phys
::
units
::
quantity
<
ScalarDim
,
double
>
const
p
)
const
{
using
res_dim
=
typename
decltype
(
BaseVector
<
dim
>::
qVector
*
p
)
::
dimension
;
return
Vector
<
res_dim
>
(
*
BaseVector
<
dim
>::
cs
,
BaseVector
<
dim
>::
qVector
*
p
);
}
auto
operator
*
(
double
const
p
)
const
{
return
Vector
<
dim
>
(
*
BaseVector
<
dim
>::
cs
,
BaseVector
<
dim
>::
qVector
*
p
);
}
auto
&
operator
+=
(
Vector
<
dim
>
const
&
pVec
)
{
BaseVector
<
dim
>::
qVector
+=
pVec
.
getComponents
(
*
BaseVector
<
dim
>::
cs
);
return
*
this
;
}
auto
&
operator
-=
(
Vector
<
dim
>
const
&
pVec
)
{
BaseVector
<
dim
>::
qVector
-=
pVec
.
getComponents
(
*
BaseVector
<
dim
>::
cs
);
return
*
this
;
}
auto
&
operator
-
()
const
{
return
Vector
<
dim
>
(
*
BaseVector
<
dim
>::
cs
,
-
BaseVector
<
dim
>::
qVector
);
}
auto
normalized
()
const
{
return
(
*
this
)
*
(
1
/
norm
());
}
//~ template <typename dim2>
//~ template <typename dim2>
//~ auto operator*(Vector<dim2> const& pVec)
//~ auto operator*(Vector<dim2> const& pVec)
//~ {
//~ {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment