PolyFEM
Loading...
Searching...
No Matches
VarFormFactory.cpp
Go to the documentation of this file.
2
10
11namespace polyfem::varform
12{
13 namespace
14 {
15 bool has_entries(const json &args, const json::json_pointer &path)
16 {
17 return args.contains(path) && !args.at(path).empty();
18 }
19 } // namespace
20
21 std::string formulation_from_args(const json &args)
22 {
23 if (!args.contains("materials") || args["materials"].is_null())
24 return "";
25
26 if (args["materials"].is_array())
27 {
28 std::string current;
29 for (const auto &m : args["materials"])
30 {
31 const std::string tmp = m["type"];
32 if (current.empty())
33 current = tmp;
34 else if (current != tmp)
35 {
38 {
39 current = "MultiModels";
40 }
41 else
42 {
43 return "";
44 }
45 }
46 }
47
48 return current;
49 }
50
51 return args["materials"].value("type", "");
52 }
53
55 {
57 const std::string formulation = formulation_from_args(args);
58 return !formulation.empty() && VarFormFactory::create(formulation, args) != nullptr;
59 }
60
61 bool VarFormFactory::supports(const std::string &formulation, const json &args)
62 {
63 if (args.value("/space/remesh/enabled"_json_pointer, false))
64 return false;
65
66 if (args.value("/contact/periodic"_json_pointer, false))
67 return false;
68
69 if (args.value("/boundary_conditions/periodic_boundary/enabled"_json_pointer, false))
70 return false;
71
72 if (args.contains("/boundary_conditions/periodic_boundary/linear_displacement_offset"_json_pointer)
73 && args.at("/boundary_conditions/periodic_boundary/linear_displacement_offset"_json_pointer).size() > 0)
74 return false;
75
76 const auto assembler = assembler::AssemblerUtils::make_assembler(formulation);
77 if (!assembler)
78 return false;
79
80 if (formulation == "OperatorSplitting")
81 return false;
82
84 return formulation == "Stokes"
85 || formulation == "NavierStokes"
86 || formulation == "IncompressibleLinearElasticity"
87 || formulation == "Bilaplacian";
88
89 if (assembler->is_fluid())
90 return false;
91
92 return assembler->is_tensor() || assembler->is_linear();
93 }
94
95 std::shared_ptr<VarForm> VarFormFactory::create(const std::string &formulation, const json &args)
96 {
97 if (!supports(formulation, args))
98 return nullptr;
99
100 const auto assembler = assembler::AssemblerUtils::make_assembler(formulation);
101 const bool has_contact = args.value("/contact/enabled"_json_pointer, false);
102 const bool has_pressure = has_entries(args, "/boundary_conditions/pressure_boundary"_json_pointer)
103 || has_entries(args, "/boundary_conditions/pressure_cavity"_json_pointer);
104 const bool has_constraints =
105 has_entries(args, "/constraints/hard"_json_pointer)
106 || has_entries(args, "/constraints/soft"_json_pointer);
107
108 if (formulation == "Stokes")
109 return (!has_contact && !has_constraints) ? std::make_shared<StokesVarForm>() : nullptr;
110 if (formulation == "NavierStokes")
111 return (!has_contact && !has_constraints) ? std::make_shared<NavierStokesVarForm>() : nullptr;
112 if (formulation == "IncompressibleLinearElasticity")
113 return (!has_contact && !has_pressure && !has_constraints) ? std::make_shared<IncompressibleElasticVarForm>() : nullptr;
114 if (formulation == "Bilaplacian")
115 return (!has_contact && !has_constraints) ? std::make_shared<BilaplacianVarForm>() : nullptr;
116
117 if (!assembler->is_tensor())
118 return (!has_contact && !has_pressure && !has_constraints) ? std::make_shared<ScalarVarForm>() : nullptr;
119
120 if (assembler->is_linear() && !has_contact && !has_pressure && !has_constraints)
121 return std::make_shared<LinearElasticVarForm>();
122
123 if (args.contains("time") && !args["time"].is_null())
124 return std::make_shared<NonlinearElasticTransientVarForm>();
125
126 return std::make_shared<NonlinearElasticStaticVarForm>();
127 }
128} // 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