Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
19a9f39f
Commit
19a9f39f
authored
Aug 26, 2019
by
niklas.baumgarten
Browse files
added 1D problems
parent
38acae70
Changes
3
Hide whitespace changes
Inline
Side-by-side
mlmc/src/StochasticFields.C
View file @
19a9f39f
#include
"StochasticFields.h"
class
StochasticFieldPair1D
:
public
StochasticFieldPair
{
int
N
;
CirculantEmbedding1D
*
circEmbedding1D
;
vector
<
double
>
fieldf
;
vector
<
double
>
fieldc
;
public:
explicit
StochasticFieldPair1D
(
int
l
)
:
StochasticFieldPair
()
{
// Todo rmv Hack!
N
=
(
int
)
pow
(
2
,
l
);
circEmbedding1D
=
new
CirculantEmbedding1D
(
N
);
}
~
StochasticFieldPair1D
()
{
delete
circEmbedding1D
;
}
void
generate
()
override
{
if
(
PPM
->
master
())
{
PPM
->
BroadcastInt
(
N
);
fieldf
=
circEmbedding1D
->
getFieldf
();
for
(
double
&
cell_value
:
fieldf
)
{
PPM
->
BroadcastDouble
(
cell_value
);
}
fieldc
=
circEmbedding1D
->
generateInterpolField
(
fieldf
);
for
(
double
&
cell_value
:
fieldc
)
{
PPM
->
BroadcastDouble
(
cell_value
);
}
}
else
{
N
=
PPM
->
BroadcastInt
();
fieldf
.
resize
(
N
);
for
(
double
&
cell_value
:
fieldf
)
cell_value
=
PPM
->
BroadcastDouble
();
fieldc
.
resize
(
N
/
2
);
for
(
double
&
cell_value
:
fieldc
)
cell_value
=
PPM
->
BroadcastDouble
();
}
}
double
getFineValue
(
const
Point
&
z
)
const
override
{
int
i
=
floor
(
z
[
0
]
*
N
);
return
fieldf
[
i
];
}
double
getCoarseValue
(
const
Point
&
z
)
const
override
{
int
i
=
floor
(
z
[
0
]
*
N
/
2
);
return
fieldc
[
i
];
}
pair
<
double
,
double
>
getFineMinMaxValues
()
const
override
{
double
max
=
0
.
0
;
double
min
=
infty
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
if
(
fieldf
[
i
]
>
max
)
max
=
fieldf
[
i
];
if
(
fieldf
[
i
]
<
min
)
min
=
fieldf
[
i
];
}
return
{
min
,
max
};
}
pair
<
double
,
double
>
getCoarseMinMaxValues
()
const
override
{
double
max
=
0
.
0
;
double
min
=
infty
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
if
(
fieldc
[
i
]
>
max
)
max
=
fieldc
[
i
];
if
(
fieldc
[
i
]
<
min
)
min
=
fieldc
[
i
];
}
return
{
min
,
max
};
}
};
class
StochasticFieldPair2D
:
public
StochasticFieldPair
{
int
N1
;
int
N2
;
CirculantEmbedding2D
*
circEmbedding2D
;
std
::
vector
<
std
::
vector
<
double
>>
field
_
f
;
std
::
vector
<
std
::
vector
<
double
>>
field
_
c
;
std
::
vector
<
std
::
vector
<
double
>>
fieldf
;
std
::
vector
<
std
::
vector
<
double
>>
fieldc
;
public:
// explicit StochasticFieldPair2D(int l, const Mesh &coarseMesh, const Mesh &fineMesh) :
// StochasticFieldPair(coarseMesh, fineMesh) {
// // Todo rmv Hack!
// N1 = (int) pow(2, l);
// N2 = N1;
// circEmbedding2D = new CirculantEmbedding2D(N1, N2);
// }
explicit
StochasticFieldPair2D
(
int
l
)
:
StochasticFieldPair
()
{
// Todo rmv Hack!
N1
=
(
int
)
pow
(
2
,
l
);
...
...
@@ -28,28 +87,28 @@ public:
if
(
PPM
->
master
())
{
PPM
->
BroadcastInt
(
N1
);
PPM
->
BroadcastInt
(
N2
);
field
_
f
=
circEmbedding2D
->
get
_f
ieldf
();
fieldf
=
circEmbedding2D
->
get
F
ieldf
();
for
(
int
i
=
0
;
i
<
N2
;
i
++
)
for
(
int
j
=
0
;
j
<
N1
;
j
++
)
PPM
->
BroadcastDouble
(
field
_
f
[
i
][
j
]);
field
_
c
=
circEmbedding2D
->
generate
_i
nterpol
_f
ield
(
field
_
f
);
PPM
->
BroadcastDouble
(
fieldf
[
i
][
j
]);
fieldc
=
circEmbedding2D
->
generate
I
nterpol
F
ield
(
fieldf
);
for
(
int
i
=
0
;
i
<
N2
/
2
;
i
++
)
for
(
int
j
=
0
;
j
<
N1
/
2
;
j
++
)
PPM
->
BroadcastDouble
(
field
_
c
[
i
][
j
]);
PPM
->
BroadcastDouble
(
fieldc
[
i
][
j
]);
}
else
{
N1
=
PPM
->
BroadcastInt
();
N2
=
PPM
->
BroadcastInt
();
field
_
f
.
resize
(
N2
);
fieldf
.
resize
(
N2
);
for
(
int
i
=
0
;
i
<
N2
;
i
++
)
{
field
_
f
[
i
].
resize
(
N1
);
fieldf
[
i
].
resize
(
N1
);
for
(
int
j
=
0
;
j
<
N1
;
j
++
)
field
_
f
[
i
][
j
]
=
PPM
->
BroadcastDouble
();
fieldf
[
i
][
j
]
=
PPM
->
BroadcastDouble
();
}
field
_
c
.
resize
(
N2
/
2
);
fieldc
.
resize
(
N2
/
2
);
for
(
int
i
=
0
;
i
<
N2
/
2
;
i
++
)
{
field
_
c
[
i
].
resize
(
N1
/
2
);
fieldc
[
i
].
resize
(
N1
/
2
);
for
(
int
j
=
0
;
j
<
N1
/
2
;
j
++
)
field
_
c
[
i
][
j
]
=
PPM
->
BroadcastDouble
();
fieldc
[
i
][
j
]
=
PPM
->
BroadcastDouble
();
}
}
}
...
...
@@ -57,13 +116,13 @@ public:
double
getFineValue
(
const
Point
&
z
)
const
override
{
int
i
=
floor
(
z
[
0
]
*
N2
);
int
j
=
floor
(
z
[
1
]
*
N1
);
return
field
_
f
[
i
][
j
];
return
fieldf
[
i
][
j
];
}
double
getCoarseValue
(
const
Point
&
z
)
const
override
{
int
i
=
floor
(
z
[
0
]
*
N2
/
2
);
int
j
=
floor
(
z
[
1
]
*
N1
/
2
);
return
field
_
c
[
i
][
j
];
return
fieldc
[
i
][
j
];
}
pair
<
double
,
double
>
getFineMinMaxValues
()
const
override
{
...
...
@@ -71,8 +130,8 @@ public:
double
min
=
infty
;
for
(
int
i
=
0
;
i
<
N2
;
i
++
)
{
for
(
int
j
=
0
;
j
<
N1
;
j
++
)
{
if
(
field
_
f
[
i
][
j
]
>
max
)
max
=
field
_
f
[
i
][
j
];
if
(
field
_
f
[
i
][
j
]
<
min
)
min
=
field
_
f
[
i
][
j
];
if
(
fieldf
[
i
][
j
]
>
max
)
max
=
fieldf
[
i
][
j
];
if
(
fieldf
[
i
][
j
]
<
min
)
min
=
fieldf
[
i
][
j
];
}
}
return
{
min
,
max
};
...
...
@@ -83,21 +142,19 @@ public:
double
min
=
infty
;
for
(
int
i
=
0
;
i
<
N2
/
2
;
i
++
)
{
for
(
int
j
=
0
;
j
<
N1
/
2
;
j
++
)
{
if
(
field
_
c
[
i
][
j
]
>
max
)
max
=
field
_
c
[
i
][
j
];
if
(
field
_
c
[
i
][
j
]
<
min
)
min
=
field
_
c
[
i
][
j
];
if
(
fieldc
[
i
][
j
]
>
max
)
max
=
fieldc
[
i
][
j
];
if
(
fieldc
[
i
][
j
]
<
min
)
min
=
fieldc
[
i
][
j
];
}
}
return
{
min
,
max
};
}
};
StochasticFieldPair
*
getStochasticFieldPair
(
int
l
,
Meshes
&
meshes
,
string
StochasticField
)
{
if
(
StochasticField
.
empty
())
ReadConfig
(
Settings
,
"StochasticField"
,
StochasticField
);
if
(
StochasticField
==
"LogNormal2D"
)
// return new StochasticFieldPair2D(l, meshes[l - 1], meshes[l]);
StochasticFieldPair
*
getStochasticFieldPair
(
int
l
,
int
dim
,
string
fieldName
)
{
if
(
dim
==
1
)
return
new
StochasticFieldPair1D
(
l
);
else
if
(
dim
==
2
)
return
new
StochasticFieldPair2D
(
l
);
else
Exit
(
"This StochasticField is not implemented"
)
return
nullptr
;
else
return
nullptr
;
}
\ No newline at end of file
mlmc/src/StochasticFields.h
View file @
19a9f39f
...
...
@@ -29,21 +29,19 @@ public:
};
};
StochasticFieldPair
*
getStochasticFieldPair
(
int
l
,
Meshes
&
meshes
,
string
StochasticField
=
""
);
StochasticFieldPair
*
getStochasticFieldPair
(
int
l
,
int
dim
,
string
fieldName
);
class
StochasticFields
{
public:
const
string
&
fieldName
;
int
currentLevel
;
bool
fineField
;
bool
fineField
=
true
;
map
<
int
,
StochasticFieldPair
*>
stochFieldPairs
;
explicit
StochasticFields
(
Meshes
&
meshes
)
{
currentLevel
=
meshes
.
pLevel
();
fineField
=
true
;
explicit
StochasticFields
(
const
string
&
fieldName
,
Meshes
&
meshes
)
:
fieldName
(
fieldName
),
currentLevel
(
meshes
.
pLevel
())
{
for
(
int
l
=
meshes
.
pLevel
();
l
<=
meshes
.
Level
();
l
++
)
{
stochFieldPairs
[
l
]
=
getStochasticFieldPair
(
l
,
meshes
,
"LogNormal2D"
);
stochFieldPairs
[
l
]
=
getStochasticFieldPair
(
l
,
meshes
.
dim
(),
fieldName
);
}
}
...
...
@@ -63,8 +61,8 @@ public:
return
stochFieldPairs
[
currentLevel
]
->
getCoarseValue
(
z
);
};
virtual
pair
<
double
,
double
>
getMinMaxValues
()
{
if
(
fineField
)
virtual
pair
<
double
,
double
>
getMinMaxValues
(
bool
_fineField
)
{
if
(
_
fineField
)
return
stochFieldPairs
[
currentLevel
]
->
getFineMinMaxValues
();
else
return
stochFieldPairs
[
currentLevel
]
->
getCoarseMinMaxValues
();
...
...
@@ -74,10 +72,9 @@ public:
currentLevel
=
l
;
}
void
setFineField
(
bool
useF
ineField
)
{
useF
ineField
=
useF
ineField
;
void
setFineField
(
bool
_f
ineField
)
{
f
ineField
=
_f
ineField
;
}
};
#endif //M_STOCHASTICFIELD_HPP
mlmc/src/StochasticProblem.C
View file @
19a9f39f
#include
"StochasticProblem.h"
class
Stochastic
Problem2
D
:
public
StochasticProblem
{
class
Stochastic
Laplace1
D
:
public
StochasticProblem
{
public:
explicit
StochasticProblem2D
(
StochasticFields
&
stochFields
)
:
explicit
StochasticLaplace1D
(
StochasticFields
&
stochFields
)
:
StochasticProblem
(
stochFields
)
{}
Scalar
Solution
(
const
Point
&
x
)
const
override
{
return
-
x
[
0
];
}
VectorField
Flux
(
int
,
const
Point
&
x
)
const
override
{
return
VectorField
(
-
1
.
0
,
0
.
0
);
}
string
Name
()
const
override
{
return
string
(
"Stochastic Laplace 1D"
);
}
};
class
StochasticLaplace2D
:
public
StochasticProblem
{
public:
explicit
StochasticLaplace2D
(
StochasticFields
&
stochFields
)
:
StochasticProblem
(
stochFields
)
{}
Scalar
Solution
(
const
Point
&
x
)
const
override
{
return
-
x
[
1
];
}
...
...
@@ -16,9 +30,11 @@ public:
StochasticProblem
*
getStochasticProblem
(
StochasticFields
&
stochFields
,
string
StochProblem
)
{
if
(
StochProblem
.
empty
())
ReadConfig
(
Settings
,
"StochProblem"
,
StochProblem
);
if
(
StochProblem
==
"StochLaplace2D"
)
return
new
StochasticProblem2D
(
stochFields
);
if
(
StochProblem
.
empty
())
ReadConfig
(
Settings
,
"Problem"
,
StochProblem
);
if
(
StochProblem
==
"StochasticLaplace1D"
)
return
new
StochasticLaplace1D
(
stochFields
);
if
(
StochProblem
==
"StochasticLaplace2D"
)
return
new
StochasticLaplace2D
(
stochFields
);
else
Exit
(
"This StochProblem is not implemented"
)
return
nullptr
;
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment