def reset_deformed_field(simulation): """ :param simulation: :return: """ dependentFieldUserNumber = 13 simulation.dependentField.Destroy() simulation.dependentField = iron.Field() simulation.equationsSet.DependentCreateStart(dependentFieldUserNumber, simulation.dependentField) simulation.dependentField.VariableLabelSet(iron.FieldVariableTypes.U, "Dependent") simulation.dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) simulation.dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) #if UsePressureBasis: # # Set the pressure to be nodally based and use the second mesh component # if InterpolationType == 4: # simulation.dependentField.ComponentInterpolationSet(iron.FieldVariableTypes.U,4,iron.FieldInterpolationTypes.NODE_BASED) # simulation.dependentField.ComponentInterpolationSet(iron.FieldVariableTypes.DELUDELN,4,iron.FieldInterpolationTypes.NODE_BASED) # simulation.dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,4,2) # simulation.dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.DELUDELN,4,2) #if InterpolationType == 4: # simulation.dependentField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN simulation.equationsSet.DependentCreateFinish() iron.Field.ParametersToFieldParametersComponentCopy( simulation.geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, simulation.dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) iron.Field.ParametersToFieldParametersComponentCopy( simulation.geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, simulation.dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2) iron.Field.ParametersToFieldParametersComponentCopy( simulation.geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, simulation.dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3) iron.Field.ComponentValuesInitialiseDP(simulation.dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, 0)
def mesh_conversion(dimension, interpolation, exfile_coordinate_field, exnode_filename, exelem_filename, results_folder, results_filename): # Read in ex mesh as a morphic mesh. cubic_hermite_morphic_mesh = mesh_tools.exfile_to_morphic( exnode_filename, exelem_filename, exfile_coordinate_field, dimension=dimension, interpolation='hermite') # Convert mesh from cubic hermite to cubic Lagrange lagrange_morphic_mesh = convert_hermite_lagrange( cubic_hermite_morphic_mesh, tol=1e-9, interpolation=interpolation) # List nodes print("Node numbers") print(lagrange_morphic_mesh.get_node_ids(group='_default')[1]) print("Node coordinates") print(lagrange_morphic_mesh.get_node_ids(group='_default')[0]) # List node ids in each element for element in lagrange_morphic_mesh.elements: print("Element number") print(element.id) print("Element node numbers") print(element.node_ids) # Export mesh in ex format using OpenCMISS module_spec = util.find_spec("opencmiss") opencmiss_found = module_spec is not None if opencmiss_found: from opencmiss.iron import iron if interpolation == "quadraticLagrange": opencmiss_mesh_interpolation = \ iron.BasisInterpolationSpecifications.QUADRATIC_LAGRANGE elif interpolation == "cubicLagrange": opencmiss_mesh_interpolation = \ iron.BasisInterpolationSpecifications.CUBIC_LAGRANGE numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() computationalNodeNumber = iron.ComputationalNodeNumberGet() coordinateSystemUserNumber = 1 regionUserNumber = 3 basisUserNumber = 2 meshUserNumber = 1 decompositionUserNumber = 1 geometricFieldUserNumber = 1 coordinateSystem = iron.CoordinateSystem() coordinateSystem.CreateStart(coordinateSystemUserNumber) coordinateSystem.dimension = 3 coordinateSystem.CreateFinish() basis = iron.Basis() basis.CreateStart(basisUserNumber) basis.TypeSet(iron.BasisTypes.LAGRANGE_HERMITE_TP) basis.NumberOfXiSet(dimension) basis.InterpolationXiSet([opencmiss_mesh_interpolation] * dimension) basis.QuadratureNumberOfGaussXiSet([4] * dimension) basis.CreateFinish() region = iron.Region() region.CreateStart(regionUserNumber, iron.WorldRegion) region.LabelSet("Region") region.CoordinateSystemSet(coordinateSystem) region.CreateFinish() mesh, coordinates, node_nums, element_nums = mesh_tools.morphic_to_OpenCMISS( lagrange_morphic_mesh, region, basis, meshUserNumber, dimension=dimension, interpolation=interpolation, UsePressureBasis=False, pressureBasis=None) decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.TypeSet(iron.DecompositionTypes.CALCULATED) decomposition.NumberOfDomainsSet(numberOfComputationalNodes) decomposition.CreateFinish() geometric_field = iron.Field() geometric_field.CreateStart(geometricFieldUserNumber, region) geometric_field.MeshDecompositionSet(decomposition) geometric_field.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometric_field.CreateFinish() # Update the geometric field parameters geometric_field.ParameterSetUpdateStart( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) for node_idx, node in enumerate(node_nums): for component_idx, component in enumerate([1, 2, 3]): for derivative_idx, derivative in enumerate( range(1, coordinates.shape[2] + 1)): geometric_field.ParameterSetUpdateNodeDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, derivative, node, component, coordinates[node_idx, component_idx, derivative_idx]) geometric_field.ParameterSetUpdateFinish( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) output_file = os.path.join(results_folder, results_filename) fields = iron.Fields() fields.CreateRegion(region) fields.NodesExport(output_file, "FORTRAN") fields.ElementsExport(output_file, "FORTRAN") fields.Finalise()
def __init__(self, instance=1, fitting_type='guass'): """ Create a new instance of a fitting problem. """ self.results_folder = './' # Fitting parameters self.num_iterations = 1 self.tau = 0.01 self.kappa = 0.005 self.smoothing_parameters = ([ self.tau, # tau_1 self.kappa, # kappa_11 self.tau, # tau_2 self.kappa, # kappa_22 self.kappa, # kappa_12 self.tau, # tau_3 self.kappa, # kappa_33 self.kappa, # kappa_13 self.kappa ]) # kappa_23 # Set fitting data default self.interpolation_type = iron.FieldInterpolationTypes.GAUSS_POINT_BASED # OpenCMISS user numbers self.data_field_user_num = 100 + instance self.dependent_field_user_num = 101 + instance self.material_field_user_num = 102 + instance self.equations_set_field_user_num = 103 + instance self.equations_set_user_num = 100 + instance self.problem_user_num = 100 + instance # Instances for setting up fitting problems self.data_field = iron.Field() self.dependent_field = iron.Field() self.material_field = iron.Field() self.equations_set_field = iron.Field() self.equations_set = iron.EquationsSet() self.problem = iron.Problem() if fitting_type == 'guass': self.specification = ([ iron.EquationsSetClasses.FITTING, iron.EquationsSetTypes.GAUSS_FITTING_EQUATION, iron.EquationsSetSubtypes.GAUSS_POINT_FITTING, iron.EquationsSetFittingSmoothingTypes.SOBOLEV_VALUE ]) self.data_interpolation_type = \ iron.FieldInterpolationTypes.GAUSS_POINT_BASED elif fitting_type == 'data': self.specification = ([ iron.EquationsSetClasses.FITTING, iron.EquationsSetTypes.DATA_FITTING_EQUATION, iron.EquationsSetSubtypes.DATA_POINT_FITTING, iron.EquationsSetFittingSmoothingTypes.SOBOLEV_VALUE ]) self.data_interpolation_type = \ iron.FieldInterpolationTypes.DATA_POINT_BASED else: raise ValueError('Specified fitting type not supported') self.problem_specification = ([ iron.ProblemClasses.FITTING, iron.ProblemTypes.DATA_FITTING, iron.ProblemSubtypes.STATIC_FITTING ]) # Boundary condition parameters self.dependent_field_mappings = False self.num_mapped_dependent_field_nodes = 0 self.mapped_dependent_field_node_nums = None
def solve_model(exportname, model=1, debug=False): # Setting debug=False will prevent output of solver progress/results to the screen. if debug: print("Solving model {0}".format(model)) # Get the number of computational nodes and this computational node number numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() # computationalNodeNumber = iron.ComputationalNodeNumberGet() # Create a 3D rectangular cartesian coordinate system coordinateSystem = iron.CoordinateSystem() coordinateSystem.CreateStart(coordinateSystemUserNumber) coordinateSystem.DimensionSet(3) coordinateSystem.CreateFinish() # Create a region and assign the coordinate system to the region region = iron.Region() region.CreateStart(regionUserNumber, iron.WorldRegion) region.LabelSet("Region") region.coordinateSystem = coordinateSystem region.CreateFinish() # Define basis basis = iron.Basis() basis.CreateStart(basisUserNumber) if InterpolationType in (1, 2, 3, 4): basis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): basis.type = iron.BasisTypes.SIMPLEX basis.numberOfXi = numberOfXi basis.interpolationXi = ( [iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE] * numberOfXi) if (NumberOfGaussXi > 0): basis.quadratureNumberOfGaussXi = [NumberOfGaussXi] * numberOfXi basis.CreateFinish() if (UsePressureBasis): # Define pressure basis pressureBasis = iron.Basis() pressureBasis.CreateStart(pressureBasisUserNumber) if InterpolationType in (1, 2, 3, 4): pressureBasis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): pressureBasis.type = iron.BasisTypes.SIMPLEX pressureBasis.numberOfXi = numberOfXi pressureBasis.interpolationXi = ( [iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE] * numberOfXi) if (NumberOfGaussXi > 0): pressureBasis.quadratureNumberOfGaussXi = [NumberOfGaussXi ] * numberOfXi pressureBasis.CreateFinish() # Start the creation of a generated mesh in the region generatedMesh = iron.GeneratedMesh() generatedMesh.CreateStart(generatedMeshUserNumber, region) generatedMesh.type = iron.GeneratedMeshTypes.REGULAR if (UsePressureBasis): generatedMesh.basis = [basis, pressureBasis] else: generatedMesh.basis = [basis] generatedMesh.extent = [width, length, height] generatedMesh.numberOfElements = ([ numberGlobalXElements, numberGlobalYElements, numberGlobalZElements ]) # Finish the creation of a generated mesh in the region mesh = iron.Mesh() generatedMesh.CreateFinish(meshUserNumber, mesh) # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) if InterpolationType == 4: geometricField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN geometricField.CreateFinish() # Update the geometric field parameters from generated mesh generatedMesh.GeometricParametersCalculate(geometricField) # Create a fibre field and attach it to the geometric field fibreField = iron.Field() fibreField.CreateStart(fibreFieldUserNumber, region) fibreField.TypeSet(iron.FieldTypes.FIBRE) fibreField.MeshDecompositionSet(decomposition) fibreField.GeometricFieldSet(geometricField) fibreField.VariableLabelSet(iron.FieldVariableTypes.U, "Fibre") if InterpolationType == 4: fibreField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN fibreField.CreateFinish() # Create a deformed geometry field, as Cmgui/Zinc doesn't like displaying # deformed fibres from the dependent field because it isn't a geometric field. deformedField = iron.Field() deformedField.CreateStart(deformedFieldUserNumber, region) deformedField.MeshDecompositionSet(decomposition) deformedField.TypeSet(iron.FieldTypes.GEOMETRIC) deformedField.VariableLabelSet(iron.FieldVariableTypes.U, "DeformedGeometry") for component in [1, 2, 3]: deformedField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, component, 1) if InterpolationType == 4: deformedField.ScalingTypeSet(iron.FieldScalingTypes.ARITHMETIC_MEAN) deformedField.CreateFinish() pressureField = iron.Field() pressureField.CreateStart(pressureFieldUserNumber, region) pressureField.MeshDecompositionSet(decomposition) pressureField.VariableLabelSet(iron.FieldVariableTypes.U, "Pressure") pressureField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) pressureField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 1, iron.FieldInterpolationTypes.ELEMENT_BASED) pressureField.NumberOfComponentsSet(iron.FieldVariableTypes.U, 1) pressureField.CreateFinish() # Create the equations_set equationsSetField = iron.Field() equationsSet = iron.EquationsSet() problemSpecification = [ iron.ProblemClasses.ELASTICITY, iron.ProblemTypes.FINITE_ELASTICITY, iron.EquationsSetSubtypes.MOONEY_RIVLIN ] equationsSet.CreateStart(equationsSetUserNumber, region, fibreField, problemSpecification, equationsSetFieldUserNumber, equationsSetField) equationsSet.CreateFinish() # Create the dependent field dependentField = iron.Field() equationsSet.DependentCreateStart(dependentFieldUserNumber, dependentField) dependentField.VariableLabelSet(iron.FieldVariableTypes.U, "Dependent") dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) if (UsePressureBasis): # Set the pressure to be nodally based and use the second mesh component if InterpolationType == 4: dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 4, 2) dependentField.ComponentMeshComponentSet( iron.FieldVariableTypes.DELUDELN, 4, 2) if InterpolationType == 4: dependentField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN equationsSet.DependentCreateFinish() # Create the material field materialField = iron.Field() equationsSet.MaterialsCreateStart(materialFieldUserNumber, materialField) materialField.VariableLabelSet(iron.FieldVariableTypes.U, "Material") equationsSet.MaterialsCreateFinish() # Set Mooney-Rivlin constants c10 and c01 respectively. materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1.0) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, 0.2) # Create equations equations = iron.Equations() equationsSet.EquationsCreateStart(equations) equations.sparsityType = iron.EquationsSparsityTypes.SPARSE equations.outputType = iron.EquationsOutputTypes.NONE equationsSet.EquationsCreateFinish() # Initialise dependent field from undeformed geometry and displacement bcs and set hydrostatic pressure iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3) iron.Field.ComponentValuesInitialiseDP(dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, 0.0) # Define the problem problem = iron.Problem() problemSpecification = [ iron.ProblemClasses.ELASTICITY, iron.ProblemTypes.FINITE_ELASTICITY, iron.ProblemSubtypes.NONE ] problem.CreateStart(problemUserNumber, problemSpecification) problem.CreateFinish() # Create the problem control loop problem.ControlLoopCreateStart() controlLoop = iron.ControlLoop() problem.ControlLoopGet([iron.ControlLoopIdentifiers.NODE], controlLoop) controlLoop.MaximumIterationsSet(numberOfLoadIncrements) problem.ControlLoopCreateFinish() # Create problem solver nonLinearSolver = iron.Solver() linearSolver = iron.Solver() problem.SolversCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, nonLinearSolver) if debug: nonLinearSolver.outputType = iron.SolverOutputTypes.PROGRESS else: nonLinearSolver.outputType = iron.SolverOutputTypes.NONE nonLinearSolver.NewtonJacobianCalculationTypeSet( iron.JacobianCalculationTypes.EQUATIONS) nonLinearSolver.NewtonLinearSolverGet(linearSolver) linearSolver.linearType = iron.LinearSolverTypes.DIRECT #linearSolver.libraryType = iron.SolverLibraries.LAPACK problem.SolversCreateFinish() # Create solver equations and add equations set to solver equations solver = iron.Solver() solverEquations = iron.SolverEquations() problem.SolverEquationsCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, solver) solver.SolverEquationsGet(solverEquations) solverEquations.sparsityType = iron.SolverEquationsSparsityTypes.SPARSE _ = solverEquations.EquationsSetAdd(equationsSet) problem.SolverEquationsCreateFinish() # Prescribe boundary conditions (absolute nodal parameters) boundaryConditions = iron.BoundaryConditions() solverEquations.BoundaryConditionsCreateStart(boundaryConditions) if model == 1: boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) p = -2. * -0.1056E+01 elif model == 2: boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) p = -2. * -0.6656E+00 elif model == 3: boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) p = -2. * -0.1450E+01 elif model == 4: boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Z, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, Z, iron.BoundaryConditionsTypes.FIXED, 0.5) p = -2. * -0.1056E+01 elif model == 5: boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, X, iron.BoundaryConditionsTypes.FIXED, 0.5) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.75) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.75) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) p = -2. * -0.1000E+01 solverEquations.BoundaryConditionsCreateFinish() # Solve the problem problem.Solve() # Copy deformed geometry into deformed field for component in [1, 2, 3]: dependentField.ParametersToFieldParametersComponentCopy( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component, deformedField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component) # Copy pressure into pressure field dependentField.ParametersToFieldParametersComponentCopy( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, pressureField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) # Export results fields = iron.Fields() fields.CreateRegion(region) fields.NodesExport(exportname, "FORTRAN") fields.ElementsExport(exportname, "FORTRAN") fields.Finalise() results = {} elementNumber = 1 xiPosition = [0.5, 0.5, 0.5] F = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.DEFORMATION_GRADIENT, elementNumber, xiPosition, (3, 3)) results['Deformation Gradient Tensor'] = F if debug: print("Deformation Gradient Tensor") print(F) C = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.R_CAUCHY_GREEN_DEFORMATION, elementNumber, xiPosition, (3, 3)) results['Right Cauchy-Green Deformation Tensor'] = C if debug: print("Right Cauchy-Green Deformation Tensor") print(C) E = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.GREEN_LAGRANGE_STRAIN, elementNumber, xiPosition, (3, 3)) results['Green-Lagrange Strain Tensor'] = E if debug: print("Green-Lagrange Strain Tensor") print(E) I1 = numpy.trace(C) I2 = 0.5 * (numpy.trace(C)**2. - numpy.tensordot(C, C)) I3 = numpy.linalg.det(C) results['Invariants'] = [I1, I2, I3] if debug: print("Invariants") print("I1={0}, I2={1}, I3={2}".format(I1, I2, I3)) TC = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.CAUCHY_STRESS, elementNumber, xiPosition, (3, 3)) results['Cauchy Stress Tensor'] = TC if debug: print("Cauchy Stress Tensor") print(TC) # Output of Second Piola-Kirchhoff Stress Tensor not implemented. It is # instead, calculated from TG=J*F^(-1)*TC*F^(-T), where T indicates the # transpose fo the matrix. #TG = equationsSet.TensorInterpolateXi( # iron.EquationsSetTensorEvaluateTypes.SECOND_PK_STRESS, # elementNumber, xiPosition,(3,3)) #J=1. #Assumes J=1 TG = numpy.dot(numpy.linalg.inv(F), numpy.dot(TC, numpy.linalg.inv(numpy.matrix.transpose(F)))) results['Second Piola-Kirchhoff Stress Tensor'] = TG if debug: print("Second Piola-Kirchhoff Stress Tensor") print(TG) # Note that the hydrostatic pressure value is different from the value quoted # in the original lab instructions. This is because the stress has been # evaluated using modified invariants (isochoric invariants) #p = dependentField.ParameterSetGetElement( # iron.FieldVariableTypes.U, # iron.FieldParameterSetTypes.VALUES,elementNumber,4) results['Hydrostatic pressure'] = p if debug: print("Hydrostatic pressure") print(p) problem.Destroy() coordinateSystem.Destroy() region.Destroy() basis.Destroy() return results
# MESH DECOMPOSITION #------------------------------------------------------------------------------------------------ #Parallelization decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() #------------------------------------------------------------------------------------------------ # GEOMETRIC FIELD #------------------------------------------------------------------------------------------------ #Geometric Field geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Coordinate") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) #geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,3,1) geometricField.CreateFinish() #Update Geometric Field from customized mesh for i in range(num_nodes): node = int(NodeNums[i, 0]) nodeDomain = decomposition.NodeDomainGet(node, 1) if nodeDomain == computationalNodeNumber: nodex = NodeCoords[i, 0]
def solve_model(exportname, model=1, debug=False): # Setting debug=False will prevent output of solver progress/results to the screen. if debug: print("Solving model {0}".format(model)) # Get the number of computational nodes and this computational node number numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() # computationalNodeNumber = iron.ComputationalNodeNumberGet() # Create a 3D rectangular cartesian coordinate system coordinateSystem = iron.CoordinateSystem() coordinateSystem.CreateStart(coordinateSystemUserNumber) coordinateSystem.DimensionSet(3) coordinateSystem.CreateFinish() # Create a region and assign the coordinate system to the region region = iron.Region() region.CreateStart(regionUserNumber, iron.WorldRegion) region.LabelSet("Region") region.coordinateSystem = coordinateSystem region.CreateFinish() # Define basis basis = iron.Basis() basis.CreateStart(basisUserNumber) if InterpolationType in (1, 2, 3, 4): basis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): basis.type = iron.BasisTypes.SIMPLEX basis.numberOfXi = numberOfXi basis.interpolationXi = ( [iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE] * numberOfXi) if (NumberOfGaussXi > 0): basis.quadratureNumberOfGaussXi = [NumberOfGaussXi] * numberOfXi basis.CreateFinish() if (UsePressureBasis): # Define pressure basis pressureBasis = iron.Basis() pressureBasis.CreateStart(pressureBasisUserNumber) if InterpolationType in (1, 2, 3, 4): pressureBasis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): pressureBasis.type = iron.BasisTypes.SIMPLEX pressureBasis.numberOfXi = numberOfXi pressureBasis.interpolationXi = ( [iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE] * numberOfXi) if (NumberOfGaussXi > 0): pressureBasis.quadratureNumberOfGaussXi = [NumberOfGaussXi ] * numberOfXi pressureBasis.CreateFinish() # Start the creation of a generated mesh in the region generatedMesh = iron.GeneratedMesh() generatedMesh.CreateStart(generatedMeshUserNumber, region) generatedMesh.type = iron.GeneratedMeshTypes.REGULAR if (UsePressureBasis): generatedMesh.basis = [basis, pressureBasis] else: generatedMesh.basis = [basis] generatedMesh.extent = [width, length, height] generatedMesh.numberOfElements = ([ numberGlobalXElements, numberGlobalYElements, numberGlobalZElements ]) # Finish the creation of a generated mesh in the region mesh = iron.Mesh() generatedMesh.CreateFinish(meshUserNumber, mesh) # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) if InterpolationType == 4: geometricField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN geometricField.CreateFinish() # Update the geometric field parameters from generated mesh generatedMesh.GeometricParametersCalculate(geometricField) # Create a fibre field and attach it to the geometric field fibreField = iron.Field() fibreField.CreateStart(fibreFieldUserNumber, region) fibreField.TypeSet(iron.FieldTypes.FIBRE) fibreField.MeshDecompositionSet(decomposition) fibreField.GeometricFieldSet(geometricField) fibreField.VariableLabelSet(iron.FieldVariableTypes.U, "Fibre") if InterpolationType == 4: fibreField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN fibreField.CreateFinish() # Create a deformed geometry field, as Cmgui/Zinc doesn't like displaying # deformed fibres from the dependent field because it isn't a geometric field. deformedField = iron.Field() deformedField.CreateStart(deformedFieldUserNumber, region) deformedField.MeshDecompositionSet(decomposition) deformedField.TypeSet(iron.FieldTypes.GEOMETRIC) deformedField.VariableLabelSet(iron.FieldVariableTypes.U, "DeformedGeometry") for component in [1, 2, 3]: deformedField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, component, 1) if InterpolationType == 4: deformedField.ScalingTypeSet(iron.FieldScalingTypes.ARITHMETIC_MEAN) deformedField.CreateFinish() pressureField = iron.Field() pressureField.CreateStart(pressureFieldUserNumber, region) pressureField.MeshDecompositionSet(decomposition) pressureField.VariableLabelSet(iron.FieldVariableTypes.U, "Pressure") pressureField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) pressureField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 1, iron.FieldInterpolationTypes.ELEMENT_BASED) pressureField.NumberOfComponentsSet(iron.FieldVariableTypes.U, 1) pressureField.CreateFinish() # Create the equations_set equationsSetField = iron.Field() equationsSet = iron.EquationsSet() problemSpecification = [ iron.ProblemClasses.ELASTICITY, iron.ProblemTypes.FINITE_ELASTICITY, iron.EquationsSetSubtypes.ORTHOTROPIC_MATERIAL_COSTA ] equationsSet.CreateStart(equationsSetUserNumber, region, fibreField, problemSpecification, equationsSetFieldUserNumber, equationsSetField) equationsSet.CreateFinish() # Create the dependent field dependentField = iron.Field() equationsSet.DependentCreateStart(dependentFieldUserNumber, dependentField) dependentField.VariableLabelSet(iron.FieldVariableTypes.U, "Dependent") dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) if (UsePressureBasis): # Set the pressure to be nodally based and use the second mesh component if InterpolationType == 4: dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 4, 2) dependentField.ComponentMeshComponentSet( iron.FieldVariableTypes.DELUDELN, 4, 2) if InterpolationType == 4: dependentField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN equationsSet.DependentCreateFinish() # Create the material field materialField = iron.Field() equationsSet.MaterialsCreateStart(materialFieldUserNumber, materialField) materialField.VariableLabelSet(iron.FieldVariableTypes.U, "Material") equationsSet.MaterialsCreateFinish() # Set Costa constitutive relation parameters. # Q=[c_ff 2c_fs 2c_fn c_ss 2c_ns c_nn]' * [E_ff E_fs E_fn E_ss E_sn E_nn].^2; if model in [1, 3, 4]: c_1 = 0.0475 c_ff = 15.25 c_fs = 6.05 c_fn = c_fs c_ss = c_ff c_sn = c_fs c_nn = c_ff elif model in [2, 5, 6]: c_1 = 0.0475 c_ff = 15.25 c_fs = 6.95 c_fn = 6.05 c_ss = 6.8 c_sn = 4.93 c_nn = 8.9 materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, c_1) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, c_ff) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, c_fs) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, c_fn) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 5, c_ss) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 6, c_sn) materialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 7, c_nn) if model in [1, 2]: angle = numpy.deg2rad(0.) elif model == 3: angle = numpy.deg2rad(30.) elif model in [4, 5]: angle = numpy.deg2rad(45.) elif model == 6: angle = numpy.deg2rad(90.) fibreField.ComponentValuesInitialiseDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, angle) # Create equations equations = iron.Equations() equationsSet.EquationsCreateStart(equations) equations.sparsityType = iron.EquationsSparsityTypes.SPARSE equations.outputType = iron.EquationsOutputTypes.NONE equationsSet.EquationsCreateFinish() # Initialise dependent field from undeformed geometry and displacement bcs and set hydrostatic pressure iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3) iron.Field.ComponentValuesInitialiseDP(dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, 0.0) # Define the problem problem = iron.Problem() problemSpecification = [ iron.ProblemClasses.ELASTICITY, iron.ProblemTypes.FINITE_ELASTICITY, iron.ProblemSubtypes.NONE ] problem.CreateStart(problemUserNumber, problemSpecification) problem.CreateFinish() # Create the problem control loop problem.ControlLoopCreateStart() controlLoop = iron.ControlLoop() problem.ControlLoopGet([iron.ControlLoopIdentifiers.NODE], controlLoop) controlLoop.MaximumIterationsSet(numberOfLoadIncrements) problem.ControlLoopCreateFinish() # Create problem solver nonLinearSolver = iron.Solver() linearSolver = iron.Solver() problem.SolversCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, nonLinearSolver) if debug: nonLinearSolver.outputType = iron.SolverOutputTypes.PROGRESS else: nonLinearSolver.outputType = iron.SolverOutputTypes.NONE nonLinearSolver.NewtonJacobianCalculationTypeSet( iron.JacobianCalculationTypes.EQUATIONS) nonLinearSolver.NewtonLinearSolverGet(linearSolver) linearSolver.linearType = iron.LinearSolverTypes.DIRECT #linearSolver.libraryType = iron.SolverLibraries.LAPACK problem.SolversCreateFinish() # Create solver equations and add equations set to solver equations solver = iron.Solver() solverEquations = iron.SolverEquations() problem.SolverEquationsCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, solver) solver.SolverEquationsGet(solverEquations) solverEquations.sparsityType = iron.SolverEquationsSparsityTypes.SPARSE _ = solverEquations.EquationsSetAdd(equationsSet) problem.SolverEquationsCreateFinish() # Prescribe boundary conditions (absolute nodal parameters) boundaryConditions = iron.BoundaryConditions() solverEquations.BoundaryConditionsCreateStart(boundaryConditions) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, X, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, X, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, Y, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, Y, iron.BoundaryConditionsTypes.FIXED, 0.25) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, Z, iron.BoundaryConditionsTypes.FIXED, 0.0) solverEquations.BoundaryConditionsCreateFinish() # Solve the problem problem.Solve() # Copy deformed geometry into deformed field for component in [1, 2, 3]: dependentField.ParametersToFieldParametersComponentCopy( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component, deformedField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component) # Copy pressure into pressure field dependentField.ParametersToFieldParametersComponentCopy( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, pressureField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) # Export results fields = iron.Fields() fields.CreateRegion(region) fields.NodesExport(exportname, "FORTRAN") fields.ElementsExport(exportname, "FORTRAN") fields.Finalise() Q = numpy.array([[numpy.cos(angle), -numpy.sin(angle), 0.], [numpy.sin(angle), numpy.cos(angle), 0.], [0., 0., 1.]]) results = {} elementNumber = 1 xiPosition = [0.5, 0.5, 0.5] # Note that there seems to be a bug with F in OpenCMISS when fibre angles are specified in x1-x2 plane #F = equationsSet.TensorInterpolateXi( # iron.EquationsSetTensorEvaluateTypes.DEFORMATION_GRADIENT, # elementNumber, xiPosition,(3,3)) Ffib = numpy.array([[0.1250E+01, 0., 0.], [0., 0.1250E+01, 0.], [0., 0., 0.6400E+00]]) Fref = Ffib results["Deformation gradient tensor (fibre coordinate system)"] = Ffib results["Deformation gradient tensor (reference coordinate system)"] = Fref if debug: print("Deformation gradient tensor (fibre coordinate system)") print(Ffib) print("Deformation gradient tensor (reference coordinate system)") print(Fref) Cfib = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.R_CAUCHY_GREEN_DEFORMATION, elementNumber, xiPosition, (3, 3)) Cref = Cfib results[ "Right Cauchy-Green deformation tensor (fibre coordinate system)"] = Cfib results[ "Right Cauchy-Green deformation tensor (reference coordinate system)"] = Cref if debug: print( "Right Cauchy-Green deformation tensor (fibre coordinate system)") print(Cfib) print( "Right Cauchy-Green deformation tensor (reference coordinate system)" ) print(Cref) Efib = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.GREEN_LAGRANGE_STRAIN, elementNumber, xiPosition, (3, 3)) results["Green-Lagrange strain tensor (fibre coordinate system)"] = Efib if debug: print("Green-Lagrange strain tensor (fibre coordinate system)") print(Efib) Eref = numpy.dot(Q, numpy.dot(Efib, numpy.matrix.transpose(Q))) results[ "Green-Lagrange strain tensor (reference coordinate system)"] = Eref if debug: print("Green-Lagrange strain tensor (reference coordinate system)") print(Eref) I1 = numpy.trace(Cfib) I2 = 0.5 * (numpy.trace(Cfib)**2. - numpy.tensordot(Cfib, Cfib)) I3 = numpy.linalg.det(Cfib) results["Invariants of Cfib (fibre coordinate system)"] = [I1, I2, I3] if debug: print("Invariants of Cfib (fibre coordinate system)") print("I1={0}, I2={1}, I3={2}".format(I1, I2, I3)) I1 = numpy.trace(Cref) I2 = 0.5 * (numpy.trace(Cref)**2. - numpy.tensordot(Cref, Cref)) I3 = numpy.linalg.det(Cref) results["Invariants of Cref (reference coordinate system)"] = [I1, I2, I3] if debug: print("Invariants of Cref (reference coordinate system)") print("I1={0}, I2={1}, I3={2}".format(I1, I2, I3)) TCref = equationsSet.TensorInterpolateXi( iron.EquationsSetTensorEvaluateTypes.CAUCHY_STRESS, elementNumber, xiPosition, (3, 3)) results["Cauchy stress tensor (reference coordinate system)"] = TCref if debug: print("Cauchy stress tensor (reference coordinate system)") print(TCref) # Output of Second Piola-Kirchhoff Stress Tensor not implemented. It is # instead, calculated from TG=J*F^(-1)*TC*F^(-T), where T indicates the # transpose fo the matrix. #TG = equationsSet.TensorInterpolateXi( # iron.EquationsSetTensorEvaluateTypes.SECOND_PK_STRESS, # elementNumber, xiPosition,(3,3)) #J=1. #Assumes J=1 TGref = numpy.dot( numpy.linalg.inv(Fref), numpy.dot(TCref, numpy.linalg.inv(numpy.matrix.transpose(Fref)))) results[ "Second Piola-Kirchhoff stress tensor (reference coordinate system)"] = TGref if debug: print( "Second Piola-Kirchhoff stress tensor (reference coordinate system)" ) print(TGref) TGfib = numpy.dot(numpy.matrix.transpose(Q), numpy.dot(TGref, Q)) results[ "Second Piola-Kirchhoff stress tensor (fibre coordinate system)"] = TGfib if debug: print("Second Piola-Kirchhoff stress tensor (fibre coordinate system)") print(TGfib) # Note that the hydrostatic pressure value is different from the value quoted # in the original lab instructions. This is because the stress has been # evaluated using modified invariants (isochoric invariants) p = -dependentField.ParameterSetGetElement( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, elementNumber, 4) results["Hydrostatic pressure"] = p if debug: print("Hydrostatic pressure") print(p) problem.Destroy() coordinateSystem.Destroy() region.Destroy() basis.Destroy() return results
# Removes duplicates from the list of nodal values and orders them ordered_nodes = dict.fromkeys(selected_element_nodes).keys() elements.CreateFinish() mesh2.CreateFinish() # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh2) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField1 = iron.Field() geometricField1.CreateStart(geometricField1UserNumber, region) geometricField1.meshDecomposition = decomposition geometricField1.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField1.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField1.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometricField1.CreateFinish() generatedMesh.GeometricParametersCalculate(geometricField1) # Create a field for the geometry geometricField2 = iron.Field() geometricField2.CreateStart(geometricField2UserNumber, region) geometricField2.meshDecomposition = decomposition geometricField2.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField2.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1)
meshComponentNumber=1 elements.CreateStart(mesh,meshComponentNumber,basis) elements.NodesSet(1,[1,2,3,4,5,6,7,8]) elements.CreateFinish() mesh.CreateFinish() # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber,mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber,region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U,"Geometry") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,1,1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,2,1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,3,1) if InterpolationType == 4: geometricField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN geometricField.CreateFinish() if useGeneratedMesh: # Update the geometric field parameters from generated mesh generatedMesh.GeometricParametersCalculate(geometricField) else:
def generate_opencmiss_geometry(interpolation=None, region_label='region', num_elements=None, dimensions=None, scaling_type=None, mesh_type=None): """ Generates an OpenCMISS geometry (mesh and geometric field) Args: interpolation (iron.BasisInterpolationSpecifications): Element interpolation e.g. LINEAR_LAGRANGE region_label (str): Region name num_elements (arr): Number of elements in the mesh along each element xi e.g. [1,1,1] dimensions (arr): Dimension of the geometry, e.g. [10, 10, 10] for a regular mesh scaling_type (iron.FieldScalingTypes): The type of field scaling to use e.g. 'NONE' mesh_type(iron.GeneratedMeshTypes): Type of mesh to generate. Options are: 'CYLINDER', 'ELLIPSOID', 'FRACTAL_TREE', 'POLAR', 'REGULAR' Returns: region, decomposition, mesh, geometric_field """ # OpenCMISS user numbers coor_sys_user_num = 1 region_user_num = 1 basis_user_num = 1 generated_mesh_user_num = 1 mesh_user_num = 1 decomposition_user_num = 1 geometric_field_user_num = 1 # Instances for setting up OpenCMISS mesh coordinate_system = iron.CoordinateSystem() region = iron.Region() basis = iron.Basis() generated_mesh = iron.GeneratedMesh() mesh = iron.Mesh() decomposition = iron.Decomposition() geometric_field = iron.Field() if interpolation is None: interpolation = iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE if dimensions is None: dimensions = np.array([1, 1, 1]) # Length, width, height if num_elements is None: num_elements = [1, 1, 1] components = [1, 2, 3] # Geometric components dimension = 3 # 3D coordinates if scaling_type is None: scaling_type = iron.FieldScalingTypes.NONE if mesh_type is None: mesh_type = iron.GeneratedMeshTypes.REGULAR # Get the number of computational nodes and this computational node number numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() computationalNodeNumber = iron.ComputationalNodeNumberGet() # Create a 3D rectangular cartesian coordinate system coordinate_system.CreateStart(coor_sys_user_num) coordinate_system.DimensionSet(dimension) coordinate_system.CreateFinish() # Create a region and assign the coordinate system to the region region.CreateStart(region_user_num, iron.WorldRegion) region.LabelSet(region_label) region.CoordinateSystemSet(coordinate_system) region.CreateFinish() # Define basis basis.CreateStart(basis_user_num) basis.TypeSet(iron.BasisTypes.LAGRANGE_HERMITE_TP) basis.NumberOfXiSet(dimension) basis.InterpolationXiSet([interpolation] * dimension) # Set number of Gauss points used for quadrature if interpolation == iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE: number_gauss_xi = 2 elif interpolation == \ iron.BasisInterpolationSpecifications.QUADRATIC_LAGRANGE: number_gauss_xi = 3 elif interpolation == \ iron.BasisInterpolationSpecifications.CUBIC_LAGRANGE: number_gauss_xi = 4 else: raise ValueError('Interpolation not supported') basis.QuadratureNumberOfGaussXiSet([number_gauss_xi] * dimension) basis.CreateFinish() # Start the creation of a generated mesh in the region generated_mesh.CreateStart(generated_mesh_user_num, region) generated_mesh.TypeSet(mesh_type) generated_mesh.BasisSet([basis]) generated_mesh.ExtentSet(dimensions) generated_mesh.NumberOfElementsSet(num_elements) generated_mesh.CreateFinish(mesh_user_num, mesh) # Create a decomposition for the mesh decomposition.CreateStart(decomposition_user_num, mesh) decomposition.TypeSet(iron.DecompositionTypes.CALCULATED) decomposition.CalculateFacesSet(True) decomposition.NumberOfDomainsSet(numberOfComputationalNodes) decomposition.CreateFinish() # Create a field for the geometry geometric_field.CreateStart(geometric_field_user_num, region) geometric_field.MeshDecompositionSet(decomposition) geometric_field.TypeSet(iron.FieldTypes.GEOMETRIC) geometric_field.VariableLabelSet(iron.FieldVariableTypes.U, "geometry") for component in components: geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, component, 1) geometric_field.ScalingTypeSet(scaling_type) geometric_field.CreateFinish() # Update the geometric field parameters from generated mesh generated_mesh.GeometricParametersCalculate(geometric_field) generated_mesh.Destroy() return region, decomposition, mesh, geometric_field
m_mesh, region, basis, meshUserNumber, dimension=2, interpolation='linear', include_derivatives=False) # Export mesh in ex format using OpenCMISS numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() computationalNodeNumber = iron.ComputationalNodeNumberGet() decompositionUserNumber = 1 geometricFieldUserNumber = 1 decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.TypeSet(iron.DecompositionTypes.CALCULATED) decomposition.NumberOfDomainsSet(numberOfComputationalNodes) decomposition.CreateFinish() geometric_field = iron.Field() geometric_field.CreateStart(geometricFieldUserNumber, region) geometric_field.MeshDecompositionSet(decomposition) geometric_field.VariableLabelSet(iron.FieldVariableTypes.U, "coordinates") geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometric_field.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometric_field.CreateFinish() mesh_tools.set_field_values( geometric_field, node_list, coordinates, derivative=1, variable=iron.FieldVariableTypes.U, update_scale_factors=False) fields = iron.Fields() fields.AddField(geometric_field)
generatedMesh.numberOfElements = [ numberOfGlobalXElements, numberOfGlobalYElements, numberOfGlobalZElements ] # Finish the creation of a generated mesh in the region mesh = iron.Mesh() generatedMesh.CreateFinish(meshUserNumber, mesh) # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometricField.CreateFinish() # Update the geometric field parameters from generated mesh generatedMesh.GeometricParametersCalculate(geometricField) # Create a fibre field and attach it to the geometric field fibreField = iron.Field() fibreField.CreateStart(fibreFieldUserNumber, region)
mesh_user_number = 1 generated_mesh.CreateFinish(mesh_user_number, mesh) #DOC-END generated mesh #DOC-START decomposition # Perform mesh decomposition. decomposition_user_number = 1 decomposition = iron.Decomposition() decomposition.CreateStart(decomposition_user_number, mesh) decomposition.CreateFinish() #DOC-END decomposition #DOC-START geometric field # Create geometric field. geometric_field_user_number = 1 geometric_field = iron.Field() geometric_field.CreateStart(geometric_field_user_number, region) geometric_field.MeshDecompositionSet(decomposition) geometric_field.CreateFinish() #DOC-END geometric field #DOC-START update geometric parameters # Set geometric field values from the generated mesh. generated_mesh.GeometricParametersCalculate(geometric_field) #DOC-END update geometric parameters #DOC-START equation set # Create standard Laplace equations set. equations_set_user_number = 1 equations_set_field_user_number = 2 equations_set_field = iron.Field()
mesh = iron.Mesh() generatedMesh.CreateFinish(meshUserNumber,mesh) #DOC-END generated mesh #DOC-START decomposition # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber,mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() #DOC-END decomposition #DOC-START geometry # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.meshDecomposition = decomposition geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "coordinates") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, linearMeshComponentNumber) geometricField.CreateFinish() # Set geometry from the generated mesh generatedMesh.GeometricParametersCalculate(geometricField) #DOC-END geometry #DOC-START equations set # Create the equations_set equationsSetField = iron.Field() equationsSet = iron.EquationsSet()
# Decompose mesh accross computational nodes if computationalNodeNumber == 0: print('Decomposing mesh...') decomposition = iron.Decomposition() decomposition.CreateStart(userNumber.getInc(), mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.NumberOfDomainsSet(numberOfComputationalNodes) decomposition.CalculateFacesSet(False) decomposition.CreateFinish() # G e o m e t r i c F i e l d # ---------------------------------------------------- if computationalNodeNumber == 0: print('Setting up geometric field...') geometricField = iron.Field() geometricField.CreateStart(userNumber.getInc(), region) geometricField.MeshDecompositionSet(decomposition) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometricField.CreateFinish() # Load in node df store = pd.HDFStore(nodeFile, 'r') df = store['Node_Coordinates'] start = time.time() for node in range(numberOfNodes): nodeDomain = decomposition.NodeDomainGet(node + 1, 1)
# Start the creation of SPACE mesh decomposition Decomposition = iron.Decomposition() Decomposition.CreateStart(DecompositionUserNumber, Mesh) Decomposition.TypeSet(iron.DecompositionTypes.CALCULATED) Decomposition.NumberOfDomainsSet(numberOfComputationalNodes) Decomposition.CreateFinish() #================================================================================================================================ # Geometric Field #================================================================================================================================ if (ProgressDiagnostics): print(" == >> GEOMETRIC FIELD << == ") # Start the creation of SPACE geometric field GeometricField = iron.Field() GeometricField.CreateStart(GeometricFieldUserNumber, region) GeometricField.meshDecomposition = Decomposition GeometricField.NumberOfVariablesSet(1) GeometricField.VariableLabelSet(iron.FieldVariableTypes.U, 'Coordinates') GeometricField.TypeSet = iron.FieldTypes.GEOMETRIC GeometricField.ScalingTypeSet = iron.FieldScalingTypes.NONE for componentNumber in range(1, CoordinateSystem.dimension + 1): GeometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, componentNumber, 1) GeometricField.CreateFinish() # Set the geometric field values for version 1 versionIdx = 1
def simulate(fibreAngleIn, materialParameters): ''' Main function to run a finite elasticity simulation using OpenCMISS with a unit cube and the Guccione material law (in CellML). fibreAngle is a scalar angle in degrees materialParameters is a list of the four Guccione material parameters. ''' # Set problem parameters - Unit cube height = 1.0 width = 1.0 length = 1.0 # if len(sys.argv) != 2: # usage(sys.argv[0]) # exit(-1) fa = fibreAngleIn print("fa = " + str(fa)) # Fibre angles in radians: fibreAngle = fa * pi / 180.0 # (transversly isotropic, so assume 0 cross-fibre angle?) sheetAngle = 90.0 * pi / 180.0 fibreAngles = [fibreAngle, 0.0, sheetAngle] # Guccione constitutive relation: constitutiveRelation = iron.EquationsSetSubtypes.CONSTITUTIVE_LAW_IN_CELLML_EVALUATE constitutiveParameters = [0.88, 18.5, 3.58, 3.26] constitutiveParameters = materialParameters initialHydrostaticPressure = 0.0 UsePressureBasis = False NumberOfGaussXi = 2 coordinateSystemUserNumber = 1 regionUserNumber = 1 basisUserNumber = 1 pressureBasisUserNumber = 2 generatedMeshUserNumber = 1 meshUserNumber = 1 decompositionUserNumber = 1 geometricFieldUserNumber = 1 fibreFieldUserNumber = 2 materialFieldUserNumber = 3 dependentFieldUserNumber = 4 equationsSetFieldUserNumber = 5 deformedFieldUserNumber = 6 equationsSetUserNumber = 1 problemUserNumber = 1 CellMLUserNumber = 1 CellMLModelsFieldUserNumber = 7 CellMLParametersFieldUserNumber = 8 CellMLIntermediateFieldUserNumber = 9 # Set all diganostic levels on for testing #iron.DiagnosticsSetOn(iron.DiagnosticTypes.ALL,[1,2,3,4,5],"Diagnostics",["DOMAIN_MAPPINGS_LOCAL_FROM_GLOBAL_CALCULATE"]) numberGlobalXElements = 1 numberGlobalYElements = 1 numberGlobalZElements = 1 totalNumberOfNodes = 8 totalNumberOfElements = 1 InterpolationType = 1 if (UsePressureBasis): numberOfMeshComponents = 2 else: numberOfMeshComponents = 1 if (numberGlobalZElements == 0): numberOfXi = 2 else: numberOfXi = 3 # Get the number of computational nodes and this computational node number numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() computationalNodeNumber = iron.ComputationalNodeNumberGet() # Create a 3D rectangular cartesian coordinate system coordinateSystem = iron.CoordinateSystem() coordinateSystem.CreateStart(coordinateSystemUserNumber) coordinateSystem.DimensionSet(3) coordinateSystem.CreateFinish() # Create a region and assign the coordinate system to the region region = iron.Region() region.CreateStart(regionUserNumber, iron.WorldRegion) region.LabelSet("Region") region.coordinateSystem = coordinateSystem region.CreateFinish() # Define basis basis = iron.Basis() basis.CreateStart(basisUserNumber) if InterpolationType in (1, 2, 3, 4): basis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): basis.type = iron.BasisTypes.SIMPLEX basis.numberOfXi = numberOfXi basis.interpolationXi = [ iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE ] * numberOfXi if (NumberOfGaussXi > 0): basis.quadratureNumberOfGaussXi = [NumberOfGaussXi] * numberOfXi basis.CreateFinish() if (UsePressureBasis): # Define pressure basis pressureBasis = iron.Basis() pressureBasis.CreateStart(pressureBasisUserNumber) if InterpolationType in (1, 2, 3, 4): pressureBasis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP elif InterpolationType in (7, 8, 9): pressureBasis.type = iron.BasisTypes.SIMPLEX pressureBasis.numberOfXi = numberOfXi pressureBasis.interpolationXi = [ iron.BasisInterpolationSpecifications.LINEAR_LAGRANGE ] * numberOfXi if (NumberOfGaussXi > 0): pressureBasis.quadratureNumberOfGaussXi = [NumberOfGaussXi ] * numberOfXi pressureBasis.CreateFinish() # Start the creation of a manually generated mesh in the region mesh = iron.Mesh() mesh.CreateStart(meshUserNumber, region, numberOfXi) mesh.NumberOfComponentsSet(numberOfMeshComponents) mesh.NumberOfElementsSet(totalNumberOfElements) #Define nodes for the mesh nodes = iron.Nodes() nodes.CreateStart(region, totalNumberOfNodes) nodes.CreateFinish() elements = iron.MeshElements() meshComponentNumber = 1 elements.CreateStart(mesh, meshComponentNumber, basis) elements.NodesSet(1, [1, 2, 3, 4, 5, 6, 7, 8]) elements.CreateFinish() mesh.CreateFinish() # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) if InterpolationType == 4: geometricField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN geometricField.CreateFinish() # Update the geometric field parameters manually geometricField.ParameterSetUpdateStart(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) # node 1 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 1, 1, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 1, 2, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 1, 3, 0.0) # node 2 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 2, 1, height) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 2, 2, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 2, 3, 0.0) # node 3 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 3, 1, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 3, 2, width) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 3, 3, 0.0) # node 4 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 4, 1, height) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 4, 2, width) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 4, 3, 0.0) # node 5 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 5, 1, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 5, 2, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 5, 3, length) # node 6 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 6, 1, height) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 6, 2, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 6, 3, length) # node 7 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 7, 1, 0.0) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 7, 2, width) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 7, 3, length) # node 8 geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 8, 1, height) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 8, 2, width) geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1, 8, 3, length) geometricField.ParameterSetUpdateFinish(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) # Create a fibre field and attach it to the geometric field fibreField = iron.Field() fibreField.CreateStart(fibreFieldUserNumber, region) fibreField.TypeSet(iron.FieldTypes.FIBRE) fibreField.MeshDecompositionSet(decomposition) fibreField.GeometricFieldSet(geometricField) fibreField.VariableLabelSet(iron.FieldVariableTypes.U, "Fibre") if InterpolationType == 4: fibreField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN fibreField.CreateFinish() iron.Field.ComponentValuesInitialiseDP(fibreField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, fibreAngle) iron.Field.ComponentValuesInitialiseDP(fibreField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, 0.0) iron.Field.ComponentValuesInitialiseDP(fibreField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, sheetAngle) # # Create the material field # materialField = iron.Field() # materialField.CreateStart(materialFieldUserNumber,region) # materialField.TypeSet(iron.FieldTypes.MATERIAL) # materialField.MeshDecompositionSet(decomposition) # materialField.GeometricFieldSet(geometricField) # materialField.NumberOfVariablesSet(1) # materialField.NumberOfComponentsSet(iron.FieldVariableTypes.U,len(constitutiveParameters)) # materialField.VariableLabelSet(iron.FieldVariableTypes.U,"Material") # materialField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,1,1) # materialField.ComponentMeshComponentSet(iron.FieldVariableTypes.U,2,1) # if InterpolationType == 4: # materialField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN # materialField.CreateFinish() # Set constant material parameters: # for (component, value) in enumerate(constitutiveParameters, 1): # materialField.ComponentValuesInitialise( # iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, # component, value) # Create the dependent field dependentField = iron.Field() dependentField.CreateStart(dependentFieldUserNumber, region) dependentField.VariableLabelSet(iron.FieldVariableTypes.U, "Dependent") dependentField.TypeSet(iron.FieldTypes.GEOMETRIC_GENERAL) dependentField.MeshDecompositionSet(decomposition) dependentField.GeometricFieldSet(geometricField) dependentField.DependentTypeSet(iron.FieldDependentTypes.DEPENDENT) dependentField.NumberOfVariablesSet(4) dependentField.VariableTypesSet([ iron.FieldVariableTypes.U, iron.FieldVariableTypes.DELUDELN, iron.FieldVariableTypes.U1, iron.FieldVariableTypes.U2 ]) dependentField.NumberOfComponentsSet(iron.FieldVariableTypes.U, 4) dependentField.NumberOfComponentsSet(iron.FieldVariableTypes.DELUDELN, 4) dependentField.NumberOfComponentsSet(iron.FieldVariableTypes.U1, 6) dependentField.NumberOfComponentsSet(iron.FieldVariableTypes.U2, 6) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.DELUDELN, 1, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.DELUDELN, 2, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.DELUDELN, 3, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 1, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 2, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 3, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 4, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 5, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U1, 6, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 1, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 2, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 3, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 4, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 5, 1) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U2, 6, 1) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.ELEMENT_BASED) if (UsePressureBasis): # Set the pressure to be nodally based and use the second mesh component if InterpolationType == 4: dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.DELUDELN, 4, iron.FieldInterpolationTypes.NODE_BASED) dependentField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 4, 2) dependentField.ComponentMeshComponentSet( iron.FieldVariableTypes.DELUDELN, 4, 2) if InterpolationType == 4: dependentField.fieldScalingType = iron.FieldScalingTypes.ARITHMETIC_MEAN dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 1, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 2, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 3, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 4, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 5, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U1, 6, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 1, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 2, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 3, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 4, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 5, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.ComponentInterpolationSet( iron.FieldVariableTypes.U2, 6, iron.FieldInterpolationTypes.GAUSS_POINT_BASED) dependentField.VariableLabelSet(iron.FieldVariableTypes.U1, "strain") dependentField.VariableLabelSet(iron.FieldVariableTypes.U2, "stress") dependentField.CreateFinish() # Initialise dependent field from undeformed geometry and displacement bcs and set hydrostatic pressure iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2) iron.Field.ParametersToFieldParametersComponentCopy( geometricField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3, dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 3) iron.Field.ComponentValuesInitialiseDP(dependentField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 4, -8.0) # Create a deformed geometry field, as cmgui doesn't like displaying # deformed fibres from the dependent field because it isn't a geometric field. deformedField = iron.Field() deformedField.CreateStart(deformedFieldUserNumber, region) deformedField.MeshDecompositionSet(decomposition) deformedField.TypeSet(iron.FieldTypes.GEOMETRIC) deformedField.VariableLabelSet(iron.FieldVariableTypes.U, "DeformedGeometry") for component in [1, 2, 3]: deformedField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, component, 1) if InterpolationType == 4: deformedField.ScalingTypeSet(iron.FieldScalingTypes.ARITHMETIC_MEAN) deformedField.CreateFinish() # Create the equations_set equationsSetField = iron.Field() equationsSet = iron.EquationsSet() equationsSetSpecification = [ iron.EquationsSetClasses.ELASTICITY, iron.EquationsSetTypes.FINITE_ELASTICITY, constitutiveRelation ] equationsSet.CreateStart(equationsSetUserNumber, region, fibreField, equationsSetSpecification, equationsSetFieldUserNumber, equationsSetField) equationsSet.CreateFinish() # Create the CellML environment CellML = iron.CellML() CellML.CreateStart(CellMLUserNumber, region) # here we get the current path of this script so that we can specify the CellML model document relative to # this script, rather than the execution folder. from os.path import dirname, join script_path = dirname(__file__) cellmlFile = join(script_path, "guccione.cellml") # guccioneCellMLParameters = [0.88, 0.0, 18.5, 3.58, 3.26] # default values in CellML model guccioneCellMLParameters = [1.0, 0.0, 5.0, 10.0, 5.0] guccioneCellMLParameters = [ materialParameters[0], 0.0, materialParameters[1], materialParameters[2], materialParameters[3] ] # the names of the variables in the CellML model for the parameters in the same order as the values above guccioneCellMLParameterIds = [ "interface/c1", "interface/c2", "interface/c3", "interface/c4", "interface/c5" ] # Import a Guccione material law from a file GuccioneModel = CellML.ModelImport(cellmlFile) # Now we have imported the model we are able to specify which variables from the model we want to set from openCMISS CellML.VariableSetAsKnown(GuccioneModel, "equations/E11") CellML.VariableSetAsKnown(GuccioneModel, "equations/E12") CellML.VariableSetAsKnown(GuccioneModel, "equations/E13") CellML.VariableSetAsKnown(GuccioneModel, "equations/E22") CellML.VariableSetAsKnown(GuccioneModel, "equations/E23") CellML.VariableSetAsKnown(GuccioneModel, "equations/E33") for component, parameter in enumerate(guccioneCellMLParameterIds): CellML.VariableSetAsKnown(GuccioneModel, parameter) # and variables to get from the CellML CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev11") CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev12") CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev13") CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev22") CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev23") CellML.VariableSetAsWanted(GuccioneModel, "equations/Tdev33") CellML.CreateFinish() # Start the creation of CellML <--> OpenCMISS field maps CellML.FieldMapsCreateStart() #Now we can set up the field variable component <--> CellML model variable mappings. #Map the strain components CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 1, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E11", iron.FieldParameterSetTypes.VALUES) CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 2, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E12", iron.FieldParameterSetTypes.VALUES) CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 3, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E13", iron.FieldParameterSetTypes.VALUES) CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 4, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E22", iron.FieldParameterSetTypes.VALUES) CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 5, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E23", iron.FieldParameterSetTypes.VALUES) CellML.CreateFieldToCellMLMap(dependentField, iron.FieldVariableTypes.U1, 6, iron.FieldParameterSetTypes.VALUES, GuccioneModel, "equations/E33", iron.FieldParameterSetTypes.VALUES) #DOC-END map strain components #DOC-START map stress components #Map the stress components CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev11", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 1, iron.FieldParameterSetTypes.VALUES) CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev12", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 2, iron.FieldParameterSetTypes.VALUES) CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev13", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 3, iron.FieldParameterSetTypes.VALUES) CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev22", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 4, iron.FieldParameterSetTypes.VALUES) CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev23", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 5, iron.FieldParameterSetTypes.VALUES) CellML.CreateCellMLToFieldMap(GuccioneModel, "equations/Tdev33", iron.FieldParameterSetTypes.VALUES, dependentField, iron.FieldVariableTypes.U2, 6, iron.FieldParameterSetTypes.VALUES) #Finish the creation of CellML <--> OpenCMISS field maps CellML.FieldMapsCreateFinish() #Create the CellML models field CellMLModelsField = iron.Field() CellML.ModelsFieldCreateStart(CellMLModelsFieldUserNumber, CellMLModelsField) CellML.ModelsFieldCreateFinish() xidiv = 1.0 / (NumberOfGaussXi + 1) for elem in [1]: #Gauss point number counter ctr = 0 #Assign model for each quadraturePoint: for xi in range(0, NumberOfGaussXi): xi1 = (1.0 + xi) * xidiv for xj in range(0, NumberOfGaussXi): xi2 = (1.0 + xj) * xidiv for xk in range(0, NumberOfGaussXi): xi3 = (1.0 + xk) * xidiv ctr = ctr + 1 CellMLModelsField.ParameterSetUpdateGaussPoint( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, ctr, 1, 1, GuccioneModel) #Create the CellML parameters field --- the strain field CellMLParametersField = iron.Field() CellML.ParametersFieldCreateStart(CellMLParametersFieldUserNumber, CellMLParametersField) CellML.ParametersFieldCreateFinish() # Create the CellML intermediate field --- the stress field CellMLIntermediateField = iron.Field() CellML.IntermediateFieldCreateStart(CellMLIntermediateFieldUserNumber, CellMLIntermediateField) CellML.IntermediateFieldCreateFinish() for valueIndex, parameter in enumerate(guccioneCellMLParameterIds, 0): component = CellML.FieldComponentGet(GuccioneModel, iron.CellMLFieldTypes.PARAMETERS, parameter) print("Setting parameter: " + parameter + "; to value: " + str(guccioneCellMLParameters[valueIndex]) + "; field component: " + str(component)) iron.Field.ComponentValuesInitialiseDP( CellMLParametersField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component, guccioneCellMLParameters[valueIndex]) #equationsSet.MaterialsCreateStart(materialFieldUserNumber,materialField) #equationsSet.MaterialsCreateFinish() equationsSet.DependentCreateStart(dependentFieldUserNumber, dependentField) equationsSet.DependentCreateFinish() # Create equations equations = iron.Equations() equationsSet.EquationsCreateStart(equations) equations.sparsityType = iron.EquationsSparsityTypes.SPARSE equations.outputType = iron.EquationsOutputTypes.NONE equationsSet.EquationsCreateFinish() def defineProblemSolver(): # Define the problem problem = iron.Problem() problemSpecification = [ iron.ProblemClasses.ELASTICITY, iron.ProblemTypes.FINITE_ELASTICITY, iron.ProblemSubtypes.FINITE_ELASTICITY_CELLML ] problem.CreateStart(problemUserNumber, problemSpecification) problem.CreateFinish() # Create control loops problem.ControlLoopCreateStart() problem.ControlLoopCreateFinish() # Create problem solver nonLinearSolver = iron.Solver() linearSolver = iron.Solver() problem.SolversCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, nonLinearSolver) nonLinearSolver.outputType = iron.SolverOutputTypes.PROGRESS nonLinearSolver.NewtonJacobianCalculationTypeSet( iron.JacobianCalculationTypes.FD) nonLinearSolver.NewtonLinearSolverGet(linearSolver) linearSolver.linearType = iron.LinearSolverTypes.DIRECT #linearSolver.libraryType = iron.SolverLibraries.LAPACK problem.SolversCreateFinish() #Create the problem solver CellML equations CellMLSolver = iron.Solver() problem.CellMLEquationsCreateStart() nonLinearSolver.NewtonCellMLSolverGet(CellMLSolver) CellMLEquations = iron.CellMLEquations() CellMLSolver.CellMLEquationsGet(CellMLEquations) CellMLEquations.CellMLAdd(CellML) problem.CellMLEquationsCreateFinish() # Create solver equations and add equations set to solver equations solver = iron.Solver() solverEquations = iron.SolverEquations() problem.SolverEquationsCreateStart() problem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, solver) solver.SolverEquationsGet(solverEquations) solverEquations.sparsityType = iron.SolverEquationsSparsityTypes.SPARSE equationsSetIndex = solverEquations.EquationsSetAdd(equationsSet) problem.SolverEquationsCreateFinish() return [problem, solverEquations] def defineBoundaryConditions(solverEquations, increment): # Prescribe boundary conditions (absolute nodal parameters) boundaryConditions = iron.BoundaryConditions() solverEquations.BoundaryConditionsCreateStart(boundaryConditions) #Set x=0 nodes to no x displacment in x. Set x=width nodes to 10% x displacement boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, 1, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, 1, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, 1, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 7, 1, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, 1, iron.BoundaryConditionsTypes.FIXED, increment) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, 1, iron.BoundaryConditionsTypes.FIXED, increment) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, 1, iron.BoundaryConditionsTypes.FIXED, increment) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 8, 1, iron.BoundaryConditionsTypes.FIXED, increment) # Set y=0 nodes to no y displacement boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, 2, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, 2, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 5, 2, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 6, 2, iron.BoundaryConditionsTypes.FIXED, 0.0) # Set z=0 nodes to no y displacement boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 1, 3, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 2, 3, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 3, 3, iron.BoundaryConditionsTypes.FIXED, 0.0) boundaryConditions.AddNode(dependentField, iron.FieldVariableTypes.U, 1, 1, 4, 3, iron.BoundaryConditionsTypes.FIXED, 0.0) solverEquations.BoundaryConditionsCreateFinish() # loop over load steps numberOfLoadSteps = 70 displacementIncrement = 0.01 # 1% displacementIncrementDimension = displacementIncrement * width # length units resultRecord = {} resultRecord["strain"] = [0.0] resultRecord["stress"] = [0.0] for counter in range(1, numberOfLoadSteps + 1): # define the problem, solver, control loops, etc. [problem, solverEquations] = defineProblemSolver() # define the boundary conditions defineBoundaryConditions(solverEquations, displacementIncrementDimension) # execute the experiment problem.Solve() # clean up problem.Finalise() solverEquations.Finalise() # export the results filename = "results-{:03d}".format(counter) # Copy deformed geometry into deformed field for component in [1, 2, 3]: dependentField.ParametersToFieldParametersComponentCopy( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component, deformedField, iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, component) # Export results fields = iron.Fields() fields.CreateRegion(region) fields.NodesExport(filename, "FORTRAN") fields.ElementsExport(filename, "FORTRAN") fields.Finalise() versionNumber = 1 derivativeNumber = 1 nodeNumber = 8 componentNumber = 1 # x-dirn reactionForceX = dependentField.ParameterSetGetNode( iron.FieldVariableTypes.DELUDELN, iron.FieldParameterSetTypes.VALUES, versionNumber, derivativeNumber, nodeNumber, componentNumber) print("Reaction force (x) at counter: " + str(counter) + ": " + str(reactionForceX)) resultRecord["strain"].append(counter * displacementIncrement) resultRecord["stress"].append(reactionForceX) coordinateSystem.Destroy() region.Destroy() basis.Destroy() return resultRecord
# Refers to elements by their user number as described in the original mesh elements.UserNumbersAllSet(element_array) elements.CreateFinish() mesh.CreateFinish() # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) geometricField.meshDecomposition = decomposition geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) geometricField.CreateFinish() # Update the geometric field parameters geometricField.ParameterSetUpdateStart(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) for idx, node_num in enumerate(node_array): [x, y, z] = node_coordinates[idx] geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U,
def setupProblem(self, showProgress=False): # Number of Gauss points used numberOfGaussXi = 3 numberOfCircumfrentialElements = self.circumferentialElements numberOfLengthElements = self.axialElements numberOfLengthNodes = self.axialElements + 1 numberOfCircumfrentialNodes = numberOfCircumfrentialElements numberOfWallNodes = self.wallElements + 1 numberOfWallElements = self.wallElements coordinateSystemUserNumber = 1 regionUserNumber = 1 tricubicHermiteBasisUserNumber = 1 meshUserNumber = 1 decompositionUserNumber = 1 geometricFieldUserNumber = 1 tau = 0.1 kappa = 0.05 lambdaFieldUserNumber = 12 fittingEquationsSetUserNumber = 13 fittingEquationsSetFieldUserNumber = 14 fittingDependentFieldUserNumber = 15 fittingIndependentFieldUserNumber = 16 fittingMaterialsFieldUserNumber = 17 fittingProblemUserNumber = 18 # Get the number of computational nodes and this computational node number numberOfComputationalNodes = iron.ComputationalNumberOfNodesGet() # Create a 3D rectangular cartesian coordinate system coordinateSystem = iron.CoordinateSystem() coordinateSystem.CreateStart(coordinateSystemUserNumber) # Set the number of dimensions to 3 coordinateSystem.DimensionSet(3) # Finish the creation of the coordinate system coordinateSystem.CreateFinish() # Create a region and assign the coordinate system to the region region = iron.Region() region.CreateStart(regionUserNumber, iron.WorldRegion) region.LabelSet("HeartTubeRegion") # Set the regions coordinate system to the 3D RC coordinate system that we have created region.coordinateSystem = coordinateSystem # Finish the creation of the region region.CreateFinish() self.region = region # Define basis # Start the creation of a tricubic Hermite basis function tricubicHermiteBasis = iron.Basis() tricubicHermiteBasis.CreateStart(tricubicHermiteBasisUserNumber) tricubicHermiteBasis.type = iron.BasisTypes.LAGRANGE_HERMITE_TP tricubicHermiteBasis.numberOfXi = 3 tricubicHermiteBasis.interpolationXi = [ iron.BasisInterpolationSpecifications.CUBIC_HERMITE ] * 3 tricubicHermiteBasis.quadratureNumberOfGaussXi = [numberOfGaussXi] * 3 tricubicHermiteBasis.CreateFinish() # Start the creation of a manually generated mesh in the region numberOfNodes = numberOfCircumfrentialElements * ( numberOfLengthElements + 1) * (numberOfWallElements + 1) numberOfElements = numberOfCircumfrentialElements * numberOfLengthElements * numberOfWallElements # Define nodes for the mesh nodes = iron.Nodes() nodes.CreateStart(region, numberOfNodes) nodes.CreateFinish() mesh = iron.Mesh() # Create the mesh. The mesh will have two components - 1. tricubic Hermite elements; 2. trilinear Lagrange elements mesh.CreateStart(meshUserNumber, region, 3) mesh.NumberOfComponentsSet(1) mesh.NumberOfElementsSet(numberOfElements) tricubicHermiteElements = iron.MeshElements() tricubicHermiteElements.CreateStart(mesh, 1, tricubicHermiteBasis) elementNumber = 0 for wallElementIdx in range(1, numberOfWallElements + 1): for lengthElementIdx in range(1, numberOfLengthElements + 1): for circumfrentialElementIdx in range( 1, numberOfCircumfrentialElements + 1): elementNumber = elementNumber + 1 localNode1 = circumfrentialElementIdx + (lengthElementIdx-1)*numberOfCircumfrentialNodes + \ (wallElementIdx-1)*numberOfCircumfrentialNodes*numberOfLengthNodes if circumfrentialElementIdx == numberOfCircumfrentialElements: localNode2 = 1 + (lengthElementIdx-1)*numberOfCircumfrentialNodes + \ (wallElementIdx-1)*numberOfCircumfrentialNodes*numberOfLengthNodes else: localNode2 = localNode1 + 1 localNode3 = localNode1 + numberOfCircumfrentialNodes localNode4 = localNode2 + numberOfCircumfrentialNodes localNode5 = localNode1 + numberOfCircumfrentialNodes * numberOfLengthNodes localNode6 = localNode2 + numberOfCircumfrentialNodes * numberOfLengthNodes localNode7 = localNode3 + numberOfCircumfrentialNodes * numberOfLengthNodes localNode8 = localNode4 + numberOfCircumfrentialNodes * numberOfLengthNodes localNodes = [ localNode1, localNode2, localNode3, localNode4, localNode5, localNode6, localNode7, localNode8 ] tricubicHermiteElements.NodesSet(elementNumber, localNodes) tricubicHermiteElements.CreateFinish() # Finish the mesh creation mesh.CreateFinish() # Create a decomposition for the mesh decomposition = iron.Decomposition() decomposition.CreateStart(decompositionUserNumber, mesh) # Set the decomposition to be a general decomposition with the specified number of domains decomposition.type = iron.DecompositionTypes.CALCULATED decomposition.numberOfDomains = numberOfComputationalNodes # Finish the decomposition decomposition.CreateFinish() # Create a field for the geometry geometricField = iron.Field() geometricField.CreateStart(geometricFieldUserNumber, region) # Set the decomposition to use geometricField.MeshDecompositionSet(decomposition) geometricField.TypeSet(iron.FieldTypes.GEOMETRIC) # Set the field label geometricField.VariableLabelSet(iron.FieldVariableTypes.U, "Geometry") # Set the domain to be used by the field components to be tricubic Hermite geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 1, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 2, 1) geometricField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, 3, 1) # Set the scaling type geometricField.ScalingTypeSet(iron.FieldScalingTypes.UNIT) # Finish creating the field geometricField.CreateFinish() self.setupGeometry(geometricField) # Update the geometric field geometricField.ParameterSetUpdateStart( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) geometricField.ParameterSetUpdateFinish( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES) lambdaField = iron.Field() lambdaField.CreateStart(lambdaFieldUserNumber, region) lambdaField.TypeSet(iron.FieldTypes.GENERAL) # Set the decomposition lambdaField.MeshDecompositionSet(decomposition) # Set the geometric field lambdaField.GeometricFieldSet(geometricField) lambdaField.ScalingTypeSet(iron.FieldScalingTypes.NONE) # Set the field variables lambdaField.NumberOfVariablesSet(1) lambdaField.VariableTypesSet([iron.FieldVariableTypes.U]) # Set the variable label lambdaField.VariableLabelSet(iron.FieldVariableTypes.U, "NodeLambda") # Set the components to be tricubic-hermite lambdaField.NumberOfComponentsSet(iron.FieldVariableTypes.U, 9) for comp in range(1, 10): lambdaField.ComponentMeshComponentSet(iron.FieldVariableTypes.U, comp, 1) # Set the interpolation types lambdaField.ComponentInterpolationSet( iron.FieldVariableTypes.U, comp, iron.FieldInterpolationTypes.NODE_BASED) lambdaField.ScalingTypeSet(iron.FieldScalingTypes.UNIT) lambdaField.CreateFinish() # Initialise the lambda field for comp in range(1, 10): lambdaField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, comp, 0.0) # Create Gauss point fitting equations set fittingEquationsSetSpecification = [ iron.EquationsSetClasses.FITTING, iron.EquationsSetTypes.GAUSS_FITTING_EQUATION, iron.EquationsSetSubtypes.GAUSS_POINT_FITTING, iron.EquationsSetFittingSmoothingTypes.SOBOLEV_VALUE ] fittingEquationsSetField = iron.Field() fittingEquationsSet = iron.EquationsSet() fittingEquationsSet.CreateStart(fittingEquationsSetUserNumber, region, geometricField, fittingEquationsSetSpecification, fittingEquationsSetFieldUserNumber, fittingEquationsSetField) fittingEquationsSet.CreateFinish() # Create the fitting dependent field fittingDependentField = iron.Field() fittingEquationsSet.DependentCreateStart( fittingDependentFieldUserNumber, fittingDependentField) fittingDependentField.VariableLabelSet(iron.FieldVariableTypes.U, "FittingU") fittingDependentField.VariableLabelSet( iron.FieldVariableTypes.DELUDELN, "FittingDelUdelN") # Set the number of components to 9 fittingDependentField.NumberOfComponentsSet(iron.FieldVariableTypes.U, 9) fittingDependentField.NumberOfComponentsSet( iron.FieldVariableTypes.DELUDELN, 9) # Set the field variables to be tricubic hermite for comp in range(1, 10): fittingDependentField.ComponentMeshComponentSet( iron.FieldVariableTypes.U, comp, 1) fittingDependentField.ComponentMeshComponentSet( iron.FieldVariableTypes.DELUDELN, comp, 1) # Finish creating the fitting dependent field fittingEquationsSet.DependentCreateFinish() # Create the fitting independent field fittingIndependentField = iron.Field() fittingEquationsSet.IndependentCreateStart( fittingIndependentFieldUserNumber, fittingIndependentField) fittingIndependentField.VariableLabelSet(iron.FieldVariableTypes.U, "GaussLambda") fittingIndependentField.VariableLabelSet(iron.FieldVariableTypes.V, "LambdaWeight") # Set the number of components to 9 fittingIndependentField.NumberOfComponentsSet( iron.FieldVariableTypes.U, 9) fittingIndependentField.NumberOfComponentsSet( iron.FieldVariableTypes.V, 9) # Finish creating the fitting independent field fittingEquationsSet.IndependentCreateFinish() # Initialise data point vector field to 0.0 for comp in range(1, 10): fittingIndependentField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, comp, 0.0) # Initialise data point weight field to 1.0 fittingIndependentField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.V, iron.FieldParameterSetTypes.VALUES, comp, 1.0) # Create material field (Sobolev parameters) fittingMaterialField = iron.Field() fittingEquationsSet.MaterialsCreateStart( fittingMaterialsFieldUserNumber, fittingMaterialField) fittingMaterialField.VariableLabelSet(iron.FieldVariableTypes.U, "SmoothingParameters") fittingEquationsSet.MaterialsCreateFinish() # Set kappa and tau - Sobolev smoothing parameters fittingMaterialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, tau) fittingMaterialField.ComponentValuesInitialiseDP( iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 2, kappa) # Create the fitting equations fittingEquations = iron.Equations() fittingEquationsSet.EquationsCreateStart(fittingEquations) # Set the fitting equations sparsity type fittingEquations.sparsityType = iron.EquationsSparsityTypes.SPARSE # Set the fitting equations output type to none fittingEquations.outputType = iron.EquationsOutputTypes.NONE # Finish creating the fitting equations fittingEquationsSet.EquationsCreateFinish() # Create fitting problem fittingProblemSpecification = [ iron.ProblemClasses.FITTING, iron.ProblemTypes.DATA_FITTING, iron.ProblemSubtypes.STATIC_FITTING ] fittingProblem = iron.Problem() fittingProblem.CreateStart(fittingProblemUserNumber, fittingProblemSpecification) fittingProblem.CreateFinish() # Create control loops fittingProblem.ControlLoopCreateStart() fittingProblem.ControlLoopCreateFinish() # Create problem solver fittingSolver = iron.Solver() fittingProblem.SolversCreateStart() fittingProblem.SolverGet([iron.ControlLoopIdentifiers.NODE], 1, fittingSolver) fittingSolver.outputType = iron.SolverOutputTypes.NONE fittingProblem.SolversCreateFinish() # Create fitting solver equations and add fitting equations set to solver equations fittingSolverEquations = iron.SolverEquations() fittingProblem.SolverEquationsCreateStart() # Get the solver equations fittingSolver.SolverEquationsGet(fittingSolverEquations) fittingSolverEquations.sparsityType = iron.SolverEquationsSparsityTypes.SPARSE fittingEquationsSetIndex = fittingSolverEquations.EquationsSetAdd( fittingEquationsSet) fittingProblem.SolverEquationsCreateFinish() # Prescribe boundary conditions for the fitting problem fittingBoundaryConditions = iron.BoundaryConditions() fittingSolverEquations.BoundaryConditionsCreateStart( fittingBoundaryConditions) fittingBoundaryConditions.AddNode( fittingDependentField, iron.FieldVariableTypes.U, 1, iron.GlobalDerivativeConstants.NO_GLOBAL_DERIV, 1, 8, iron.BoundaryConditionsTypes.FIXED, 0.0) fittingSolverEquations.BoundaryConditionsCreateFinish() self.fittingIndependentField = fittingIndependentField self.fittingDependentField = fittingDependentField self.lambdaField = lambdaField self.fittingProblem = fittingProblem