14class StencilMC:
public StencilTemplate{
18 StencilMC(
AdaptiveSparseGrid& grid_,
const F &varCoeff_,
int c_) : StencilTemplate(grid_), varCoeff(varCoeff_), c(c_){
20 gen =std::mt19937(rd());
27 inline double integration(CellDimension& cell, CellIndexDirection& dirP, CellIndexDirection& dirQ){
28 FunctionClass functionClass(cell,dirP,dirQ);
34 for(
int d=0; d<DimensionSparseGrid;d++){
35 l+=cell.getDepth(d)-1;
40 int vol_cell= POW2(
unsigned (l));
43 if(vol_cell>dofs) numberMC=1;
44 else numberMC= dofs/vol_cell;
57 for(
int j=0; j<numberMC;j++){
58 double x[DimensionSparseGrid];
59 for(
int d=0;d<DimensionSparseGrid;d++){
60 x[d]=std::uniform_real_distribution<>(cell.getLeftBoundary(d),cell.getRightBoundary(d))(gen);
62 double vC = varCoeff(x)*functionClass.evaluation(x);
66 value = (1.0/vol_cell)*(sum/
double(numberMC));
77 FunctionClass (CellDimension& cell_, CellIndexDirection& dirP_, CellIndexDirection &dirQ_): cell(cell_),dirP(dirP_),dirQ(dirQ_){
79 for(
int i=0; i<DimensionSparseGrid; i++){
80 double h = cell.getRightBoundary(i)-cell.getLeftBoundary(i);
87 double evaluation(
double* x){
96 for(
int i = 0; i < DimensionSparseGrid; ++i )
100 if(dirP.getDirection(i)==Left){
102 value *= (cell.getRightBoundary(i)-x[i]) / (meshwidth[i]);
106 value *= (x[i] - cell.getLeftBoundary(i)) / (meshwidth[i]);
110 if(dirQ.getDirection(i)==Left){
112 value *= (cell.getRightBoundary(i)-x[i]) / (meshwidth[i]);
117 value *= (x[i] - cell.getLeftBoundary(i)) / (meshwidth[i]);
137 double meshwidth[DimensionSparseGrid];
139 CellIndexDirection dirP;
140 CellIndexDirection dirQ;
146 std::random_device rd;
147 std::uniform_real_distribution<> dist[DimensionSparseGrid];
153class RHS_MC:
public StencilTemplate{
157 RHS_MC(
AdaptiveSparseGrid& grid_,
const F &varCoeff_,
int c_) : StencilTemplate(grid_), varCoeff(varCoeff_), c(c_){
159 gen =std::mt19937(rd());
166 inline double integration(CellDimension& cell, CellIndexDirection& dirP, CellIndexDirection& dirQ){
167 FunctionClass functionClass(cell,dirP,dirQ);
173 for(
int d=0; d<DimensionSparseGrid;d++){
174 l+=cell.getDepth(d)-1;
179 int vol_cell= POW2(
unsigned (l));
182 if(vol_cell>dofs) numberMC=1;
183 else numberMC= dofs/vol_cell;
196 for(
int j=0; j<numberMC;j++){
197 double x[DimensionSparseGrid];
198 for(
int d=0;d<DimensionSparseGrid;d++){
199 x[d]=std::uniform_real_distribution<>(cell.getLeftBoundary(d),cell.getRightBoundary(d))(gen);
201 double vC = varCoeff(x)*functionClass.evaluation(x);
205 value = (1.0/vol_cell)*(sum/
double(numberMC));
216 FunctionClass (CellDimension& cell_, CellIndexDirection& dirP_, CellIndexDirection &dirQ_): cell(cell_),dirP(dirP_),dirQ(dirQ_){
218 for(
int i=0; i<DimensionSparseGrid; i++){
219 double h = cell.getRightBoundary(i)-cell.getLeftBoundary(i);
226 double evaluation(
double* x){
230 for(
int i = 0; i < DimensionSparseGrid; ++i )
234 if(dirP.getDirection(i)==Left){
236 value *= (cell.getRightBoundary(i)-x[i]) / (meshwidth[i]);
240 value *= (x[i] - cell.getLeftBoundary(i)) / (meshwidth[i]);
244 if(dirQ.getDirection(i)==Left){
246 value *= (cell.getRightBoundary(i)-x[i]) / (meshwidth[i]);
251 value *= (x[i] - cell.getLeftBoundary(i)) / (meshwidth[i]);
271 double meshwidth[DimensionSparseGrid];
273 CellIndexDirection dirP;
274 CellIndexDirection dirQ;
280 std::random_device rd;
281 std::uniform_real_distribution<> dist[DimensionSparseGrid];
Definition sparseGrid.h:277