Currently, pyFANS wraps the FANS functionality into an interface as required by the Micro Manager. However, pyFANS can also provide a general interface so that FANS functionality can be used via a Python script. To use the current interface in a Python script, pyFANS needs to be compiled as a shared library. The shared library file (for example, PyFANS.cpython-312-x86_64-linux-gnu.so) needs to be in the same folder as the Python script that uses PyFANS. The current interface can be used in the following way:
import importlib
micro_problem = getattr(importlib.import_module("PyFANS", "MicroSimulation"),"MicroSimulation")
input_data = dict()
input_data["strains1to3"] = [1, 2, 3] # dummy strain values
intput_data["strains4to6"] = [4, 5, 6] # dummy strain values
micro_output = micro_problem.solve(input_data)
stresses1to3 = micro_output["stresses1to3"]
stresses4to6 = micro_output["stresses4to6"]
stresses = stresses1to3 + stresses4to6
cmat1 = micro_output["cmat1"]
cmat2 = micro_output["cmat2"]
cmat3 = micro_output["cmat3"]
cmat4 = micro_output["cmat4"]
cmat5 = micro_output["cmat5"]
cmat6 = micro_output["cmat6"]
cmat7 = micro_output["cmat7"]
cmat = cmat1 + cmat2 + cmat3 + cmat4 + cmat5 + cmat6 + cmat7
This interface is restrictive in the way it breaks down the stress and stiffness tensors. This is done because preCICE currently cannot handle tensorial data. But a general interface of pyFANS could look like:
import importlib
micro_problem = getattr(importlib.import_module("PyFANS", "MicroSimulation"),"MicroSimulation")
strains = [1, 2, 3, 4, 5, 6] # dummy values
micro_output = micro_problem.get_solution(strains)
stresses = micro_output[0]
cmat = micro_output[1]
Eventually, we can also make pyFANS a Python package, such that one can directly do import pyFANS. The shared library style of importing is a requirement of the Micro Manager.
Open questions about the general interface are:
- Should there be one function called
get_solution or solve which accepts strains and returns the stress and stiffness values?
- Should there be separate functions
get_stresses and get_stiffness?
- What should be the Python side input data format for strains and the output data format for stress and stiffness? Is Python
list sufficient?
Currently, pyFANS wraps the FANS functionality into an interface as required by the Micro Manager. However, pyFANS can also provide a general interface so that FANS functionality can be used via a Python script. To use the current interface in a Python script, pyFANS needs to be compiled as a shared library. The shared library file (for example,
PyFANS.cpython-312-x86_64-linux-gnu.so) needs to be in the same folder as the Python script that uses PyFANS. The current interface can be used in the following way:This interface is restrictive in the way it breaks down the stress and stiffness tensors. This is done because preCICE currently cannot handle tensorial data. But a general interface of pyFANS could look like:
Eventually, we can also make pyFANS a Python package, such that one can directly do
import pyFANS. The shared library style of importing is a requirement of the Micro Manager.Open questions about the general interface are:
get_solutionorsolvewhich accepts strains and returns the stress and stiffness values?get_stressesandget_stiffness?listsufficient?