Skip to content

Commit

Permalink
Merge pull request #121 from KOS-UJ/solver_methods
Browse files Browse the repository at this point in the history
Solver methods
  • Loading branch information
piotrbartman authored Nov 13, 2023
2 parents 98c43fd + f7d392b commit 9f7f7b2
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 431 deletions.
6 changes: 4 additions & 2 deletions conmech/helpers/nph.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ def generate_normal(rows: int, columns: int, scale: float) -> np.ndarray:


@numba.njit(inline="always")
def length(p_1, p_2):
return np.sqrt((p_1[0] - p_2[0]) ** 2 + (p_1[1] - p_2[1]) ** 2)
def length(edge, nodes):
return np.sqrt(
(nodes[edge[0]][0] - nodes[edge[1]][0]) ** 2 + (nodes[edge[0]][1] - nodes[edge[1]][1]) ** 2
)
2 changes: 1 addition & 1 deletion conmech/simulations/problem_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def find_solution(self, state, validator, *, verbose=False, **kwargs) -> np.ndar
quality = 0
initial_guess = state[self.coordinates].reshape(state.body.mesh.dimension, -1)
solution = self.step_solver.solve(initial_guess, **kwargs)
quality = validator.check_quality(state, solution, quality)
# quality = validator.check_quality(state, solution, quality)
self.print_iteration_info(quality, validator.error_tolerance, verbose)
return solution

Expand Down
54 changes: 22 additions & 32 deletions conmech/solvers/optimization/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@
StaticPoissonStatement,
)
from conmech.scenarios.problems import ContactLaw
from conmech.scene.body_forces import BodyForces
from conmech.solvers.solver import Solver
from conmech.solvers.solver_methods import (
make_cost_functional,
make_cost_functional_temperature,
make_cost_functional_piezoelectricity,
make_cost_functional_poisson,
make_cost_functional_3d,
)
from conmech.solvers.solver_methods import make_cost_functional


class Optimization(Solver):
def __init__(
self,
statement: Statement,
body: BodyForces,
body: "Body",
time_step: float,
contact_law: Optional[ContactLaw],
friction_bound,
Expand All @@ -41,38 +34,35 @@ def __init__(
contact_law,
friction_bound,
)
if statement.dimension == 2: # TODO
if statement.dimension >= 2: # TODO
self.loss = make_cost_functional(
jn=contact_law.potential_normal_direction,
jt=contact_law.potential_tangential_direction
if hasattr(contact_law, "potential_tangential_direction")
else None,
h_functional=friction_bound,
)
elif statement.dimension == 3: # TODO
self.loss = make_cost_functional_3d(
jn=contact_law.potential_normal_direction,
jt=contact_law.potential_tangential_direction
normal_condition=contact_law.potential_normal_direction,
tangential_condition=contact_law.potential_tangential_direction
if hasattr(contact_law, "potential_tangential_direction")
else None,
h_functional=friction_bound,
tangential_condition_bound=friction_bound,
variable_dimension=statement.dimension,
problem_dimension=body.mesh.dimension,
)
elif isinstance(statement, TemperatureStatement):
self.loss = make_cost_functional_temperature(
h_functional=contact_law.h_temp,
hn=contact_law.h_nu,
ht=contact_law.h_tau,
heat_exchange=contact_law.temp_exchange,
self.loss = make_cost_functional(
tangential_condition=contact_law.h_temp,
normal_condition=contact_law.temp_exchange,
normal_condition_bound=-1,
)
elif isinstance(statement, PiezoelectricStatement):
self.loss = make_cost_functional_piezoelectricity(
h_functional=contact_law.h_temp,
hn=contact_law.h_nu,
ht=contact_law.h_tau,
self.loss = make_cost_functional(
tangential_condition=contact_law.electric_charge_tangetial,
tangential_condition_bound=-1,
normal_condition=None,
variable_dimension=statement.dimension,
problem_dimension=body.mesh.dimension,
)
elif isinstance(statement, StaticPoissonStatement):
self.loss = make_cost_functional_poisson(
jn=contact_law.potential_normal_direction,
self.loss = make_cost_functional(
normal_condition=contact_law.potential_normal_direction,
variable_dimension=statement.dimension,
problem_dimension=body.mesh.dimension,
)
else:
raise ValueError(f"Unknown statement: {statement}")
Expand Down
Loading

0 comments on commit 9f7f7b2

Please sign in to comment.