ABLATE Source Documentation  0.12.34
fieldDescription.hpp
1 #ifndef ABLATELIBRARY_FIELDDESCRIPTION_HPP
2 #define ABLATELIBRARY_FIELDDESCRIPTION_HPP
3 
4 #include <petsc.h>
5 #include <algorithm>
6 #include <memory>
7 #include <parameters/parameters.hpp>
8 #include <string>
9 #include <utility>
10 #include <vector>
11 #include "domain/field.hpp"
12 #include "domain/region.hpp"
13 #include "fieldDescriptor.hpp"
14 
15 namespace ablate::domain {
16 
20 struct FieldDescription : public FieldDescriptor, public std::enable_shared_from_this<FieldDescription> {
21  ~FieldDescription() override;
22 
23  // Helper variable, replaces any components with this value with one for each dimension
24  inline const static std::string DIMENSION = "_DIMENSION_";
25  inline const static std::vector<std::string> ONECOMPONENT = {"_"};
26 
27  // The name of the field
28  const std::string name;
29 
30  // The prefix for field options
31  const std::string prefix;
32 
33  // The components held in this field
34  std::vector<std::string> components = {"_"};
35 
36  // If the field is solution or aux
37  const enum FieldLocation location = FieldLocation::SOL;
38 
39  // The type of field (FEM/FVM)
40  const enum FieldType type = FieldType::FEM;
41 
42  // The region for the field (nullptr is everywhere)
43  const std::shared_ptr<domain::Region> region;
44 
45  // store any optional tags, there are strings that can be used to describe the field
46  const std::vector<std::string> tags;
47 
48  FieldDescription(std::string name, const std::string& prefix, const std::vector<std::string>& components, FieldLocation location, FieldType type, std::shared_ptr<domain::Region> = {},
49  const std::shared_ptr<parameters::Parameters>& = {}, std::vector<std::string> tags = {});
50 
54  void DecompressComponents(PetscInt dim);
55 
57  std::vector<std::shared_ptr<FieldDescription>> GetFields() override;
58 
64  virtual PetscObject CreatePetscField(DM dm) const;
65 
70  inline std::shared_ptr<FieldDescription> Specialize(FieldType typeIn, std::shared_ptr<domain::Region> regionIn, std::shared_ptr<parameters::Parameters> optionsIn = {},
71  std::vector<std::string> tagsIn = {}) {
72  return std::make_shared<FieldDescription>(name, prefix, components, location, typeIn, regionIn, optionsIn, tagsIn);
73  }
74 
75  private:
76  // keep the original Parameters
77  std::shared_ptr<parameters::Parameters> options;
78 
79  // Petsc options specific for this field
80  mutable PetscOptions petscOptions = nullptr;
81 };
82 
83 } // namespace ablate::domain
84 #endif // ABLATELIBRARY_FIELDDESCRIPTION_HPP
Definition: fieldDescriptor.hpp:15
Definition: fieldDescription.hpp:20
std::shared_ptr< FieldDescription > Specialize(FieldType typeIn, std::shared_ptr< domain::Region > regionIn, std::shared_ptr< parameters::Parameters > optionsIn={}, std::vector< std::string > tagsIn={})
Definition: fieldDescription.hpp:70
void DecompressComponents(PetscInt dim)
Definition: fieldDescription.cpp:98
virtual PetscObject CreatePetscField(DM dm) const
Definition: fieldDescription.cpp:21
std::vector< std::shared_ptr< FieldDescription > > GetFields() override
Definition: fieldDescription.cpp:113