NuTo
Numerics Tool
Cell.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 
11 
12 namespace NuTo
13 {
14 class Cell : public CellInterface
15 {
16 public:
17  Cell(const ElementCollection& elements, const IntegrationTypeBase& integrationType, const int id)
18  : mElements(elements)
19  , mIntegrationType(integrationType)
20  , mId(id)
21  , mShape(elements.GetShape())
22  {
23  if (elements.GetShape() != integrationType.GetShape())
24  {
25  std::stringstream message;
26  message << "The shape of the element (" << elements.GetShape() << ") and integrationtype ("
27  << integrationType.GetShape() << ") don't match.";
28  throw Exception(__PRETTY_FUNCTION__, message.str());
29  }
30  }
31 
33  {
34  return IntegrateGeneric(f, DofVector<double>());
35  }
36 
38  {
39  return IntegrateGeneric(f, DofMatrix<double>());
40  }
41 
42  double Integrate(ScalarFunction f) override
43  {
44  return IntegrateGeneric(f, double{0});
45  }
46 
47  void Apply(VoidFunction f) override
48  {
49  CellData cellData(mElements, Id());
50  for (int iIP = 0; iIP < mIntegrationType.GetNumIntegrationPoints(); ++iIP)
51  {
52  auto ipCoords = mIntegrationType.GetLocalIntegrationPointCoordinates(iIP);
53  Jacobian jacobian(mElements.CoordinateElement().ExtractNodeValues(),
54  mElements.CoordinateElement().GetDerivativeShapeFunctions(ipCoords));
55  CellIpData cellipData(cellData, jacobian, ipCoords, iIP);
56  f(cellipData);
57  }
58  }
59 
60  Eigen::VectorXi DofNumbering(DofType dof) override
61  {
62  return mElements.DofElement(dof).GetDofNumbering();
63  }
64 
65  int Id() const
66  {
67  return mId;
68  }
69 
70  Eigen::VectorXd Interpolate(Eigen::VectorXd naturalCoords) const override
71  {
72  return NuTo::Interpolate(mElements.CoordinateElement(), naturalCoords);
73  }
74 
75  Eigen::VectorXd Interpolate(Eigen::VectorXd naturalCoords, DofType dof) const override
76  {
77  return NuTo::Interpolate(mElements.DofElement(dof), naturalCoords);
78  }
79 
80  std::vector<Eigen::VectorXd> Eval(EvalFunction f) const override
81  {
82  CellData cellData(mElements, Id());
83  std::vector<Eigen::VectorXd> result;
84  for (int iIP = 0; iIP < mIntegrationType.GetNumIntegrationPoints(); ++iIP)
85  {
86  auto ipCoords = mIntegrationType.GetLocalIntegrationPointCoordinates(iIP);
87  Jacobian jacobian(mElements.CoordinateElement().ExtractNodeValues(),
88  mElements.CoordinateElement().GetDerivativeShapeFunctions(ipCoords));
89  CellIpData cellipData(cellData, jacobian, ipCoords, iIP);
90  result.push_back(f(cellipData));
91  }
92  return result;
93  }
94 
95  const Shape& GetShape() const override
96  {
97  return mShape;
98  }
99 
100 private:
105  template <typename TOperation, typename TReturn>
106  TReturn IntegrateGeneric(TOperation&& f, TReturn result)
107  {
108  CellData cellData(mElements, Id());
109  for (int iIP = 0; iIP < mIntegrationType.GetNumIntegrationPoints(); ++iIP)
110  {
111  auto ipCoords = mIntegrationType.GetLocalIntegrationPointCoordinates(iIP);
112  auto ipWeight = mIntegrationType.GetIntegrationPointWeight(iIP);
113  Jacobian jacobian(mElements.CoordinateElement().ExtractNodeValues(),
114  mElements.CoordinateElement().GetDerivativeShapeFunctions(ipCoords));
115  CellIpData cellipData(cellData, jacobian, ipCoords, iIP);
116  result += f(cellipData) * jacobian.Det() * ipWeight;
117  }
118  return result;
119  }
120 
121 private:
122  const ElementCollection& mElements;
123  const IntegrationTypeBase& mIntegrationType;
124  const int mId;
125  const Shape& mShape;
126 };
127 } /* NuTo */
virtual const ElementInterface & DofElement(DofType) const =0
Definition: Cell.h:14
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
Definition: Jacobian.h:10
DofMatrix< double > Integrate(MatrixFunction f) override
Definition: Cell.h:37
virtual const Shape & GetShape() const =0
Determines the shape of the integration type.
interface for all the cell operations, simply forwarding the corresponding element interfaces ...
Definition: ElementCollection.h:14
std::vector< Eigen::VectorXd > Eval(EvalFunction f) const override
Definition: Cell.h:80
std::function< DofMatrix< double >(const CellIpData &)> MatrixFunction
Definition: CellInterface.h:20
virtual const Shape & GetShape() const =0
std::function< DofVector< double >(const CellIpData &)> VectorFunction
Definition: CellInterface.h:19
std::function< Eigen::VectorXd(const CellIpData &)> EvalFunction
Definition: CellInterface.h:23
const Shape & GetShape() const override
Definition: Cell.h:95
void Apply(VoidFunction f) override
Definition: Cell.h:47
Eigen::VectorXd Interpolate(Eigen::VectorXd naturalCoords, DofType dof) const override
Dof interpolation.
Definition: Cell.h:75
Eigen::VectorXd Interpolate(const ElementInterface &element, NaturalCoords ipCoords)
Definition: ElementInterface.h:31
std::function< double(const CellIpData &)> ScalarFunction
Definition: CellInterface.h:18
double Integrate(ScalarFunction f) override
Definition: Cell.h:42
Similar to NuTo::CellData.
Definition: CellIpData.h:14
Definition: DofType.h:8
std::function< void(const CellIpData &)> VoidFunction
Definition: CellInterface.h:22
virtual int GetNumIntegrationPoints() const =0
returns the total number of integration points for this integration type
virtual double GetIntegrationPointWeight(int rIpNum) const =0
returns the weight of an integration point
virtual Eigen::VectorXd GetLocalIntegrationPointCoordinates(int rIpNum) const =0
returns the local coordinates of an integration point
virtual Eigen::VectorXi GetDofNumbering() const =0
extract the dof numbers from its nodes.
virtual const ElementInterface & CoordinateElement() const =0
DofVector< double > Integrate(VectorFunction f) override
Definition: Cell.h:32
standard abstract class for all integration types
Definition: IntegrationTypeBase.h:14
virtual Eigen::MatrixXd GetDerivativeShapeFunctions(NaturalCoords ipCoords) const =0
virtual Eigen::VectorXd ExtractNodeValues(int instance=0) const =0
extracts all node values of this element
dof container that is also capable of performing calculations.
Definition: DofMatrixContainer.h:13
Definition: Shape.h:20
Eigen::VectorXd Interpolate(Eigen::VectorXd naturalCoords) const override
Coordinate interpolation.
Definition: Cell.h:70
Definition: Exception.h:6
Extracts &#39;cell data&#39; like nodal values from the cell.
Definition: CellData.h:14
int Id() const
Definition: Cell.h:65
Cell(const ElementCollection &elements, const IntegrationTypeBase &integrationType, const int id)
Definition: Cell.h:17
Eigen::VectorXi DofNumbering(DofType dof) override
Definition: Cell.h:60
Definition: CellInterface.h:13