|
dune-grid 2.10
|
Loading...
Searching...
No Matches
recipe-integration.cc
See explanation at Integrate a function on a grid
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file COPYING in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// C++ includes
#include<math.h>
#include<iostream>
// dune-common includes
#include<dune/common/parallel/mpihelper.hh>
#include<dune/common/parametertreeparser.hh>
#include<dune/common/timer.hh>
// dune-geometry includes
#include<dune/geometry/referenceelements.hh>
#include<dune/geometry/quadraturerules.hh>
// dune-grid includes
#include <dune/grid/yaspgrid.hh>
{
// Maybe initialize Mpi
// [set up grid]
Grid grid(len,cells);
// [small vectors and matrices]
Dune::FieldVector<double,4> x({1,2,3,4}); // make a vector
auto y(x); // copy constructor
y *= 1.0/3.0; // scaling
[[maybe_unused]] auto s = x*y; // scalar product
A.usmv(0.5,x,y); // axpy: y += 0.5*Ax
// [a function to integrate]
// [integration with midpoint rule]
double integral=0.0;
auto gv = grid.leafGridView(); // extract the grid view
for (const auto& e : elements(gv))
integral += u(e.geometry().center())*e.geometry().volume();
// [integration with quadrature rule]
double integral2 = 0.0;
for (const auto& e : elements(gv))
{
auto geo = e.geometry();
auto quadrature = QR::rule(geo.type(),5);
for (const auto& qp : quadrature)
integral2 += u(geo.global(qp.position()))
*geo.integrationElement(qp.position())*qp.weight();
}
// [integrating a flux]
auto f = [](const auto& x){return x;};
double divergence=0.0;
for (const auto& i : elements(gv)) {
for (const auto& I : intersections(gv,i))
if (!I.neighbor())
{
auto geoI = I.geometry();
divergence += f(geoI.center())*I.centerUnitOuterNormal()*geoI.volume();
}
}
}
int main(int argc, char **argv)
size_type dim() const
void mv(const X &x, Y &y) const
FieldTraits< value_type >::real_type two_norm() const
static DUNE_EXPORT MPIHelper & instance(int &argc, char **&argv)
T endl(T... args)
T exp(T... args)
Legal Statements / Impressum | Hosted by TU Dresden & Uni Heidelberg | Generated by
1.9.8