예제 #1
0
    def __init__(self, name, terms):
        Struct.__init__(self, name=name)

        if isinstance(terms, Term):  # A single term.
            terms = Terms([terms])

        self.terms = terms

        self.terms.setup()
예제 #2
0
    def from_desc(name, desc, variables, regions, materials, integrals, caches=None, user=None):
        term_descs = parse_definition(desc)
        terms = Terms.from_desc(term_descs, regions, integrals)

        terms.setup()
        terms.assign_args(variables, materials, user)

        obj = Equation(name, terms, caches=caches)

        return obj
예제 #3
0
파일: equations.py 프로젝트: mfkiwl/sfepy
    def from_desc(name, desc, variables, regions, materials, integrals,
                  user=None):
        term_descs = parse_definition(desc)
        terms = Terms.from_desc(term_descs, regions, integrals)

        terms.setup()
        terms.assign_args(variables, materials, user)

        obj = Equation(name, terms)

        return obj
예제 #4
0
    def create_subequations(self, var_names, known_var_names=None):
        """
        Create sub-equations containing only terms with the given virtual
        variables.

        Parameters
        ----------
        var_names : list
            The list of names of virtual variables.
        known_var_names : list
            The list of  names of (already) known state variables.

        Returns
        -------
        subequations : Equations instance
            The sub-equations.
        """
        from sfepy.fem import FieldVariable

        known_var_names = get_default(known_var_names, [])

        objs = []
        for iv, var_name in enumerate(var_names):
            terms = [
                term.copy(name=term.name) for eq in self for term in eq.terms
                if term.get_virtual_name() == var_name
            ]

            # Make parameter variables from known state variables in terms
            # arguments.
            for known_name in known_var_names:
                for term in terms:
                    if known_name in term.arg_names:
                        ii = term.arg_names.index(known_name)
                        state = self.variables[known_name]
                        par = FieldVariable(known_name,
                                            'parameter',
                                            state.field,
                                            state.n_components,
                                            primary_var_name='(set-to-None)')
                        term.args[ii] = par
                        term._kwargs[known_name] = par
                        par.set_data(state())

            new_terms = Terms(terms)
            objs.append(Equation('eq_%d' % iv, new_terms))

        subequations = Equations(objs)

        return subequations
예제 #5
0
def get_problem(u_field, v_field, calc_stiffness, calc_prestress, delta_x):
    """Get the problem

    Args:
      u_field: the displacement field
      v_field: the test function field
      calc_stiffness: a functioin to calcuate the stiffness tensor
      calc_prestress: a function to calculate the prestress tensor
      delta_x: the mesh spacing

    Returns:
      the Sfepy problem
    """
    return pipe(
        get_terms(u_field, v_field, calc_stiffness, calc_prestress),
        lambda x: Equation("balance_of_forces", Terms([x[0], x[1]])),
        lambda x: Problem("elasticity", equations=Equations([x])),
        do(lambda x: x.time_update(ebcs=get_bcs(v_field.field.region.domain, delta_x))),
        do(lambda x: x.set_solver(get_nls(x.get_evaluator()))),
    )
예제 #6
0
    def from_desc(name,
                  desc,
                  variables,
                  regions,
                  materials,
                  integrals,
                  user=None,
                  eterm_options=None):
        term_descs = parse_definition(desc)
        terms = Terms.from_desc(term_descs, regions, integrals)

        terms.setup()
        terms.assign_args(variables, materials, user)

        if eterm_options is not None:
            for term in terms:
                if isinstance(term, ETermBase):
                    term.set_verbosity(eterm_options.get('verbosity', 0))
                    term.set_backend(**eterm_options.get('backend_args', {}))

        obj = Equation(name, terms)

        return obj