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

Linear solver for post-process chemical potential #579

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
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
31 changes: 20 additions & 11 deletions festim/concentration/theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,35 @@ def post_processing_solution_to_concentration(self):
The attribute post_processing_solution is fenics.Product (if self.S is
festim.ArheniusCoeff)
"""
du = f.TrialFunction(self.post_processing_solution.function_space())
J = f.derivative(self.form_post_processing, self.post_processing_solution, du)
problem = f.NonlinearVariationalProblem(
self.form_post_processing, self.post_processing_solution, [], J
problem = f.LinearVariationalProblem(
a=f.lhs(self.form_post_processing),
L=f.rhs(self.form_post_processing),
u=self.post_processing_solution,
bcs=[],
)
solver = f.NonlinearVariationalSolver(problem)
# TODO these prms should be the same as in Simulation.settings I think
solver.parameters["newton_solver"]["absolute_tolerance"] = 1e-10
solver.parameters["newton_solver"]["relative_tolerance"] = 1e-10
solver.parameters["newton_solver"]["maximum_iterations"] = 50
solver = f.LinearVariationalSolver(problem)
solver.solve()

def create_form_post_processing(self, V, materials, dx):
"""Creates a variational formulation for c = theta * S or theta**2 * S

Args:
V (fenics.FunctionSpace): the DG1 function space of the concentration field
materials (festim.Materials): the materials
dx (fenics.Measurement): the dx measure of the problem
"""
F = 0
v = f.TestFunction(V)
self.post_processing_solution = f.Function(V)
F += -self.post_processing_solution * v * dx
c = f.TrialFunction(V)

F += -c * v * dx
for mat in materials.materials:
if mat.solubility_law == "sievert":
# for sievert materials c = theta * S
F += self.solution * self.S * v * dx(mat.id)
elif mat.solubility_law == "henry":
# for henry materials c = theta**2 * S
F += self.solution**2 * self.S * v * dx(mat.id)

self.form_post_processing = F
self.post_processing_solution = f.Function(V)
Loading