Skip to content

Commit

Permalink
Merge branch 'geoelements:main' into bingham
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinJalan authored Jul 16, 2023
2 parents 123f164 + ca126a5 commit 014c4fe
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
7 changes: 7 additions & 0 deletions benchmarks/2d/uniaxial_nodal_forces/entity_sets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"node_sets":
{
"0": [3, 7],
"1": [0, 4]
}
}
5 changes: 3 additions & 2 deletions benchmarks/2d/uniaxial_nodal_forces/mpm-nodal-forces.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ nelements = [3, 1]
element_length = [0.1, 0.1]
particle_element_ids = [0]
element = "Quadrilateral4Node"
entity_sets = "entity_sets.json"

[[mesh.constraints]]
node_ids = [0, 4]
nset_ids = [1]
dir = 0
velocity = 0.0

Expand All @@ -56,7 +57,7 @@ init_velocity = 0.0
gravity = [0, 0]

[[external_loading.concentrated_nodal_forces]]
node_ids = [3, 7]
nset_ids = [0]
math_function_id = 0
dir = 0
force = 0.05
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/2d/uniaxial_particle_traction/entity_sets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"particle_sets": [
{
"0": [5, 11]
}
],
"node_sets": {
"0": [3, 7],
"1": [0, 4]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ nelements = [3, 1]
element_length = [0.1, 0.1]
particle_element_ids = [0]
element = "Quadrilateral4Node"
entity_sets = "entity_sets.json"

[[mesh.constraints]]
node_ids = [0, 4]
nset_ids = [1]
dir = 0
velocity = 0.0

Expand All @@ -57,7 +58,7 @@ gravity = [0, 0]

[[external_loading.particle_surface_traction]]
pset = [0]
pids = [[5, 11]]
pset_ids = [0]
math_function_id = 0
dir = 0
traction = 1
Expand Down
7 changes: 7 additions & 0 deletions benchmarks/2d/uniaxial_stress/entity_sets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"node_sets":
{
"0": [0, 1],
"1": [2, 3]
}
}
5 changes: 3 additions & 2 deletions benchmarks/2d/uniaxial_stress/mpm-uniaxial-stress.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ nelements = [1, 1]
element_length = [1, 1]
particle_element_ids = [0]
element = "Quadrilateral4Node"
entity_sets = "entity_sets.json"

[[mesh.constraints]]
node_ids = [0, 1]
nset_ids = [0]
dir = 1
velocity = 0.0

[[mesh.constraints]]
node_ids = [2, 3]
nset_ids = [1]
dir = 1
velocity = -0.01

Expand Down
30 changes: 27 additions & 3 deletions diffmpm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def parse(self):
with open(self._filepath, "rb") as f:
self._fileconfig = tl.load(f)

self.entity_sets = json.load(open(self._fileconfig["mesh"]["entity_sets"]))
self._parse_meta(self._fileconfig)
self._parse_output(self._fileconfig)
self._parse_materials(self._fileconfig)
Expand All @@ -33,6 +34,21 @@ def parse(self):
mesh = self._parse_mesh(self._fileconfig)
return mesh

def _get_node_set_ids(self, set_ids):
all_ids = []
for set_id in set_ids:
ids = self.entity_sets["node_sets"][str(set_id)]
all_ids.extend(ids)
return jnp.asarray(all_ids)

def _get_particle_set_ids(self, set_type, set_nos, set_ids):
all_ids = []
for set_no in set_nos:
for set_id in set_ids:
ids = self.entity_sets["particle_sets"][set_no][str(set_id)]
all_ids.extend(ids)
return jnp.asarray(all_ids)

def _parse_meta(self, config):
self.parsed_config["meta"] = config["meta"]

Expand Down Expand Up @@ -91,7 +107,7 @@ def _parse_external_loading(self, config):
else:
fn = Unit(-1)
cnf = NodalForce(
node_ids=jnp.array(cnfconfig["node_ids"]),
node_ids=self._get_node_set_ids(cnfconfig["nset_ids"]),
function=fn,
dir=cnfconfig["dir"],
force=cnfconfig["force"],
Expand All @@ -110,7 +126,9 @@ def _parse_external_loading(self, config):
fn = Unit(-1)
pst = ParticleTraction(
pset=pstconfig["pset"],
pids=jnp.array(pstconfig["pids"]),
pids=self._get_particle_set_ids(
"particle", pstconfig["pset"], pstconfig["pset_ids"]
),
function=fn,
dir=pstconfig["dir"],
traction=pstconfig["traction"],
Expand All @@ -123,10 +141,15 @@ def _parse_external_loading(self, config):
def _parse_mesh(self, config):
element_cls = getattr(mpel, config["mesh"]["element"])
mesh_cls = getattr(mpmesh, f"Mesh{config['meta']['dimension']}D")

constraints = [
(jnp.asarray(c["node_ids"]), Constraint(c["dir"], c["velocity"]))
(
self._get_node_set_ids(c["nset_ids"]),
Constraint(c["dir"], c["velocity"]),
)
for c in config["mesh"]["constraints"]
]

if config["mesh"]["type"] == "generator":
elements = element_cls(
config["mesh"]["nelements"],
Expand All @@ -141,6 +164,7 @@ def _parse_mesh(self, config):
raise NotImplementedError(
"Mesh type other than `generator` not yet supported."
)

self.parsed_config["elements"] = elements
mesh = mesh_cls(self.parsed_config)
return mesh
2 changes: 1 addition & 1 deletion diffmpm/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def apply_traction_on_particles(self, curr_time):
traction_val = factor * ptraction.traction
for i, pset_id in enumerate(ptraction.pset):
self.particles[pset_id].assign_traction(
ptraction.pids[i], ptraction.dir, traction_val
ptraction.pids, ptraction.dir, traction_val
)

# breakpoint()
Expand Down

0 comments on commit 014c4fe

Please sign in to comment.