Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Dmitri Naumov
ogs
Commits
0d2f9524
Commit
0d2f9524
authored
7 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[BL] Added a class computing subdivisions for fixed number of sub divs.
parent
89dd4b9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/Subdivision.cpp
+70
-0
70 additions, 0 deletions
BaseLib/Subdivision.cpp
BaseLib/Subdivision.h
+29
-2
29 additions, 2 deletions
BaseLib/Subdivision.h
with
99 additions
and
2 deletions
BaseLib/Subdivision.cpp
0 → 100644
+
70
−
0
View file @
0d2f9524
/**
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include
"Subdivision.h"
#include
<BaseLib/Error.h>
namespace
BaseLib
{
GradualSubdivision
::
GradualSubdivision
(
const
double
L
,
const
double
dL0
,
const
double
max_dL
,
const
double
multiplier
)
:
_length
(
L
),
_dL0
(
dL0
),
_max_dL
(
max_dL
),
_multiplier
(
multiplier
)
{
// Check if accumulated subdivisions can ever sum up to length.
// Cf. geometric series formula.
if
(
multiplier
<
1.0
&&
dL0
/
(
1.0
-
multiplier
)
<
L
)
{
OGS_FATAL
(
"Using dL0=%g and multiplier=%g the generated subdivisions can not "
"sum up to a total length of %g."
,
dL0
,
multiplier
,
L
);
}
}
GradualSubdivisionFixedNum
::
GradualSubdivisionFixedNum
(
const
double
L
,
const
std
::
size_t
num_subdivisions
,
const
double
multiplier
)
:
_length
{
L
},
_num_subdivisions
{
num_subdivisions
},
_multiplier
{
multiplier
}
{
}
std
::
vector
<
double
>
GradualSubdivisionFixedNum
::
operator
()()
const
{
std
::
vector
<
double
>
subdivisions
;
subdivisions
.
reserve
(
_num_subdivisions
+
1
);
subdivisions
.
push_back
(
0.0
);
auto
const
q
=
_multiplier
;
if
(
q
==
1.0
)
{
double
const
dx
=
_length
/
_num_subdivisions
;
for
(
std
::
size_t
i
=
1
;
i
<
_num_subdivisions
;
++
i
)
{
subdivisions
.
push_back
(
dx
*
i
);
}
}
else
{
// compute initial subdivision size
auto
const
a
=
_length
*
(
q
-
1.0
)
/
(
std
::
pow
(
q
,
_num_subdivisions
)
-
1.0
);
double
qi
=
q
;
// q^i
for
(
std
::
size_t
i
=
1
;
i
<
_num_subdivisions
;
++
i
)
{
subdivisions
.
push_back
(
a
*
(
qi
-
1.0
)
/
(
q
-
1.0
));
qi
*=
q
;
}
}
subdivisions
.
push_back
(
_length
);
return
subdivisions
;
}
}
// namespace BaseLib
This diff is collapsed.
Click to expand it.
BaseLib/Subdivision.h
+
29
−
2
View file @
0d2f9524
...
...
@@ -10,6 +10,7 @@
#pragma once
#include
<cmath>
#include
<vector>
namespace
BaseLib
{
...
...
@@ -73,8 +74,7 @@ public:
const
double
L
,
const
double
dL0
,
const
double
max_dL
,
const
double
multiplier
)
:
_length
(
L
),
_dL0
(
dL0
),
_max_dL
(
max_dL
),
_multiplier
(
multiplier
)
{}
const
double
multiplier
);
/// Returns a vector of subdivided points
std
::
vector
<
double
>
operator
()()
const
override
...
...
@@ -106,4 +106,31 @@ private:
const
double
_multiplier
;
};
/**
* Gradual subdivision operator with a constant _multiplier.
*
* In this class the number of subdivisions is known a priori.
*/
class
GradualSubdivisionFixedNum
:
public
ISubdivision
{
public:
/**
* Constructor
* @param L total length to be subdivided
* @param num_subdivisions number of subdivisions to generate
* @param multiplier multiplier to cell length
*/
GradualSubdivisionFixedNum
(
const
double
L
,
const
std
::
size_t
num_subdivisions
,
const
double
multiplier
);
/// Returns a vector of subdivided points
std
::
vector
<
double
>
operator
()()
const
override
;
private:
const
double
_length
;
const
std
::
size_t
_num_subdivisions
;
const
double
_multiplier
;
};
}
// BaseLib
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