metafold 0.15.dev0__py3-none-any.whl → 0.15.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metafold/materials.py CHANGED
@@ -211,6 +211,111 @@ class MaxwellWeichertParams(ParamsBase):
211
211
  )
212
212
 
213
213
 
214
+ @dataclass
215
+ class HyperfoamTerm:
216
+ """One Ogden term of a hyperfoam material (mpmgpu allows up to 3)."""
217
+ mu: float
218
+ alpha: float
219
+ poisson_ratio: float
220
+
221
+ def to_dict(self):
222
+ # "_element" tells the ups emitter to render this as a <term>.
223
+ return {
224
+ "_element": "term",
225
+ "mu": float(self.mu),
226
+ "alpha": float(self.alpha),
227
+ "poisson_ratio": float(self.poisson_ratio),
228
+ }
229
+
230
+
231
+ @dataclass
232
+ class HyperfoamParams(ParamsBase):
233
+ """Ogden hyperfoam (mpmgpu only; no Uintah equivalent).
234
+
235
+ The Ogden hyperfoam model is defined entirely by its terms (bulk_modulus is
236
+ not used, so it is not part of this material; a legacy "bulk_modulus"/"K" is
237
+ ignored if present on from_dict).
238
+
239
+ An optional viscoelastic overlay (Prony series) may be supplied via
240
+ terminal_shear_modulus + viscoelastic_series, matching the MaxwellWeichert
241
+ mode structure. Omit both for a purely elastic hyperfoam.
242
+ """
243
+ terms: List[HyperfoamTerm]
244
+ terminal_shear_modulus: Optional[float] = None
245
+ viscoelastic_series: Optional[List[ViscoelasticMode]] = None
246
+
247
+ @classmethod
248
+ def get_type(self):
249
+ return "hyperfoam"
250
+
251
+ def to_dict(self):
252
+ d = {
253
+ "terms": [t.to_dict() for t in self.terms],
254
+ }
255
+ if self.terminal_shear_modulus is not None:
256
+ d["terminal_shear_modulus"] = float(self.terminal_shear_modulus)
257
+ if self.viscoelastic_series:
258
+ d["viscoelastic_series"] = [m.to_dict() for m in self.viscoelastic_series]
259
+ return d
260
+
261
+ @classmethod
262
+ def from_dict(cls, d: dict) -> "HyperfoamParams":
263
+ # A legacy bulk_modulus/K is ignored (older scripts may still send it).
264
+ series = d.get("viscoelastic_series")
265
+ return cls(
266
+ terms=[
267
+ HyperfoamTerm(
268
+ mu=t["mu"], alpha=t["alpha"], poisson_ratio=t["poisson_ratio"])
269
+ for t in d["terms"]
270
+ ],
271
+ terminal_shear_modulus=d.get("terminal_shear_modulus"),
272
+ viscoelastic_series=(
273
+ [ViscoelasticMode(**m) for m in series] if series else None),
274
+ )
275
+
276
+
277
+ @dataclass
278
+ class OrthotropicParams(ParamsBase):
279
+ """Linear-elastic orthotropic (mpmgpu only; no Uintah equivalent)."""
280
+ E1: float
281
+ E2: float
282
+ E3: float
283
+ nu12: float
284
+ nu13: float
285
+ nu23: float
286
+ G12: float
287
+ G13: float
288
+ G23: float
289
+ direction_a: List[float]
290
+ direction_b: List[float]
291
+
292
+ @classmethod
293
+ def get_type(self):
294
+ return "orthotropic"
295
+
296
+ def to_dict(self):
297
+ return {
298
+ "E1": float(self.E1), "E2": float(self.E2), "E3": float(self.E3),
299
+ "nu12": float(self.nu12), "nu13": float(self.nu13), "nu23": float(self.nu23),
300
+ "G12": float(self.G12), "G13": float(self.G13), "G23": float(self.G23),
301
+ # Numeric lists so simulation_configurator emits them as vectors.
302
+ "direction_a": [float(x) for x in self.direction_a],
303
+ "direction_b": [float(x) for x in self.direction_b],
304
+ }
305
+
306
+ @classmethod
307
+ def from_dict(cls, d: dict) -> "OrthotropicParams":
308
+ def vec(v):
309
+ return [float(x) for x in (v.split() if isinstance(v, str) else v)]
310
+ return cls(
311
+ E1=d["E1"], E2=d["E2"], E3=d["E3"],
312
+ nu12=d["nu12"], nu13=d["nu13"], nu23=d["nu23"],
313
+ G12=d["G12"], G13=d["G13"], G23=d["G23"],
314
+ direction_a=vec(d["direction_a"]),
315
+ direction_b=vec(d["direction_b"]),
316
+ )
317
+
318
+
214
319
  @dataclass
215
320
  class CompNeoHookParams(ParamsBase):
216
321
  bulk_modulus: float
@@ -351,10 +456,24 @@ class Material:
351
456
  ElasticPlasticParams,
352
457
  HypoElasticParams,
353
458
  ViscoTransIsoHyperParams,
459
+ HyperfoamParams,
460
+ OrthotropicParams,
354
461
  ]
355
462
  PARAMS_CLASSES = {c.get_type(): c for c in params_classes}
356
463
  cm = d["constitutive_model"]
357
- params = PARAMS_CLASSES[cm["type"]].from_dict(cm["params"])
464
+ model_type = cm.get("type")
465
+ if model_type not in PARAMS_CLASSES:
466
+ # ValueError so API callers reject with a 400, not a 500. An
467
+ # unknown type usually means a client newer than the server.
468
+ raise ValueError(
469
+ f"Unknown constitutive model type {model_type!r}. "
470
+ f"Known types: {', '.join(sorted(PARAMS_CLASSES))}.")
471
+ try:
472
+ params = PARAMS_CLASSES[model_type].from_dict(cm["params"])
473
+ except KeyError as e:
474
+ # Missing param -> ValueError (400) rather than an uncaught 500.
475
+ raise ValueError(
476
+ f"{model_type} material is missing required param {e}.")
358
477
  return cls(
359
478
  density=d["density"],
360
479
  thermal_conductivity=d["thermal_conductivity"],
@@ -251,6 +251,34 @@ def _build_parts(parts_config: list[dict]) -> list[ExperimentPart]:
251
251
  return parts
252
252
 
253
253
 
254
+ # Constitutive models that only the experimental (mpmgpu GPU) solver supports;
255
+ # Uintah has no equivalent, so they require use_experimental_solver.
256
+ _EXPERIMENTAL_ONLY_MATERIALS = {
257
+ _materials_module.OrthotropicParams.get_type(),
258
+ _materials_module.HyperfoamParams.get_type(),
259
+ }
260
+
261
+
262
+ def _material_type(material: Material) -> str:
263
+ return material.constitutive_model.params.get_type()
264
+
265
+
266
+ def _validate_experimental_materials(config: dict, parts, varying) -> None:
267
+ """Reject experimental-only materials unless use_experimental_solver is set."""
268
+ if config.get("use_experimental_solver", False):
269
+ return
270
+ materials = [p.material for p in parts]
271
+ for v in varying:
272
+ if isinstance(v, VaryMaterial):
273
+ materials.extend(v.materials)
274
+ used = {_material_type(m) for m in materials} & _EXPERIMENTAL_ONLY_MATERIALS
275
+ if used:
276
+ names = ", ".join(sorted(used))
277
+ raise ValueError(
278
+ f"Material(s) {names} are only supported with the experimental "
279
+ f"solver. Set use_experimental_solver to true to use them.")
280
+
281
+
254
282
  def validate_experiment_config(config: dict) -> None:
255
283
  """Raise ValueError if a manifest can't produce a runnable experiment.
256
284
  Mirrors the checks run_experiment performs so an API can reject bad
@@ -258,7 +286,10 @@ def validate_experiment_config(config: dict) -> None:
258
286
  """
259
287
  if not config.get("project_name", ""):
260
288
  raise ValueError("project_name is required")
261
- validate_simulation_parts(_build_parts(config.get("parts", [])))
289
+ parts = _build_parts(config.get("parts", []))
290
+ validate_simulation_parts(parts)
291
+ _validate_experimental_materials(
292
+ config, parts, _build_varying(config.get("varying", [])))
262
293
 
263
294
 
264
295
  def _build_varying(varying_config: list[dict]) -> list[ExperimentVarying]:
@@ -379,6 +410,8 @@ def run_experiment(
379
410
  varying = _build_varying(config.get("varying", []))
380
411
  sim_params = _build_simulation_parameters(config.get("simulation", {}))
381
412
 
413
+ _validate_experimental_materials(config, parts, varying)
414
+
382
415
  use_experimental_solver = config.get("use_experimental_solver", False)
383
416
 
384
417
  sim_kwargs: dict = dict(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: metafold
3
- Version: 0.15.dev0
3
+ Version: 0.15.dev2
4
4
  Summary: Metafold SDK for Python
5
5
  Author-email: Metafold 3D <info@metafold3d.com>
6
6
  License: Copyright 2024 Metafold 3D
@@ -38,7 +38,7 @@ Requires-Dist: dotenv>=0.9.9; extra == "simulation"
38
38
  Requires-Dist: pandas>=2.3.3; extra == "simulation"
39
39
  Requires-Dist: plyfile>=1.1.3; extra == "simulation"
40
40
  Requires-Dist: pyyaml>=6.0.3; extra == "simulation"
41
- Requires-Dist: simulation-configurator==0.2.*; extra == "simulation"
41
+ Requires-Dist: simulation-configurator==0.3.*; extra == "simulation"
42
42
  Requires-Dist: tables>=3.11.1; extra == "simulation"
43
43
  Dynamic: license-file
44
44
 
@@ -5,16 +5,16 @@ metafold/auth.py,sha256=O4B5vGUr2UmHbw_1BfWqZn-GWvmf_eFpZEpKGgBGrQQ,1079
5
5
  metafold/client.py,sha256=ZFftCr5gbRFkrxgBK7NYspBQEQnNzj2tWCbjPqxg5gw,3714
6
6
  metafold/exceptions.py,sha256=dJhBgbryBhJUf20FT3eU1rjQJQ-aDEZ25g-YCn_TwQk,110
7
7
  metafold/jobs.py,sha256=y-8LknS9yAO26MEPh73z4rTrXxjZjPff-1qxpIARebM,4642
8
- metafold/materials.py,sha256=QwCWNvF3iR7WzUKq4Q9T6wIRK4_YW1UNOJ_FiC8AVY0,13564
8
+ metafold/materials.py,sha256=gOvkO9zfnumYtL5Xi_Y-6pTPeT2r97THWx4cK_3Ze3Y,17767
9
9
  metafold/projects.py,sha256=uZZOuXe80F53SZ5ZFpxFYhhMnfgd4SpPaFgkKTSZvTo,6384
10
10
  metafold/utils.py,sha256=DnsW1Xr9mLpVHBNdPrdxNLLcjxSNMkWVvr7cH7UTAxY,1174
11
11
  metafold/workflows.py,sha256=Mhv3n3ChUHw1Vaj3q8HNDbOgljn03AF6WslZfXzexsI,7802
12
12
  metafold/simulation/__init__.py,sha256=tUW4PfyWnI6UFvIR__JKUD2FjNTM74fSeKuee7Ewjfo,816
13
13
  metafold/simulation/compression_experiment.py,sha256=kLtX6V4vc_v2l-mJqpkE29TWE-fb6fCudOqhxv1Bz9U,18442
14
14
  metafold/simulation/compression_simulation.py,sha256=69tJPRIXE2G_buqB50gUH2K6790skzRhDLYmc0GZ8ss,121287
15
- metafold/simulation/run_experiment.py,sha256=RGaQSNhacJwfRZQYzB_jw2_AINhPNNZXp95qfmwWseY,18665
16
- metafold-0.15.dev0.dist-info/licenses/LICENSE,sha256=LejZXzGwe9t0Ezk6g0bRmWUuFSI9vQSk1wJAc1NrrhE,1059
17
- metafold-0.15.dev0.dist-info/METADATA,sha256=2ES2fXgEdfah0CMIs3yTktO2PasfSzZ4sDrRM5dDVSo,3495
18
- metafold-0.15.dev0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
19
- metafold-0.15.dev0.dist-info/top_level.txt,sha256=0dvwa2N6gvl2x4T9c62V4MbYD2soFedI6hm3-lWgyew,9
20
- metafold-0.15.dev0.dist-info/RECORD,,
15
+ metafold/simulation/run_experiment.py,sha256=ot507fJJra6qZLv_o1hqFoAtwmyE3iBKfhWRR9eNhD0,19930
16
+ metafold-0.15.dev2.dist-info/licenses/LICENSE,sha256=LejZXzGwe9t0Ezk6g0bRmWUuFSI9vQSk1wJAc1NrrhE,1059
17
+ metafold-0.15.dev2.dist-info/METADATA,sha256=WVMmhNM44KI_IgoL6IneTSy9_izLz4uRDOq7QOKP50M,3495
18
+ metafold-0.15.dev2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
19
+ metafold-0.15.dev2.dist-info/top_level.txt,sha256=0dvwa2N6gvl2x4T9c62V4MbYD2soFedI6hm3-lWgyew,9
20
+ metafold-0.15.dev2.dist-info/RECORD,,