def __init__(self, mesh, variables_order=(2, 0, 0), quadrature_rules=None, quadrature_type=None, function_spaces=None): if mesh.element_type != "tet" and mesh.element_type != "tri": raise NotImplementedError(type(self.__name__), "has not been implemented for", mesh.element_type, "elements") if isinstance(variables_order, int): self.variables_order = (self.variables_order, ) self.variables_order = variables_order super(NearlyIncompressibleHuWashizu, self).__init__(mesh, variables_order=self.variables_order, quadrature_type=quadrature_type, quadrature_rules=quadrature_rules, function_spaces=function_spaces) C = mesh.InferPolynomialDegree() - 1 if C == 0 and self.variables_order[0] > 1: warn( "Incompatible mesh and for the interpolation degree chosen for function spaces" ) mesh.GetHighOrderMesh(p=C + 1) # OPTION FOR QUADRATURE TECHNIQUE FOR TRIS AND TETS if mesh.element_type == "tri" or mesh.element_type == "tet": optimal_quadrature = 3 norder = 2 * C # TAKE CARE OF C=0 CASE if norder == 0: norder = 1 # GET QUADRATURE quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder, mesh_type=mesh.element_type) function_space = FunctionSpace(mesh, quadrature, p=C + 1) # COMPUTE INTERPOLATION FUNCTIONS AT ALL INTEGRATION POINTS FOR POST-PROCESSING norder_post = 2 * (C + 1) post_quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder_post, mesh_type=mesh.element_type) # CREATE FUNCTIONAL SPACES post_function_space = FunctionSpace(mesh, post_quadrature, p=C + 1) self.quadrature_rules = (quadrature, post_quadrature) self.function_spaces = (function_space, post_function_space)
def DistributedMatrices(elem, MainData, mesh, material, Eulerx, I_stiff_elem, J_stiff_elem, I_mass_elem, J_mass_elem): massel = [] f = [] # GET THE FIELDS AT THE ELEMENT LEVEL LagrangeElemCoords = mesh.points[mesh.elements[elem, :], :] EulerElemCoords = Eulerx[mesh.elements[elem, :], :] if MainData.Fields == 'ElectroMechanics': ElectricPotentialElem = TotalPot[elements[elem, :], :] else: ElectricPotentialElem = [] nodeperelem = mesh.elements.shape[1] from Florence import FunctionSpace, QuadratureRule norder = 2 * MainData.C if norder == 0: norder = 1 QuadratureOpt = 3 quadrature = QuadratureRule(optimal=QuadratureOpt, norder=norder, mesh_type=mesh.element_type) function_space = FunctionSpace(mesh, quadrature, p=MainData.C + 1) MainData.Domain, MainData.Boundary = function_space, function_space.Boundary norder_post = (MainData.C + 1) + (MainData.C + 1) post_quadrature = QuadratureRule(optimal=QuadratureOpt, norder=norder_post, mesh_type=mesh.element_type) function_space = FunctionSpace(mesh, post_quadrature, p=MainData.C + 1) MainData.PostDomain, MainData.PostBoundary = function_space, function_space.Boundary # MainData.Domain, MainData.Boundary, MainData.Quadrature = GetBasesAtInegrationPoints(MainData.C, # norder,QuadratureOpt,mesh.element_type) # norder_post = (MainData.C+1)+(MainData.C+1) # MainData.PostDomain, MainData.PostBoundary, MainData.PostQuadrature = GetBasesAtInegrationPoints(MainData.C, # norder_post,QuadratureOpt,mesh.element_type) stiffnessel, t = Stiffness(MainData, material, LagrangeElemCoords, EulerElemCoords, ElectricPotentialElem, elem) # FROM THE LOCAL I & J VECTORS GET GLOBAL I & J VECTORS full_current_row_stiff, full_current_column_stiff = SparseAssembly_Step_1( I_stiff_elem, J_stiff_elem, MainData.nvar, nodeperelem, elem, mesh.elements) return full_current_row_stiff, full_current_column_stiff, stiffnessel.ravel( ), t, f, [], [], []
def GetBoundaryBases(C, Quadrature, info, bases_type="nodal", equally_spaced=False, is_flattened=False): binfo, ndim = None, None if info == "hex": binfo = "quad" ndim == 3 elif info == "tet": binfo = "tri" ndim == 3 elif info == "quad" or info == "tri": binfo = "line" ndim == 2 if Quadrature is None: norder = C + 2 from Florence import QuadratureRule Quadrature = QuadratureRule(norder=norder, mesh_type=binfo, is_flattened=is_flattened) if ndim == 3: return GetBases2D(C, Quadrature, info, bases_type=bases_type, equally_spaced=equally_spaced, is_flattened=is_flattened) elif ndim == 2: return GetBases1D(C, Quadrature, info, bases_type=bases_type, equally_spaced=equally_spaced, is_flattened=is_flattened)
def __init__(self, mesh, variables_order=(1,0,0), subtype="lagrange_multiplier", quadrature_rules=None, quadrature_type=None, function_spaces=None, compute_post_quadrature=False, equally_spaced_bases=False, save_condensed_matrices=True): """ Input: subtype: [str] either "lagrange_multiplier", "augmented_lagrange" or "penalty" """ if mesh.element_type != "tet" and mesh.element_type != "tri" and \ mesh.element_type != "quad" and mesh.element_type != "hex": raise NotImplementedError( type(self).__name__, "has not been implemented for", mesh.element_type, "elements") if isinstance(variables_order,int): self.variables_order = (self.variables_order,) self.variables_order = variables_order super(CoupleStressFormulation, self).__init__(mesh,variables_order=self.variables_order, quadrature_type=quadrature_type,quadrature_rules=quadrature_rules,function_spaces=function_spaces, compute_post_quadrature=compute_post_quadrature) self.fields = "couple_stress" self.nvar = self.ndim self.subtype = subtype self.save_condensed_matrices = save_condensed_matrices C = mesh.InferPolynomialDegree() - 1 mesh.InferBoundaryElementType() if C < 1: raise ValueError("Incorrect initial mesh provided for the formulation. Mesh has to be at least order 2") # CHECK IF MESH IS APPROPRIATE # if C == 0: # warn('Mesh not appropriate for formulation') # raise ValueError('Mesh not appropriate for formulation. p>1 for primary variable (displacement)') # BUILD MESHES FOR ALL FIELDS p = C+1 # DISPLACEMENTS mesh0 = deepcopy(mesh) # ROTATIONS mesh1 = deepcopy(mesh) mesh1 = mesh1.GetLinearMesh(remap=True) mesh1.GetHighOrderMesh(p=p-1) # LAGRANGE MULTIPLIER mesh2 = deepcopy(mesh) mesh2 = mesh2.GetLinearMesh(remap=True) mesh2.GetHighOrderMesh(p=p-1) # ALL MESHES self.meshes = (mesh0,mesh1,mesh2) # GET QUADRATURE RULES norder = C+2 if mesh.element_type == "quad" or mesh.element_type == "hex": norder = C+1 if quadrature_rules == None and self.quadrature_rules == None: # FOR DISPLACEMENT quadrature0 = QuadratureRule(optimal=3, norder=self.GetQuadratureOrder(norder,mesh.element_type)[0], mesh_type=mesh.element_type, is_flattened=False) # FOR ROTATIONS quadrature1 = QuadratureRule(optimal=3, norder=self.GetQuadratureOrder(norder,mesh.element_type)[0], mesh_type=mesh.element_type, is_flattened=False) # FOR LAGRANGE MULTIPLIER quadrature2 = QuadratureRule(optimal=3, norder=self.GetQuadratureOrder(norder,mesh.element_type)[0], mesh_type=mesh.element_type, is_flattened=False) # BOUNDARY bquadrature = QuadratureRule(optimal=3, norder=C+2, mesh_type=mesh.boundary_element_type, is_flattened=False) self.quadrature_rules = (quadrature0,quadrature1,quadrature2,bquadrature) else: self.quadrature_rules = quadrature_rules # GET FUNCTIONAL SPACES if function_spaces == None and self.function_spaces == None: # FOR DISPLACEMENT function_space0 = FunctionSpace(mesh0, self.quadrature_rules[0], p=mesh0.degree, equally_spaced=equally_spaced_bases, use_optimal_quadrature=False) # FOR ROTATIONS function_space1 = FunctionSpace(mesh1, self.quadrature_rules[1], p=mesh1.degree, equally_spaced=equally_spaced_bases, use_optimal_quadrature=False) # FOR LAGRANGE MULTIPLIER function_space2 = FunctionSpace(mesh2, self.quadrature_rules[2], p=mesh2.degree, equally_spaced=equally_spaced_bases, use_optimal_quadrature=False) # BOUNDARY bfunction_space = FunctionSpace(mesh0.CreateDummyLowerDimensionalMesh(), self.quadrature_rules[3], p=mesh0.degree, equally_spaced=equally_spaced_bases, use_optimal_quadrature=False) self.function_spaces = (function_space0, function_space1, function_space2, bfunction_space) else: self.function_spaces = function_spaces # local_size = function_space.Bases.shape[0]*self.nvar local_size = self.function_spaces[0].Bases.shape[0]*self.nvar self.local_rows = np.repeat(np.arange(0,local_size),local_size,axis=0) self.local_columns = np.tile(np.arange(0,local_size),local_size) self.local_size = local_size # FOR MASS local_size_m = self.function_spaces[0].Bases.shape[0]*self.nvar self.local_rows_mass = np.repeat(np.arange(0,local_size_m),local_size_m,axis=0) self.local_columns_mass = np.tile(np.arange(0,local_size_m),local_size_m) self.local_size_m = local_size_m if self.save_condensed_matrices: # elist = [0]*mesh.nelem # CANT USE ONE PRE-CREATED LIST AS IT GETS MODIFIED # KEEP VECTORS AND MATRICES SEPARATE BECAUSE OF THE SAME REASON if self.subtype == "lagrange_multiplier": self.condensed_matrices = {'k_uu':[0]*mesh.nelem,'k_us':[0]*mesh.nelem, 'k_ww':[0]*mesh.nelem,'k_ws':[0]*mesh.nelem,'inv_k_ws':[0]*mesh.nelem} self.condensed_vectors = {'tu':[0]*mesh.nelem,'tw':[0]*mesh.nelem,'ts':[0]*mesh.nelem} elif self.subtype == "augmented_lagrange": self.condensed_matrices = {'k_uu':[0]*mesh.nelem,'k_us':[0]*mesh.nelem, 'k_ww':[0]*mesh.nelem,'k_ws':[0]*mesh.nelem,'k_ss':[0]*mesh.nelem,'inv_k_ws':[0]*mesh.nelem} self.condensed_vectors = {'tu':[0]*mesh.nelem,'tw':[0]*mesh.nelem,'ts':[0]*mesh.nelem} elif self.subtype == "penalty": self.condensed_matrices = {'k_uu':[0]*mesh.nelem,'k_uw':[0]*mesh.nelem,'k_ww':[0]*mesh.nelem} self.condensed_vectors = {'tu':[0]*mesh.nelem,'tw':[0]*mesh.nelem} # COMPUTE THE COMMON/NEIGHBOUR NODES ONCE self.all_nodes = np.unique(self.meshes[1].elements) self.Elss, self.Poss = self.meshes[1].GetNodeCommonality()[:2]
def GetQuadraturesAndFunctionSpaces(self, mesh, variables_order=(1, ), quadrature_rules=None, quadrature_type=None, function_spaces=None, compute_post_quadrature=True, equally_spaced_bases=False, quadrature_degree=None): """"The default function for computing quadrature rules and function spaces for equall order single and multi-physics/fields problems""" C = mesh.InferPolynomialDegree() - 1 mesh.InferBoundaryElementType() if quadrature_rules == None and self.quadrature_rules == None: # OPTION FOR QUADRATURE TECHNIQUE FOR TRIS AND TETS optimal_quadrature = 3 if mesh.element_type == "quad" or mesh.element_type == "hex": if quadrature_type == "wv": optimal_quadrature = 4 norder, norder_post = self.GetQuadratureOrder( C, mesh.element_type, quadrature_degree=quadrature_degree) # GET QUADRATURE quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder, mesh_type=mesh.element_type) if self.compute_post_quadrature: # COMPUTE INTERPOLATION FUNCTIONS AT ALL INTEGRATION POINTS FOR POST-PROCESSING post_quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder_post, mesh_type=mesh.element_type) else: post_quadrature = None # BOUNDARY QUADRATURE bquadrature = QuadratureRule(optimal=optimal_quadrature, norder=C + 2, mesh_type=mesh.boundary_element_type) self.quadrature_rules = (quadrature, post_quadrature, bquadrature) else: self.quadrature_rules = quadrature_rules if function_spaces == None and self.function_spaces == None: # CREATE FUNCTIONAL SPACES function_space = FunctionSpace(mesh, self.quadrature_rules[0], p=C + 1, equally_spaced=equally_spaced_bases) if self.compute_post_quadrature: post_function_space = FunctionSpace( mesh, self.quadrature_rules[1], p=C + 1, equally_spaced=equally_spaced_bases) else: post_function_space = None # CREATE BOUNDARY FUNCTIONAL SPACES bfunction_space = FunctionSpace( mesh.CreateDummyLowerDimensionalMesh(), self.quadrature_rules[2], p=C + 1, equally_spaced=equally_spaced_bases) self.function_spaces = (function_space, post_function_space, bfunction_space) else: self.function_spaces = function_spaces local_size = self.function_spaces[0].Bases.shape[0] * self.nvar self.local_rows = np.repeat(np.arange(0, local_size), local_size, axis=0) self.local_columns = np.tile(np.arange(0, local_size), local_size) self.local_size = local_size # FOR MASS local_size_m = self.function_spaces[0].Bases.shape[0] * self.ndim self.local_rows_mass = np.repeat(np.arange(0, local_size_m), local_size_m, axis=0) self.local_columns_mass = np.tile(np.arange(0, local_size_m), local_size_m) self.local_size_m = local_size_m
def test_BEM(): """Unnecessary test for the ugly and non-working and legacy BEM for the sake of coverage """ from Florence.BoundaryElements import GetBasesBEM2D from Florence.BoundaryElements import GenerateCoordinates from Florence.BoundaryElements import CoordsJacobianRadiusatGaussPoints, CoordsJacobianRadiusatGaussPoints_LM from Florence.BoundaryElements import AssemblyBEM2D from Florence.BoundaryElements.Assembly import AssemblyBEM2D_Sparse from Florence.BoundaryElements import Sort_BEM from Florence import QuadratureRule, FunctionSpace, Mesh # Unnecessary loop for i in range(10): mesh = Mesh() mesh.element_type = "line" mesh.points = np.array([ [0.,0.], [1.,0.], [1.,1.], [0.,1.], ]) mesh.elements = np.array([ [0,1], [1,2], [2,3], [3,0], ]) mesh.nelem = 4 q = QuadratureRule(mesh_type="line") for C in range(10): N, dN = GetBasesBEM2D(C,q.points) N, dN = GetBasesBEM2D(2,q.points) global_coord = np.zeros((mesh.points.shape[0],3)) global_coord[:,:2] = mesh.points Jacobian = 2*np.ones((q.weights.shape[0],mesh.nelem)) nx = 4*np.ones((q.weights.shape[0],mesh.nelem)) ny = 3*np.ones((q.weights.shape[0],mesh.nelem)) XCO = 2*np.ones((q.weights.shape[0],mesh.nelem)) YCO = np.ones((q.weights.shape[0],mesh.nelem)) N = np.ones((mesh.elements.shape[1],q.weights.shape[0])) dN = 0.5*np.ones((mesh.elements.shape[1],q.weights.shape[0])) GenerateCoordinates(mesh.elements,mesh.points,0,q.points) CoordsJacobianRadiusatGaussPoints(mesh.elements,global_coord,0,N,dN,q.weights) # Not working # CoordsJacobianRadiusatGaussPoints_LM(mesh.elements,global_coord[:,:3],0,N,dN,q.weights,mesh.elements) class GeoArgs(object): Lagrange_Multipliers = "activated" def __init__(self): Lagrange_Multipliers = "activated" geo_args = GeoArgs() K1, K2 = AssemblyBEM2D(0,global_coord,mesh.elements,mesh.elements,dN,N, q.weights,q.points,Jacobian, nx, ny, XCO, YCO, geo_args) AssemblyBEM2D_Sparse(0,global_coord,mesh.elements,mesh.elements,dN,N, q.weights,q.points,Jacobian, nx, ny, XCO, YCO, geo_args) bdata = np.zeros((2*mesh.points.shape[0],2)) bdata[:4,1] = -1 bdata[4:,0] = -1 Sort_BEM(bdata,K1, K2)
for fs in function_spaces: if ndim == 3 and fs.ndim == 2: has_boundary_spaces = True break <<<<<<< HEAD if not has_boundary_spaces: raise ValueError("Boundary functional spaces not available for computing Neumman and body forces") ======= elif ndim == 2 and fs.ndim == 1: has_boundary_spaces = True break if not has_boundary_spaces: from Florence import QuadratureRule, FunctionSpace # COMPUTE BOUNDARY FUNCTIONAL SPACES p = mesh.InferPolynomialDegree() bquadrature = QuadratureRule(optimal=3, norder=2*p+1, mesh_type=mesh.boundary_element_type, is_flattened=False) bfunction_space = FunctionSpace(mesh.CreateDummyLowerDimensionalMesh(), bquadrature, p=p, equally_spaced=mesh.IsEquallySpaced, use_optimal_quadrature=False) function_spaces = (function_spaces[0],bfunction_space) # raise ValueError("Boundary functional spaces not available for computing Neumman and body forces") >>>>>>> upstream/master t_tassembly = time() if self.analysis_type == "static": F = AssembleForces(self, mesh, material, function_spaces, compute_traction_forces=compute_traction_forces, compute_body_forces=compute_body_forces) elif self.analysis_type == "dynamic": if self.neumann_flags.ndim==2: # THE POSITION OF NEUMANN DATA APPLIED AT FACES CAN CHANGE DYNAMICALLY tmp_flags = np.copy(self.neumann_flags) tmp_data = np.copy(self.applied_neumann)
def __init__(self, mesh, variables_order=(1,), quadrature_rules=None, quadrature_type=None, function_spaces=None, compute_post_quadrature=True, equally_spaced_bases=False): if mesh.element_type != "tet" and mesh.element_type != "tri" and \ mesh.element_type != "quad" and mesh.element_type != "hex": raise NotImplementedError( type(self).__name__, "has not been implemented for", mesh.element_type, "elements") if isinstance(variables_order,int): self.variables_order = (self.variables_order,) self.variables_order = variables_order super(DisplacementFormulation, self).__init__(mesh,variables_order=self.variables_order, quadrature_type=quadrature_type,quadrature_rules=quadrature_rules,function_spaces=function_spaces, compute_post_quadrature=compute_post_quadrature) self.fields = "mechanics" self.nvar = self.ndim C = mesh.InferPolynomialDegree() - 1 mesh.InferBoundaryElementType() if quadrature_rules == None and self.quadrature_rules == None: # OPTION FOR QUADRATURE TECHNIQUE FOR TRIS AND TETS optimal_quadrature = 3 # is_flattened = True is_flattened = False if mesh.element_type == "tri" or mesh.element_type == "tet": norder = 2*C # TAKE CARE OF C=0 CASE if norder == 0: norder = 1 norder_post = 2*(C+1) else: norder = C+2 norder_post = 2*(C+2) # GET QUADRATURE quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder, mesh_type=mesh.element_type, is_flattened=is_flattened) if self.compute_post_quadrature != None: # COMPUTE INTERPOLATION FUNCTIONS AT ALL INTEGRATION POINTS FOR POST-PROCESSING post_quadrature = QuadratureRule(optimal=optimal_quadrature, norder=norder_post, mesh_type=mesh.element_type) else: post_quadrature = None # BOUNDARY QUADRATURE bquadrature = QuadratureRule(optimal=optimal_quadrature, norder=C+2, mesh_type=mesh.boundary_element_type, is_flattened=is_flattened) self.quadrature_rules = (quadrature,post_quadrature,bquadrature) else: self.quadrature_rules = quadrature_rules if function_spaces == None and self.function_spaces == None: # CREATE FUNCTIONAL SPACES function_space = FunctionSpace(mesh, quadrature, p=C+1, equally_spaced=equally_spaced_bases, use_optimal_quadrature=is_flattened) if self.compute_post_quadrature != None: post_function_space = FunctionSpace(mesh, post_quadrature, p=C+1, equally_spaced=equally_spaced_bases) else: post_function_space = None # CREATE BOUNDARY FUNCTIONAL SPACES bfunction_space = FunctionSpace(mesh.CreateDummyLowerDimensionalMesh(), bquadrature, p=C+1, equally_spaced=equally_spaced_bases, use_optimal_quadrature=is_flattened) self.function_spaces = (function_space,post_function_space,bfunction_space) else: self.function_spaces = function_spaces # local_size = function_space.Bases.shape[0]*self.nvar local_size = self.function_spaces[0].Bases.shape[0]*self.nvar self.local_rows = np.repeat(np.arange(0,local_size),local_size,axis=0) self.local_columns = np.tile(np.arange(0,local_size),local_size) self.local_size = local_size # FOR MASS local_size_m = self.function_spaces[0].Bases.shape[0]*self.ndim self.local_rows_mass = np.repeat(np.arange(0,local_size_m),local_size_m,axis=0) self.local_columns_mass = np.tile(np.arange(0,local_size_m),local_size_m) self.local_size_m = local_size_m