PolyFEM
Loading...
Searching...
No Matches
VarFormFactory.cpp
Go to the documentation of this file.
2
12
13namespace polyfem::varform
14{
15 namespace
16 {
17 bool has_entries(const json &args, const json::json_pointer &path)
18 {
19 return args.contains(path) && !args.at(path).empty();
20 }
21 } // namespace
22
23 std::string formulation_from_args(const json &args)
24 {
25 if (!args.contains("materials") || args["materials"].is_null())
26 return "";
27
28 if (args["materials"].is_array())
29 {
30 std::string current;
31 for (const auto &m : args["materials"])
32 {
33 const std::string tmp = m["type"];
34 if (current.empty())
35 current = tmp;
36 else if (current != tmp)
37 {
40 {
41 current = "MultiModels";
42 }
43 else
44 {
45 return "";
46 }
47 }
48 }
49
50 return current;
51 }
52
53 return args["materials"].value("type", "");
54 }
55
57 {
59 const std::string formulation = formulation_from_args(args);
60 return !formulation.empty() && VarFormFactory::create(formulation, args) != nullptr;
61 }
62
63 bool VarFormFactory::supports(const std::string &formulation, const json &args)
64 {
65 if (args.value("/space/remesh/enabled"_json_pointer, false))
66 return false;
67
68 if (args.value("/contact/periodic"_json_pointer, false))
69 return false;
70
71 if (args.value("/boundary_conditions/periodic_boundary/enabled"_json_pointer, false))
72 return false;
73
74 if (args.contains("/boundary_conditions/periodic_boundary/linear_displacement_offset"_json_pointer)
75 && args.at("/boundary_conditions/periodic_boundary/linear_displacement_offset"_json_pointer).size() > 0)
76 return false;
77
78 if (formulation == "OperatorSplitting")
79 return args.contains("time") && !args["time"].is_null();
80
81 if (formulation == "ThermoElasticity")
82 return true;
83
84 const auto assembler = assembler::AssemblerUtils::make_assembler(formulation);
85 if (!assembler)
86 return false;
87
89 return formulation == "Stokes"
90 || formulation == "NavierStokes"
91 || formulation == "IncompressibleLinearElasticity"
92 || formulation == "Bilaplacian";
93
94 if (assembler->is_fluid())
95 return false;
96
97 return assembler->is_tensor() || assembler->is_linear();
98 }
99
100 std::shared_ptr<VarForm> VarFormFactory::create(const std::string &formulation, const json &args)
101 {
102 if (!supports(formulation, args))
103 return nullptr;
104
105 const bool has_contact = args.value("/contact/enabled"_json_pointer, false);
106 const bool has_pressure = has_entries(args, "/boundary_conditions/pressure_boundary"_json_pointer)
107 || has_entries(args, "/boundary_conditions/pressure_cavity"_json_pointer);
108 const bool has_constraints =
109 has_entries(args, "/constraints/hard"_json_pointer)
110 || has_entries(args, "/constraints/soft"_json_pointer);
111
112 if (formulation == "ThermoElasticity")
113 return (!has_pressure && !has_constraints) ? std::make_shared<ThermoElasticVarForm>() : nullptr;
114
115 const auto assembler = assembler::AssemblerUtils::make_assembler(formulation);
116
117 if (formulation == "Stokes")
118 return (!has_contact && !has_constraints) ? std::make_shared<StokesVarForm>() : nullptr;
119 if (formulation == "NavierStokes")
120 return (!has_contact && !has_constraints) ? std::make_shared<NavierStokesVarForm>() : nullptr;
121 if (formulation == "OperatorSplitting")
122 return (!has_contact && !has_constraints) ? std::make_shared<OperatorSplittingVarForm>() : nullptr;
123 if (formulation == "IncompressibleLinearElasticity")
124 return (!has_contact && !has_pressure && !has_constraints) ? std::make_shared<IncompressibleElasticVarForm>() : nullptr;
125 if (formulation == "Bilaplacian")
126 return (!has_contact && !has_constraints) ? std::make_shared<BilaplacianVarForm>() : nullptr;
127
128 if (!assembler->is_tensor())
129 return (!has_contact && !has_pressure && !has_constraints) ? std::make_shared<ScalarVarForm>() : nullptr;
130
131 if (assembler->is_linear() && !has_contact && !has_pressure && !has_constraints)
132 return std::make_shared<LinearElasticVarForm>();
133
134 if (args.contains("time") && !args["time"].is_null())
135 return std::make_shared<NonlinearElasticTransientVarForm>();
136
137 return std::make_shared<NonlinearElasticStaticVarForm>();
138 }
139} // namespace polyfem::varform
static std::string other_assembler_name(const std::string &formulation)
static bool is_elastic_material(const std::string &material)
utility to check if material is one of the elastic materials
static std::shared_ptr< Assembler > make_assembler(const std::string &formulation)
static std::shared_ptr< VarForm > create(const std::string &formulation, const json &args)
static bool supports(const std::string &formulation, const json &args)
void apply_common_params(json &args)
Definition JSONUtils.cpp:14
std::string formulation_from_args(const json &args)
Extracts the formulation type from the given JSON arguments.
bool uses_varform_state(json args)
Checks if the given JSON arguments use a VarForm state.
nlohmann::json json
Definition Common.hpp:9