@@ -204,3 +204,93 @@ def __rmul__(self, other):
204204 return me
205205 else :
206206 raise DataError ("Type error: cannot multiply %s to %s" % (type (other ), type (self )))
207+
208+
209+ class parallel_comp2_mesh (object ):
210+ """
211+ Numpy-based datatype for multi-implicit RHS of parallel meshes.
212+
213+ Attributes:
214+ comp1 (parallel_mesh): first part
215+ comp2 (parallel_mesh): second part
216+ """
217+
218+ def __init__ (self , init , val = 0.0 ):
219+ """
220+ Initialization routine
221+
222+ Args:
223+ init: another pmesh_datatype or a tuple containing the communicator and the local dimensions
224+ val (float): an initial number (default: 0.0)
225+ Raises:
226+ DataError: if init is none of the types above
227+ """
228+ if isinstance (init , type (self )):
229+ self .comp1 = parallel_mesh (init .comp1 )
230+ self .comp2 = parallel_mesh (init .comp2 )
231+ elif isinstance (init , tuple ) and (init [1 ] is None or isinstance (init [1 ], MPI .Intracomm )):
232+ self .comp1 = parallel_mesh (init , val = val )
233+ self .comp2 = parallel_mesh (init , val = val )
234+ # something is wrong, if none of the ones above hit
235+ else :
236+ raise DataError ('something went wrong during %s initialization' % type (self ))
237+
238+ def __sub__ (self , other ):
239+ """
240+ Overloading the subtraction operator for rhs types
241+
242+ Args:
243+ other: rhs object to be subtracted
244+ Raises:
245+ DataError: if other is not a rhs object
246+ Returns:
247+ differences between caller and other values (self-other)
248+ """
249+
250+ if isinstance (other , type (self )):
251+ me = parallel_imex_mesh (self )
252+ me .comp1 = self .comp1 - other .comp1
253+ me .comp2 = self .comp2 - other .comp2
254+ return me
255+ else :
256+ raise DataError ("Type error: cannot subtract %s from %s" % (type (other ), type (self )))
257+
258+ def __add__ (self , other ):
259+ """
260+ Overloading the addition operator for rhs types
261+
262+ Args:
263+ other: rhs object to be added
264+ Raises:
265+ DataError: if other is not a rhs object
266+ Returns:
267+ sum of caller and other values (self-other)
268+ """
269+
270+ if isinstance (other , type (self )):
271+ me = parallel_imex_mesh (self )
272+ me .comp1 = self .comp1 + other .comp1
273+ me .comp2 = self .comp2 + other .comp2
274+ return me
275+ else :
276+ raise DataError ("Type error: cannot add %s to %s" % (type (other ), type (self )))
277+
278+ def __rmul__ (self , other ):
279+ """
280+ Overloading the right multiply by factor operator for rhs types
281+
282+ Args:
283+ other (float): factor
284+ Raises:
285+ DataError: is other is not a float
286+ Returns:
287+ copy of original values scaled by factor
288+ """
289+
290+ if isinstance (other , float ):
291+ me = parallel_imex_mesh (self )
292+ me .comp1 = other * self .comp1
293+ me .comp2 = other * self .comp2
294+ return me
295+ else :
296+ raise DataError ("Type error: cannot multiply %s to %s" % (type (other ), type (self )))
0 commit comments