Chi-Tech
fieldfunction_gridbased.h
Go to the documentation of this file.
1#ifndef CHITECH_FIELDFUNCTION_GRIDBASED_H
2#define CHITECH_FIELDFUNCTION_GRIDBASED_H
3
4#include "fieldfunction.h"
5
6#include "mesh/chi_mesh.h"
7
10
11#include <string>
12#include <memory>
13#include <vector>
14#include <utility>
15
16// ######################################################### Forward decls
17namespace chi_math
18{
19class SpatialDiscretization;
20typedef std::shared_ptr<SpatialDiscretization> SDMPtr;
22} // namespace chi_math
23
24namespace chi_physics
25{
26
27// ################################################################### Class def
28/***/
30{
31public:
32 typedef std::pair<chi_mesh::Vector3, chi_mesh::Vector3> BoundingBox;
33
34 /**Returns required input parameters.*/
36
37 /**ObjectMaker based constructor.*/
38 explicit FieldFunctionGridBased(const chi::InputParameters& params);
39
40 /**Creates a field function, filling it with zeros.*/
41 FieldFunctionGridBased(const std::string& text_name,
42 chi_math::SDMPtr& discretization_ptr,
43 chi_math::Unknown unknown);
44
45 /**Creates a field function with an associated field vector.
46 * The field's data vector is set to the incoming field vector.*/
47 FieldFunctionGridBased(const std::string& text_name,
48 chi_math::SDMPtr& sdm_ptr,
49 chi_math::Unknown unknown,
50 const std::vector<double>& field_vector);
51
52 /**Creates a field function where all the values are assigned to
53 * the single supplied value.*/
54 FieldFunctionGridBased(const std::string& text_name,
55 chi_math::SDMPtr& sdm_ptr,
56 chi_math::Unknown unknown,
57 double field_value);
58
59 virtual ~FieldFunctionGridBased() = default;
60
61 // Getters
62 /**Returns the spatial discretization method.*/
64
65 /**Returns a read-only reference to the locally stored field data.*/
66 const std::vector<double>& FieldVectorRead() const;
67 /**Returns a reference to the locally stored field data.*/
68 std::vector<double>& FieldVector();
69
70 // 01 Updates
71 /**Updates the field vector with a local STL vector.*/
72 void UpdateFieldVector(const std::vector<double>& field_vector);
73 /**Updates the field vector with a PETSc vector. This only operates locally.*/
74 void UpdateFieldVector(const Vec& field_vector);
75
76 // 03 Export VTK
77 /**Static method to export multiple grid-based field functions.*/
78 typedef std::vector<std::shared_ptr<const FieldFunctionGridBased>> FFList;
79 static void ExportMultipleToVTK(const std::string& file_base_name,
80 const FFList& ff_list);
81
82 // 04 Utils
83 /**Makes a copy of the locally stored data with ghost access.*/
84 std::vector<double> GetGhostedFieldVector() const;
85
86 // 05 Point Values
87 /**\brief Returns the component values at requested point.*/
88 virtual std::vector<double>
89 GetPointValue(const chi_mesh::Vector3& point) const;
90
91 /**Evaluates the field function, on a cell, at the specified point.*/
92 double Evaluate(const chi_mesh::Cell& cell,
93 const chi_mesh::Vector3& position,
94 unsigned int component) const override;
95
96protected:
98 std::unique_ptr<chi_math::GhostedParallelSTLVector> ghosted_field_vector_;
99
100private:
101 /**Static method for making the GetSpatialDiscretization for the
102 * constructors.*/
103 static chi_math::SDMPtr
105 /**Static method for making the ghosted vector for the constructors.*/
106 static std::unique_ptr<chi_math::GhostedParallelSTLVector>
108 const chi_math::UnknownManager& uk_man);
109
111};
112
113} // namespace chi_physics
114
115#endif // CHITECH_FIELDFUNCTION_GRIDBASED_H
static std::unique_ptr< chi_math::GhostedParallelSTLVector > MakeFieldVector(const chi_math::SpatialDiscretization &discretization, const chi_math::UnknownManager &uk_man)
const std::vector< double > & FieldVectorRead() const
FieldFunctionGridBased(const chi::InputParameters &params)
static chi::InputParameters GetInputParameters()
std::pair< chi_mesh::Vector3, chi_mesh::Vector3 > BoundingBox
static void ExportMultipleToVTK(const std::string &file_base_name, const FFList &ff_list)
const chi_math::SpatialDiscretization & GetSpatialDiscretization() const
std::unique_ptr< chi_math::GhostedParallelSTLVector > ghosted_field_vector_
virtual ~FieldFunctionGridBased()=default
virtual std::vector< double > GetPointValue(const chi_mesh::Vector3 &point) const
Returns the component values at requested point.
std::vector< double > GetGhostedFieldVector() const
std::vector< std::shared_ptr< const FieldFunctionGridBased > > FFList
void UpdateFieldVector(const std::vector< double > &field_vector)
static chi_math::SDMPtr MakeSpatialDiscretization(const chi::InputParameters &params)
double Evaluate(const chi_mesh::Cell &cell, const chi_mesh::Vector3 &position, unsigned int component) const override
std::shared_ptr< SpatialDiscretization > SDMPtr
struct _p_Vec * Vec