Skip to content

Commit

Permalink
push to main for code release week 3 (#42)
Browse files Browse the repository at this point in the history
* delete odb for veni sve simulation

* smaller radius threshold

* reduce log info for microstructure

* add asca rve

* naming of pp/pe mixture

* add cddm with f3dasm

* modify the bash script

* handling errors for pp/pe mixture class

* cddm data

* flake8 test
  • Loading branch information
JiaxiangYi96 authored Dec 5, 2023
1 parent 9508af1 commit 3a2f0cf
Show file tree
Hide file tree
Showing 19 changed files with 13,644 additions and 47 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,7 @@ dmypy.json

# folders
examples/
tutorials/Data/
tutorials/Data/
studies/cddm_data_generation/Data/
studies/cddm_data_generation/err*
studies/cddm_data_generation/out*
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.8

[options]
package_dir=
=src
packages=find:
python_requires = >=3.10
python_requires = >=3.8
install_requires =
numpy
pandas
Expand Down
10 changes: 3 additions & 7 deletions src/rvesimulator/additions/ampitudesampler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Modules
# =============================================================================
# Standard
from typing import Any
from typing import Any, Tuple

# Third-party
import numpy as np
Expand Down Expand Up @@ -100,10 +100,7 @@ def get_amplitude(
@staticmethod
def generate_control_points(
seed: int, num_control: int, num_steps: int, num_dim: int = 3
) -> tuple[
np.ndarray[Any, np.dtype[np.floating]],
np.ndarray[Any, np.dtype[np.floating]],
]:
) -> Tuple[Any, Any]:
"""generate control points
Parameters
Expand All @@ -119,8 +116,7 @@ def generate_control_points(
Returns
-------
tuple[ np.ndarray[any, np.dtype[np.floating]],
np.ndarray[any, np.dtype[np.floating]], ]
Tuple[Any, Any]
x_location of control points, y_location of control points
"""
num_control = int(num_control)
Expand Down
3 changes: 2 additions & 1 deletion src/rvesimulator/additions/hardening_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
# =============================================================================


# Base Classes
# Classes
# =============================================================================

class HardeningLaw(ABC):
def __init__(self) -> None:
"""Abstract class for the hardening law. The hardening law is defined
Expand Down
3 changes: 2 additions & 1 deletion src/rvesimulator/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from .asca_rve import ASCA_RVE
from .cddm_rve import CDDM_RVE
from .hollow_plate_sve import (ElasticRegularLoads, VonMisesPlasticPathLoads,
VonMisesPlasticRegularLoads)
from .veni_nocohesive_rve import VeniNoCohRVE
from .pppe_no_cohesive_rve import PPPEMixtureNoCohesive
252 changes: 252 additions & 0 deletions src/rvesimulator/benchmarks/asca_rve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
# Modules
# =============================================================================
# Standard
import logging
import os
import time
from typing import Any

import rvesimulator
from rvesimulator.abaqus2py.abaqus_simulator import AbaqusSimulator
from rvesimulator.additions.hardening_law import LinearHardeningLaw
from rvesimulator.microstructure.circle_particles import CircleParticles

from .shared_functionalities import SimulationBase

# Authorship & Credits
# =============================================================================
__author__ = "Jiaxiang Yi ([email protected])"
__credits__ = ["Jiaxiang Yi"]
__status__ = "Stable"
# =============================================================================

class ASCA_RVE(SimulationBase):
"""Interface between python and abaqus of the ASCA RVE case
Parameters
----------
SimulationBase : class
base class for simulation
"""
def __init__(self) -> None:
"""Interface between python and abaqus of the ASCA case"""

logging.basicConfig(level=logging.INFO, filename="asca_rve.log")
self.logger = logging.getLogger("abaqus_simulation")

self.main_folder = os.getcwd()
self.folder_info = {
"main_work_directory": os.path.join(os.getcwd(), "Data"),
"script_path": os.path.dirname(rvesimulator.__file__) + \
"/scriptbase",
"current_work_directory": "point_1",
"sim_path": "benchmark_abaqus_scripts.two_materials_rve",
"sim_script": "VonMisesPlasticElasticRegularLoads",
"post_path": "basic_analysis_scripts.post_process",
"post_script": "PostProcess2D",
}


def update_sim_info(
self,
size: float = 0.048,
radius_mu: float = 0.003,
radius_std: float = 0.0,
vol_req: float = 0.30,
youngs_modulus_matrix: float = 100.0,
poisson_ratio_matrix: float = 0.3,
youngs_modulus_fiber: float = 1.0,
poisson_ratio_fiber: float = 0.19,
mesh_partition: int = 30,
strain: list = [0.1, 0.0, 0.0],
num_steps: int = 100,
simulation_time: float = 1.0,
num_cpu: int = 1,
platform: str = "ubuntu",
hardening_law: Any = LinearHardeningLaw(),
seed: Any = None,
print_info: bool = False,
) -> None:
"""path dependent rve for cddm
Parameters
----------
size : float, optional
size of the rve, by default 0.048
radius_mu : float, optional
radius mean of the rve, by default 0.003
radius_std : float, optional
radius deviation of the rve, by default 0.0
vol_req : float, optional
volume fraction requirement, by default 0.30
youngs_modulus_matrix : float, optional
youngs modulus of the matrix material, by default 100.0
poisson_ratio_matrix : float, optional
poisson ratio of the matrix material, by default 0.3
youngs_modulus_fiber : float, optional
youngs modulus of the fiber material, by default 1.0
poisson_ratio_fiber : float, optional
poisson ratio of the fiber material, by default 0.19
mesh_partition : int, optional
mesh partition for the edges, by default 30
strain : list, optional
applied maximum strain, by default [0.1, 0.0, 0.0]
num_steps : int, optional
number of simulation steps, by default 100
simulation_time : float, optional
total simulation time, by default 1.0
num_cpu : int, optional
number of cpu used for simulation, by default 1
platform : str, optional
platform for simulation, by default "ubuntu"
hardening_law : class, optional
hardening law for the simulation, by default LinearHardeningLaw()
seed : Any, optional
seed number, by default None
print_info : bool, optional
print simulation information or not, by default False
"""

# get simulation information
self.size = size
self.radius_mu = radius_mu
self.radius_std = radius_std
self.vol_req = vol_req
self.youngs_modulus_matrix = youngs_modulus_matrix
self.poisson_ratio_matrix = poisson_ratio_matrix
self.youngs_modulus_fiber = youngs_modulus_fiber
self.poisson_ratio_fiber = poisson_ratio_fiber
self.mesh_partition = mesh_partition
self.strain = strain
self.num_steps = num_steps
self.simulation_time = simulation_time
self.num_cpu = num_cpu
self.platform = platform
self.hardening_law = hardening_law
self.seed = seed
# get hardening law
self.hardening_table = hardening_law.calculate_hardening_table()

self.sim_paras = {
"size": size,
"radius_mu": radius_mu,
"radius_std": radius_std,
"vol_req": vol_req,
"youngs_modulus_matrix": youngs_modulus_matrix,
"poisson_ratio_matrix": poisson_ratio_matrix,
"youngs_modulus_fiber": youngs_modulus_fiber,
"poisson_ratio_fiber": poisson_ratio_fiber,
"hardening_table": self.hardening_table,
"mesh_partition": mesh_partition,
"strain": strain,
"num_steps": num_steps,
"simulation_time": simulation_time,
"num_cpu": num_cpu,
"platform": platform, }

# print simulation information to screen
if print_info:
self._print_sim_info(info=self.sim_paras)

def _get_sim_info(self) -> None:
"""get simulation information"""
self.sim_info = {
"job_name": "asca_rve",
"location_information": self.microstructure.microstructure_info[
"location_information"
],
"radius_mu": self.microstructure.microstructure_info["radius_mu"],
"radius_std": self.microstructure.microstructure_info[
"radius_std"],
"len_start": self.microstructure.microstructure_info["len_start"],
"len_end": self.microstructure.microstructure_info["len_end"],
"wid_start": self.microstructure.microstructure_info["wid_start"],
"wid_end": self.microstructure.microstructure_info["wid_end"],
"youngs_modulus_matrix": self.youngs_modulus_matrix,
"poisson_ratio_matrix": self.poisson_ratio_matrix,
"youngs_modulus_fiber": self.youngs_modulus_fiber,
"poisson_ratio_fiber": self.poisson_ratio_fiber,
"mesh_partition": self.mesh_partition,
"hardening_table": self.hardening_table,
"num_steps": self.num_steps,
"simulation_time": self.simulation_time,
"strain": self.strain,
"num_cpu": self.num_cpu,
"platform": self.platform,
}

def run_simulation(
self,
sample: dict = None,
folder_index: int = None,
sub_folder_index: int = None,
third_folder_index: int = None,
) -> dict:
"""run single simulation
Parameters
----------
sample : dict, optional
a dict contains the information of design variables
folder_index : int, optional
first folder index, by default None
sub_folder_index : int, optional
second folder index, by default None
third_folder_index : int, optional
third folder index, by default None
Returns
-------
dict
all the simulation results from abaqus
"""
# number of samples
self._create_working_folder(
folder_index,
sub_folder_index,
third_folder_index,
)
os.chdir(self.working_folder)
self.logger.info("working folder: {}".format(self.working_folder))
# create microstructure
self.microstructure = CircleParticles(
length=self.size,
width=self.size,
radius_mu=self.radius_mu,
radius_std=self.radius_std,
vol_req=self.vol_req,
)
self.microstructure.generate_microstructure(seed=self.seed)
self.microstructure.to_abaqus_format()
self.microstructure.plot_microstructure(save_figure=True,
fig_name="rve_{}.png".
format(self.seed))
self.vol_frac = self.microstructure.vol_frac
self.logger.info("volume fraction: {}".format(self.vol_frac))
# update simulation information
self._get_sim_info()
# update the geometry info for microstructure
self._update_sample_info(sample=sample)
# update logger on samples
self.logger.info("============== update info ============")
self.logger.info("sample: {}".format(sample))
# change folder to main folder
# save microstructure
# update simulation information
self.logger.info("============== Start abaqus simulation ============")
start_time = time.time()
simulator = AbaqusSimulator(
sim_info=self.sim_info, folder_info=self.folder_info
)
# run abaqus simulation
simulator.run()
# get the simulation results back
results = simulator.read_back_results()
end_time = time.time()
self.logger.info("time used: {} s".format(end_time - start_time))
self.logger.info("============== End abaqus simulation ============")

# back to main folder
os.chdir(self.main_folder)

return results
11 changes: 9 additions & 2 deletions src/rvesimulator/benchmarks/cddm_rve.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,16 @@ def run_simulation(
sim_info=self.sim_info, folder_info=self.folder_info
)
# run abaqus simulation
simulator.run()
try:
simulator.execute()
simulator.post_process(delete_odb=True)
results = simulator.read_back_results()
self.logger.info("simulation finished")
except Exception as e:
self.logger.info("simulation failed")
self.logger.info(e)
results = None
# get the simulation results back
results = simulator.read_back_results()
end_time = time.time()
self.logger.info("time used: {} s".format(end_time - start_time))
self.logger.info("============== End abaqus simulation ============")
Expand Down
8 changes: 4 additions & 4 deletions src/rvesimulator/benchmarks/hollow_plate_sve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# =============================================================================


class HollowplateBase(SimulationBase):
class HollowPlateBase(SimulationBase):

def _get_sim_info(self) -> None:
"""get simulation info
Expand Down Expand Up @@ -103,7 +103,7 @@ def run_simulation(

return results

class ElasticRegularLoads(HollowplateBase):
class ElasticRegularLoads(HollowPlateBase):
def __init__(self) -> None:
"""Interface between python and abaqus of the Hollow plate case"""
logging.basicConfig(level=logging.INFO,
Expand Down Expand Up @@ -197,7 +197,7 @@ def update_sim_info(
# =============================================================================


class VonMisesPlasticRegularLoads(HollowplateBase):
class VonMisesPlasticRegularLoads(HollowPlateBase):

def __init__(self) -> None:
"""Interface between python and abaqus of the Hollow plate case"""
Expand Down Expand Up @@ -312,7 +312,7 @@ def update_sim_info(


# =============================================================================
class VonMisesPlasticPathLoads(HollowplateBase):
class VonMisesPlasticPathLoads(HollowPlateBase):
"""Hollow plate simulation case, with von mises plasticity and path loading
Parameters
Expand Down
Loading

0 comments on commit 3a2f0cf

Please sign in to comment.