Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

79 add random field feature #109

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modified paraview output
  • Loading branch information
danielandresarcones committed May 15, 2023
commit 452cc0a0e0a37e500cdc84d6d3082c81b7104355
5 changes: 5 additions & 0 deletions src/fenicsxconcrete/finite_element_problem/base_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC, abstractmethod
from pathlib import Path, PosixPath

import dolfinx as df
import jsonschema
import pint

Expand Down Expand Up @@ -65,6 +66,10 @@ def __init__(

self.residual = None # initialize residual

# set up xdmf file with mesh info
with df.io.XDMFFile(self.mesh.comm, self.pv_output_file, "w") as f:
f.write_mesh(self.mesh)

# setup the material object to access the function
self.setup()

Expand Down
39 changes: 21 additions & 18 deletions src/fenicsxconcrete/finite_element_problem/linear_elasticity_grf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def __init__(
) -> None:
super().__init__(experiment, parameters, pv_name, pv_path)
# TODO There should be more elegant ways of doing this
danielandresarcones marked this conversation as resolved.
Show resolved Hide resolved
self.pv_egrf_file = Path(pv_path) / (pv_name + "egrf.xdmf")
self.pv_nugrf_file = Path(pv_path) / (pv_name + "nugrf.xdmf")
self.pv_file = Path(pv_path) / (pv_name + ".xdmf")

def setup(self) -> None:
self.field_function_space = df.fem.FunctionSpace(self.experiment.mesh, ("CG", 1))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the degree 1 compulsory or should it accept any?

Expand Down Expand Up @@ -125,19 +124,23 @@ def get_lames_constants(
return lame1, lame2

# TODO move this to sensor definition!?!?!
def pv_plot(self, t: int = 0) -> None:
# TODO add possibility for multiple time steps???
# Displacement Plot

# "Displacement.xdmf"
# pv_output_file
# TODO Look into how to unify in one file
with df.io.XDMFFile(self.mesh.comm, self.pv_output_file, "w") as xdmf:
xdmf.write_mesh(self.mesh)
xdmf.write_function(self.displacement)
with df.io.XDMFFile(self.mesh.comm, self.pv_egrf_file, "w") as xdmf:
xdmf.write_mesh(self.mesh)
xdmf.write_function(self.E_randomfield.field)
with df.io.XDMFFile(self.mesh.comm, self.pv_nugrf_file, "w") as xdmf:
xdmf.write_mesh(self.mesh)
xdmf.write_function(self.nu_randomfield.field)
def pv_plot(self, t: pint.Quantity | float = 1) -> None:
"""creates paraview output at given time step

Args:
t: time point of output (default = 1)
"""
print("create pv plot for t", t)
try:
_t = t.magnitude
except:
_t = t

self.displacement.name = "Displacement"
self.E_randomfield.field.name = "E_field"
self.nu_randomfield.field.name = "nu_field"

with df.io.XDMFFile(self.mesh.comm, self.pv_output_file, "a") as f:
f.write_function(self.displacement, _t)
f.write_function(self.E_randomfield.field, _t)
f.write_function(self.nu_randomfield.field, _t)
Loading