@banghuazhao
I edited the code that @Haodong shared based on my instructions. I deleted the default values because CompositesAI seem to ignore user inputs and only use the default values. Hope this works.
import requests
class Tools:
def __init__(self):
self.base_url = (
"https://composites-ai-tools-api-a88cb33feb62.herokuapp.com/api/v1/"
)
def cylindrical_bending_analysis(
self,
L: float = None,
h: float = None,
q0: float = None,
layer_angles: list = None,
material_props: dict = None,
disp_x1: list = None,
strain_x1: list = None,
stress_x1: list = None,
probe_x1: list = None,
probe_x3: list = None,
plots: list = None,
) -> dict:
"""
Perform a cylindrical bending laminate analysis and obtain generated figures and numerical probe results. If required inputs are missing, prompt the user to provide them.
:param L: Length of the laminate in meters.
Example: 4.0
:param h: Thickness of the laminate in meters.
Example: 1.0
:param q0: Applied transverse load in Pascals.
Example: 1_000_000
:param layer_angles: List of fiber orientation angles (in degrees) from bottom to top for each laminate layer.
Example: [0, 45, -45, 90]
:param material_props: Dictionary of material properties for orthotropic materials. If the input describes an isotropic or transversely isotropic material,
the following engineering constants must be automatically computed based on given inputs:
- E1, E2, E3: Young’s moduli
- G12, G13, G23: Shear moduli
- nu12, nu13, nu23: Poisson’s ratios
Example:
{
"E1": 1.4e11,
"E2": 1e10,
"E3": 1e10,
"G12": 7e9,
"G13": 7e9,
"G23": 3.36e9,
"nu12": 0.3,
"nu13": 0.3,
"nu23": 0.49
}
:param disp_x1: x₁ coordinates for extracting displacement components [U, V, W].
Must lie within the laminate: 0 ≤ x₁ ≤ L.
Example: [0, 0, 2] means U and V at x₁ = 0; W at x₁ = 2
:param strain_x1: x₁ coordinates for extracting strain components [ε₁₁, ε₃₃, γ₂₃, γ₁₃, γ₁₂].
Must lie within the laminate: 0 ≤ x₁ ≤ L.
Example: [2, 2, 0, 0, 2] means ε₁₁, γ₁₂ at x₁ = 2; γ₂₃, γ₁₃ at x₁ = 0; ε₃₃ at x₁ = 2
:param stress_x1: x₁ coordinates for extracting stress components [σ₁₁, σ₂₂, σ₃₃, σ₂₃, σ₁₃, σ₁₂].
Must lie within the laminate length: 0 ≤ x₁ ≤ L.
Example: [2, 2, 2, 0, 0, 2] means σ₁₁, σ₂₂, σ₃₃, σ₁₂ at x₁ = 2; σ₂₃, σ₁₃ at x₁ = 0
:param probe_x1: x₁ coordinate for probing a specific point.
Must satisfy: 0 ≤ x₁ ≤ L.
Required if "probe" is included in `plots`.
Example: 2.0
:param probe_x3: x₃ coordinate through the laminate thickness for probing.
Must satisfy: -h/2 ≤ x₃ ≤ h/2.
Required if "probe" is included in `plots`.
Example: 0.0
:param plots: List of plots/numerical values for output. Must choose the option(s) below (do not specify options not listed below in this parameter):
- "2d_combined": Generates three 2D plots at the specified x₁. One plot for all displacement components, one for all strain components, and one for all stress components.
The x axis is x₁ and the y axis is displacements/strains/stresses in SI unit.
- "2d_standalone": Separate plots for each displacement, strain, and stress component. The x axis is x₁ and the y axis is displacement/strain/stress component in SI unit.
- "3d": 3D plots with the x axis being x₁, the y axis being x₃, and the z axis being displacement/strain/stress component in SI unit.
- "probe": Get the numerical values of displacements, strains, and stresses at a specific (x₁, x₃) location inside the laminate.
Examples:
["2d_combined", "3d"] means 2D plots where all displacements, strain components, and stress components are plotted together and 3D plots are requested
["2d_standalone", "probe"] means separate 2D plots and values at specific point specified are requested
:return: Dictionary containing URLs to generated plots and numerical results for probing if specified.
"""
url = self.base_url + "cylindrical-bending-analysis"
payload = {
"L": L,
"h": h,
"q0": q0,
"layer_angles": layer_angles,
"material_props": material_props,
"disp_x1": disp_x1,
"strain_x1": strain_x1,
"stress_x1": stress_x1,
"plots": plots,
}
if probe_x1 is not None and probe_x3 is not None:
payload["probe_x1"] = probe_x1
payload["probe_x3"] = probe_x3
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
try:
response.raise_for_status()
return response.json()
except Exception as e:
return {
"error": str(e),
"status_code": response.status_code,
"text": response.text,
}