Exemplo n.º 1
0
#%%
import llgeo.quad4m.props_elems as q4m_elems
import llgeo.quad4m.props_nodes as q4m_nodes
import llgeo.quad4m.db_utils as q4m_db
import llgeo.quad4m.geometry as q4m_geom

import matplotlib.pyplot as plt
import numpy as np

# Get nodes and elems to play with
dxf_path = './CAD/'
dxf_inf = 'test_dike.dxf'
nodes, elems = q4m_geom.dxf_to_dfs(dxf_path, dxf_inf, lay_id='Soil_')

# Add boundary conditions, acceleration outputs, and initial conditions
acc_locations = [(0, 'all', 'dec'), (1, 'all', 'dec'), (0.5, 'all', 'dec')]
jwater = 3
props_ini = [{
    'unit_w': 21000,
    'po': 0.450,
    'PI': 0,
    'OCR': 1
}, {
    'unit_w': 19000,
    'po': 0.450,
    'PI': 15,
    'OCR': 1
}]

nodes = q4m_nodes.add_bound_conds('rigidbase_box', nodes)
nodes = q4m_nodes.add_acc_outputs(acc_locations, 'X', nodes)
Exemplo n.º 2
0
TO_DO:
'''
#%% Import modules

# Import standard pacakges
import numpy as np
import pandas as pd

# Import LLGEO modules
import llgeo.quad4m.geometry as geom
import llgeo.quad4m.genfiles as q4m_files

#%% STEP #1 --------------------------------------------------------------------
#   Obtain model geometry from DXF file
print('Generating geometry')
nodes, elems = geom.dxf_to_dfs('./CAD/',
                               '01_01.dxf')  # Read dxf and create dfs
geom.dfs_to_dxf('./CAD/', '01_01_check.dxf', nodes,
                elems)  # Output to dxf again, as a check

#%% STEP #2 --------------------------------------------------------------------
#   Element and node properties
print('Filling soil properties')

# Get number of nodes and elements
nelm = len(elems)
ndpt = len(nodes)

# Boundary conditions
BC = 0 * np.ones(ndpt)
BC[nodes['x'] == np.min(nodes['x'])] = 2  # Left Boundary
BC[nodes['x'] == np.max(nodes['x'])] = 2  # Right Boundary
Exemplo n.º 3
0
#%%

#%% Import modules

# Import standard pacakges
import numpy as np
import pandas as pd

# Import LLGEO modules
import llgeo.quad4m.geometry as geom
import llgeo.quad4m.genfiles as q4m_files

#%% STEP #1 --------------------------------------------------------------------
#   Obtain model geometry from DXF file
print('Generating geometry')
nodes, elems = geom.dxf_to_dfs('../quad4m_genfiles_q4r/CAD/', '01_01.dxf')  # Read dxf and create dfs


class model():

    def __init__(self, nodes, elems):

        # Initialize node information
        self.nodes = []

        for _, n in nodes.iterrows():
            node(n['node_n'], n['node_i'], n['node_j'], n['node_x'], n['node_y'])

            self.nodes += node(n, i, j, )

Exemplo n.º 4
0
def update_db_geoms(path_db, file_db, path_DXF, new_DXF_files, path_check):
    ''' Adds new entries to database of geometries
        
    Purpose
    -------
    Given a list of dxf files, this:
        * Processes new entries by generating elems and nodes dataframes and
          getting sizes of mesh. 
        * Saves pkl for each new geometry with all info
        * Updates the summary file "file_db" with new entries and returns it.
        * Returns list of dict with geometry info that was saved.

    Each processed geometry dictionary contains the following keys:
       *id     | entry id
       *name   | entry name
       *fname  | name of file where dfs are saved (includes extension .pkl)
       *W      | maximum width of the overall mesh
       *H      | maximum height of the overall meesh
       *nelm   | number of elements in the mesh
       *welm   | average width of all elements in mesh
       *helm   | average height of all elements in mesh
        nodes  | dataframe with node info (see llgeo/quad4m/geometry.py)
        elems  | dataframe with element info (see llgeo/quad4m/geometry.py)
        readme | short description of file

    (Items marked with * are included in summary file)
        
    Parameters
    ----------
    path_db : str
        directory containing geometry "database".
        
    file_db : str
        name of "database" summary file (usually ending in .pkl).

    path_DXF : str
        directory contianing new DXF files to be processed

    new_DXF_files : list of str
        list of dxf file names (usually ending in .dxf)

    path_check : str
        directory where "check" DXFs will be printed out
        If doesn't exist, will exit eith error.
        if set to False, then no check DXFs will be printed

    Returns
    -------
    db_geoms : dataframe
        "database" summary file, which now includes information on new_DXF_files

    geom_dicts : list of dictionaries
        Each element corresponds to a the DXF files provided in "new_DXF_files".
        Each element is a dict containing geometry info as described above. 
                        
    '''

    # Get the current database
    db_geoms = get_db(path_db, file_db, db_type='geoms')

    # Determine current id based on database
    if len(db_geoms) > 0:
        i = np.max(db_geoms['id'])
    else:
        i = 0

    # Readme to be included in new entries
    readme = ''' This geometry was processed using llgeo/quad4m/db_utils.
                 It contains dataframes of elems and nodes, and some summary
                 info. Will be used to probabilistically run ground response 
                 analyses using QUAD4MU.'''

    # Loop through new files and process them
    geom_dicts = []
    for new_DXF_file in new_DXF_files:

        # Name of entry to be processed
        name = new_DXF_file.replace('.dxf', '')

        # If name already exists, read data continue to next entry
        if name in db_geoms['name'].tolist():

            # Warn user that no new data is being processed
            mssg = 'Entry alread exists: {:10s}'.format(name)
            mssg += '\n Reading (not creating) data'
            warnings.showwarning(mssg, UserWarning, 'db_utils.py', '')

            # Determine name of entry
            f_exist = db_geoms.loc[db_geoms['name'] == name, 'fname'].item()

            # Read existing file and add to output dictionary
            geom_dicts += [llgeo_fls.read_pkl(path_db, f_exist)]
            continue

        # Otherwise, process new entry
        i += 1  # Update entry ID
        nodes, elems = q4m_geom.dxf_to_dfs(path_DXF, new_DXF_file)
        W, H, N, w, h = q4m_geom.get_mesh_sizes(nodes, elems)

        # Save new entry to pickle in database directory
        fname = '{i:03d}_{name}.pkl'.format(i=i, name=name)
        out_data = {
            'id': i,
            'name': name,
            'fname': fname,
            'W': W,
            'H': H,
            'nelm': N,
            'welm': w,
            'helm': h,
            'nodes': nodes,
            'elems': elems,
            'readme': readme
        }

        llgeo_fls.save_pkl(path_db, fname, out_data, True)

        # Make sure check directory exists (if needed)
        if path_check and not os.path.exists(path_check):
            err = 'DXF check directory does not exists\n'
            err += 'Create it, or set path_check = False'
            raise Exception(err)

        # Output DXFs as a check (if path_check is not False)
        elif path_check:
            file_check = fname.replace('.pkl', '.dxf')
            q4m_geom.dfs_to_dxf(path_check, file_check, nodes, elems)

        # Add summary info to db_geoms
        cols = list(db_geoms)
        new_row = pd.DataFrame([[i, name, fname, W, H, N, w, h]], columns=cols)
        db_geoms = db_geoms.append(new_row, ignore_index=True)

        # Add new data for list export
        geom_dicts += [out_data]

    # Save db_geoms summary file
    db_geoms.to_pickle(path_db + file_db)

    return db_geoms, geom_dicts