Region

Understanding the RegionManager

The RegionManager is a core component of the Femora library that serves as a centralized system for creating, retrieving, tracking, and managing region objects. It implements the Singleton pattern to ensure a single, consistent point of region management across the entire application.

Regions defined in Femora are automatically tracked, tagged, and organized by the RegionManager, simplifying the process of defining specific parts of your model for targeted analysis and damping assignments.

Accessing the RegionManager

There are two ways to access the RegionManager in your code:

  1. Direct Access: Import and use the RegionManager class directly

    from femora.components.Region.regionBase import RegionManager
    
    # Get the singleton instance
    region_manager = RegionManager()
    
    # Use the region manager directly
    region_manager.create_region(...)
    
  2. Through femora (Recommended): Access via the Femora class’s .region property

    import femora as fm
    
    # Create a Femora instance
    
    
    # Access the RegionManager through the .region property
    fm.region.create_region(...)
    

The second approach is recommended as it provides a unified interface to all of Femora’s components and ensures proper initialization of all dependencies.

How RegionManager Works

The RegionManager provides several key capabilities:

  1. Region Creation: Creates region objects of various types with appropriate parameters

  2. Region Tracking: Keeps track of all region instances by tag

  3. Region Tagging: Automatically assigns sequential tags to region instances

  4. Region Management: Provides methods to retrieve, update, and delete region instances

When a region is created, the RegionManager:

  1. Assigns a unique numeric tag automatically (starting from 1, as tag 0 is reserved for the GlobalRegion)

  2. Validates that all required parameters are present and valid

  3. Registers it for use in defining parts of the model

Global Region

The GlobalRegion is a special region with tag 0 that represents the entire model. It’s automatically created when the RegionManager is initialized, and there can only be one instance of GlobalRegion in the system.

This region serves as the default region for operations that don’t specify a specific region, providing a convenient way to apply configurations to the entire model.

Region Tagging System

The RegionManager implements an intelligent tagging system that:

  • Reserves tag 0 for the GlobalRegion

  • Assigns sequential tags to other regions starting from 1

  • Automatically retags instances when one is removed to maintain sequential numbering

  • Ensures uniqueness of tags across the model

RegionManager API Reference

Key Methods:

class femora.components.Region.regionBase.RegionManager[source]

Bases: object

A centralized manager for all region instances in MeshMaker.

The RegionManager implements the Singleton pattern to ensure a single, consistent point of region management across the entire application. It provides methods for creating, retrieving, and managing region objects used to define specific parts of structural models for analysis and damping assignments.

All region objects created through this manager are automatically tracked and tagged, simplifying the process of defining and managing model regions. A special GlobalRegion with tag 0 is automatically created when the RegionManager is initialized.

GlobalRegion()[source]

Get the GlobalRegion instance.

Returns:

The global region instance

Return type:

GlobalRegion

__init__()[source]

Initialize the RegionManager and create the GlobalRegion.

This method ensures that the global region (tag 0) is automatically created when the RegionManager is initialized. The initialization only happens once due to the singleton pattern.

clear_regions()[source]

Remove all regions and reinitialize the GlobalRegion.

This method clears all region instances, including the GlobalRegion, and then recreates the GlobalRegion with tag 0.

create_region(regionType, damping=None, **kwargs)[source]

Create a new region instance of the specified type.

This method creates and returns a new region object based on the provided type and parameters. The region is automatically registered and tracked.

Parameters:
  • regionType (str) – The type of region to create. Available types include: ‘ElementRegion’: A region defined by a set of elements or element range ‘NodeRegion’: A region defined by a set of nodes or node range ‘GlobalRegion’: The global region representing the entire model

  • damping – Optional damping instance to associate with the region

  • **kwargs – Specific parameters for the region type being created (e.g., elements, element_range for ElementRegion, nodes, node_range for NodeRegion)

Returns:

A new instance of the requested region type

Return type:

RegionBase

Raises:

ValueError – If the region type is unknown or if required parameters are missing or invalid

get_region(tag)[source]

Get a region by its tag.

Parameters:

tag (int) – The unique identifier of the region instance

Returns:

The region instance with the specified tag, or None if not found

Return type:

RegionBase

print_regions()[source]

Print information about all regions.

This method prints detailed information about all region instances including their tags, types, elements/nodes, and damping assignments.

property regions

Get all regions as a dictionary mapping tags to region instances.

Returns:

A dictionary mapping tags to region instances

Return type:

Dict[int, RegionBase]

remove_region(tag)[source]

Remove a region by its tag.

This method removes the specified region instance and automatically updates the tags of the remaining region instances to maintain sequential numbering. The GlobalRegion (tag 0) cannot be removed.

Parameters:

tag (int) – The unique identifier of the region instance to remove

Raises:

ValueError – If attempting to remove the GlobalRegion (tag 0)

Region Creation

Creating regions is one of the primary functions of the RegionManager. When creating a region, you need to specify:

  1. regionType: Specifies the region type to create. Available types include: - ElementRegion: A region defined by a set of elements or element range - NodeRegion: A region defined by a set of nodes or node range - GlobalRegion: The global region representing the entire model (typically not created directly)

  2. damping: Optional damping instance to associate with the region

  3. Region-specific parameters: Each region type requires specific parameters (like elements, element_range for ElementRegion)

The RegionManager handles all the details of creating the appropriate region object based on these parameters, ensuring type safety and parameter validation.

Usage Example

from femora.components.Region.regionBase import RegionManager
from femora.components.Damping.dampingBase import DampingManager

# Get the region manager instance
region_manager = RegionManager()

# Get the damping manager instance
damping_manager = DampingManager()

# Create a Rayleigh damping instance
rayleigh_damping = damping_manager.create_damping(
    'rayleigh',
    alphaM=0.1,
    betaK=0.2
)

# Create an element region with specific elements and the damping
element_region = region_manager.create_region(
    'ElementRegion',
    damping=rayleigh_damping,
    elements=[1, 2, 3, 4, 5]
)

# Create a node region with a node range
node_region = region_manager.create_region(
    'NodeRegion',
    node_range=[1, 100]
)

# Access the global region
global_region = region_manager.get_region(0)

# Remove a region
region_manager.remove_region(2)

# Print all regions
region_manager.print_regions()

Available Region Types

The region types available in Femora provide different ways to define specific parts of your model for targeted analysis and configuration. Follow the link above to explore the different region types available.

Each region type has its own documentation page with detailed parameter descriptions and usage examples.