def forward(self): """ Forwarding discrete solver. """ # Setting potential rhs. if self.config.rhs is None: self.ustar.fill(0.) else: raise NotImplementedError() # Appending previous steps contributions. fe_op.mlt_add(self.operator2, self.u2, self.ustar) fe_op.mlt_add(self.operator1, self.u1, self.ustar) # Appending potential boundary condition contributions. self.__add_boundary_contrib_prediction( self.config.left_boundary_condition, self.fe_space.get_left_idx()) self.__add_boundary_contrib_prediction( self.config.right_boundary_condition, self.fe_space.get_right_idx()) # Applying invert operator. fe_op.mlt(self.inv_operator, self.ustar, self.u0)
def test_mlt_add(): """ Testing addition & multiplication operation on finite element operators. """ # Testing assembled case. op = fe_op.make_from_data(np.diag(np.array([1.0, 2.0, 3.0])), fe_op.AssemblyType.ASSEMBLED) u = np.array([1.0, 1.0, 1.0]) v = np.array([2.0, 3.0, 4.0]) fe_op.mlt_add(op, u, v, coef=2.0) np_test.assert_array_almost_equal(v, [4.0, 7.0, 10.0]) # Testing lumped case. op = fe_op.make_from_data(np.array([1.0, 2.0, 3.0]), fe_op.AssemblyType.LUMPED) u = np.array([1.0, 1.0, 1.0]) v = np.array([2.0, 3.0, 4.0]) fe_op.mlt_add(op, u, v) np_test.assert_array_almost_equal(v, [3.0, 5.0, 7.0])
def forward(self): """ Forwarding discrete solver. """ # Setting potential rhs. self.ustar.fill(0.) if self.config.rhs is not None: fe_op.mlt_add(self.rhs_operator, self.config.rhs(self.fe_space, self.time), self.ustar, self.timestep**2) # Appending previous steps contributions. fe_op.mlt_add(self.operator2, self.u2, self.ustar) fe_op.mlt_add(self.operator1, self.u1, self.ustar) # Appending potential boundary condition contributions. self.__add_boundary_contrib_prediction( self.config.left_boundary_condition, self.fe_space.get_left_idx()) self.__add_boundary_contrib_prediction( self.config.right_boundary_condition, self.fe_space.get_right_idx()) # Applying invert operator. fe_op.mlt(self.inv_operator, self.ustar, self.u0)
def forward(self): """ Forwarding discrete solver. """ # Initializing predictions. self.ustar.fill(0.) self.sstar.fill(0.) # Appending previous steps contributions into displacement prediction. fe_op.mlt_add(self.operator2_u, self.u2, self.ustar) fe_op.mlt_add(self.operator1_u, self.u1, self.ustar) fe_op.mlt_add(self.transposed_gradient, self.s1, self.ustar, coef=-self.timestep**2) # Appending potential boundary condition contributions. self.__add_boundary_contrib_prediction( self.config.left_boundary_condition, self.fe_space.get_left_idx()) self.__add_boundary_contrib_prediction( self.config.right_boundary_condition, self.fe_space.get_right_idx()) # Applying inverse operator on displacement prediction. fe_op.mlt(self.inv_operator_u, self.ustar, self.u0) # Appending previous step contribution into internal variable prediction. fe_op.mlt_add(self.operator1_s, self.s1, self.sstar) fe_op.mlt_add(self.gradient, self.u0, self.sstar, coef=1.0) fe_op.mlt_add(self.gradient, self.u1, self.sstar, coef=-1.0) # Applying inverse operator on internal variable predication. fe_op.mlt(self.inv_operator_s, self.sstar, self.s0)
def rhs_d2theta(fe_space, time): rhs = np.zeros(fe_space.get_ndof()) fe_op.mlt_add(minv_k, propag_dtheta.u1, rhs, -2.0) return rhs